def test_04_reoccuring_snapshot_rules(self): """ 1) Create a VM using the Service offering IsVolatile enabled 2) Apply a recurring snapshot rule on the Volume. 3) After a couple of snapshots are taken reboot the VM. Verify the following conditions 1) New root disk should be formed 2) The recurring snapshot rule should be deleted """ vms = VirtualMachine.list(self.apiclient, id=self.vm_with_reset.id, listall=True) vm_list_validation_result = validateList(vms) self.assertEqual( vm_list_validation_result[0], PASS, "vm list validation failed due to %s" % vm_list_validation_result[2]) vm_with_reset = vm_list_validation_result[1] vm_with_reset_root_disk_id = self.get_root_device_uuid_for_vm( vm_with_reset.id, vm_with_reset.rootdeviceid) now = datetime.now() delta = timedelta(minutes=15) scheduled_time = now + delta self.services["recurring_snapshot"]["schedule"] = scheduled_time.minute self.debug( "Creating recurring snapshot policy for root disk on vm created with IsVolatile=True" ) self.debug("Snapshot Policy - Type : %s Scheduled minute : %s" % (self.services["recurring_snapshot"]["intervaltype"], self.services["recurring_snapshot"]["schedule"])) recurring_snapshot = SnapshotPolicy.create( self.apiclient, vm_with_reset_root_disk_id, self.services["recurring_snapshot"]) #ListSnapshotPolicy should return newly created policy list_snapshots_policy = SnapshotPolicy.list( self.apiclient, id=recurring_snapshot.id, volumeid=vm_with_reset_root_disk_id) snapshot_list_validation_result = validateList(list_snapshots_policy) self.assertEqual( snapshot_list_validation_result[0], PASS, "snapshot list validation failed due to %s" % snapshot_list_validation_result[2]) snapshots_policy = snapshot_list_validation_result[1] self.assertEqual(snapshots_policy.id, recurring_snapshot.id, "Check recurring snapshot id in list resources call") self.assertEqual(snapshots_policy.maxsnaps, self.services["recurring_snapshot"]["maxsnaps"], "Check interval type in list resources call") sleep_seconds = delta.seconds + 600 sleep_minutes = sleep_seconds / 60 self.debug("Sleeping for %s minutes till the volume is snapshoted" % sleep_minutes) time.sleep(sleep_seconds) retriesCount = self.services["retriesCount"] while True: snapshots = Snapshot.list( self.apiclient, volumeid=vm_with_reset_root_disk_id, intervaltype=\ self.services["recurring_snapshot"]["intervaltype"], snapshottype=RECURRING, listall=True ) snapshot_list_validation_result = validateList(snapshots) if snapshot_list_validation_result[0] == PASS: break elif retriesCount == 0: self.fail("Failed to get snapshots list") time.sleep(60) retriesCount = retriesCount - 1 # rebooting the vm with isVolatile = True try: self.vm_with_reset.reboot(self.apiclient) except Exception as e: self.fail("Failed to reboot the virtual machine. Error: %s" % e) # Check if the the root disk was destroyed and recreated for isVolatile=True self.debug( "Checking whether root disk of VM with isVolatile=True was destroyed" ) vms = VirtualMachine.list(self.apiclient, id=self.vm_with_reset.id, listall=True) vm_list_validation_result = validateList(vms) self.assertEqual( vm_list_validation_result[0], PASS, "list validation failed due to %s" % vm_list_validation_result[2]) vm_with_reset_after_reboot = vm_list_validation_result[1] vm_with_reset_root_disk_id_after_reboot = self.get_root_device_uuid_for_vm( vm_with_reset_after_reboot.id, vm_with_reset_after_reboot.rootdeviceid) self.assertNotEqual( vm_with_reset_root_disk_id, vm_with_reset_root_disk_id_after_reboot, "VM created with IsVolatile=True has same rootdeviceid : %s after reboot" % vm_with_reset_root_disk_id_after_reboot) # Make sure it has the same IP after reboot self.assertEqual( vm_with_reset.nic[0].ipaddress, vm_with_reset_after_reboot.nic[0].ipaddress, "VM created with IsVolatile=True doesn't have same ip after reboot. Got : %s Expected : %s" % (vm_with_reset_after_reboot.nic[0].ipaddress, vm_with_reset.nic[0].ipaddress)) # Check whether the recurring policy has been deleted from the database self.debug( "Checking whether snapshot rule for VM with isVolatile=True was destroyed \ Here we are passing root disk id of vm before reboot which does not exist hence\ listing should fail") with self.assertRaises(Exception): list_snapshots_policy = SnapshotPolicy.list( self.apiclient, volumeid=vm_with_reset_root_disk_id) return
def test_01_snapshot_on_rootVolume(self): """Test create VM with default cent os template and create snapshot on root disk of the vm """ # Validate the following # 1. Deploy a Linux VM using default CentOS template, use small service # offering, disk offering # 2. Create snapshot on the root disk of this newly cteated vm # 3. listSnapshots should list the snapshot that was created. # 4. verify that secondary storage NFS share contains the reqd # volume under /secondary/snapshots/$accountid/$volumeid/$snapshot_uuid # 5. verify backup_snap_id was non null in the `snapshots` table # Create virtual machine with small systerm offering and disk offering new_virtual_machine = VirtualMachine.create( self.apiclient, self.services["virtual_machine"], templateid=self.template.id, zoneid=self.zone.id, accountid=self.account.name, domainid=self.account.domainid, serviceofferingid=self.service_offering.id, diskofferingid=self.disk_offering.id, ) self.debug("Virtual machine got created with id: %s" % new_virtual_machine.id) list_virtual_machine_response = VirtualMachine.list( self.apiclient, id=new_virtual_machine.id) self.assertEqual(isinstance(list_virtual_machine_response, list), True, "Check listVirtualMachines returns a valid list") self.assertNotEqual(len(list_virtual_machine_response), 0, "Check listVirtualMachines response") self.cleanup.append(new_virtual_machine) # Getting root volume id of the vm created above list_volume_response = Volume.list( self.apiclient, virtualmachineid=list_virtual_machine_response[0].id, type="ROOT", account=self.account.name, domainid=self.account.domainid) self.assertEqual(isinstance(list_volume_response, list), True, "Check listVolumes returns a valid list") self.assertNotEqual(len(list_volume_response), 0, "Check listVolumes response") self.debug( "Snapshot will be created on the volume with voluem id: %s" % list_volume_response[0].id) # Perform snapshot on the root volume root_volume_snapshot = Snapshot.create( self.apiclient, volume_id=list_volume_response[0].id) self.debug( "Created snapshot: %s for vm: %s" % (root_volume_snapshot.id, list_virtual_machine_response[0].id)) list_snapshot_response = Snapshot.list(self.apiclient, id=root_volume_snapshot.id, account=self.account.name, domainid=self.account.domainid) self.assertEqual(isinstance(list_snapshot_response, list), True, "Check listSnapshots returns a valid list") self.assertNotEqual(len(list_snapshot_response), 0, "Check listSnapshots response") # Verify Snapshot state self.assertEqual( list_snapshot_response[0].state in ['BackedUp', 'CreatedOnPrimary'], True, "Snapshot state is not as expected. It is %s" % list_snapshot_response[0].state) self.assertEqual( list_snapshot_response[0].volumeid, list_volume_response[0].id, "Snapshot volume id is not matching with the vm's volume id") self.cleanup.append(root_volume_snapshot) # Below code is to verify snapshots in the backend and in db. # Verify backup_snap_id field in the snapshots table for the snapshot created, it should not be null self.debug( "select id, removed, backup_snap_id from snapshots where uuid = '%s';" % root_volume_snapshot.id) qryresult = self.dbclient.execute( "select id, removed, backup_snap_id from snapshots where uuid = '%s';" % root_volume_snapshot.id) self.assertNotEqual(len(qryresult), 0, "Check sql query to return snapshots list") snapshot_qry_response = qryresult[0] snapshot_id = snapshot_qry_response[0] is_removed = snapshot_qry_response[1] backup_snap_id = snapshot_qry_response[2] self.assertNotEqual( is_removed, "NULL", "Snapshot is removed from CS, please check the logs") msg = "Backup snapshot id is set to null for the backedup snapshot :%s" % snapshot_id self.assertNotEqual(backup_snap_id, "NULL", msg) # Check if the snapshot is present on the secondary storage self.assertTrue( is_snapshot_on_nfs(self.apiclient, self.dbclient, self.config, self.zone.id, root_volume_snapshot.id)) return
def test_01_snapshot_on_rootVolume(self): """Test create VM with default cent os template and create snapshot on root disk of the vm """ # Validate the following # 1. Deploy a Linux VM using default CentOS template, use small service # offering, disk offering # 2. Create snapshot on the root disk of this newly cteated vm # 3. listSnapshots should list the snapshot that was created. # 4. verify that secondary storage NFS share contains the reqd # volume under /secondary/snapshots/$accountid/$volumeid/$snapshot_uuid # 5. verify backup_snap_id was non null in the `snapshots` table # Create virtual machine with small systerm offering and disk offering new_virtual_machine = VirtualMachine.create( self.apiclient, self.services["virtual_machine"], templateid=self.template.id, zoneid=self.zone.id, accountid=self.account.name, domainid=self.account.domainid, serviceofferingid=self.service_offering.id, diskofferingid=self.disk_offering.id, ) self.debug("Virtual machine got created with id: %s" % new_virtual_machine.id) list_virtual_machine_response = VirtualMachine.list( self.apiclient, id=new_virtual_machine.id) self.assertEqual(isinstance(list_virtual_machine_response, list), True, "Check listVirtualMachines returns a valid list") self.assertNotEqual(len(list_virtual_machine_response), 0, "Check listVirtualMachines response") self.cleanup.append(new_virtual_machine) # Getting root volume id of the vm created above list_volume_response = Volume.list( self.apiclient, virtualmachineid=list_virtual_machine_response[0].id, type="ROOT", account=self.account.name, domainid=self.account.domainid) self.assertEqual(isinstance(list_volume_response, list), True, "Check listVolumes returns a valid list") self.assertNotEqual(len(list_volume_response), 0, "Check listVolumes response") self.debug( "Snapshot will be created on the volume with voluem id: %s" % list_volume_response[0].id) # Perform snapshot on the root volume root_volume_snapshot = Snapshot.create( self.apiclient, volume_id=list_volume_response[0].id) self.debug("Created snapshot: %s for vm: %s" % ( root_volume_snapshot.id, list_virtual_machine_response[0].id)) list_snapshot_response = Snapshot.list( self.apiclient, id=root_volume_snapshot.id, account=self.account.name, domainid=self.account.domainid) self.assertEqual(isinstance(list_snapshot_response, list), True, "Check listSnapshots returns a valid list") self.assertNotEqual(len(list_snapshot_response), 0, "Check listSnapshots response") # Verify Snapshot state self.assertEqual( list_snapshot_response[0].state in [ 'BackedUp', 'CreatedOnPrimary' ], True, "Snapshot state is not as expected. It is %s" % list_snapshot_response[0].state ) self.assertEqual( list_snapshot_response[0].volumeid, list_volume_response[0].id, "Snapshot volume id is not matching with the vm's volume id") self.cleanup.append(root_volume_snapshot) # Below code is to verify snapshots in the backend and in db. # Verify backup_snap_id field in the snapshots table for the snapshot created, it should not be null self.debug("select id, removed, backup_snap_id from snapshots where uuid = '%s';" % root_volume_snapshot.id) qryresult = self.dbclient.execute("select id, removed, backup_snap_id from snapshots where uuid = '%s';" % root_volume_snapshot.id) self.assertNotEqual(len(qryresult), 0, "Check sql query to return snapshots list") snapshot_qry_response = qryresult[0] snapshot_id = snapshot_qry_response[0] is_removed = snapshot_qry_response[1] backup_snap_id = snapshot_qry_response[2] self.assertNotEqual(is_removed, "NULL", "Snapshot is removed from CS, please check the logs") msg = "Backup snapshot id is set to null for the backedup snapshot :%s" % snapshot_id self.assertNotEqual(backup_snap_id, "NULL", msg ) # Check if the snapshot is present on the secondary storage self.assertTrue(is_snapshot_on_nfs(self.apiclient, self.dbclient, self.config, self.zone.id, root_volume_snapshot.id)) return
def test_04_reoccuring_snapshot_rules(self): """ 1) Create a VM using the Service offering IsVolatile enabled 2) Apply a recurring snapshot rule on the Volume. 3) After a couple of snapshots are taken reboot the VM. Verify the following conditions 1) New root disk should be formed 2) The recurring snapshot rule should be deleted """ vms = VirtualMachine.list(self.apiclient, id=self.vm_with_reset.id, listall=True) vm_list_validation_result = validateList(vms) self.assertEqual( vm_list_validation_result[0], PASS, "vm list validation failed due to %s" % vm_list_validation_result[2] ) vm_with_reset = vm_list_validation_result[1] vm_with_reset_root_disk_id = self.get_root_device_uuid_for_vm(vm_with_reset.id, vm_with_reset.rootdeviceid) self.debug("Creating recurring snapshot policy for root disk on vm created with IsVolatile=True") self.debug( "Snapshot Policy - Type : %s Scheduled Hours : %s" % (self.services["recurring_snapshot"]["intervaltype"], self.services["recurring_snapshot"]["schedule"]) ) recurring_snapshot = SnapshotPolicy.create( self.apiclient, vm_with_reset_root_disk_id, self.services["recurring_snapshot"] ) # ListSnapshotPolicy should return newly created policy list_snapshots_policy = SnapshotPolicy.list( self.apiclient, id=recurring_snapshot.id, volumeid=vm_with_reset_root_disk_id ) snapshot_list_validation_result = validateList(list_snapshots_policy) self.assertEqual( snapshot_list_validation_result[0], PASS, "snapshot list validation failed due to %s" % snapshot_list_validation_result[2], ) snapshots_policy = snapshot_list_validation_result[1] self.assertEqual( snapshots_policy.id, recurring_snapshot.id, "Check recurring snapshot id in list resources call" ) self.assertEqual( snapshots_policy.maxsnaps, self.services["recurring_snapshot"]["maxsnaps"], "Check interval type in list resources call", ) sleep_seconds = (self.services["recurring_snapshot"]["schedule"]) * 3600 + 600 sleep_minutes = sleep_seconds / 60 self.debug("Sleeping for %s minutes till the volume is snapshoted" % sleep_minutes) time.sleep(sleep_seconds) retriesCount = self.services["retriesCount"] while True: snapshots = Snapshot.list( self.apiclient, volumeid=vm_with_reset_root_disk_id, intervaltype=self.services["recurring_snapshot"]["intervaltype"], snapshottype=RECURRING, listall=True, ) snapshot_list_validation_result = validateList(snapshots) if snapshot_list_validation_result[0] == PASS: break elif retriesCount == 0: self.fail("Failed to get snapshots list") time.sleep(60) retriesCount = retriesCount - 1 # rebooting the vm with isVolatile = True try: self.vm_with_reset.reboot(self.apiclient) except Exception as e: self.fail("Failed to reboot the virtual machine. Error: %s" % e) # Check if the the root disk was destroyed and recreated for isVolatile=True self.debug("Checking whether root disk of VM with isVolatile=True was destroyed") vms = VirtualMachine.list(self.apiclient, id=self.vm_with_reset.id, listall=True) vm_list_validation_result = validateList(vms) self.assertEqual( vm_list_validation_result[0], PASS, "list validation failed due to %s" % vm_list_validation_result[2] ) vm_with_reset_after_reboot = vm_list_validation_result[1] vm_with_reset_root_disk_id_after_reboot = self.get_root_device_uuid_for_vm( vm_with_reset_after_reboot.id, vm_with_reset_after_reboot.rootdeviceid ) self.assertNotEqual( vm_with_reset_root_disk_id, vm_with_reset_root_disk_id_after_reboot, "VM created with IsVolatile=True has same rootdeviceid : %s after reboot" % vm_with_reset_root_disk_id_after_reboot, ) # Make sure it has the same IP after reboot self.assertEqual( vm_with_reset.nic[0].ipaddress, vm_with_reset_after_reboot.nic[0].ipaddress, "VM created with IsVolatile=True doesn't have same ip after reboot. Got : %s Expected : %s" % (vm_with_reset_after_reboot.nic[0].ipaddress, vm_with_reset.nic[0].ipaddress), ) # Check whether the recurring policy has been deleted from the database self.debug( "Checking whether snapshot rule for VM with isVolatile=True was destroyed \ Here we are passing root disk id of vm before reboot which does not exist hence\ listing should fail" ) with self.assertRaises(Exception): list_snapshots_policy = SnapshotPolicy.list(self.apiclient, volumeid=vm_with_reset_root_disk_id) return