@@ -83,6 +83,12 @@ def setUpClass(cls):
8383 )
8484 cls ._cleanup .append (cls .network_offering )
8585 cls .network_offering .update (cls .apiclient , state = 'Enabled' )
86+ cls .isolated_network_offering = NetworkOffering .create (
87+ cls .apiclient ,
88+ cls .services ["nw_off_isolated_persistent" ],
89+ )
90+ cls ._cleanup .append (cls .isolated_network_offering )
91+ cls .isolated_network_offering .update (cls .apiclient , state = 'Enabled' )
8692
8793 @classmethod
8894 def tearDownClass (cls ):
@@ -92,16 +98,37 @@ def setUp(self):
9298 self .apiclient = self .testClient .getApiClient ()
9399 self .dbclient = self .testClient .getDbConnection ()
94100 self .services ["network" ]["networkoffering" ] = self .network_offering .id
101+ self .cleanup = []
102+ self .created_networks = []
103+ network_data = self .services ["l2-network" ]
95104 self .network = Network .create (
96105 self .apiclient ,
97- self .services ["l2-network" ],
106+ network_data ,
107+ zoneid = self .zone .id ,
108+ networkofferingid = self .network_offering .id
109+ )
110+ self .cleanup .append (self .network )
111+ self .created_networks .append (self .network )
112+ network_data ['name' ] = "Test L2 Network1"
113+ network_data ['displaytext' ] = "Test L2 Network1"
114+ self .network1 = Network .create (
115+ self .apiclient ,
116+ network_data ,
98117 zoneid = self .zone .id ,
99118 networkofferingid = self .network_offering .id
100119 )
101- self .cleanup = [
102- self .network
103- ]
120+ self .cleanup .append (self .network1 )
121+ self .created_networks .append (self .network1 )
122+ self .network2 = Network .create (
123+ self .apiclient ,
124+ self .services ["isolated_network" ],
125+ zoneid = self .zone .id ,
126+ networkofferingid = self .isolated_network_offering .id
127+ )
128+ self .cleanup .append (self .network2 )
129+ self .created_networks .append (self .network2 )
104130 self .unmanaged_instance = None
131+ self .imported_vm = None
105132
106133 '''
107134 Fetch vmware datacenter login details
@@ -128,6 +155,9 @@ def tearDown(self):
128155 self .delete_vcenter_vm (self .unmanaged_instance )
129156 except Exception as e :
130157 print ("Warning: Exception during cleaning up vCenter VM: %s : %s" % (self .unmanaged_instance , e ))
158+ else :
159+ if self .virtual_machine is not None and self .imported_vm is None :
160+ self .cleanup .append (self .virtual_machine )
131161 super (TestUnmanageVM , self ).tearDown ()
132162
133163 def check_vm_state (self , vm_id ):
@@ -158,7 +188,8 @@ def test_01_unmanage_vm_cycle(self):
158188 3. Verify VM is not listed in CloudStack
159189 4. Verify VM is listed as part of the unmanaged instances
160190 5. Import VM
161- 6. Destroy VM
191+ 6. Verify details of imported VM
192+ 7. Destroy VM
162193 """
163194
164195 # 1 - Deploy VM
@@ -167,11 +198,18 @@ def test_01_unmanage_vm_cycle(self):
167198 self .services ["virtual_machine" ],
168199 templateid = self .template .id ,
169200 serviceofferingid = self .small_offering .id ,
170- networkids = self .network .id ,
201+ networkids = [ self .network .id , self . network1 . id , self . network2 . id ] ,
171202 zoneid = self .zone .id
172203 )
173204 vm_id = self .virtual_machine .id
174205 vm_instance_name = self .virtual_machine .instancename
206+ networks = []
207+ for network in self .created_networks :
208+ n = Network .list (
209+ self .apiclient ,
210+ id = network .id
211+ )[0 ]
212+ networks .append (n )
175213 hostid = self .virtual_machine .hostid
176214 hosts = Host .list (
177215 self .apiclient ,
@@ -212,13 +250,20 @@ def test_01_unmanage_vm_cycle(self):
212250 )
213251 # 5 - Import VM
214252 unmanaged_vm_nic = unmanaged_vm .nic [0 ]
215- nicnetworklist = [{}]
216- nicnetworklist [0 ]["nic" ] = unmanaged_vm_nic .id
217- nicnetworklist [0 ]["network" ] = self .network .id
218- nicipaddresslist = [{}]
219- if self .network .type == "Isolated" :
220- nicipaddresslist [0 ]["nic" ] = unmanaged_vm_nic .id
221- nicipaddresslist [0 ]["ip4Address" ] = "auto"
253+ nicnetworklist = []
254+ nicipaddresslist = []
255+ for nic in unmanaged_vm .nic :
256+ for network in networks :
257+ if int (network .vlan ) == int (nic .vlanid ):
258+ nicnetworklist .append ({
259+ "nic" : nic .id ,
260+ "network" : network .id
261+ })
262+ if network .type == "Isolated" :
263+ nicipaddresslist .append ({
264+ "nic" : nic .id ,
265+ "ip4Address" : "auto"
266+ })
222267 import_vm_service = {
223268 "nicnetworklist" : nicnetworklist ,
224269 "nicipaddresslist" : nicipaddresslist
@@ -232,6 +277,7 @@ def test_01_unmanage_vm_cycle(self):
232277 templateid = self .template .id )
233278 self .cleanup .append (self .imported_vm )
234279 self .unmanaged_instance = None
280+ # 6 - Verify details of the imported VM
235281 self .assertEqual (
236282 self .small_offering .id ,
237283 self .imported_vm .serviceofferingid ,
@@ -242,4 +288,17 @@ def test_01_unmanage_vm_cycle(self):
242288 self .imported_vm .templateid ,
243289 "Imported VM template is different, expected: %s, actual: %s" % (self .template .id , self .imported_vm .templateid )
244290 )
291+ self .assertEqual (
292+ len (nicnetworklist ),
293+ len (self .imported_vm .nic ),
294+ "Imported VM number of NICs is different, expected: %d, actual: %d" % (len (nicnetworklist ), len (self .imported_vm .nic ))
295+ )
296+ for nic in self .imported_vm .nic :
297+ index = int (nic .deviceid ) # device id of imported nics will be in order of their import
298+ self .assertEqual (
299+ nicnetworklist [index ]["network" ],
300+ nic .networkid ,
301+ "Imported VM NIC with id: %s has wrong network, expected: %s, actual: %s" % (nic .id , nicnetworklist [index ]["network" ], nic .networkid )
302+ )
245303 self .check_vm_state (self .imported_vm .id )
304+ # 7 - Destroy VM. This will be done during cleanup
0 commit comments