@@ -118,7 +118,9 @@ def test_driver_ngs_config(self):
118118 "ngs_physical_networks" : "physnet1,physnet2" ,
119119 "ngs_port_default_vlan" : "20" ,
120120 "ngs_disable_inactive_ports" : "true" ,
121- "ngs_network_name_format" : "net-{network_id}" }
121+ "ngs_network_name_format" : "net-{network_id}" ,
122+ "ngs_allowed_vlans" : "123,124" ,
123+ "ngs_allowed_ports" : "Ethernet1/1,Ethernet1/2" }
122124 device = devices .device_manager (device_cfg )
123125 self .assertIsInstance (device , devices .GenericSwitchDevice )
124126 self .assertNotIn ('ngs_mac_address' , device .config )
@@ -127,6 +129,8 @@ def test_driver_ngs_config(self):
127129 self .assertNotIn ('ngs_trunk_ports' , device .config )
128130 self .assertNotIn ('ngs_physical_networks' , device .config )
129131 self .assertNotIn ('ngs_port_default_vlan' , device .config )
132+ self .assertNotIn ('ngs_allowed_vlans' , device .config )
133+ self .assertNotIn ('ngs_allowed_ports' , device .config )
130134 self .assertEqual ('aa:bb:cc:dd:ee:ff' ,
131135 device .ngs_config ['ngs_mac_address' ])
132136 self .assertEqual ('120' , device .ngs_config ['ngs_ssh_connect_timeout' ])
@@ -139,6 +143,49 @@ def test_driver_ngs_config(self):
139143 device .ngs_config ['ngs_disable_inactive_ports' ])
140144 self .assertEqual ('net-{network_id}' ,
141145 device .ngs_config ['ngs_network_name_format' ])
146+ self .assertEqual ("123,124" ,
147+ device .ngs_config ['ngs_allowed_vlans' ])
148+ self .assertEqual (["123" , "124" ],
149+ device ._get_allowed_vlans ())
150+ self .assertEqual ("Ethernet1/1,Ethernet1/2" ,
151+ device .ngs_config ['ngs_allowed_ports' ])
152+ self .assertEqual (["Ethernet1/1" , "Ethernet1/2" ],
153+ device ._get_allowed_ports ())
154+
155+ def test_driver_ngs_is_allowed (self ):
156+ device_cfg = {"device_type" : 'netmiko_ovs_linux' ,
157+ "ngs_allowed_vlans" : "123,124" ,
158+ "ngs_allowed_ports" : "Ethernet1/1,Ethernet1/2" }
159+ device = devices .device_manager (device_cfg )
160+
161+ # test all allowed
162+ self .assertTrue (device .is_allowed ("Ethernet1/1" , 123 ))
163+ self .assertTrue (device .is_allowed ("Ethernet1/2" , 124 ))
164+ # fail on vlan
165+ self .assertFalse (device .is_allowed ("Ethernet1/2" , 125 ))
166+ # fail on port
167+ self .assertFalse (device .is_allowed ("Ethernet1/3" , 124 ))
168+ # fail on both
169+ self .assertFalse (device .is_allowed ("Ethernet2/2" , 1 ))
170+
171+ def test_driver_ngs_is_allowed_fails_on_empty_ports (self ):
172+ device_cfg = {"device_type" : 'netmiko_ovs_linux' ,
173+ "ngs_allowed_vlans" : "123" ,
174+ "ngs_allowed_ports" : "" }
175+ device = devices .device_manager (device_cfg )
176+ self .assertFalse (device .is_allowed ("Ethernet1/1" , 123 ))
177+
178+ def test_driver_ngs_is_allowed_fails_on_empty_vlans (self ):
179+ device_cfg = {"device_type" : 'netmiko_ovs_linux' ,
180+ "ngs_allowed_vlans" : "" ,
181+ "ngs_allowed_ports" : "Ethernet1/1" }
182+ device = devices .device_manager (device_cfg )
183+ self .assertFalse (device .is_allowed ("Ethernet1/1" , 123 ))
184+
185+ def test_driver_ngs_is_allowed_default (self ):
186+ device_cfg = {"device_type" : 'netmiko_ovs_linux' }
187+ device = devices .device_manager (device_cfg )
188+ self .assertTrue (device .is_allowed ("Ethernet1/1" , 123 ))
142189
143190 def test_driver_ngs_config_defaults (self ):
144191 device_cfg = {"device_type" : 'netmiko_ovs_linux' }
@@ -153,6 +200,8 @@ def test_driver_ngs_config_defaults(self):
153200 self .assertFalse (device .ngs_config ['ngs_disable_inactive_ports' ])
154201 self .assertEqual ('{network_id}' ,
155202 device .ngs_config ['ngs_network_name_format' ])
203+ self .assertNotIn ('ngs_allowed_vlans' , device .ngs_config )
204+ self .assertNotIn ('ngs_allowed_ports' , device .ngs_config )
156205
157206 def test__get_trunk_ports (self ):
158207 device_cfg = {"ngs_trunk_ports" : 'port1, Po 1/30,port42' }
0 commit comments