3838 StoragePool )
3939from marvin .lib .common import (get_domain ,
4040 get_zone ,
41- get_template )
41+ get_template ,
42+ list_disk_offering )
4243from marvin .lib .decoratorGenerators import skipTestIf
4344from marvin .codes import FAILED , PASS
4445from nose .plugins .attrib import attr
4546import logging
4647from sp_util import (TestData , StorPoolHelper )
4748import math
49+ import uuid
4850
4951class TestSnapshotCopy (cloudstackTestCase ):
5052
@@ -111,6 +113,10 @@ def setUpClass(cls):
111113 cls .helper = StorPoolHelper ()
112114
113115 compute_offering_service = cls .services ["service_offerings" ]["tiny" ].copy ()
116+ td = TestData ()
117+ cls .testdata = td .testdata
118+ cls .helper = StorPoolHelper ()
119+ cls .disk_offerings = cls .create_do_if_not_exists (cls .testdata [TestData .diskOfferingCustomAdditionalZone ])
114120 cls .service_offering = ServiceOffering .create (
115121 cls .apiclient ,
116122 compute_offering_service )
@@ -160,8 +166,7 @@ def test_01_take_snapshot_multi_zone(self):
160166 snapshot = Snapshot .create (self .userapiclient , volume_id = self .volume .id , zoneids = [str (self .additional_zone .id )], usestoragereplication = True )
161167 self .snapshot_id = snapshot .id
162168 self .helper .verify_snapshot_copies (self .userapiclient , self .snapshot_id , [self .zone .id , self .additional_zone .id ])
163- time .sleep (420 )
164- Snapshot .delete (snapshot , self .userapiclient )
169+ self ._cleanup .append (snapshot )
165170 return
166171
167172 @skipTestIf ("testsNotSupported" )
@@ -174,8 +179,8 @@ def test_02_copy_snapshot_multi_pools(self):
174179 self .snapshot_id = snapshot .id
175180 Snapshot .copy (self .userapiclient , self .snapshot_id , zone_ids = [str (self .additional_zone .id )], source_zone_id = self .zone .id , usestoragereplication = True )
176181 self .helper .verify_snapshot_copies (self .userapiclient , self .snapshot_id , [self .zone .id , self .additional_zone .id ])
177- time . sleep ( 420 )
178- Snapshot . delete (snapshot , self . userapiclient )
182+
183+ self . _cleanup . append (snapshot )
179184 return
180185
181186 @skipTestIf ("testsNotSupported" )
@@ -190,7 +195,7 @@ def test_03_take_snapshot_multi_pools_delete_single_zone(self):
190195 time .sleep (420 )
191196 Snapshot .delete (snapshot , self .userapiclient , self .zone .id )
192197 self .helper .verify_snapshot_copies (self .userapiclient , self .snapshot_id , [self .additional_zone .id ])
193- self .cleanup .append (snapshot )
198+ self ._cleanup .append (snapshot )
194199 return
195200
196201 @skipTestIf ("testsNotSupported" )
@@ -227,13 +232,12 @@ def test_05_take_snapshot_multi_zone_create_volume_additional_zone(self):
227232 self .apiclient ,
228233 service
229234 )
230- self .cleanup .append (self .disk_offering )
235+ self ._cleanup .append (self .disk_offering )
231236 disk_offering_id = self .disk_offering .id
232237
233238 self .volume = Volume .create (self .userapiclient , {"diskname" :"StorPoolDisk-1" }, snapshotid = self .snapshot_id , zoneid = self .zone .id , diskofferingid = disk_offering_id )
234- self .cleanup .append (self .volume )
235- time .sleep (420 )
236- Snapshot .delete (snapshot , self .userapiclient )
239+ self ._cleanup .append (self .volume )
240+ self ._cleanup .append (snapshot )
237241 if self .zone .id != self .volume .zoneid :
238242 self .fail ("Volume from snapshot not created in the additional zone" )
239243 return
@@ -249,7 +253,96 @@ def test_06_take_snapshot_multi_zone_create_template_additional_zone(self):
249253 self .template = self .helper .create_snapshot_template (self .userapiclient , self .services , self .snapshot_id , self .additional_zone .id )
250254 if self .additional_zone .id != self .template .zoneid :
251255 self .fail ("Template from snapshot not created in the additional zone" )
256+ self ._cleanup .append (snapshot )
257+ self ._cleanup .append (self .template )
258+ return
259+
260+ @skipTestIf ("testsNotSupported" )
261+ @attr (tags = ["devcloud" , "advanced" , "advancedns" , "smoke" , "basic" , "sg" ], required_hardware = "false" )
262+ def test_07_take_snapshot_multi_zone_deply_vm_additional_zone (self ):
263+ """Test to take volume snapshot in multiple StorPool primary storages in diff zones and deploy a VM from snapshot in one of the additional zones
264+ """
265+ snapshot = Snapshot .create (self .userapiclient , volume_id = self .volume .id , zoneids = [str (self .additional_zone .id )], usestoragereplication = True )
266+ self ._cleanup .append (snapshot )
267+ self .snapshot_id = snapshot .id
268+ self .helper .verify_snapshot_copies (self .userapiclient , self .snapshot_id , [self .zone .id , self .additional_zone .id ])
269+ vm = self .deploy_vm_from_snapshot (snapshot , self .additional_zone .id )
270+ if self .additional_zone .id != vm .zoneid :
271+ self .fail ("VM from snapshot not created in the additional zone" )
272+ return
273+
274+
275+ @skipTestIf ("testsNotSupported" )
276+ @attr (tags = ["devcloud" , "advanced" , "advancedns" , "smoke" , "basic" , "sg" ], required_hardware = "false" )
277+ def test_08_take_snapshot_multi_zone_create_volume_additional_zone_deploy_vm (self ):
278+ """Test to take volume snapshot in multiple StorPool primary storages in diff zones
279+ create a volume from the snapshot in the additional zone
280+ and deploy a VM from the volume in one of the additional zones
281+ """
282+ snapshot = Snapshot .create (self .userapiclient , volume_id = self .volume .id , zoneids = [str (self .additional_zone .id )], usestoragereplication = True )
283+ self ._cleanup .append (snapshot )
284+ self .snapshot_id = snapshot .id
285+ self .helper .verify_snapshot_copies (self .userapiclient , self .snapshot_id , [self .zone .id , self .additional_zone .id ])
286+ vm = self .create_volume_from_snapshot_deploy_vm (snapshotid = self .snapshot_id , zoneid = self .additional_zone .id )
252287 time .sleep (420 )
253- Snapshot . delete ( snapshot , self .userapiclient )
254- self .cleanup . append ( self . template )
288+ if self .additional_zone . id != vm . zoneid :
289+ self .fail ( "VM from snapshot not created in the additional zone" )
255290 return
291+
292+ def create_volume_from_snapshot_deploy_vm (self , snapshotid , zoneid = None ):
293+ volume = Volume .create_from_snapshot (
294+ self .apiclient ,
295+ snapshot_id = snapshotid ,
296+ services = self .services ,
297+ disk_offering = self .disk_offerings .id ,
298+ size = 8 ,
299+ account = self .account .name ,
300+ domainid = self .account .domainid ,
301+ zoneid = zoneid ,
302+ )
303+ virtual_machine = VirtualMachine .create (self .apiclient ,
304+ {"name" : "Test-%s" % uuid .uuid4 ()},
305+ accountid = self .account .name ,
306+ domainid = self .account .domainid ,
307+ zoneid = zoneid ,
308+ serviceofferingid = self .service_offering .id ,
309+ volumeid = volume .id ,
310+ mode = "basic" ,
311+ )
312+ self ._cleanup .append (virtual_machine )
313+ try :
314+ ssh_client = virtual_machine .get_ssh_client ()
315+ except Exception as e :
316+ self .fail ("SSH failed for virtual machine: %s - %s" %
317+ (virtual_machine .ipaddress , e ))
318+ return virtual_machine
319+
320+ def deploy_vm_from_snapshot (self , snapshot , zoneid = None ):
321+ virtual_machine = VirtualMachine .create (self .apiclient ,
322+ {"name" : "Test-%s" % uuid .uuid4 ()},
323+ accountid = self .account .name ,
324+ domainid = self .account .domainid ,
325+ zoneid = zoneid ,
326+ serviceofferingid = self .service_offering .id ,
327+ snapshotid = snapshot .id ,
328+ mode = "basic" ,
329+ )
330+ self ._cleanup .append (virtual_machine )
331+ try :
332+ ssh_client = virtual_machine .get_ssh_client ()
333+ except Exception as e :
334+ self .fail ("SSH failed for virtual machine: %s - %s" %
335+ (virtual_machine .ipaddress , e ))
336+ return virtual_machine
337+
338+ @classmethod
339+ def create_do_if_not_exists (cls , data ):
340+ disk_offerings = list_disk_offering (
341+ cls .apiclient ,
342+ name = data ["name" ]
343+ )
344+ if disk_offerings is None :
345+ disk_offerings = DiskOffering .create (cls .apiclient , services = data , custom = True )
346+ else :
347+ disk_offerings = disk_offerings [0 ]
348+ return disk_offerings
0 commit comments