1919from marvin .cloudstackAPI import listZones
2020from marvin .cloudstackTestCase import cloudstackTestCase
2121from marvin .lib .utils import (cleanup_resources )
22- from marvin .lib .base import (Account , ServiceOffering , DiskOffering , VirtualMachine , BackupOffering ,
23- BackupRepository , Backup , Configurations , Volume , StoragePool )
22+ from marvin .lib .base import (Account , Network , ServiceOffering , DiskOffering , VirtualMachine , BackupOffering ,
23+ NetworkOffering , BackupRepository , Backup , Configurations , Volume , StoragePool )
2424from marvin .lib .common import (get_domain , get_zone , get_template )
2525from nose .plugins .attrib import attr
2626from marvin .codes import FAILED
@@ -110,7 +110,7 @@ def tearDown(self):
110110 except Exception as e :
111111 raise Exception ("Warning: Exception during cleanup : %s" % e )
112112
113- def vm_backup_create_vm_from_backup_int (self , destination_zone ):
113+ def vm_backup_create_vm_from_backup_int (self , templateid = None , networkids = None ):
114114 self .backup_offering .assignOffering (self .apiclient , self .vm .id )
115115
116116 # Create a file and take backup
@@ -146,7 +146,9 @@ def vm_backup_create_vm_from_backup_int(self, destination_zone):
146146 vmname = new_vm_name ,
147147 accountname = self .account .name ,
148148 domainid = self .account .domainid ,
149- zoneid = self .zone .id
149+ zoneid = self .destZone .id ,
150+ networkids = networkids ,
151+ templateid = templateid
150152 )
151153 self .cleanup .append (new_vm )
152154
@@ -162,7 +164,7 @@ def vm_backup_create_vm_from_backup_int(self, destination_zone):
162164 "New VM should have the correct service offering" )
163165
164166 # Verify the new VM has the correct zone
165- self .assertEqual (new_vm .zoneid , self .zone .id , "New VM should be in the correct zone" )
167+ self .assertEqual (new_vm .zoneid , self .destZone .id , "New VM should be in the correct zone" )
166168
167169 # Verify the new VM has the correct number of volumes (ROOT + DATADISK)
168170 volumes = Volume .list (
@@ -220,7 +222,8 @@ def test_vm_backup_create_vm_from_backup(self):
220222 """
221223 Test creating a new VM from a backup
222224 """
223- self .vm_backup_create_vm_from_backup_int (self .zone .id )
225+ self .destZone = self .zone
226+ self .vm_backup_create_vm_from_backup_int ()
224227
225228 @attr (tags = ["advanced" , "backup" ], required_hardware = "true" )
226229 def test_vm_backup_create_vm_from_backup_in_another_zone (self ):
@@ -234,7 +237,31 @@ def test_vm_backup_create_vm_from_backup_in_another_zone(self):
234237 if len (zones ) < 2 :
235238 self .skipTest ("Skipping test due to there are less than two zones." )
236239 return
237-
238240 self .destZone = zones [1 ]
239241
240- self .vm_backup_create_vm_from_backup_int (self .destZone )
242+ template = get_template (self .api_client , self .destZone .id , self .services ["ostype" ])
243+
244+ list_isolated_network_offerings_response = NetworkOffering .list (
245+ self .apiclient ,
246+ name = "DefaultIsolatedNetworkOfferingWithSourceNatService"
247+ )
248+ isolated_network_offering_id = list_isolated_network_offerings_response [0 ].id
249+ network = {
250+ "name" : "Network-" ,
251+ "displaytext" : "Network-"
252+ }
253+ network ["name" ] = self .account .name + " -destZone"
254+ network ["displaytext" ] = self .account .name + " -destZone"
255+ network = Network .create (
256+ self .apiclient ,
257+ network ,
258+ accountid = self .account .name ,
259+ domainid = self .domain .id ,
260+ networkofferingid = isolated_network_offering_id ,
261+ zoneid = self .destZone .id
262+ )
263+
264+ backup_repository = self .backup_repository .update (self .api_client , crosszoneinstancecreation = True )
265+ self .assertEqual (backup_repository .crosszoneinstancecreation , True , "Cross-Zone Instance Creation could not be enabled on the backup repository" )
266+
267+ self .vm_backup_create_vm_from_backup_int (template .id , [network .id ])
0 commit comments