11package ignition
22
33import (
4+ "bytes"
45 "context"
56 "os"
67 "path/filepath"
@@ -440,6 +441,18 @@ var _ = Describe("Disconnected Ignition", func() {
440441 {"mac_address": "52:54:00:aa:bb:cc", "logical_nic_name": "eth0"}
441442 ],
442443 "network_yaml": "interfaces:\n- name: eth0\n type: ethernet\n state: up\n ipv4:\n enabled: true\n address:\n - ip: 192.168.1.10\n prefix-length: 24\n dhcp: false\n"
444+ },
445+ {
446+ "mac_interface_map": [
447+ {"mac_address": "53:54:00:aa:bb:cc", "logical_nic_name": "eth0"}
448+ ],
449+ "network_yaml": "interfaces:\n- name: eth0\n type: ethernet\n state: up\n ipv4:\n enabled: true\n address:\n - ip: 192.168.1.11\n prefix-length: 24\n dhcp: false\n"
450+ },
451+ {
452+ "mac_interface_map": [
453+ {"mac_address": "54:54:00:aa:bb:cc", "logical_nic_name": "eth0"}
454+ ],
455+ "network_yaml": "interfaces:\n- name: eth0\n type: ethernet\n state: up\n ipv4:\n enabled: true\n address:\n - ip: 192.168.1.12\n prefix-length: 24\n dhcp: false\n"
443456 }
444457 ]`
445458
@@ -458,20 +471,46 @@ var _ = Describe("Disconnected Ignition", func() {
458471 oveDir := args [4 ]
459472
460473 By ("Verifying NMStateConfig manifest was created" )
461- nmstateConfigContent , err := os .ReadFile (filepath .Join (oveDir , "cluster-manifests" , "nmstateconfig-0.yaml" ))
462- Expect (err ).NotTo (HaveOccurred ())
474+ nmstateConfigContent , err := os .ReadFile (filepath .Join (oveDir , "cluster-manifests" , "nmstateconfig.yaml" ))
475+ Expect (err ).NotTo (HaveOccurred ())
476+
477+ // Split the YAML content by document separator
478+ // Note: We use sigs.k8s.io/yaml (not gopkg.in/yaml.v2) because Kubernetes types
479+ // use json struct tags, which sigs.k8s.io/yaml handles correctly but gopkg.in/yaml.v2 doesn't
480+ var nmstateConfigs []v1beta1.NMStateConfig
481+ docs := bytes .Split (nmstateConfigContent , []byte ("---\n " ))
482+ for _ , doc := range docs {
483+ doc = bytes .TrimSpace (doc )
484+ if len (doc ) == 0 {
485+ continue
486+ }
487+
488+ var config v1beta1.NMStateConfig
489+ err = yaml .Unmarshal (doc , & config )
490+ Expect (err ).NotTo (HaveOccurred ())
491+ nmstateConfigs = append (nmstateConfigs , config )
492+ }
463493
464- var nmstateConfig v1beta1.NMStateConfig
465- err = yaml .Unmarshal (nmstateConfigContent , & nmstateConfig )
466- Expect (err ).NotTo (HaveOccurred ())
494+ Expect (nmstateConfigs ).To (HaveLen (3 ))
467495
468- Expect (nmstateConfig .APIVersion ).To (Equal ("agent-install.openshift.io/v1beta1" ))
469- Expect (nmstateConfig .Kind ).To (Equal ("NMStateConfig" ))
470- Expect (nmstateConfig .ObjectMeta .Name ).To (Equal ("nmstate-config-0" ))
471- Expect (nmstateConfig .ObjectMeta .Labels ).To (HaveKeyWithValue (nmStateConfigInfraEnvLabelKey , infraEnv .ID .String ()))
472- Expect (nmstateConfig .Spec .Interfaces ).To (HaveLen (1 ))
473- Expect (nmstateConfig .Spec .Interfaces [0 ].Name ).To (Equal ("eth0" ))
474- Expect (nmstateConfig .Spec .Interfaces [0 ].MacAddress ).To (Equal ("52:54:00:aa:bb:cc" ))
496+ expectedConfigs := []struct {
497+ name string
498+ macAddress string
499+ }{
500+ {"nmstate-config-0" , "52:54:00:aa:bb:cc" },
501+ {"nmstate-config-1" , "53:54:00:aa:bb:cc" },
502+ {"nmstate-config-2" , "54:54:00:aa:bb:cc" },
503+ }
504+
505+ for i , expected := range expectedConfigs {
506+ Expect (nmstateConfigs [i ].APIVersion ).To (Equal ("agent-install.openshift.io/v1beta1" ))
507+ Expect (nmstateConfigs [i ].Kind ).To (Equal ("NMStateConfig" ))
508+ Expect (nmstateConfigs [i ].ObjectMeta .Name ).To (Equal (expected .name ))
509+ Expect (nmstateConfigs [i ].ObjectMeta .Labels ).To (HaveKeyWithValue (nmStateConfigInfraEnvLabelKey , infraEnv .ID .String ()))
510+ Expect (nmstateConfigs [i ].Spec .Interfaces ).To (HaveLen (1 ))
511+ Expect (nmstateConfigs [i ].Spec .Interfaces [0 ].Name ).To (Equal ("eth0" ))
512+ Expect (nmstateConfigs [i ].Spec .Interfaces [0 ].MacAddress ).To (Equal (expected .macAddress ))
513+ }
475514
476515 By ("Verifying InfraEnv manifest selector references NMStateConfig labels" )
477516 infraEnvContent , err := os .ReadFile (filepath .Join (oveDir , "cluster-manifests" , "infraenv.yaml" ))
@@ -512,7 +551,7 @@ var _ = Describe("Disconnected Ignition", func() {
512551 oveDir := args [4 ]
513552
514553 By ("Verifying no NMStateConfig manifest was created" )
515- _ , err := os .Stat (filepath .Join (oveDir , "cluster-manifests" , "nmstateconfig-0 .yaml" ))
554+ _ , err := os .Stat (filepath .Join (oveDir , "cluster-manifests" , "nmstateconfig.yaml" ))
516555 Expect (os .IsNotExist (err )).To (BeTrue ())
517556
518557 By ("Verifying InfraEnv manifest does not set NMStateConfig selector" )
0 commit comments