From fc7f402319eb802c31b0b916d2faed340c9d289f Mon Sep 17 00:00:00 2001 From: Tamilmani Manoharan Date: Thu, 31 May 2018 17:38:25 -0700 Subject: [PATCH 1/3] convert time to utc --- platform/os_linux.go | 6 +++--- store/json.go | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/platform/os_linux.go b/platform/os_linux.go index d4b4a6033a..f84fd0308c 100644 --- a/platform/os_linux.go +++ b/platform/os_linux.go @@ -37,7 +37,7 @@ func GetLastRebootTime() (time.Time, error) { out, err := exec.Command("uptime", "-s").Output() if err != nil { //log.Printf("Failed to query uptime, err:%v", err) - return time.Time{}, err + return time.Time{}.UTC(), err } // Parse the output. @@ -45,10 +45,10 @@ func GetLastRebootTime() (time.Time, error) { rebootTime, err := time.Parse(layout, string(out[:len(out)-1])) if err != nil { //log.Printf("Failed to parse uptime, err:%v", err) - return time.Time{}, err + return time.Time{}.UTC(), err } - return rebootTime, nil + return rebootTime.UTC(), nil } // ExecuteShellCommand executes a shell command. diff --git a/store/json.go b/store/json.go index 3ead92ce1e..7e3f96f6ec 100644 --- a/store/json.go +++ b/store/json.go @@ -198,8 +198,8 @@ 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 + return time.Time{}.UTC(), err } - return info.ModTime(), nil + return info.ModTime().UTC(), nil } From bc8bda15e2100381763e6fc51e072a8e37e4db86 Mon Sep 17 00:00:00 2001 From: Tamilmani Manoharan Date: Thu, 31 May 2018 18:41:07 -0700 Subject: [PATCH 2/3] Added a fix in getting last reboot time. --- ipam/manager.go | 4 ++-- network/manager.go | 4 +--- platform/os_linux.go | 2 +- 3 files changed, 4 insertions(+), 6 deletions(-) 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/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 f84fd0308c..a65299dfa7 100644 --- a/platform/os_linux.go +++ b/platform/os_linux.go @@ -42,7 +42,7 @@ func GetLastRebootTime() (time.Time, error) { // 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{}.UTC(), err From 44cee299652f3f224b9c5cbbdd40e4a95baac2b8 Mon Sep 17 00:00:00 2001 From: Tamilmani Manoharan Date: Mon, 4 Jun 2018 16:37:12 -0700 Subject: [PATCH 3/3] moved logpath from platform to log package to prevent cycle --- log/logger.go | 6 ++---- log/logger_linux.go | 5 +++++ log/logger_windows.go | 5 +++++ platform/os_linux.go | 8 +++----- platform/os_windows.go | 3 --- store/json.go | 3 +++ 6 files changed, 18 insertions(+), 12 deletions(-) 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/platform/os_linux.go b/platform/os_linux.go index a65299dfa7..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,7 +34,7 @@ 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) + log.Printf("Failed to query uptime, err:%v", err) return time.Time{}.UTC(), err } @@ -44,7 +42,7 @@ func GetLastRebootTime() (time.Time, error) { layout := "2006-01-02 15:04:05" rebootTime, err := time.ParseInLocation(layout, string(out[:len(out)-1]), time.Local) if err != nil { - //log.Printf("Failed to parse uptime, err:%v", err) + log.Printf("Failed to parse uptime, err:%v", err) return time.Time{}.UTC(), err } 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 7e3f96f6ec..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,6 +200,7 @@ func (kvs *jsonFileStore) Unlock() error { func (kvs *jsonFileStore) GetModificationTime() (time.Time, error) { info, err := os.Stat(kvs.fileName) if err != nil { + log.Printf("os.stat() for file %v failed with error %v", kvs.fileName, err) return time.Time{}.UTC(), err }