@@ -184,20 +184,28 @@ def setUpClass(cls):
184184 cls .services ["service_offerings" ]["tiny" ]
185185 )
186186 cls ._cleanup .append (cls .service_offering )
187- cls .network_offering = NetworkOffering .create (
188- cls .apiclient ,
189- cls .services ["l2-network_offering" ],
190- )
191- cls .network_offering .update (cls .apiclient , state = 'Enabled' )
192- cls .services ["network" ]["networkoffering" ] = cls .network_offering .id
193- cls .l2_network = Network .create (
194- cls .apiclient ,
195- cls .services ["l2-network" ],
196- zoneid = cls .zone .id ,
197- networkofferingid = cls .network_offering .id
198- )
199- cls ._cleanup .append (cls .l2_network )
200- cls ._cleanup .append (cls .network_offering )
187+
188+ if cls .zone .networktype == 'Basic' :
189+ networks = Network .list (cls .apiclient )
190+ if len (networks ) == 0 :
191+ self .skipTest ("Skipping test since no network found in basic zone" )
192+ else :
193+ cls .network = networks [0 ]
194+ else :
195+ cls .network_offering = NetworkOffering .create (
196+ cls .apiclient ,
197+ cls .services ["l2-network_offering" ],
198+ )
199+ cls ._cleanup .append (cls .network_offering )
200+ cls .network_offering .update (cls .apiclient , state = 'Enabled' )
201+ cls .services ["network" ]["networkoffering" ] = cls .network_offering .id
202+ cls .network = Network .create (
203+ cls .apiclient ,
204+ cls .services ["l2-network" ],
205+ zoneid = cls .zone .id ,
206+ networkofferingid = cls .network_offering .id
207+ )
208+ cls ._cleanup .append (cls .network )
201209
202210 storage_pools = StoragePool .list (
203211 cls .apiclient ,
@@ -221,11 +229,7 @@ def setUpClass(cls):
221229
222230 @classmethod
223231 def tearDownClass (cls ):
224- try :
225- cleanup_resources (cls .apiclient , cls ._cleanup )
226- except Exception as e :
227- raise Exception ("Warning: Exception during cleanup : %s" % e )
228- return
232+ super (TestDirectDownloadTemplates , cls ).tearDownClass ()
229233
230234 def setUp (self ):
231235 self .apiclient = self .testClient .getApiClient ()
@@ -234,11 +238,7 @@ def setUp(self):
234238 return
235239
236240 def tearDown (self ):
237- try :
238- cleanup_resources (self .apiclient , self .cleanup )
239- except Exception as e :
240- raise Exception ("Warning: Exception during cleanup : %s" % e )
241- return
241+ super (TestDirectDownloadTemplates , self ).tearDown ()
242242
243243 def getCurrentStoragePoolTags (self , poolId ):
244244 local_pool = StoragePool .list (
@@ -269,6 +269,22 @@ def createServiceOffering(self, name, type, tags):
269269 tags = tags
270270 )
271271
272+ def deployVM (self , offering ) :
273+ if self .zone .networktype == 'Basic' :
274+ vm = VirtualMachine .create (
275+ self .apiclient ,
276+ self .services ["virtual_machine" ],
277+ serviceofferingid = offering .id
278+ )
279+ else :
280+ vm = VirtualMachine .create (
281+ self .apiclient ,
282+ self .services ["virtual_machine" ],
283+ serviceofferingid = offering .id ,
284+ networkids = self .network .id
285+ )
286+ self .cleanup .append (vm )
287+ return vm
272288
273289 @skipTestIf ("nfsKvmNotAvailable" )
274290 @attr (tags = ["advanced" , "basic" , "eip" , "advancedns" , "sg" ], required_hardware = "false" )
@@ -282,12 +298,7 @@ def test_01_deploy_vm_from_direct_download_template_nfs_storage(self):
282298 self .updateStoragePoolTags (self .nfsPoolId , test_tag )
283299 nfs_storage_offering = self .createServiceOffering ("TestNFSStorageDirectDownload" , "shared" , test_tag )
284300
285- vm = VirtualMachine .create (
286- self .apiclient ,
287- self .services ["virtual_machine" ],
288- serviceofferingid = nfs_storage_offering .id ,
289- networkids = self .l2_network .id
290- )
301+ vm = self .deployVM (nfs_storage_offering )
291302 self .assertEqual (
292303 vm .state ,
293304 "Running" ,
@@ -296,7 +307,6 @@ def test_01_deploy_vm_from_direct_download_template_nfs_storage(self):
296307
297308 # Revert storage tags for the storage pool used in this test
298309 self .updateStoragePoolTags (self .nfsPoolId , tags )
299- self .cleanup .append (vm )
300310 self .cleanup .append (nfs_storage_offering )
301311 return
302312
@@ -313,12 +323,7 @@ def test_02_deploy_vm_from_direct_download_template_local_storage(self):
313323 local_storage_offering = self .createServiceOffering ("TestLocalStorageDirectDownload" , "local" , test_tag )
314324
315325 # Deploy VM
316- vm = VirtualMachine .create (
317- self .apiclient ,
318- self .services ["virtual_machine" ],
319- serviceofferingid = local_storage_offering .id ,
320- networkids = self .l2_network .id ,
321- )
326+ vm = self .deployVM (local_storage_offering )
322327 self .assertEqual (
323328 vm .state ,
324329 "Running" ,
@@ -327,7 +332,6 @@ def test_02_deploy_vm_from_direct_download_template_local_storage(self):
327332
328333 # Revert storage tags for the storage pool used in this test
329334 self .updateStoragePoolTags (self .localPoolId , tags )
330- self .cleanup .append (vm )
331335 self .cleanup .append (local_storage_offering )
332336 return
333337
0 commit comments