@@ -46,6 +46,90 @@ func TestCreateOrUpdateNetworkContainerInternal(t *testing.T) {
4646 validateCreateOrUpdateNCInternal (t , 2 , "-1" )
4747}
4848
49+ // TestReconcileNCStatePrimaryIPChangeShouldFail tests that reconciling NC state with
50+ // a NC whose IP has changed should fail
51+ func TestReconcileNCStatePrimaryIPChangeShouldFail (t * testing.T ) {
52+ restartService ()
53+ setEnv (t )
54+ setOrchestratorTypeInternal (cns .KubernetesCRD )
55+ svc .state .ContainerStatus = make (map [string ]containerstatus )
56+
57+ // start with a NC in state
58+ ncID := "555ac5c9-89f2-4b5d-b8d0-616894d6d151"
59+ svc .state .ContainerStatus [ncID ] = containerstatus {
60+ ID : ncID ,
61+ VMVersion : "0" ,
62+ HostVersion : "0" ,
63+ CreateNetworkContainerRequest : cns.CreateNetworkContainerRequest {
64+ NetworkContainerid : ncID ,
65+ IPConfiguration : cns.IPConfiguration {
66+ IPSubnet : cns.IPSubnet {
67+ IPAddress : "10.0.1.0" ,
68+ PrefixLength : 24 ,
69+ },
70+ },
71+ },
72+ }
73+
74+ // now try to reconcile the state where the NC primary IP has changed
75+ resp := svc .ReconcileNCState (& cns.CreateNetworkContainerRequest {
76+ NetworkContainerid : ncID ,
77+ IPConfiguration : cns.IPConfiguration {
78+ IPSubnet : cns.IPSubnet {
79+ IPAddress : "10.0.2.0" , // note this IP has changed
80+ PrefixLength : 24 ,
81+ },
82+ },
83+ }, map [string ]cns.PodInfo {}, & v1alpha.NodeNetworkConfig {})
84+
85+ assert .Equal (t , types .PrimaryCANotSame , resp )
86+ }
87+
88+ // TestReconcileNCStateGatewayChange tests that NC state gets updated when reconciled
89+ // if the NC's gateway IP has changed
90+ func TestReconcileNCStateGatewayChange (t * testing.T ) {
91+ restartService ()
92+ setEnv (t )
93+ setOrchestratorTypeInternal (cns .KubernetesCRD )
94+ svc .state .ContainerStatus = make (map [string ]containerstatus )
95+
96+ // start with a NC in state
97+ ncID := "555ac5c9-89f2-4b5d-b8d0-616894d6d151"
98+ oldGW := "10.0.0.0"
99+ newGW := "10.0.1.0"
100+ ncPrimaryIP := cns.IPSubnet {
101+ IPAddress : "10.0.1.1" ,
102+ PrefixLength : 24 ,
103+ }
104+ svc .state .ContainerStatus [ncID ] = containerstatus {
105+ ID : ncID ,
106+ VMVersion : "0" ,
107+ HostVersion : "0" ,
108+ CreateNetworkContainerRequest : cns.CreateNetworkContainerRequest {
109+ NetworkContainerid : ncID ,
110+ NetworkContainerType : cns .Kubernetes ,
111+ IPConfiguration : cns.IPConfiguration {
112+ IPSubnet : ncPrimaryIP ,
113+ GatewayIPAddress : oldGW ,
114+ },
115+ },
116+ }
117+
118+ // now try to reconcile the state where the NC gateway has changed
119+ resp := svc .ReconcileNCState (& cns.CreateNetworkContainerRequest {
120+ NetworkContainerid : ncID ,
121+ NetworkContainerType : cns .Kubernetes ,
122+ IPConfiguration : cns.IPConfiguration {
123+ IPSubnet : ncPrimaryIP ,
124+ GatewayIPAddress : newGW , // note this IP has changed
125+ },
126+ }, map [string ]cns.PodInfo {}, & v1alpha.NodeNetworkConfig {})
127+
128+ assert .Equal (t , types .Success , resp )
129+ // assert the new state reflects the gateway update
130+ assert .Equal (t , newGW , svc .state .ContainerStatus [ncID ].CreateNetworkContainerRequest .IPConfiguration .GatewayIPAddress )
131+ }
132+
49133func TestCreateOrUpdateNCWithLargerVersionComparedToNMAgent (t * testing.T ) {
50134 restartService ()
51135
0 commit comments