Skip to content

MGMT-18930: Consolidate static network configuration log messages #7592

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
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
13 changes: 12 additions & 1 deletion pkg/staticnetworkconfig/generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -248,20 +248,31 @@ func (s *StaticNetworkConfigGenerator) createNMConnectionFiles(nmstateOutput, ho
if len(connectionsList) == 0 {
return nil, errors.Errorf("nmstate generated an empty NetworkManager config file content")
}

for _, connection := range connectionsList {
connectionElems := connection.([]interface{})
fileName := connectionElems[0].(string)
fileContents, err := s.formatNMConnection(connectionElems[1].(string))
if err != nil {
return nil, err
}
s.log.Infof("Adding NMConnection file <%s>", fileName)

newFile := StaticNetworkConfigData{
FilePath: filepath.Join(hostDir, fileName),
FileContents: fileContents,
}

filesList = append(filesList, newFile)
}

if len(filesList) > 0 {
s.log.Infof("Adding NMConnection files: <%s>",
strings.Join(lo.Map(filesList, func(f StaticNetworkConfigData, _ int) string {
return filepath.Base(f.FilePath)
}), ">, <"),
)
}

return filesList, nil
}

Expand Down
41 changes: 41 additions & 0 deletions pkg/staticnetworkconfig/generator_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package staticnetworkconfig_test

import (
"bytes"
"context"
"encoding/json"
"fmt"
Expand Down Expand Up @@ -489,6 +490,46 @@ var _ = Describe("StaticNetworkConfig", func() {
Expect(err).ToNot(HaveOccurred())
Expect(formattedOutput).To(Equal(""))
})

It("logs all NMConnection files in a consolidated format", func() {

var logBuffer bytes.Buffer
testLog := logrus.New()
testLog.SetOutput(&logBuffer)

testGenerator := snc.New(testLog, snc.Config{MinVersionForNmstateService: common.MinimalVersionForNmstatectl})

staticNetworkConfig := []*models.HostStaticNetworkConfig{
{
MacInterfaceMap: models.MacInterfaceMap{
{
LogicalNicName: "eth0",
MacAddress: "f8:75:a4:a4:00:fe",
},
{
LogicalNicName: "eth1",
MacAddress: "f8:75:a4:a4:00:ff",
},
{
LogicalNicName: "eth2",
MacAddress: "f8:75:a4:a4:01:00",
},
},
NetworkYaml: multipleInterfacesYAML,
},
}

staticNetworkConfigBytes, err := json.Marshal(staticNetworkConfig)
Expect(err).NotTo(HaveOccurred())

_, err = testGenerator.GenerateStaticNetworkConfigData(context.Background(), string(staticNetworkConfigBytes))

if err == nil {
logOutput := logBuffer.String()

Expect(logOutput).To(ContainSubstring("Adding NMConnection files: <eth0.nmconnection>, <eth1.nmconnection>, <eth2.nmconnection>"))
}
})
})

var _ = Describe("StaticNetworkConfig.GenerateStaticNetworkConfigDataYAML - generate nmpolicy", func() {
Expand Down