def checkCPUAndMemory(self, ssh, service_offering): 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), service_offering.cpunumber, "Check CPU Count for service offering" ) range = 40 if self.hypervisor.lower() == "hyperv": range = 200 self.assertTrue( isAlmostEqual(int(int(total_mem) / 1024), int(service_offering.memory), range=range ), "Check Memory(kb) for service offering" )
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_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_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