def create_vm(self, account, domain, isRunning=False, project =None, limit =None, pfrule =False, lbrule =None, natrule =None, volume =None, snapshot =False): #TODO: Implemnt pfrule/lbrule/natrule self.debug("Deploying instance in the account: %s" % account.name) self.virtual_machine = VirtualMachine.create(self.apiclient, self.services["virtual_machine"], accountid=account.name, domainid=domain.id, serviceofferingid=self.service_offering.id, mode=self.zone.networktype if pfrule else 'basic', projectid=project.id if project else None) self.debug("Deployed instance in account: %s" % account.name) list_virtual_machines(self.apiclient, id=self.virtual_machine.id) if snapshot: volumes = list_volumes(self.apiclient, virtualmachineid=self.virtual_machine.id, type='ROOT', listall=True) self.snapshot = Snapshot.create(self.apiclient, volumes[0].id, account=account.name, domainid=account.domainid) if volume: self.virtual_machine.attach_volume(self.apiclient, volume) if not isRunning: self.virtual_machine.stop(self.apiclient) self.cleanup.append(self.virtual_machine)
def create_vm(self, account, domain, isRunning=False, project=None, limit=None, pfrule=False, lbrule=None, natrule=None, volume=None, snapshot=False): #TODO: Implemnt pfrule/lbrule/natrule self.debug("Deploying instance in the account: %s" % account.name) self.virtual_machine = VirtualMachine.create( self.apiclient, self.services["virtual_machine"], accountid=account.name, domainid=domain.id, serviceofferingid=self.service_offering.id, mode=self.zone.networktype if pfrule else 'basic', projectid=project.id if project else None) self.debug("Deployed instance in account: %s" % account.name) list_virtual_machines(self.apiclient, id=self.virtual_machine.id) if snapshot: volumes = list_volumes(self.apiclient, virtualmachineid=self.virtual_machine.id, type='ROOT', listall=True) self.snapshot = Snapshot.create(self.apiclient, volumes[0].id, account=account.name, domainid=account.domainid) if volume: self.virtual_machine.attach_volume(self.apiclient, volume) if not isRunning: self.virtual_machine.stop(self.apiclient) self.cleanup.append(self.virtual_machine)
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