def test_05_deploy_vm_with_extraconfig_vmware(self): ''' Test that extra config is added on VMware hosts ''' hypervisor = self.hypervisor.lower() if hypervisor != 'vmware': raise self.skipTest("Skipping test case for non-vmware hypervisor") name = 'allow.additional.vm.configuration.list.vmware' value = 'hypervisor.cpuid.v0' add_config_response = self.add_global_config(name, value) if add_config_response.name: ''' The following extra configuration is used to set Hyper-V instance to run on ESXi host hypervisor.cpuid.v0 = FALSE ''' extraconfig = 'hypervisor.cpuid.v0%3DFALSE' try: response = self.deploy_vm(hypervisor, extraconfig) host_id = response.hostid host = list_hosts(self.apiclient, id=host_id) instance_name = response.instancename host_ipaddress = host[0].ipaddress ssh_client = SshClient(host_ipaddress, port=22, user=self.hostConfig['username'], passwd=self.hostConfig['password']) extraconfig_decoded = urllib.parse.unquote(extraconfig) config_arr = extraconfig_decoded.splitlines() for config in config_arr: vmx_config = self.prepare_vmware_config(config) vmx_file_name = "\"$(esxcli vm process list | grep %s | tail -1 | awk '{print $3}')\"" % instance_name # parse vm instance vmx file to see if extraconfig has been added grep_config = "cat %s | grep -w '%s'" % (vmx_file_name, vmx_config) result = ssh_client.execute(grep_config) # Match exact configuration from vmx file, return empty result array if configuration is not found self.assertNotEqual( 0, len(result), 'Extra configuration not found in instance vmx file') finally: self.destroy_vm(response.id) self.add_global_config(name, "")
def test_deploy_vgpu_enabled_vm(self): """Test Deploy Virtual Machine # Validate the following: # 1. Virtual Machine is accessible via SSH # 2. Virtual Machine is vGPU enabled (via SSH) # 3. listVirtualMachines returns accurate information """ self.virtual_machine = VirtualMachine.create( self.apiclient, self.testdata["small"], accountid=self.account.name, domainid=self.account.domainid, serviceofferingid=self.service_offering.id, mode=self.testdata['mode']) list_vms = VirtualMachine.list(self.apiclient, id=self.virtual_machine.id) self.debug( "Verify listVirtualMachines response for virtual machine: %s" % self.virtual_machine.id) self.assertEqual(isinstance(list_vms, list), True, "List VM response was not a valid list") self.assertNotEqual(len(list_vms), 0, "List VM response was empty") vm = list_vms[0] self.assertEqual(vm.id, self.virtual_machine.id, "Virtual Machine ids do not match") self.assertEqual(vm.name, self.virtual_machine.name, "Virtual Machine names do not match") self.assertEqual(vm.state, "Running", msg="VM is not in Running state") hosts = list_hosts(self.apiclient, id=vm.hostid) hostip = hosts[0].ipaddress try: sshClient = SshClient( host=hostip, port=self.testdata['configurableData']['host']["publicport"], user=self.testdata['configurableData']['host']["username"], passwd=self.testdata['configurableData']['host']["password"]) res = sshClient.execute( "xe vgpu-list vm-name-label=%s params=type-uuid %s" % (vm.instancename)) self.debug("SSH result: %s" % res) except Exception as e: self.fail("SSH Access failed for %s: %s" % (hostip, e)) result = str(res) self.assertEqual(result.count("type-uuid"), 1, "VM is vGPU enabled.")
def _get_source_and_dest_hosts(self): hosts = list_hosts(self.apiClient) for host in hosts: if host.name == "XenServer-6.5-1": src_host = host elif host.name == "XenServer-6.5-3": dest_host = host self.assertIsNotNone(src_host, "Could not locate the source host") self.assertIsNotNone(dest_host, "Could not locate the destination host") return src_host, dest_host
def get_host_details(self, router, username='******', password='******', port=22): hosts = list_hosts(self.apiclient, id=router.hostid, type="Routing") self.assertEqual(isinstance(hosts, list), True, "Check for list hosts response return valid data") host = hosts[0] host.user = username host.passwd = password host.port = port return host
def _get_source_and_dest_hosts(self): hosts = list_hosts(self.apiClient) for host in hosts: if host.name == TestData.xen_server_hostname_src: src_host = host elif host.name == TestData.xen_server_hostname_dest: dest_host = host self.assertIsNotNone(src_host, "Could not locate the source host") self.assertIsNotNone(dest_host, "Could not locate the destination host") return src_host, dest_host
def test_07_reboot_ssvm(self): """Test reboot SSVM """ # Validate the following # 1. The SSVM should go to stop and return to Running state # 2. SSVM's public-ip and private-ip must remain the same # before and after reboot # 3. The cloud process should still be running within the SSVM list_ssvm_response = list_ssvms(self.apiclient, systemvmtype='secondarystoragevm', state='Running', zoneid=self.zone.id) self.assertEqual(isinstance(list_ssvm_response, list), True, "Check list response returns a valid list") ssvm_response = list_ssvm_response[0] hosts = list_hosts(self.apiclient, id=ssvm_response.hostid) self.assertEqual(isinstance(hosts, list), True, "Check list response returns a valid list") # Store the public & private IP values before reboot old_public_ip = ssvm_response.publicip old_private_ip = ssvm_response.privateip self.debug("Rebooting SSVM: %s" % ssvm_response.id) cmd = rebootSystemVm.rebootSystemVmCmd() cmd.id = ssvm_response.id self.apiclient.rebootSystemVm(cmd) ssvm_response = self.checkForRunningSystemVM(ssvm_response) self.debug("SSVM State: %s" % ssvm_response.state) self.assertEqual('Running', str(ssvm_response.state), "Check whether CPVM is running or not") self.assertEqual( ssvm_response.publicip, old_public_ip, "Check Public IP after reboot with that of before reboot") # Private IP Address of System VMs are allowed to change after reboot - CLOUDSTACK-7745 # Wait for the agent to be up self.waitForSystemVMAgent(ssvm_response.name) # Call to verify cloud process is running self.test_03_ssvm_internals()
def setUpClass(self): testClient = super(TestDeployvGPUenabledVM, self).getClsTestClient() self.apiclient = testClient.getApiClient() self.testdata = self.testClient.getParsedTestDataConfig() # Need to add check whether zone containing the xen hypervisor or not # as well hosts = list_hosts( self.apiclient, hypervisor="XenServer" ) if hosts is None: raise unittest.SkipTest( "There are no XenServers available. GPU feature is supported only on XenServer.Check listhosts response") else: gpuhosts = 0 for ghost in hosts: if ghost.hypervisorversion >= "6.2.0": sshClient = SshClient( host=ghost.ipaddress, port=self.testdata['configurableData']['host']["publicport"], user=self.testdata['configurableData']['host']["username"], passwd=self.testdata['configurableData']['host']["password"]) if ghost.hypervisorversion == "6.2.0": res = sshClient.execute( "xe patch-list uuid=0850b186-4d47-11e3-a720-001b2151a503") if len(res) == 0: continue res = sshClient.execute( "xe vgpu-type-list model-name=\"GRID K120Q\"") if len(res) != 0: gpuhosts = gpuhosts + 1 else: continue if gpuhosts == 0: raise unittest.SkipTest( "No XenServer available with GPU Drivers installed") self.domain = get_domain(self.apiclient) self.zone = get_zone(self.apiclient, self.testClient.getZoneForTests()) # Creating Account self.account = Account.create( self.apiclient, self.testdata["account"], domainid=self.domain.id ) self._cleanup = [ self.account ]
def wait_for_system_vm_agent(self, vmname): self.logger.debug("Waiting for system VM %s agent to be UP" % vmname) timeout = self.services["timeout"] sleep_interval = self.services["sleep"] while timeout > 0: list_host_response = list_hosts(self.apiclient, name=vmname) if list_host_response and list_host_response[0].state == 'Up': self.debug("System VM %s agent is UP" % vmname) break time.sleep(sleep_interval) timeout = timeout - sleep_interval if timeout <= 0 and list_host_response[0].state != 'Up': self.fail("Timed out waiting for SVM agent to be Up")
def setUpClass(cls): cls.testClient = super(TestL2PersistentNetworks, cls).getClsTestClient() cls.api_client = cls.testClient.getApiClient() cls.hypervisor = cls.testClient.getHypervisorInfo() isKVM = cls.hypervisor.lower() in ["kvm"] isOVSEnabled = False hostConfig = cls.config.__dict__["zones"][0].__dict__["pods"][0].__dict__["clusters"][0].__dict__["hosts"][0].__dict__ if isKVM : # Test only if all the hosts use OVS grepCmd = 'grep "network.bridge.type=openvswitch" /etc/cloudstack/agent/agent.properties' hosts = list_hosts(cls.api_client, type='Routing', hypervisor='kvm') for host in hosts : if len(SshClient(host.ipaddress, port=22, user=hostConfig["username"], passwd=hostConfig["password"]).execute(grepCmd)) != 0 : isOVSEnabled = True break if isKVM and isOVSEnabled : cls.skipTest(cls, "KVM with OVS doesn't support persistent networks, skipping") # Fill services from the external config file cls.services = cls.testClient.getParsedTestDataConfig() cls.hostConfig = cls.config.__dict__["zones"][0].__dict__["pods"][0].__dict__["clusters"][0].__dict__["hosts"][ 0].__dict__ # Get Zone and templates cls.zone = get_zone(cls.api_client, cls.testClient.getZoneForTests()) cls.template = get_template( cls.api_client, cls.zone.id, cls.services["ostype"] ) cls.services["virtual_machine"]["zoneid"] = cls.zone.id cls.services["virtual_machine"]["template"] = cls.template.id cls.service_offering = ServiceOffering.create( cls.api_client, cls.services["service_offering"] ) cls.l2_persistent_network_offering = cls.create_network_offering("nw_off_L2_persistent") cls.isolated_persistent_network_offering = cls.create_network_offering("nw_off_isolated_persistent") # network will be deleted as part of account cleanup cls._cleanup = [ cls.service_offering, cls.isolated_persistent_network_offering, cls.l2_persistent_network_offering] return
def test_10_reboot_cpvm_forced(self): """Test force reboot CPVM """ list_cpvm_response = list_ssvms( self.apiclient, systemvmtype='consoleproxy', state='Running', zoneid=self.zone.id ) self.assertEqual( isinstance(list_cpvm_response, list), True, "Check list response returns a valid list" ) cpvm_response = list_cpvm_response[0] hosts = list_hosts( self.apiclient, id=cpvm_response.hostid ) self.assertEqual( isinstance(hosts, list), True, "Check list response returns a valid list" ) self.debug("Force rebooting CPVM: %s" % cpvm_response.id) cmd = rebootSystemVm.rebootSystemVmCmd() cmd.id = cpvm_response.id cmd.forced = True self.apiclient.rebootSystemVm(cmd) cpvm_response = self.checkForRunningSystemVM(cpvm_response) self.debug("CPVM state: %s" % cpvm_response.state) self.assertEqual( 'Running', str(cpvm_response.state), "Check whether CPVM is running or not" ) # Wait for the agent to be up self.waitForSystemVMAgent(cpvm_response.name) # Call to verify cloud process is running self.test_04_cpvm_internals()
def test_01_routervm_iptables_policies(self): """ Test iptables default INPUT/FORWARD policy on RouterVM """ self.logger.debug("Starting test_01_routervm_iptables_policies") vm1 = self.entity_manager.deployvm() routers = self.entity_manager.query_routers() self.assertEqual(isinstance(routers, list), True, "Check for list routers response return valid data") for router in routers: if not router.isredundantrouter and not router.vpcid: hosts = list_hosts(self.apiclient, id=router.hostid) self.assertEqual( isinstance(hosts, list), True, "Check for list hosts response return valid data") host = hosts[0] host.user = self.services["configurableData"]["host"][ "username"] host.passwd = self.services["configurableData"]["host"][ "password"] host.port = self.services["configurableData"]["host"]["port"] tables = [ self.services["configurableData"]["input"], self.services["configurableData"]["forward"] ] for table in tables: try: result = get_process_status(host.ipaddress, host.port, host.user, host.passwd, router.linklocalip, 'iptables -L %s' % table) except KeyError: self.skipTest("Provide a marvin config file with host\ credentials to run %s" % self._testMethodName) self.logger.debug("iptables -L %s: %s" % (table, result)) res = str(result) self.assertEqual( res.count("policy DROP"), 1, "%s Default Policy should be DROP" % table)
def test_stop_svm(self, svm_type): # Validate the following # 1. The SVM should go to stop state # 2. The SVM should be restarted and return to Running state with the checks of the previous two test cases still passing # 3. If either of the two above steps fail the test is a failure list_svm_response = list_ssvms( self.apiclient, systemvmtype=svm_type, state='Running', zoneid=self.zone.id ) self.assertEqual( isinstance(list_svm_response, list), True, "Check list response returns a valid list" ) svm = list_svm_response[0] hosts = list_hosts( self.apiclient, id=svm.hostid ) self.assertEqual( isinstance(hosts, list), True, "Check list response returns a valid list" ) self.logger.debug("Stopping System VM: %s" % svm.id) cmd = stopSystemVm.stopSystemVmCmd() cmd.id = svm.id cmd.forced = "true" self.apiclient.stopSystemVm(cmd) self.wait_for_svm_state(svm.id, 'Stopped', self.services["timeout"], self.services["sleep"]) self.logger.debug("Starting System VM: %s" % svm.id) cmd = startSystemVm.startSystemVmCmd() cmd.id = svm.id self.apiclient.startSystemVm(cmd) self.wait_for_svm_state(svm.id, 'Running', self.services["timeout"], self.services["sleep"]) self.wait_for_system_vm_agent(svm.name) return
def check_routers_state(self, count=2, status_to_check="MASTER", expected_count=1, showall=False): vals = ["MASTER", "BACKUP", "UNKNOWN"] cnts = [0, 0, 0] result = "UNKNOWN" self.query_routers(count, showall) for router in self.routers: if router.state == "Running": hosts = list_hosts( self.apiclient, zoneid=router.zoneid, type='Routing', state='Up', id=router.hostid ) self.assertEqual( isinstance(hosts, list), True, "Check list host returns a valid list" ) host = hosts[0] try: host.user, host.passwd = get_host_credentials( self.config, host.ipaddress) result = str(get_process_status( host.ipaddress, 22, host.user, host.passwd, router.linklocalip, "sh /opt/cloud/bin/checkrouter.sh " )) except KeyError: self.skipTest( "Marvin configuration has no host credentials to\ check router services") if result.count(status_to_check) == 1: cnts[vals.index(status_to_check)] += 1 if cnts[vals.index(status_to_check)] != expected_count: self.fail("Expected '%s' router[s] at state '%s', but found '%s'!" % (expected_count, status_to_check, cnts[vals.index(status_to_check)]))
def check_routers_interface(self, count=2, interface_to_check="eth1", expected_exists=True, showall=False): result = "" self.query_routers(count, showall) for router in self.routers: if router.state == "Running": hosts = list_hosts( self.apiclient, zoneid=router.zoneid, type='Routing', state='Up', id=router.hostid ) self.assertEqual( isinstance(hosts, list), True, "Check list host returns a valid list" ) host = hosts[0] try: host.user, host.passwd = get_host_credentials(self.config, host.ipaddress) result = str(get_process_status( host.ipaddress, 22, host.user, host.passwd, router.linklocalip, "ip a | grep %s | grep state | awk '{print $9;}'" % interface_to_check )) except KeyError: self.skipTest("Marvin configuration has no host credentials to check router services") if expected_exists: if (result.count("UP") == 1) or (result.count("DOWN") == 1): self.logger.debug("Expected interface '%s' to exist and it does!" % interface_to_check) else: self.fail("Expected interface '%s' to exist, but it didn't!" % interface_to_check) else: if (result.count("UP") == 1) or (result.count("DOWN") == 1): self.fail("Expected interface '%s' to not exist, but it did!" % interface_to_check) else: self.logger.debug("Expected interface '%s' to not exist, and it didn't!" % interface_to_check)
def wait_for_system_vm_agent(self, vmname): self.logger.debug("Waiting for system VM %s agent to be UP" % vmname) timeout = self.services["timeout"] sleep_interval = self.services["sleep"] while timeout > 0: list_host_response = list_hosts(self.apiclient, name=vmname) if list_host_response and list_host_response[0].state == 'Up': self.debug("System VM %s agent is UP" % vmname) break time.sleep(sleep_interval) timeout = timeout - sleep_interval if timeout <= 0 and list_host_response[0].state != 'Up': self.logger.debug( "Warning: List CPVM didn't return systemvms in Running state. This is a known issue, ignoring it for now!" ) return
def get_router_host(self, router): self.assertEqual( router.state, 'Running', "Check list router response for router state" ) hosts = list_hosts( self.apiclient, id=router.hostid) self.assertEqual( isinstance(hosts, list), True, "Check for list hosts response return valid data") host = hosts[0] if host.hypervisor.lower() not in "kvm": return host.user, host.password = get_host_credentials(self.config, host.ipaddress) host.port=22 return host
def setUpClass(self): testClient = super(TestDeployvGPUenabledVM, self).getClsTestClient() self.apiclient = testClient.getApiClient() self.testdata = self.testClient.getParsedTestDataConfig() self.hostConfig = self.config.__dict__["zones"][0].__dict__["pods"][ 0].__dict__["clusters"][0].__dict__["hosts"][0].__dict__ self._cleanup = [] self.unsupportedHypervisor = False self.noSuitableHost = False # Need to add check whether zone containing the xen hypervisor or not # as well hosts = list_hosts(self.apiclient, hypervisor="XenServer") if hosts is None: # GPU feature is supported only on XenServer.Check listhosts response self.unsupportedHypervisor = True return else: gpuhosts = 0 for ghost in hosts: if ghost.hypervisorversion >= "6.2.0": sshClient = SshClient( host=ghost.ipaddress, port=self.testdata['configurableData']['host'] ["publicport"], user=self.hostConfig['username'], passwd=self.hostConfig['password']) if ghost.hypervisorversion == "6.2.0": res = sshClient.execute( "xe patch-list uuid=0850b186-4d47-11e3-a720-001b2151a503" ) if len(res) == 0: continue res = sshClient.execute( "xe vgpu-type-list model-name=\"GRID K120Q\"") if len(res) != 0: gpuhosts = gpuhosts + 1 else: continue if gpuhosts == 0: # No XenServer available with GPU Drivers installed self.noSuitableHost = True return
def test_06_stop_cpvm(self): """Test stop CPVM """ # Validate the following # 1. The CPVM should go to stop state # 2. After a brief delay of say one minute, the SSVM should be # restarted once again and return to Running state with previous # two test cases still passing # 3. If either of the two above steps fail the test is a failure list_cpvm_response = list_ssvms(self.apiclient, systemvmtype='consoleproxy', state='Running', zoneid=self.zone.id) self.assertEqual(isinstance(list_cpvm_response, list), True, "Check list response returns a valid list") cpvm = list_cpvm_response[0] hosts = list_hosts(self.apiclient, id=cpvm.hostid) self.assertEqual(isinstance(hosts, list), True, "Check list response returns a valid list") self.debug("Stopping CPVM: %s" % cpvm.id) cmd = stopSystemVm.stopSystemVmCmd() cmd.id = cpvm.id self.apiclient.stopSystemVm(cmd) cpvm_response = self.checkForRunningSystemVM(cpvm) self.debug("CPVM state after debug: %s" % cpvm_response.state) self.assertEqual(cpvm_response.state, 'Running', "Check whether CPVM is running or not") # Wait for the agent to be up self.waitForSystemVMAgent(cpvm_response.name) # Call above tests to ensure CPVM is properly running self.test_02_list_cpvm_vm() self.test_04_cpvm_internals()
def test_04_userdata_service_on_alias_IP(self): """Deploy guest vm in new CIDR and verify userdata service on alias ip 1.Deploy guest vm in new cidr 2.Verify userdata service(apache2) listens on alias ip in VR """ list_router_response = list_routers(self.apiclient, zoneid=self.zone.id, listall=True) self.assertEqual(isinstance(list_router_response, list), True, "Check list response returns a valid list") router = list_router_response[0] hosts = list_hosts(self.apiclient, zoneid=router.zoneid, type='Routing', state='Up', id=router.hostid) self.assertEqual(isinstance(hosts, list), True, "Check list host returns a valid list") host = hosts[0] self.debug("Router ID: %s, state: %s" % (router.id, router.state)) self.assertEqual(router.state, 'Running', "Check list router response for router state") port = self.testdata['configurableData']['host']["publicport"] username = self.testdata['configurableData']['host']["username"] password = self.testdata['configurableData']['host']["password"] # SSH to host so that host key is saved in first # attempt SshClient(host.ipaddress, port, username, password) proc = "apache2" result = get_process_status(host.ipaddress, port, username, password, router.linklocalip, "netstat -atnp | grep %s" % proc) res = str(result) self.debug("userdata process status on VR: %s" % res) self.assertNotEqual( res.find(self.alias_ip + ":80 ") - 1, "password service is not running on alias ip") return
def stop_master_router(self, vpc): self.logger.debug("Stopping Master Router of VPC '%s'...", vpc.name) routers = list_routers(self.api_client, domainid=self.domain.id, account=self.account.name, vpcid=vpc.id) for router in routers: if router.redundantstate == 'MASTER': cmd = stopRouter.stopRouterCmd() cmd.id = router.id cmd.forced = 'true' self.api_client.stopRouter(cmd) break routers = list_routers(self.api_client, domainid=self.domain.id, account=self.account.name, vpcid=vpc.id) for router in routers: if router.state == 'Running': hosts = list_hosts(self.api_client, zoneid=router.zoneid, type='Routing', state='Up', id=router.hostid) self.assertTrue(isinstance(hosts, list)) host = next(iter(hosts or []), None) try: host.user, host.passwd = get_host_credentials( self.config, host.ipaddress) get_process_status( host.ipaddress, 22, host.user, host.passwd, router.linklocalip, "sh /opt/cosmic/router/scripts/checkrouter.sh ") except KeyError as e: raise Exception("Exception: %s" % e) self.logger.debug("Master Router of VPC '%s' stopped", vpc.name)
def setUpClass(cls): cls.testClient = super(TestHosts, cls).getClsTestClient() cls.testdata = cls.testClient.getParsedTestDataConfig() cls.apiclient = cls.testClient.getApiClient() cls.dbclient = cls.testClient.getDbConnection() cls._cleanup = [] #get zone, domain etc cls.zone = get_zone(cls.apiclient, cls.testClient.getZoneForTests()) cls.domain = get_domain(cls.apiclient) cls.pod = get_pod(cls.apiclient, cls.zone.id) # list hosts hosts = list_hosts(cls.apiclient) if len(hosts) > 0: cls.my_host_id = hosts[0].id cls.host_db_id = cls.dbclient.execute( "select id from host where uuid='%s';" % cls.my_host_id) cls.my_cluster_id = hosts[0].clusterid else: raise unittest.SkipTest("There is no host available in the setup")
def test_dhcphosts(self, vm, router): hosts = list_hosts(self.apiclient, id=router.hostid) self.assertEqual(isinstance(hosts, list), True, "Check for list hosts response return valid data") host = hosts[0] host.user = self.hostConfig['username'] host.passwd = self.hostConfig['password'] host.port = self.services["configurableData"]["host"]["port"] if self.hypervisor.lower() in ('vmware', 'hyperv'): result = get_process_status( self.apiclient.connection.mgtSvr, 22, self.apiclient.connection.user, self.apiclient.connection.passwd, router.linklocalip, "cat /etc/dhcphosts.txt | grep %s | sed 's/\,/ /g' | awk '{print $2}'" % (vm.nic[0].ipaddress), hypervisor=self.hypervisor) else: try: result = get_process_status( host.ipaddress, host.port, host.user, host.passwd, router.linklocalip, "cat /etc/dhcphosts.txt | grep %s | sed 's/\,/ /g' | awk '{print $2}'" % (vm.nic[0].ipaddress)) except KeyError: self.skipTest("Provide a marvin config file with host\ credentials to run %s" % self._testMethodName) self.logger.debug( "cat /etc/dhcphosts.txt | grep %s | sed 's/\,/ /g' | awk '{print $2}' RESULT IS ==> %s" % (vm.nic[0].ipaddress, result)) res = str(result) self.assertEqual( res.count(vm.nic[0].ipaddress), 1, "DHCP hosts file contains duplicate IPs ==> %s!" % res)
def _check_system_vms(self, system_vms, primary_storage_id): sf_active_volumes = sf_util.get_active_sf_volumes(self.sfe) sf_vag_id = sf_util.get_vag_id(self.cs_api, self.cluster.id, primary_storage_id, self) for system_vm in system_vms: cs_root_volume = self._get_root_volume_for_system_vm( system_vm.id, 'Ready') sf_root_volume = sf_util.check_and_get_sf_volume( sf_active_volumes, cs_root_volume.name, self) sf_volume_size = sf_util.get_volume_size_with_hsr( self.cs_api, cs_root_volume, self) sf_util.check_size_and_iops(sf_root_volume, cs_root_volume, sf_volume_size, self) self._check_iops_against_iops_of_system_offering( cs_root_volume, self.testdata[TestData.systemOffering]) sf_util.check_vag(sf_root_volume, sf_vag_id, self) if TestData.hypervisor_type == TestData.xenServer: sr_name = sf_util.format_iqn(sf_root_volume.iqn) sf_util.check_xen_sr(sr_name, self.xen_session, self) elif TestData.hypervisor_type == TestData.kvm: list_hosts_response = list_hosts(self.apiClient, type="Routing") kvm_login = self.testdata[TestData.kvm] sf_util.check_kvm_access_to_volume( sf_root_volume.iqn, list_hosts_response, kvm_login[TestData.username], kvm_login[TestData.password], self) else: self.assertTrue(False, "Invalid hypervisor type")
def setUpXenServer(cls): # Set up xenAPI connection hosts = list_hosts(cls.apiClient, clusterid=cls.testdata[TestData.clusterId]) xenserver_info = cls.testdata[TestData.xenServer] for h in hosts: host_ip = "https://" + h.ipaddress try: cls.xen_session = XenAPI.Session(host_ip) cls.xen_session.xenapi.login_with_password( xenserver_info[TestData.username], xenserver_info[TestData.password]) break except XenAPI.Failure as e: pass cls.compute_offering = ServiceOffering.create( cls.apiClient, cls.testdata[TestData.managedComputeOffering]) cls.device_name = 'xvdb'
def test_password_file_not_empty(self, vm, router): hosts = list_hosts(self.apiclient, id=router.hostid) self.assertEqual(isinstance(hosts, list), True, "Check for list hosts response return valid data") host = hosts[0] host.user = self.hostConfig['username'] host.passwd = self.hostConfig['password'] host.port = self.services["configurableData"]["host"]["port"] if self.hypervisor.lower() in ('vmware', 'hyperv'): result = get_process_status( self.apiclient.connection.mgtSvr, 22, self.apiclient.connection.user, self.apiclient.connection.passwd, router.linklocalip, "cat /var/cache/cloud/passwords-%s | grep %s | sed 's/=/ /g' | awk '{print $1}'" % (vm.nic[0].gateway, vm.nic[0].ipaddress), hypervisor=self.hypervisor) else: try: result = get_process_status( host.ipaddress, host.port, host.user, host.passwd, router.linklocalip, "cat /var/cache/cloud/passwords-%s | grep %s | sed 's/=/ /g' | awk '{print $1}'" % (vm.nic[0].gateway, vm.nic[0].ipaddress)) except KeyError: self.skipTest("Provide a marvin config file with host\ credentials to run %s" % self._testMethodName) self.logger.debug( "cat /var/cache/cloud/passwords-%s | grep %s | sed 's/=/ /g' | awk '{print $1}' RESULT IS ==> %s" % (vm.nic[0].gateway, vm.nic[0].ipaddress, result)) res = str(result) self.assertEqual(res.count(vm.nic[0].ipaddress), 1, "Password file is empty or doesn't exist!")
def test_dhcphopts(self, ipaddress, router): hosts = list_hosts(self.apiclient, id=router.hostid) self.assertEqual(isinstance(hosts, list), True, "Check for list hosts response return valid data") host = hosts[0] host.user = self.hostConfig['username'] host.passwd = self.hostConfig['password'] host.port = self.services["configurableData"]["host"]["port"] host_tag = ipaddress.replace(".", "_") if self.hypervisor.lower() in ('vmware', 'hyperv'): result = get_process_status(self.apiclient.connection.mgtSvr, 22, self.apiclient.connection.user, self.apiclient.connection.passwd, router.linklocalip, "cat /etc/dhcpopts.txt | grep %s" % (host_tag), hypervisor=self.hypervisor) else: try: result = get_process_status( host.ipaddress, host.port, host.user, host.passwd, router.linklocalip, "cat /etc/dhcpopts.txt | grep %s" % (host_tag)) except KeyError: self.skipTest("Provide a marvin config file with host\ credentials to run %s" % self._testMethodName) self.logger.debug("cat /etc/dhcpopts.txt | grep %s RESULT IS ==> %s" % (host_tag, result)) res = str(result) self.assertNotEqual( res.count(host_tag), 0, "DHCP opts file does not contain exception for IP ==> %s!" % res)
def getCommandResultFromRouter(self, router, command): """Run given command on router and return the result""" if (self.hypervisor.lower() == 'vmware' or self.hypervisor.lower() == 'hyperv'): result = get_process_status( self.apiclient.connection.mgtSvr, 22, self.apiclient.connection.user, self.apiclient.connection.passwd, router.linklocalip, command, hypervisor=self.hypervisor ) else: hosts = list_hosts( self.apiclient, id=router.hostid, ) self.assertEqual( isinstance(hosts, list), True, "Check for list hosts response return valid data" ) host = hosts[0] host.user = self.hostConfig['username'] host.passwd = self.hostConfig['password'] result = get_process_status( host.ipaddress, 22, host.user, host.passwd, router.linklocalip, command ) return result
def verify_network_rules(self, vm_id): virtual_machine = VirtualMachine.list(self.apiclient, id=vm_id) vm = virtual_machine[0] hosts = list_hosts(self.apiclient, id=vm.hostid) host = hosts[0] if host.hypervisor.lower() not in "kvm": return host.user, host.password = get_host_credentials( self.config, host.ipaddress) for nic in vm.nic: secips = "" if len(nic.secondaryip) > 0: for secip in nic.secondaryip: secips += secip.ipaddress + ";" command = "/usr/share/cloudstack-common/scripts/vm/network/security_group.py verify_network_rules --vmname %s --vmip %s --vmmac %s --nicsecips '%s'" % ( vm.instancename, nic.ipaddress, nic.macaddress, secips) self.logger.debug("Executing command '%s' in host %s" % (command, host.ipaddress)) result = execute_command_in_host(host.ipaddress, 22, host.user, host.password, command) if len(result) > 0: self.fail( "The iptables/ebtables rules for nic %s on vm %s on host %s are not correct" % (nic.ipaddress, vm.instancename, host.name))
def test_02_deploy_vm_anti_affinity_group_fail_on_not_enough_hosts(self): """ test DeployVM in anti-affinity groups with more vms than hosts. """ hosts = list_hosts(self.api_client, type="routing") aff_grp = self.create_aff_grp(self.account_api_client) vms = [] for host in hosts: vms.append( self.create_vm_in_aff_grps(self.account_api_client, ag_list=[aff_grp.name])) vm_failed = None with self.assertRaises(Exception): vm_failed = self.create_vm_in_aff_grps(self.account_api_client, ag_list=[aff_grp.name]) self.assertEqual(len(hosts), len(vms), "Received %s and %s " % (hosts, vms)) if vm_failed: vm_failed.expunge(self.api_client) self.cleanup.append(aff_grp)
def _verify_managed_system_vm_deleted(self, cs_root_volume_name): sf_not_active_volumes = sf_util.get_not_active_sf_volumes(self.sfe) sf_root_volume = sf_util.check_and_get_sf_volume(sf_not_active_volumes, cs_root_volume_name, self) self.assertEqual( len(sf_root_volume.volume_access_groups), 0, "The volume should not be in a volume access group." ) if TestData.hypervisor_type == TestData.xenServer: sr_name = sf_util.format_iqn(sf_root_volume.iqn) sf_util.check_xen_sr(sr_name, self.xen_session, self, False) elif TestData.hypervisor_type == TestData.kvm: list_hosts_response = list_hosts( self.apiClient, type="Routing" ) sf_util.check_kvm_access_to_volume(sf_root_volume.iqn, list_hosts_response, self.testdata[TestData.kvm], self, False) else: self.assertTrue(False, "Invalid hypervisor type")