Skip to content

Commit faebe18

Browse files
committed
Integration test added for Cross-zone instance creation in test_backup_recovery_nas.py
1 parent 6f39390 commit faebe18

File tree

3 files changed

+51
-12
lines changed

3 files changed

+51
-12
lines changed

api/src/main/java/org/apache/cloudstack/api/command/user/backup/repository/UpdateBackupRepositoryCmd.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,13 +44,13 @@ public class UpdateBackupRepositoryCmd extends BaseCmd {
4444
//////////////// API parameters /////////////////////
4545
/////////////////////////////////////////////////////
4646

47-
@Parameter(name = ApiConstants.ID, type = CommandType.UUID, entityType = BackupRepositoryResponse.class, description = "ID of the backup repository")
47+
@Parameter(name = ApiConstants.ID, type = CommandType.UUID, required = true, entityType = BackupRepositoryResponse.class, description = "ID of the backup repository")
4848
private Long id;
4949

50-
@Parameter(name = ApiConstants.NAME, type = CommandType.STRING, required = true, description = "name of the backup repository")
50+
@Parameter(name = ApiConstants.NAME, type = CommandType.STRING, description = "name of the backup repository")
5151
private String name;
5252

53-
@Parameter(name = ApiConstants.ADDRESS, type = CommandType.STRING, required = true, description = "address of the backup repository")
53+
@Parameter(name = ApiConstants.ADDRESS, type = CommandType.STRING, description = "address of the backup repository")
5454
private String address;
5555

5656
@Parameter(name = ApiConstants.MOUNT_OPTIONS, type = CommandType.STRING, description = "shared storage mount options")

test/integration/smoke/test_backup_recovery_nas.py

Lines changed: 35 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@
1919
from marvin.cloudstackAPI import listZones
2020
from marvin.cloudstackTestCase import cloudstackTestCase
2121
from 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)
2424
from marvin.lib.common import (get_domain, get_zone, get_template)
2525
from nose.plugins.attrib import attr
2626
from 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])

tools/marvin/marvin/lib/base.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6246,7 +6246,7 @@ def restoreVolumeFromBackupAndAttachToVM(self, apiclient, backupid, volumeid, vi
62466246
return (apiclient.restoreVolumeFromBackupAndAttachToVM(cmd))
62476247

62486248
@classmethod
6249-
def createVMFromBackup(cls, apiclient, services, mode, backupid, accountname, domainid, zoneid, vmname=None):
6249+
def createVMFromBackup(cls, apiclient, services, mode, backupid, accountname, domainid, zoneid, vmname=None, networkids=None, templateid=None):
62506250
"""Create new VM from backup
62516251
"""
62526252
cmd = createVMFromBackup.createVMFromBackupCmd()
@@ -6256,6 +6256,10 @@ def createVMFromBackup(cls, apiclient, services, mode, backupid, accountname, do
62566256
cmd.zoneid = zoneid
62576257
if vmname:
62586258
cmd.name = vmname
6259+
if networkids:
6260+
cmd.networkids = networkids
6261+
if templateid:
6262+
cmd.templateid = templateid
62596263
response = apiclient.createVMFromBackup(cmd)
62606264
virtual_machine = VirtualMachine(response.__dict__, [])
62616265
VirtualMachine.program_ssh_access(apiclient, services, mode, cmd.networkids, virtual_machine)
@@ -6327,6 +6331,14 @@ def delete(self, apiclient):
63276331
cmd.id = self.id
63286332
return (apiclient.deleteBackupRepository(cmd))
63296333

6334+
def update(self, apiclient, crosszoneinstancecreation):
6335+
"""Update backup repository"""
6336+
6337+
cmd = updateBackupRepository.updateBackupRepositoryCmd()
6338+
cmd.id = self.id
6339+
cmd.crosszoneinstancecreation = crosszoneinstancecreation
6340+
return (apiclient.updateBackupRepository(cmd))
6341+
63306342
def list(self, apiclient):
63316343
"""List backup repository"""
63326344

0 commit comments

Comments
 (0)