diff --git a/ipam/manager.go b/ipam/manager.go index ca93cfbf96..517daa68fa 100644 --- a/ipam/manager.go +++ b/ipam/manager.go @@ -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 } } diff --git a/log/logger.go b/log/logger.go index 2841fafc61..8c72fd08b8 100644 --- a/log/logger.go +++ b/log/logger.go @@ -9,8 +9,6 @@ import ( "log" "os" "path" - - "github.com/Azure/azure-container-networking/platform" ) // Log level @@ -103,7 +101,7 @@ func (logger *Logger) GetLogDirectory() string { return logger.directory } - return platform.LogPath + return LogPath } // GetLogFileName returns the full log file name. @@ -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 diff --git a/log/logger_linux.go b/log/logger_linux.go index e1c1372e1e..78450bc38b 100644 --- a/log/logger_linux.go +++ b/log/logger_linux.go @@ -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 diff --git a/log/logger_windows.go b/log/logger_windows.go index 37c03ae5b0..815e93faa5 100644 --- a/log/logger_windows.go +++ b/log/logger_windows.go @@ -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 diff --git a/network/manager.go b/network/manager.go index 07e1c63132..41126615c2 100644 --- a/network/manager.go +++ b/network/manager.go @@ -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 } } diff --git a/platform/os_linux.go b/platform/os_linux.go index d4b4a6033a..fa79a022e8 100644 --- a/platform/os_linux.go +++ b/platform/os_linux.go @@ -5,6 +5,7 @@ package platform import ( "io/ioutil" + "log" "os/exec" "time" ) @@ -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. @@ -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. diff --git a/platform/os_windows.go b/platform/os_windows.go index a96e216068..5d4a467c6c 100644 --- a/platform/os_windows.go +++ b/platform/os_windows.go @@ -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. diff --git a/store/json.go b/store/json.go index 3ead92ce1e..0c9298ba04 100644 --- a/store/json.go +++ b/store/json.go @@ -9,6 +9,8 @@ import ( "strconv" "sync" "time" + + "github.com/Azure/azure-container-networking/log" ) const ( @@ -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 }