Skip to content

Commit

Permalink
add logging to net and fs in go_agent
Browse files Browse the repository at this point in the history
Signed-off-by: Maria Shaldibina <[email protected]>
  • Loading branch information
dmitriy kalinin authored and caleb miles committed Jul 24, 2014
1 parent e7020be commit 20b18d0
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 26 deletions.
2 changes: 2 additions & 0 deletions platform/net/arp/arping.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ func NewArping(

// BroadcastMACAddresses broadcasts multiple IP/MAC pairs, multiple times
func (a arping) BroadcastMACAddresses(addresses []boship.InterfaceAddress) {
a.logger.Debug(arpingLogTag, "Broadcasting MAC addresses")

var wg sync.WaitGroup

for _, addr := range addresses {
Expand Down
8 changes: 7 additions & 1 deletion platform/net/centos_net_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ func NewCentosNetManager(
}

func (net centosNetManager) SetupDhcp(networks boshsettings.Networks, errCh chan error) error {
net.logger.Debug(centosNetManagerLogTag, "Configuring DHCP networking")

buffer := bytes.NewBuffer([]byte{})
t := template.Must(template.New("dhcp-config").Parse(centosDHCPConfigTemplate))

Expand Down Expand Up @@ -99,6 +101,8 @@ prepend domain-name-servers {{ . }};{{ end }}
`

func (net centosNetManager) SetupManualNetworking(networks boshsettings.Networks, errCh chan error) error {
net.logger.Debug(centosNetManagerLogTag, "Configuring manual networking")

modifiedNetworks, err := net.writeIfcfgs(networks)
if err != nil {
return bosherr.WrapError(err, "Writing network interfaces")
Expand Down Expand Up @@ -222,8 +226,10 @@ func (net centosNetManager) detectMacAddresses() (map[string]string, error) {
}

func (net centosNetManager) restartNetwork() {
net.logger.Debug(centosNetManagerLogTag, "Restarting networking")

_, _, _, err := net.cmdRunner.RunCommand("service", "network", "restart")
if err != nil {
net.logger.Info(centosNetManagerLogTag, "Ignoring network restart failure: %#v", err)
net.logger.Error(centosNetManagerLogTag, "Ignoring network restart failure: %#v", err)
}
}
20 changes: 15 additions & 5 deletions platform/net/ubuntu_net_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ func NewUbuntuNetManager(
}

func (net ubuntuNetManager) SetupDhcp(networks boshsettings.Networks, errCh chan error) error {
net.logger.Debug(ubuntuNetManagerLogTag, "Configuring DHCP networking")

buffer := bytes.NewBuffer([]byte{})
t := template.Must(template.New("dhcp-config").Parse(ubuntuDHCPConfigTemplate))

Expand All @@ -71,14 +73,16 @@ func (net ubuntuNetManager) SetupDhcp(networks boshsettings.Networks, errCh chan
if written {
args := net.restartNetworkArguments()

net.logger.Debug(ubuntuNetManagerLogTag, "Restarting network interfaces")

_, _, _, err := net.cmdRunner.RunCommand("ifdown", args...)
if err != nil {
net.logger.Info(ubuntuNetManagerLogTag, "Ignoring ifdown failure: %#v", err)
net.logger.Error(ubuntuNetManagerLogTag, "Ignoring ifdown failure: %s", err)
}

_, _, _, err = net.cmdRunner.RunCommand("ifup", args...)
if err != nil {
net.logger.Info(ubuntuNetManagerLogTag, "Ignoring ifup failure: %#v", err)
net.logger.Error(ubuntuNetManagerLogTag, "Ignoring ifup failure: %s", err)
}
}

Expand Down Expand Up @@ -115,6 +119,8 @@ prepend domain-name-servers {{ . }};{{ end }}
`

func (net ubuntuNetManager) SetupManualNetworking(networks boshsettings.Networks, errCh chan error) error {
net.logger.Debug(ubuntuNetManagerLogTag, "Configuring manual networking")

modifiedNetworks, written, err := net.writeNetworkInterfaces(networks)
if err != nil {
return bosherr.WrapError(err, "Writing network interfaces")
Expand Down Expand Up @@ -194,6 +200,8 @@ iface {{ .Interface }} inet static
{{ if .HasDefaultGateway }} gateway {{ .Gateway }}{{ end }}{{ end }}`

func (net ubuntuNetManager) writeResolvConf(networks boshsettings.Networks) error {
net.logger.Debug(ubuntuNetManagerLogTag, "Writing resolv.conf")

buffer := bytes.NewBuffer([]byte{})
t := template.Must(template.New("resolv-conf").Parse(ubuntuResolvConfTemplate))

Expand Down Expand Up @@ -243,14 +251,16 @@ func (net ubuntuNetManager) detectMacAddresses() (map[string]string, error) {

func (net ubuntuNetManager) restartNetworkingInterfaces(networks []customNetwork) {
for _, network := range networks {
net.logger.Debug(ubuntuNetManagerLogTag, "Restarting network interface %s", network.Interface)

_, _, _, err := net.cmdRunner.RunCommand("service", "network-interface", "stop", "INTERFACE="+network.Interface)
if err != nil {
net.logger.Info(ubuntuNetManagerLogTag, "Ignoring network stop failure: %#v", err)
net.logger.Error(ubuntuNetManagerLogTag, "Ignoring network stop failure: %s", err)
}

_, _, _, err = net.cmdRunner.RunCommand("service", "network-interface", "start", "INTERFACE="+network.Interface)
if err != nil {
net.logger.Info(ubuntuNetManagerLogTag, "Ignoring network start failure: %#v", err)
net.logger.Error(ubuntuNetManagerLogTag, "Ignoring network start failure: %s", err)
}
}
}
Expand All @@ -267,7 +277,7 @@ func (net ubuntuNetManager) dhclientConfigFile() string {
func (net ubuntuNetManager) restartNetworkArguments() []string {
stdout, _, _, err := net.cmdRunner.RunCommand("ifup", "--version")
if err != nil {
net.logger.Info(ubuntuNetManagerLogTag, "Ignoring ifup version failure: %#v", err)
net.logger.Error(ubuntuNetManagerLogTag, "Ignoring ifup version failure: %s", err)
}

// Check if command accepts --no-loopback argument
Expand Down
40 changes: 20 additions & 20 deletions system/os_file_system.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,57 +83,57 @@ func (fs osFileSystem) WriteFileString(path, content string) (err error) {
return fs.WriteFile(path, []byte(content))
}

func (fs osFileSystem) WriteFile(path string, content []byte) (err error) {
err = fs.MkdirAll(filepath.Dir(path), os.ModePerm)
func (fs osFileSystem) WriteFile(path string, content []byte) error {
fs.logger.Debug(fs.logTag, "Writing %s", path)

err := fs.MkdirAll(filepath.Dir(path), os.ModePerm)
if err != nil {
err = bosherr.WrapError(err, "Creating dir to write file")
return
return bosherr.WrapError(err, "Creating dir to write file")
}

file, err := os.OpenFile(path, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0666)
if err != nil {
err = bosherr.WrapError(err, "Creating file %s", path)
return
return bosherr.WrapError(err, "Creating file %s", path)
}

defer file.Close()

fs.logger.DebugWithDetails(fs.logTag, "Write content", content)

_, err = file.Write(content)
if err != nil {
err = bosherr.WrapError(err, "Writing content to file %s", path)
return
return bosherr.WrapError(err, "Writing content to file %s", path)
}

return
return nil
}

func (fs osFileSystem) ConvergeFileContents(path string, content []byte) (written bool, err error) {
func (fs osFileSystem) ConvergeFileContents(path string, content []byte) (bool, error) {
if fs.filesAreIdentical(content, path) {
return
fs.logger.Debug(fs.logTag, "Skipping writing %s because contents are identical", path)
return false, nil
}

err = fs.MkdirAll(filepath.Dir(path), os.ModePerm)
fs.logger.Debug(fs.logTag, "File %s will be overwritten", path)

err := fs.MkdirAll(filepath.Dir(path), os.ModePerm)
if err != nil {
err = bosherr.WrapError(err, "Making dir for file %s", path)
return
return true, bosherr.WrapError(err, "Making dir for file %s", path)
}

file, err := os.Create(path)
if err != nil {
err = bosherr.WrapError(err, "Creating file %s", path)
return
return true, bosherr.WrapError(err, "Creating file %s", path)
}

defer file.Close()

_, err = file.Write(content)
if err != nil {
err = bosherr.WrapError(err, "Writing content to file %s", path)
return
return true, bosherr.WrapError(err, "Writing content to file %s", path)
}

written = true
return
return true, nil
}

func (fs osFileSystem) ReadFileString(path string) (content string, err error) {
Expand Down

0 comments on commit 20b18d0

Please sign in to comment.