def test_04_change_offering_small(self): """Test to change service to a small capacity """ # Validate the following # 1. Log in to the Vm .We should see that the CPU and memory Info of # this Vm matches the one specified for "Small" service offering. # 2. Using listVM command verify that this Vm # has Small service offering Id. try: self.medium_virtual_machine.stop(self.apiclient) except Exception as e: self.fail("Failed to stop VM: %s" % e) cmd = changeServiceForVirtualMachine.changeServiceForVirtualMachineCmd( ) cmd.id = self.medium_virtual_machine.id cmd.serviceofferingid = self.small_offering.id self.apiclient.changeServiceForVirtualMachine(cmd) self.debug("Starting VM - ID: %s" % self.medium_virtual_machine.id) self.medium_virtual_machine.start(self.apiclient) # Ensure that VM is in running state list_vm_response = list_virtual_machines( self.apiclient, id=self.medium_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) else: raise Exception("Failed to start VM (ID: %s) after changing\ service offering" % vm.id) try: ssh = self.medium_virtual_machine.get_ssh_client() except Exception as e: self.fail("SSH Access failed for %s: %s" % (self.medium_virtual_machine.ipaddress, e)) cpuinfo = ssh.execute("cat /proc/cpuinfo") cpu_cnt = len([i for i in cpuinfo if "processor" in i]) # 'cpu MHz\t\t: 2660.499' cpu_speed = [i for i in cpuinfo if "cpu MHz" in i][0].split()[3] meminfo = ssh.execute("cat /proc/meminfo") # MemTotal: 1017464 kB total_mem = [i for i in meminfo if "MemTotal" in i][0].split()[1] self.debug("CPU count: %s, CPU Speed: %s, Mem Info: %s" % (cpu_cnt, cpu_speed, total_mem)) self.assertAlmostEqual(int(cpu_cnt), self.small_offering.cpunumber, "Check CPU Count for small offering") self.assertAlmostEqual(list_vm_response[0].cpuspeed, self.small_offering.cpuspeed, "Check CPU Speed for small offering") range = 20 if self.hypervisor.lower() == "hyperv": range = 200 # TODO: Find the memory allocated to VM on hyperv hypervisor using # powershell commands and use that value to equate instead of # manipulating range, currently we get the memory count much less # because of the UI component self.assertTrue( isAlmostEqual(int(int(total_mem) / 1024), int(self.small_offering.memory), range=range), "Check Memory(kb) for small offering") return
def test_06_disk_offering_strictness_false(self): """Test to see change service offering is possible when disk offering strictness is set to false """ # Validate the following # 1. Create service offering linked a disk offering and disk offering strictness is false # 2. Create a VM with that service offering # 3. Create another service offering with a different disk offering and disk offering strictness is false # 4. Try change service offering for VM should succeed if self.hypervisor.lower() == "lxc": self.skipTest("Skipping this test for {} due to bug CS-38153".format(self.hypervisor)) self.storeCloneValues = {} if self.hypervisor.lower() == "vmware": self.fullClone = Configurations.list(self.apiclient, name="vmware.create.full.clone") assert isinstance(self.fullClone, list), "Config list not retrieved for vmware.create.full.clone" allStoragePools = StoragePool.list( self.apiclient ) for pool in allStoragePools: self.storeCloneValues[pool.id] = Configurations.list(self.apiclient, name="vmware.create.full.clone", storageid=pool.id)[0].value.lower() self.updateVmwareCreateFullCloneSetting(False) offering_data = { 'displaytext': 'TestDiskOfferingStrictnessFalse', 'cpuspeed': 512, 'cpunumber': 2, 'name': 'TestDiskOfferingStrictnessFalse', 'memory': 1024, 'diskofferingstrictness': False } self.serviceOfferingWithDiskOfferingStrictnessFalse = ServiceOffering.create( self.apiclient, offering_data, ) self._cleanup.append(self.serviceOfferingWithDiskOfferingStrictnessFalse) self.virtual_machine_with_diskoffering_strictness_false = VirtualMachine.create( self.apiclient, self.services["small"], accountid=self.account.name, domainid=self.account.domainid, serviceofferingid=self.serviceOfferingWithDiskOfferingStrictnessFalse.id, mode=self.services["mode"] ) try: self.virtual_machine_with_diskoffering_strictness_false.stop(self.apiclient) timeout = self.services["timeout"] while True: time.sleep(self.services["sleep"]) # Ensure that VM is in stopped state list_vm_response = list_virtual_machines( self.apiclient, id=self.virtual_machine_with_diskoffering_strictness_false.id ) if isinstance(list_vm_response, list): vm = list_vm_response[0] if vm.state == 'Stopped': self.debug("VM state: %s" % vm.state) break if timeout == 0: raise Exception( "Failed to stop VM (ID: %s) in change service offering" % vm.id) timeout = timeout - 1 except Exception as e: self.fail("Failed to stop VM: %s" % e) self.disk_offering2 = DiskOffering.create( self.apiclient, self.services["disk_offering"], ) self._cleanup.append(self.disk_offering2) offering_data = { 'displaytext': 'TestDiskOfferingStrictnessFalse2', 'cpuspeed': 1000, 'cpunumber': 2, 'name': 'TestDiskOfferingStrictnessFalse2', 'memory': 1024, 'diskofferingstrictness': False, 'diskofferingid': self.disk_offering2.id } self.serviceOfferingWithDiskOfferingStrictnessFalse2 = ServiceOffering.create( self.apiclient, offering_data, ) self._cleanup.append(self.serviceOfferingWithDiskOfferingStrictnessFalse2) cmd = changeServiceForVirtualMachine.changeServiceForVirtualMachineCmd() cmd.id = self.virtual_machine_with_diskoffering_strictness_false.id cmd.serviceofferingid = self.serviceOfferingWithDiskOfferingStrictnessFalse2.id self.apiclient.changeServiceForVirtualMachine(cmd) list_vm_response = VirtualMachine.list( self.apiclient, id=self.virtual_machine_with_diskoffering_strictness_false.id ) vm_response = list_vm_response[0] self.assertEqual( vm_response.id, self.virtual_machine_with_diskoffering_strictness_false.id, "Check virtual machine ID of upgraded VM" ) self.assertEqual( vm_response.serviceofferingid, self.serviceOfferingWithDiskOfferingStrictnessFalse2.id, "Check service offering of the VM" ) if self.hypervisor.lower() == "vmware": self.updateVmwareCreateFullCloneSetting(True) return
def test_04_change_offering_small(self): """Test to change service to a small capacity """ # Validate the following # 1. Log in to the Vm .We should see that the CPU and memory Info of # this Vm matches the one specified for "Small" service offering. # 2. Using listVM command verify that this Vm # has Small service offering Id. if self.hypervisor.lower() == "lxc": self.skipTest("Skipping this test for {} due to bug CS-38153".format(self.hypervisor)) try: self.medium_virtual_machine.stop(self.apiclient) except Exception as e: self.fail("Failed to stop VM: %s" % e) cmd = changeServiceForVirtualMachine.changeServiceForVirtualMachineCmd() cmd.id = self.medium_virtual_machine.id cmd.serviceofferingid = self.small_offering.id self.apiclient.changeServiceForVirtualMachine(cmd) self.debug("Starting VM - ID: %s" % self.medium_virtual_machine.id) self.medium_virtual_machine.start(self.apiclient) # Ensure that VM is in running state list_vm_response = list_virtual_machines( self.apiclient, id=self.medium_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) else: raise Exception( "Failed to start VM (ID: %s) after changing\ service offering" % vm.id) try: ssh = self.medium_virtual_machine.get_ssh_client() except Exception as e: self.fail( "SSH Access failed for %s: %s" % (self.medium_virtual_machine.ipaddress, e) ) cpuinfo = ssh.execute("cat /proc/cpuinfo") cpu_cnt = len([i for i in cpuinfo if "processor" in i]) # 'cpu MHz\t\t: 2660.499' cpu_speed = [i for i in cpuinfo if "cpu MHz" in i][0].split()[3] meminfo = ssh.execute("cat /proc/meminfo") # MemTotal: 1017464 kB total_mem = [i for i in meminfo if "MemTotal" in i][0].split()[1] self.debug( "CPU count: %s, CPU Speed: %s, Mem Info: %s" % ( cpu_cnt, cpu_speed, total_mem )) self.assertAlmostEqual( int(cpu_cnt), self.small_offering.cpunumber, "Check CPU Count for small offering" ) self.assertAlmostEqual( list_vm_response[0].cpuspeed, self.small_offering.cpuspeed, "Check CPU Speed for small offering" ) range = 20 if self.hypervisor.lower() == "hyperv": range = 200 # TODO: Find the memory allocated to VM on hyperv hypervisor using # powershell commands and use that value to equate instead of # manipulating range, currently we get the memory count much less # because of the UI component self.assertTrue( isAlmostEqual(int(int(total_mem) / 1024), int(self.small_offering.memory), range=range ), "Check Memory(kb) for small offering" ) return
def test_05_disk_offering_strictness_true(self): """Test to see change service offering is not possible when disk offering strictness is set to true """ # Validate the following # 1. Create service offering linked a disk offering and disk offering strictness is true # 2. Create a VM with that service offering # 3. Create another service offering with a different disk offering # 4. Try change service offering for VM and it will fail since disk offering strictness is true (not allowed to change the disk offering) if self.hypervisor.lower() == "lxc": self.skipTest("Skipping this test for {} due to bug CS-38153".format(self.hypervisor)) offering_data = { 'displaytext': 'TestDiskOfferingStrictnessTrue', 'cpuspeed': 512, 'cpunumber': 2, 'name': 'TestDiskOfferingStrictnessTrue', 'memory': 1024, 'diskofferingstrictness': True } self.serviceOfferingWithDiskOfferingStrictnessTrue = ServiceOffering.create( self.apiclient, offering_data, ) self._cleanup.append(self.serviceOfferingWithDiskOfferingStrictnessTrue) self.virtual_machine_with_diskoffering_strictness_true = VirtualMachine.create( self.apiclient, self.services["small"], accountid=self.account.name, domainid=self.account.domainid, serviceofferingid=self.serviceOfferingWithDiskOfferingStrictnessTrue.id, mode=self.services["mode"] ) try: self.virtual_machine_with_diskoffering_strictness_true.stop(self.apiclient) timeout = self.services["timeout"] while True: time.sleep(self.services["sleep"]) # Ensure that VM is in stopped state list_vm_response = list_virtual_machines( self.apiclient, id=self.virtual_machine_with_diskoffering_strictness_true.id ) if isinstance(list_vm_response, list): vm = list_vm_response[0] if vm.state == 'Stopped': self.debug("VM state: %s" % vm.state) break if timeout == 0: raise Exception( "Failed to stop VM (ID: %s) in change service offering" % vm.id) timeout = timeout - 1 except Exception as e: self.fail("Failed to stop VM: %s" % e) offering_data = { 'displaytext': 'TestDiskOfferingStrictnessTrue2', 'cpuspeed': 1000, 'cpunumber': 2, 'name': 'TestDiskOfferingStrictnessTrue2', 'memory': 1024, 'diskofferingstrictness': True } self.serviceOfferingWithDiskOfferingStrictnessTrue2 = ServiceOffering.create( self.apiclient, offering_data, ) self._cleanup.append(self.serviceOfferingWithDiskOfferingStrictnessTrue2) cmd = changeServiceForVirtualMachine.changeServiceForVirtualMachineCmd() cmd.id = self.virtual_machine_with_diskoffering_strictness_true.id cmd.serviceofferingid = self.serviceOfferingWithDiskOfferingStrictnessTrue2.id with self.assertRaises(Exception) as e: self.apiclient.changeServiceForVirtualMachine(cmd) self.debug("Upgrade VM with new service offering having different disk offering operation failed as expected with exception: %s" % e.exception) return
def test_04_change_offering_small(self): """Test to change service to a small capacity """ # Validate the following # 1. Log in to the Vm .We should see that the CPU and memory Info of # this Vm matches the one specified for "Small" service offering. # 2. Using listVM command verify that this Vm # has Small service offering Id. self.debug("Stopping VM - ID: %s" % self.medium_virtual_machine.id) self.medium_virtual_machine.stop(self.apiclient) # Ensure that VM is in stopped state list_vm_response = list_virtual_machines( self.apiclient, id=self.medium_virtual_machine.id ) if isinstance(list_vm_response, list): vm = list_vm_response[0] if vm.state == 'Stopped': self.debug("VM state: %s" % vm.state) else: raise Exception( "Failed to stop VM (ID: %s) in change service offering" % vm.id) self.debug("Change Service offering VM - ID: %s" % self.medium_virtual_machine.id) cmd = changeServiceForVirtualMachine.changeServiceForVirtualMachineCmd() cmd.id = self.medium_virtual_machine.id cmd.serviceofferingid = self.small_offering.id self.apiclient.changeServiceForVirtualMachine(cmd) self.debug("Starting VM - ID: %s" % self.medium_virtual_machine.id) self.medium_virtual_machine.start(self.apiclient) # Ensure that VM is in running state list_vm_response = list_virtual_machines( self.apiclient, id=self.medium_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) else: raise Exception( "Failed to start VM (ID: %s) after changing service offering" % vm.id) try: ssh = self.medium_virtual_machine.get_ssh_client() except Exception as e: self.fail( "SSH Access failed for %s: %s" %\ (self.medium_virtual_machine.ipaddress, e) ) cpuinfo = ssh.execute("cat /proc/cpuinfo") cpu_cnt = len([i for i in cpuinfo if "processor" in i]) #'cpu MHz\t\t: 2660.499' cpu_speed = [i for i in cpuinfo if "cpu MHz" in i][0].split()[3] meminfo = ssh.execute("cat /proc/meminfo") #MemTotal: 1017464 kB total_mem = [i for i in meminfo if "MemTotal" in i][0].split()[1] self.debug( "CPU count: %s, CPU Speed: %s, Mem Info: %s" % ( cpu_cnt, cpu_speed, total_mem )) self.assertAlmostEqual( int(cpu_cnt), self.small_offering.cpunumber, "Check CPU Count for small offering" ) self.assertAlmostEqual( list_vm_response[0].cpuspeed, self.small_offering.cpuspeed, "Check CPU Speed for small offering" ) self.assertTrue( isAlmostEqual(int(int(total_mem) / 1024), int(self.small_offering.memory), range=20 ), "Check Memory(kb) for small offering" ) return