Skip to content

Commit ab72088

Browse files
committed
MGMT-18930: Consolidate static network configuration log messages
This commit changes the logging behavior in the StaticNetworkConfigGenerator to reduce log verbosity by consolidating multiple individual "Adding NMConnection file" log messages into a single message. Instead of logging each NM connection file separately, the code now collects all file names and outputs them in a single log entry.
1 parent b6266c1 commit ab72088

File tree

2 files changed

+53
-1
lines changed

2 files changed

+53
-1
lines changed

pkg/staticnetworkconfig/generator.go

+12-1
Original file line numberDiff line numberDiff line change
@@ -248,20 +248,31 @@ func (s *StaticNetworkConfigGenerator) createNMConnectionFiles(nmstateOutput, ho
248248
if len(connectionsList) == 0 {
249249
return nil, errors.Errorf("nmstate generated an empty NetworkManager config file content")
250250
}
251+
251252
for _, connection := range connectionsList {
252253
connectionElems := connection.([]interface{})
253254
fileName := connectionElems[0].(string)
254255
fileContents, err := s.formatNMConnection(connectionElems[1].(string))
255256
if err != nil {
256257
return nil, err
257258
}
258-
s.log.Infof("Adding NMConnection file <%s>", fileName)
259+
259260
newFile := StaticNetworkConfigData{
260261
FilePath: filepath.Join(hostDir, fileName),
261262
FileContents: fileContents,
262263
}
264+
263265
filesList = append(filesList, newFile)
264266
}
267+
268+
if len(filesList) > 0 {
269+
s.log.Infof("Adding NMConnection files: <%s>",
270+
strings.Join(lo.Map(filesList, func(f StaticNetworkConfigData, _ int) string {
271+
return filepath.Base(f.FilePath)
272+
}), ">, <"),
273+
)
274+
}
275+
265276
return filesList, nil
266277
}
267278

pkg/staticnetworkconfig/generator_test.go

+41
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package staticnetworkconfig_test
22

33
import (
4+
"bytes"
45
"context"
56
"encoding/json"
67
"fmt"
@@ -489,6 +490,46 @@ var _ = Describe("StaticNetworkConfig", func() {
489490
Expect(err).ToNot(HaveOccurred())
490491
Expect(formattedOutput).To(Equal(""))
491492
})
493+
494+
It("logs all NMConnection files in a consolidated format", func() {
495+
496+
var logBuffer bytes.Buffer
497+
testLog := logrus.New()
498+
testLog.SetOutput(&logBuffer)
499+
500+
testGenerator := snc.New(testLog, snc.Config{MinVersionForNmstateService: common.MinimalVersionForNmstatectl})
501+
502+
staticNetworkConfig := []*models.HostStaticNetworkConfig{
503+
{
504+
MacInterfaceMap: models.MacInterfaceMap{
505+
{
506+
LogicalNicName: "eth0",
507+
MacAddress: "f8:75:a4:a4:00:fe",
508+
},
509+
{
510+
LogicalNicName: "eth1",
511+
MacAddress: "f8:75:a4:a4:00:ff",
512+
},
513+
{
514+
LogicalNicName: "eth2",
515+
MacAddress: "f8:75:a4:a4:01:00",
516+
},
517+
},
518+
NetworkYaml: multipleInterfacesYAML,
519+
},
520+
}
521+
522+
staticNetworkConfigBytes, err := json.Marshal(staticNetworkConfig)
523+
Expect(err).NotTo(HaveOccurred())
524+
525+
_, err = testGenerator.GenerateStaticNetworkConfigData(context.Background(), string(staticNetworkConfigBytes))
526+
527+
if err == nil {
528+
logOutput := logBuffer.String()
529+
530+
Expect(logOutput).To(ContainSubstring("Adding NMConnection files: <eth0.nmconnection>, <eth1.nmconnection>, <eth2.nmconnection>"))
531+
}
532+
})
492533
})
493534

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

0 commit comments

Comments
 (0)