def test_01_create_volume(self): """Test Volume creation for all Disk Offerings (incl. custom) """ # Validate the following # 1. Create volumes from the different sizes # 2. Verify the size of volume with actual size allocated self.volumes = [] for k, v in self.services["volume_offerings"].items(): volume = Volume.create( self.apiClient, v, zoneid=self.zone.id, account=self.account.name, domainid=self.account.domainid, diskofferingid=self.disk_offering.id ) self.debug("Created a volume with ID: %s" % volume.id) self.volumes.append(volume) if self.virtual_machine.hypervisor == "KVM": sparse_volume = Volume.create( self.apiClient, self.services, zoneid=self.zone.id, account=self.account.name, domainid=self.account.domainid, diskofferingid=self.sparse_disk_offering.id ) self.debug("Created a sparse volume: %s" % sparse_volume.id) self.volumes.append(sparse_volume) volume = Volume.create_custom_disk( self.apiClient, self.services, account=self.account.name, domainid=self.account.domainid, ) self.debug("Created a volume with custom offering: %s" % volume.id) self.volumes.append(volume) #Attach a volume with different disk offerings #and check the memory allocated to each of them for volume in self.volumes: list_volume_response = Volume.list( self.apiClient, id=volume.id) self.assertEqual( isinstance(list_volume_response, list), True, "Check list response returns a valid list" ) self.assertNotEqual( list_volume_response, None, "Check if volume exists in ListVolumes" ) self.debug( "Attaching volume (ID: %s) to VM (ID: %s)" % ( volume.id, self.virtual_machine.id )) self.virtual_machine.attach_volume( self.apiClient, volume ) try: ssh = self.virtual_machine.get_ssh_client() self.debug("Rebooting VM %s" % self.virtual_machine.id) ssh.execute("reboot") except Exception as e: self.fail("SSH access failed for VM %s - %s" % (self.virtual_machine.ipaddress, e)) # Poll listVM to ensure VM is started properly timeout = self.services["timeout"] while True: time.sleep(self.services["sleep"]) # Ensure that VM is in running state list_vm_response = VirtualMachine.list( self.apiClient, id=self.virtual_machine.id ) if isinstance(list_vm_response, list): vm = list_vm_response[0] if vm.state == 'Running': self.debug("VM state: %s" % vm.state) break if timeout == 0: raise Exception( "Failed to start VM (ID: %s) " % vm.id) timeout = timeout - 1 vol_sz = str(list_volume_response[0].size) ssh = self.virtual_machine.get_ssh_client( reconnect=True ) # Get the updated volume information list_volume_response = Volume.list( self.apiClient, id=volume.id) if list_volume_response[0].hypervisor.lower() == XEN_SERVER.lower(): volume_name = "/dev/xvd" + chr(ord('a') + int(list_volume_response[0].deviceid)) self.debug(" Using XenServer volume_name: %s" % (volume_name)) ret = checkVolumeSize(ssh_handle=ssh,volume_name=volume_name,size_to_verify=vol_sz) else: ret = checkVolumeSize(ssh_handle=ssh,size_to_verify=vol_sz) self.debug(" Volume Size Expected %s Actual :%s" %(vol_sz,ret[1])) self.virtual_machine.detach_volume(self.apiClient, volume) self.assertEqual(ret[0],SUCCESS,"Check if promised disk size actually available") time.sleep(self.services["sleep"])
def test_01_create_volume(self): """Test Volume creation for all Disk Offerings (incl. custom) """ # Validate the following # 1. Create volumes from the different sizes # 2. Verify the size of volume with actual size allocated self.volumes = [] for k, v in self.services["volume_offerings"].items(): volume = Volume.create(self.apiClient, v, zoneid=self.zone.id, account=self.account.name, domainid=self.account.domainid, diskofferingid=self.disk_offering.id) self.debug("Created a volume with ID: %s" % volume.id) self.volumes.append(volume) if self.virtual_machine.hypervisor == "KVM": sparse_volume = Volume.create( self.apiClient, self.services, zoneid=self.zone.id, account=self.account.name, domainid=self.account.domainid, diskofferingid=self.sparse_disk_offering.id) self.debug("Created a sparse volume: %s" % sparse_volume.id) self.volumes.append(sparse_volume) volume = Volume.create_custom_disk( self.apiClient, self.services, account=self.account.name, domainid=self.account.domainid, ) self.debug("Created a volume with custom offering: %s" % volume.id) self.volumes.append(volume) # Attach a volume with different disk offerings # and check the memory allocated to each of them for volume in self.volumes: list_volume_response = Volume.list(self.apiClient, id=volume.id) self.assertEqual(isinstance(list_volume_response, list), True, "Check list response returns a valid list") self.assertNotEqual(list_volume_response, None, "Check if volume exists in ListVolumes") self.debug("Attaching volume (ID: %s) to VM (ID: %s)" % (volume.id, self.virtual_machine.id)) self.virtual_machine.attach_volume(self.apiClient, volume) try: ssh = self.virtual_machine.get_ssh_client() self.debug("Rebooting VM %s" % self.virtual_machine.id) ssh.execute("reboot") except Exception as e: self.fail("SSH access failed for VM %s - %s" % (self.virtual_machine.ipaddress, e)) # Poll listVM to ensure VM is started properly timeout = self.services["timeout"] while True: time.sleep(self.services["sleep"]) # Ensure that VM is in running state list_vm_response = VirtualMachine.list( self.apiClient, id=self.virtual_machine.id) if isinstance(list_vm_response, list): vm = list_vm_response[0] if vm.state == 'Running': self.debug("VM state: %s" % vm.state) break if timeout == 0: raise Exception("Failed to start VM (ID: %s) " % vm.id) timeout = timeout - 1 vol_sz = str(list_volume_response[0].size) ssh = self.virtual_machine.get_ssh_client(reconnect=True) # Get the updated volume information list_volume_response = Volume.list(self.apiClient, id=volume.id) if list_volume_response[0].hypervisor.lower() == XEN_SERVER.lower( ): volume_name = "/dev/xvd" + chr( ord('a') + int(list_volume_response[0].deviceid)) self.debug(" Using XenServer volume_name: %s" % (volume_name)) ret = checkVolumeSize(ssh_handle=ssh, volume_name=volume_name, size_to_verify=vol_sz) elif list_volume_response[0].hypervisor.lower() == "kvm": volume_name = "/dev/vd" + chr( ord('a') + int(list_volume_response[0].deviceid)) self.debug(" Using KVM volume_name: %s" % (volume_name)) ret = checkVolumeSize(ssh_handle=ssh, volume_name=volume_name, size_to_verify=vol_sz) else: ret = checkVolumeSize(ssh_handle=ssh, size_to_verify=vol_sz) self.debug(" Volume Size Expected %s Actual :%s" % (vol_sz, ret[1])) self.virtual_machine.detach_volume(self.apiClient, volume) self.assertEqual(ret[0], SUCCESS, "Check if promised disk size actually available") time.sleep(self.services["sleep"])
def test_5_vmdeployment_with_size(self): """Test vm deployment with new rootdisk size parameter # Validate the following # 1. Deploy a VM without any disk offering (only root disk) # 2. Verify the root disksize after deployment """ templateSize = (self.template.size / (1024 ** 3)) newsize = templateSize + 2 # deploy a vm try: if self.updateclone: self.virtual_machine = VirtualMachine.create( self.apiclient, self.services["virtual_machine"], accountid=self.parentd_admin.name, domainid=self.parent_domain.id, serviceofferingid=self.services_offering_vmware.id, mode=self.zone.networktype ) else: self.virtual_machine = VirtualMachine.create( self.apiclient, self.services["virtual_machine"], accountid=self.parentd_admin.name, domainid=self.parent_domain.id, serviceofferingid=self.service_offering.id, mode=self.zone.networktype ) # listVirtual macine list_vms = VirtualMachine.list(self.apiclient, id=self.virtual_machine.id) self.debug( "Verify listVirtualMachines response for virtual machine: %s" % self.virtual_machine.id ) res = validateList(list_vms) self.assertNotEqual(res[2], INVALID_INPUT, "Invalid list response") self.cleanup.append(self.virtual_machine) vm = list_vms[0] ssh = SshClient(self.virtual_machine.ssh_ip, 22, "root", "password") newsize = newsize * 1024 * 1024 * 1024 list_volume_response = Volume.list( self.apiclient, virtualmachineid= self.virtual_machine.id, type='ROOT', listall='True' ) res = validateList(list_volume_response) self.assertNotEqual(res[2], INVALID_INPUT, "listVolumes returned invalid object in response") if vm.hypervisor.lower() == "xenserver": volume_name = "/dev/xvd" + chr(ord('a') + int( list_volume_response[0].deviceid)) self.debug(" Using XenServer" " volume_name: %s" % volume_name) ret = checkVolumeSize(ssh_handle=ssh, volume_name=volume_name, size_to_verify=newsize) elif vm.hypervisor.lower() == "kvm": volume_name = "/dev/vd" + chr(ord('a') + int( list_volume_response[0].deviceid)) self.debug(" Using KVM volume_name: %s" % volume_name) ret = checkVolumeSize(ssh_handle=ssh, volume_name=volume_name, size_to_verify=newsize) elif vm.hypervisor.lower() == "vmware": ret = checkVolumeSize(ssh_handle=ssh, volume_name="/dev/sdb", size_to_verify=newsize) self.debug(" Volume Size Expected %s" " Actual :%s" % (newsize, ret[1])) except Exception as e: raise Exception("Warning: Exception during" " VM deployment with new" " rootdisk paramter : %s" % e)
def chk_volume_resize(self, apiclient, vm): self.assertEqual( vm.state, "Running", msg="VM is not in Running state" ) # get root vol from created vm, verify its size list_volume_response = Volume.list( apiclient, virtualmachineid=vm.id, type='ROOT', listall='True' ) rootvolume = list_volume_response[0] if vm.state == "Running" and \ (vm.hypervisor.lower() == "xenserver" or \ vm.hypervisor.lower() == "vmware"): self.virtual_machine.stop(apiclient) time.sleep(self.services["sleep"]) if vm.hypervisor.lower() == "vmware": rootdiskcontroller = self.getDiskController(vm) if rootdiskcontroller!="scsi": raise Exception("root volume resize only supported on scsi disk ," "please check rootdiskcontroller type") rootvolobj = Volume(rootvolume.__dict__) newsize = (rootvolume.size >> 30) + 2 success = False if rootvolume is not None: try: rootvolobj.resize(apiclient, size=newsize) if vm.hypervisor.lower() == "xenserver" or \ vm.hypervisor.lower() == "vmware": self.virtual_machine.start(apiclient) time.sleep(self.services["sleep"]) ssh = SshClient(self.virtual_machine.ssh_ip, 22, "root", "password") newsizeinbytes = newsize * 1024 * 1024 * 1024 if vm.hypervisor.lower() == "xenserver": volume_name = "/dev/xvd" + \ chr(ord('a') + int( list_volume_response[0].deviceid)) self.debug(" Using XenServer" " volume_name: %s" % volume_name) ret = checkVolumeSize(ssh_handle=ssh, volume_name=volume_name, size_to_verify=newsizeinbytes) success = True elif vm.hypervisor.lower() == "kvm": volume_name = "/dev/vd" + chr(ord('a') + int (list_volume_response[0] .deviceid)) self.debug(" Using KVM volume_name:" " %s" % volume_name) ret = checkVolumeSize(ssh_handle=ssh, volume_name=volume_name, size_to_verify=newsizeinbytes) success = True elif vm.hypervisor.lower() == "vmware": ret = checkVolumeSize(ssh_handle=ssh, volume_name="/dev/sdb", size_to_verify=newsizeinbytes) success = True self.debug(" Volume Size Expected %s " " Actual :%s" % (newsizeinbytes, ret[1])) except Exception as e: # need to write the rootdisk controller code. if vm.hypervisor == "vmware" and rootdiskcontroller == "ide": assert "Found unsupported root disk " \ "controller :ide" in e.message, \ "able to resize ide root volume Testcase failed" else: raise Exception("fail to resize the volume: %s" % e) else: self.debug("hypervisor %s unsupported for test " ", verifying it errors properly" % self.hypervisor) success = False return success
def test_05_vmdeployment_with_size(self): """Test vm deployment with new rootdisk size parameter # Validate the following # 1. Deploy a VM without any disk offering (only root disk) # 2. Verify the root disksize after deployment """ templateSize = (self.template.size / (1024**3)) newsize = templateSize + 2 # deploy a vm try: if self.updateclone: self.virtual_machine = VirtualMachine.create( self.apiclient, self.services["virtual_machine"], accountid=self.parentd_admin.name, domainid=self.parent_domain.id, serviceofferingid=self.services_offering_vmware.id, mode=self.zone.networktype) else: self.virtual_machine = VirtualMachine.create( self.apiclient, self.services["virtual_machine"], accountid=self.parentd_admin.name, domainid=self.parent_domain.id, serviceofferingid=self.service_offering.id, mode=self.zone.networktype) # listVirtual macine list_vms = VirtualMachine.list(self.apiclient, id=self.virtual_machine.id) self.debug( "Verify listVirtualMachines response for virtual machine: %s" % self.virtual_machine.id) res = validateList(list_vms) self.assertNotEqual(res[2], INVALID_INPUT, "Invalid list response") self.cleanup.append(self.virtual_machine) vm = list_vms[0] ssh = SshClient(self.virtual_machine.ssh_ip, 22, "root", "password") newsize = newsize * 1024 * 1024 * 1024 list_volume_response = Volume.list( self.apiclient, virtualmachineid=self.virtual_machine.id, type='ROOT', listall='True') res = validateList(list_volume_response) self.assertNotEqual( res[2], INVALID_INPUT, "listVolumes returned invalid object in response") if vm.hypervisor.lower() == "xenserver": volume_name = "/dev/xvd" + chr( ord('a') + int(list_volume_response[0].deviceid)) self.debug(" Using XenServer" " volume_name: %s" % volume_name) ret = checkVolumeSize(ssh_handle=ssh, volume_name=volume_name, size_to_verify=newsize) elif vm.hypervisor.lower() == "kvm": volume_name = "/dev/vd" + chr( ord('a') + int(list_volume_response[0].deviceid)) self.debug(" Using KVM volume_name: %s" % volume_name) ret = checkVolumeSize(ssh_handle=ssh, volume_name=volume_name, size_to_verify=newsize) elif vm.hypervisor.lower() == "vmware": ret = checkVolumeSize(ssh_handle=ssh, volume_name="/dev/sdb", size_to_verify=newsize) self.debug(" Volume Size Expected %s" " Actual :%s" % (newsize, ret[1])) except Exception as e: raise Exception("Warning: Exception during" " VM deployment with new" " rootdisk parameter : %s" % e)
def chk_volume_resize(self, apiclient, vm): self.assertEqual(vm.state, "Running", msg="VM is not in Running state") # get root vol from created vm, verify its size list_volume_response = Volume.list(apiclient, virtualmachineid=vm.id, type='ROOT', listall='True') rootvolume = list_volume_response[0] if vm.state == "Running" and vm.hypervisor.lower() == "xenserver": self.virtual_machine.stop(apiclient) time.sleep(self.services["sleep"]) if vm.hypervisor.lower() == "vmware": rootdiskcontroller = self.getDiskController(vm) if rootdiskcontroller != "scsi": raise Exception( "root volume resize only supported on scsi disk ," "please check rootdiskcontroller type") rootvolobj = Volume(rootvolume.__dict__) newsize = (rootvolume.size >> 30) + 2 success = False if rootvolume is not None: try: rootvolobj.resize(apiclient, size=newsize) if vm.hypervisor.lower() == "xenserver": self.virtual_machine.start(apiclient) time.sleep(self.services["sleep"]) ssh = SshClient(self.virtual_machine.ssh_ip, 22, "root", "password") newsizeinbytes = newsize * 1024 * 1024 * 1024 if vm.hypervisor.lower() == "xenserver": volume_name = "/dev/xvd" + \ chr(ord('a') + int( list_volume_response[0].deviceid)) self.debug(" Using XenServer" " volume_name: %s" % volume_name) ret = checkVolumeSize(ssh_handle=ssh, volume_name=volume_name, size_to_verify=newsizeinbytes) success = True elif vm.hypervisor.lower() == "kvm": volume_name = "/dev/vd" + chr( ord('a') + int(list_volume_response[0].deviceid)) self.debug(" Using KVM volume_name:" " %s" % volume_name) ret = checkVolumeSize(ssh_handle=ssh, volume_name=volume_name, size_to_verify=newsizeinbytes) success = True elif vm.hypervisor.lower() == "vmware": ret = checkVolumeSize(ssh_handle=ssh, volume_name="/dev/sdb", size_to_verify=newsizeinbytes) success = True self.debug(" Volume Size Expected %s " " Actual :%s" % (newsizeinbytes, ret[1])) except Exception as e: # need to write the rootdisk controller code. if vm.hypervisor == "vmware" and rootdiskcontroller == "ide": assert "Found unsupported root disk " \ "controller :ide" in e.message, \ "able to resize ide root volume Testcase failed" else: raise Exception("fail to resize the volume: %s" % e) else: self.debug("hypervisor %s unsupported for test " ", verifying it errors properly" % self.hypervisor) success = False return success