Skip to content

Commit 40237b7

Browse files
Convert time to UTC (#162)
* convert time to utc * Added a fix in getting last reboot time. * moved logpath from platform to log package to prevent cycle
1 parent 8c1aac5 commit 40237b7

File tree

8 files changed

+27
-23
lines changed

8 files changed

+27
-23
lines changed

ipam/manager.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,11 +104,11 @@ func (am *addressManager) restore() error {
104104
// Check if the VM is rebooted.
105105
modTime, err := am.store.GetModificationTime()
106106
if err == nil {
107-
log.Printf("[ipam] Store timestamp is %v.", modTime)
108107

109108
rebootTime, err := platform.GetLastRebootTime()
109+
log.Printf("[ipam] reboot time %v store mod time %v", rebootTime, modTime)
110+
110111
if err == nil && rebootTime.After(modTime) {
111-
log.Printf("[ipam] reboot time %v mod time %v", rebootTime, modTime)
112112
rebooted = true
113113
}
114114
}

log/logger.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@ import (
99
"log"
1010
"os"
1111
"path"
12-
13-
"github.com/Azure/azure-container-networking/platform"
1412
)
1513

1614
// Log level
@@ -103,7 +101,7 @@ func (logger *Logger) GetLogDirectory() string {
103101
return logger.directory
104102
}
105103

106-
return platform.LogPath
104+
return LogPath
107105
}
108106

109107
// GetLogFileName returns the full log file name.
@@ -113,7 +111,7 @@ func (logger *Logger) getLogFileName() string {
113111
if logger.directory != "" {
114112
logFileName = path.Join(logger.directory, logger.name+logFileExtension)
115113
} else {
116-
logFileName = platform.LogPath + logger.name + logFileExtension
114+
logFileName = LogPath + logger.name + logFileExtension
117115
}
118116

119117
return logFileName

log/logger_linux.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,11 @@ import (
1010
"os"
1111
)
1212

13+
const (
14+
// LogPath is the path where log files are stored.
15+
LogPath = "/var/log/"
16+
)
17+
1318
// SetTarget sets the log target.
1419
func (logger *Logger) SetTarget(target int) error {
1520
var err error

log/logger_windows.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,11 @@ import (
88
"os"
99
)
1010

11+
const (
12+
// LogPath is the path where log files are stored.
13+
LogPath = ""
14+
)
15+
1116
// SetTarget sets the log target.
1217
func (logger *Logger) SetTarget(target int) error {
1318
var err error

network/manager.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,11 +93,9 @@ func (nm *networkManager) restore() error {
9393

9494
modTime, err := nm.store.GetModificationTime()
9595
if err == nil {
96-
log.Printf("[net] Store timestamp is %v.", modTime)
97-
9896
rebootTime, err := platform.GetLastRebootTime()
97+
log.Printf("[net] reboot time %v store mod time %v", rebootTime, modTime)
9998
if err == nil && rebootTime.After(modTime) {
100-
log.Printf("[net] reboot time %v mod time %v", rebootTime, modTime)
10199
rebooted = true
102100
}
103101
}

platform/os_linux.go

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ package platform
55

66
import (
77
"io/ioutil"
8+
"log"
89
"os/exec"
910
"time"
1011
)
@@ -16,9 +17,6 @@ const (
1617

1718
// CNIRuntimePath is the path where CNM state files are stored.
1819
CNIRuntimePath = "/var/run/"
19-
20-
// LogPath is the path where log files are stored.
21-
LogPath = "/var/log/"
2220
)
2321

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

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

51-
return rebootTime, nil
49+
return rebootTime.UTC(), nil
5250
}
5351

5452
// ExecuteShellCommand executes a shell command.

platform/os_windows.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,6 @@ const (
1414

1515
// CNIRuntimePath is the path where CNM state files are stored.
1616
CNIRuntimePath = ""
17-
18-
// LogPath is the path where log files are stored.
19-
LogPath = ""
2017
)
2118

2219
// GetOSInfo returns OS version information.

store/json.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ import (
99
"strconv"
1010
"sync"
1111
"time"
12+
13+
"github.com/Azure/azure-container-networking/log"
1214
)
1315

1416
const (
@@ -198,8 +200,9 @@ func (kvs *jsonFileStore) Unlock() error {
198200
func (kvs *jsonFileStore) GetModificationTime() (time.Time, error) {
199201
info, err := os.Stat(kvs.fileName)
200202
if err != nil {
201-
return time.Time{}, err
203+
log.Printf("os.stat() for file %v failed with error %v", kvs.fileName, err)
204+
return time.Time{}.UTC(), err
202205
}
203206

204-
return info.ModTime(), nil
207+
return info.ModTime().UTC(), nil
205208
}

0 commit comments

Comments
 (0)