Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions ipam/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,11 +104,11 @@ func (am *addressManager) restore() error {
// Check if the VM is rebooted.
modTime, err := am.store.GetModificationTime()
if err == nil {
log.Printf("[ipam] Store timestamp is %v.", modTime)

rebootTime, err := platform.GetLastRebootTime()
log.Printf("[ipam] reboot time %v store mod time %v", rebootTime, modTime)

if err == nil && rebootTime.After(modTime) {
log.Printf("[ipam] reboot time %v mod time %v", rebootTime, modTime)
rebooted = true
}
}
Expand Down
6 changes: 2 additions & 4 deletions log/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ import (
"log"
"os"
"path"

"github.com/Azure/azure-container-networking/platform"
)

// Log level
Expand Down Expand Up @@ -103,7 +101,7 @@ func (logger *Logger) GetLogDirectory() string {
return logger.directory
}

return platform.LogPath
return LogPath
}

// GetLogFileName returns the full log file name.
Expand All @@ -113,7 +111,7 @@ func (logger *Logger) getLogFileName() string {
if logger.directory != "" {
logFileName = path.Join(logger.directory, logger.name+logFileExtension)
} else {
logFileName = platform.LogPath + logger.name + logFileExtension
logFileName = LogPath + logger.name + logFileExtension
}

return logFileName
Expand Down
5 changes: 5 additions & 0 deletions log/logger_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ import (
"os"
)

const (
// LogPath is the path where log files are stored.
LogPath = "/var/log/"
)

// SetTarget sets the log target.
func (logger *Logger) SetTarget(target int) error {
var err error
Expand Down
5 changes: 5 additions & 0 deletions log/logger_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ import (
"os"
)

const (
// LogPath is the path where log files are stored.
LogPath = ""
)

// SetTarget sets the log target.
func (logger *Logger) SetTarget(target int) error {
var err error
Expand Down
4 changes: 1 addition & 3 deletions network/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,11 +93,9 @@ func (nm *networkManager) restore() error {

modTime, err := nm.store.GetModificationTime()
if err == nil {
log.Printf("[net] Store timestamp is %v.", modTime)

rebootTime, err := platform.GetLastRebootTime()
log.Printf("[net] reboot time %v store mod time %v", rebootTime, modTime)
if err == nil && rebootTime.After(modTime) {
log.Printf("[net] reboot time %v mod time %v", rebootTime, modTime)
rebooted = true
}
}
Expand Down
16 changes: 7 additions & 9 deletions platform/os_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ package platform

import (
"io/ioutil"
"log"
"os/exec"
"time"
)
Expand All @@ -16,9 +17,6 @@ const (

// CNIRuntimePath is the path where CNM state files are stored.
CNIRuntimePath = "/var/run/"

// LogPath is the path where log files are stored.
LogPath = "/var/log/"
)

// GetOSInfo returns OS version information.
Expand All @@ -36,19 +34,19 @@ func GetLastRebootTime() (time.Time, error) {
// Query last reboot time.
out, err := exec.Command("uptime", "-s").Output()
if err != nil {
//log.Printf("Failed to query uptime, err:%v", err)
return time.Time{}, err
log.Printf("Failed to query uptime, err:%v", err)
return time.Time{}.UTC(), err
}

// Parse the output.
layout := "2006-01-02 15:04:05"
rebootTime, err := time.Parse(layout, string(out[:len(out)-1]))
rebootTime, err := time.ParseInLocation(layout, string(out[:len(out)-1]), time.Local)
if err != nil {
//log.Printf("Failed to parse uptime, err:%v", err)
return time.Time{}, err
log.Printf("Failed to parse uptime, err:%v", err)
return time.Time{}.UTC(), err
}

return rebootTime, nil
return rebootTime.UTC(), nil
}

// ExecuteShellCommand executes a shell command.
Expand Down
3 changes: 0 additions & 3 deletions platform/os_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,6 @@ const (

// CNIRuntimePath is the path where CNM state files are stored.
CNIRuntimePath = ""

// LogPath is the path where log files are stored.
LogPath = ""
)

// GetOSInfo returns OS version information.
Expand Down
7 changes: 5 additions & 2 deletions store/json.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import (
"strconv"
"sync"
"time"

"github.com/Azure/azure-container-networking/log"
)

const (
Expand Down Expand Up @@ -198,8 +200,9 @@ func (kvs *jsonFileStore) Unlock() error {
func (kvs *jsonFileStore) GetModificationTime() (time.Time, error) {
info, err := os.Stat(kvs.fileName)
if err != nil {
return time.Time{}, err
log.Printf("os.stat() for file %v failed with error %v", kvs.fileName, err)
return time.Time{}.UTC(), err
}

return info.ModTime(), nil
return info.ModTime().UTC(), nil
}