def _perform_add_remove_host(self, primary_storage_id, sr_name): xen_sr = self.xen_session.xenapi.SR.get_by_name_label(sr_name)[0] pbds = self.xen_session.xenapi.SR.get_PBDs(xen_sr) self._verify_all_pbds_attached(pbds) num_pbds = len(pbds) sf_vag_id = self._get_sf_vag_id(self.cluster.id, primary_storage_id) host_iscsi_iqns = self._get_host_iscsi_iqns() sf_vag = self._get_sf_vag(sf_vag_id) sf_vag_initiators = self._get_sf_vag_initiators(sf_vag) self._verifyVag(host_iscsi_iqns, sf_vag_initiators) sf_vag_initiators_len_orig = len(sf_vag_initiators) xen_session = XenAPI.Session(self.testdata[TestData.urlOfNewHost]) xenserver = self.testdata[TestData.xenServer] xen_session.xenapi.login_with_password(xenserver[TestData.username], xenserver[TestData.password]) xen_session.xenapi.pool.join(self.xs_pool_master_ip, xenserver[TestData.username], xenserver[TestData.password]) time.sleep(60) pbds = self.xen_session.xenapi.SR.get_PBDs(xen_sr) self.assertEqual(len(pbds), num_pbds + 1, "'len(pbds)' is not equal to 'num_pbds + 1'.") num_pbds = num_pbds + 1 num_pbds_not_attached = 0 for pbd in pbds: pbd_record = self.xen_session.xenapi.PBD.get_record(pbd) if pbd_record["currently_attached"] == False: num_pbds_not_attached = num_pbds_not_attached + 1 self.assertEqual(num_pbds_not_attached, 1, "'num_pbds_not_attached' is not equal to 1.") host = Host.create(self.apiClient, self.cluster, self.testdata[TestData.newHost], hypervisor="XenServer") self.assertTrue(isinstance(host, Host), "'host' is not a 'Host'.") pbds = self.xen_session.xenapi.SR.get_PBDs(xen_sr) self.assertEqual(len(pbds), num_pbds, "'len(pbds)' is not equal to 'num_pbds'.") self._verify_all_pbds_attached(pbds) host_iscsi_iqns = self._get_host_iscsi_iqns() sf_vag = self._get_sf_vag(sf_vag_id) sf_vag_initiators = self._get_sf_vag_initiators(sf_vag) self._verifyVag(host_iscsi_iqns, sf_vag_initiators) sf_vag_initiators_len_new = len(sf_vag_initiators) self.assertEqual( sf_vag_initiators_len_new, sf_vag_initiators_len_orig + 1, "sf_vag_initiators_len_new' != sf_vag_initiators_len_orig + 1") host.delete(self.apiClient) pbds = self.xen_session.xenapi.SR.get_PBDs(xen_sr) self.assertEqual(len(pbds), num_pbds, "'len(pbds)' is not equal to 'num_pbds'.") self._verify_all_pbds_attached(pbds) host_iscsi_iqns = self._get_host_iscsi_iqns() sf_vag = self._get_sf_vag(sf_vag_id) sf_vag_initiators = self._get_sf_vag_initiators(sf_vag) self.assertEqual( len(host_iscsi_iqns) - 1, len(sf_vag_initiators), "'len(host_iscsi_iqns) - 1' is not equal to 'len(sf_vag_initiators)'." ) host_ref = self.xen_session.xenapi.host.get_by_name_label( self.testdata[TestData.newHostDisplayName])[0] self.xen_session.xenapi.pool.eject(host_ref) time.sleep(120) pbds = self.xen_session.xenapi.SR.get_PBDs(xen_sr) self.assertEqual(len(pbds), num_pbds - 1, "'len(pbds)' is not equal to 'num_pbds - 1'.") self._verify_all_pbds_attached(pbds) host_iscsi_iqns = self._get_host_iscsi_iqns() sf_vag = self._get_sf_vag(sf_vag_id) sf_vag_initiators = self._get_sf_vag_initiators(sf_vag) self._verifyVag(host_iscsi_iqns, sf_vag_initiators) sf_vag_initiators_len_new = len(sf_vag_initiators) self.assertEqual( sf_vag_initiators_len_new, sf_vag_initiators_len_orig, "sf_vag_initiators_len_new' != sf_vag_initiators_len_orig")
def _perform_add_remove_kvm_host(self, primary_storage_id): sf_vag_id = self._get_sf_vag_id(self.cluster.id, primary_storage_id) kvm_login = self.testdata[TestData.kvm] kvm_hosts = [] kvm_hosts.append(TestData.kvm_1_ip_address) host_iscsi_iqns = self._get_kvm_host_iscsi_iqns(kvm_hosts, kvm_login[TestData.username], kvm_login[TestData.password]) sf_vag = self._get_sf_vag(sf_vag_id) sf_vag_initiators = self._get_sf_vag_initiators(sf_vag) self._verifyVag(host_iscsi_iqns, sf_vag_initiators) sf_vag_initiators_len_orig = len(sf_vag_initiators) host = Host.create( self.apiClient, self.cluster, self.testdata[TestData.newKvmHost], hypervisor="KVM" ) self.assertTrue( isinstance(host, Host), "'host' is not a 'Host'." ) kvm_hosts = [] kvm_hosts.append(TestData.kvm_1_ip_address) kvm_hosts.append(TestData.ip_address_of_new_kvm_host) host_iscsi_iqns = self._get_kvm_host_iscsi_iqns(kvm_hosts, kvm_login[TestData.username], kvm_login[TestData.password]) sf_vag = self._get_sf_vag(sf_vag_id) sf_vag_initiators = self._get_sf_vag_initiators(sf_vag) self._verifyVag(host_iscsi_iqns, sf_vag_initiators) sf_vag_initiators_len_new = len(sf_vag_initiators) self.assertEqual( sf_vag_initiators_len_new, sf_vag_initiators_len_orig + 1, "sf_vag_initiators_len_new' != sf_vag_initiators_len_orig + 1" ) host.delete(self.apiClient) kvm_hosts = [] kvm_hosts.append(TestData.kvm_1_ip_address) host_iscsi_iqns = self._get_kvm_host_iscsi_iqns(kvm_hosts, kvm_login[TestData.username], kvm_login[TestData.password]) sf_vag = self._get_sf_vag(sf_vag_id) sf_vag_initiators = self._get_sf_vag_initiators(sf_vag) self._verifyVag(host_iscsi_iqns, sf_vag_initiators) sf_vag_initiators_len_new = len(sf_vag_initiators) self.assertEqual( sf_vag_initiators_len_new, sf_vag_initiators_len_orig, "sf_vag_initiators_len_new' != sf_vag_initiators_len_orig" )
def _perform_add_remove_xenserver_host(self, primary_storage_id, sr_name): xen_sr = self.xen_session.xenapi.SR.get_by_name_label(sr_name)[0] pbds = self.xen_session.xenapi.SR.get_PBDs(xen_sr) self._verify_all_pbds_attached(pbds) num_pbds = len(pbds) sf_vag_id = self._get_sf_vag_id(self.cluster.id, primary_storage_id) host_iscsi_iqns = self._get_xenserver_host_iscsi_iqns() sf_vag = self._get_sf_vag(sf_vag_id) sf_vag_initiators = self._get_sf_vag_initiators(sf_vag) self._verifyVag(host_iscsi_iqns, sf_vag_initiators) sf_vag_initiators_len_orig = len(sf_vag_initiators) xen_session = XenAPI.Session("https://" + TestData.ip_address_of_new_xenserver_host) xenserver = self.testdata[TestData.xenServer] xen_session.xenapi.login_with_password(xenserver[TestData.username], xenserver[TestData.password]) xen_session.xenapi.pool.join(self.xs_pool_master_ip, xenserver[TestData.username], xenserver[TestData.password]) time.sleep(60) pbds = self.xen_session.xenapi.SR.get_PBDs(xen_sr) self.assertEqual( len(pbds), num_pbds + 1, "'len(pbds)' is not equal to 'num_pbds + 1'." ) num_pbds = num_pbds + 1 num_pbds_not_attached = 0 for pbd in pbds: pbd_record = self.xen_session.xenapi.PBD.get_record(pbd) if pbd_record["currently_attached"] == False: num_pbds_not_attached = num_pbds_not_attached + 1 self.assertEqual( num_pbds_not_attached, 1, "'num_pbds_not_attached' is not equal to 1." ) host = Host.create( self.apiClient, self.cluster, self.testdata[TestData.newXenServerHost], hypervisor="XenServer" ) self.assertTrue( isinstance(host, Host), "'host' is not a 'Host'." ) pbds = self.xen_session.xenapi.SR.get_PBDs(xen_sr) self.assertEqual( len(pbds), num_pbds, "'len(pbds)' is not equal to 'num_pbds'." ) self._verify_all_pbds_attached(pbds) host_iscsi_iqns = self._get_xenserver_host_iscsi_iqns() sf_vag = self._get_sf_vag(sf_vag_id) sf_vag_initiators = self._get_sf_vag_initiators(sf_vag) self._verifyVag(host_iscsi_iqns, sf_vag_initiators) sf_vag_initiators_len_new = len(sf_vag_initiators) self.assertEqual( sf_vag_initiators_len_new, sf_vag_initiators_len_orig + 1, "sf_vag_initiators_len_new' != sf_vag_initiators_len_orig + 1" ) host.delete(self.apiClient) pbds = self.xen_session.xenapi.SR.get_PBDs(xen_sr) self.assertEqual( len(pbds), num_pbds, "'len(pbds)' is not equal to 'num_pbds'." ) self._verify_all_pbds_attached(pbds) host_iscsi_iqns = self._get_xenserver_host_iscsi_iqns() sf_vag = self._get_sf_vag(sf_vag_id) sf_vag_initiators = self._get_sf_vag_initiators(sf_vag) self.assertEqual( len(host_iscsi_iqns) - 1, len(sf_vag_initiators), "'len(host_iscsi_iqns) - 1' is not equal to 'len(sf_vag_initiators)'." ) host_ref = self.xen_session.xenapi.host.get_by_name_label(self.testdata[TestData.newHostDisplayName])[0] self.xen_session.xenapi.pool.eject(host_ref) time.sleep(120) pbds = self.xen_session.xenapi.SR.get_PBDs(xen_sr) self.assertEqual( len(pbds), num_pbds - 1, "'len(pbds)' is not equal to 'num_pbds - 1'." ) self._verify_all_pbds_attached(pbds) host_iscsi_iqns = self._get_xenserver_host_iscsi_iqns() sf_vag = self._get_sf_vag(sf_vag_id) sf_vag_initiators = self._get_sf_vag_initiators(sf_vag) self._verifyVag(host_iscsi_iqns, sf_vag_initiators) sf_vag_initiators_len_new = len(sf_vag_initiators) self.assertEqual( sf_vag_initiators_len_new, sf_vag_initiators_len_orig, "sf_vag_initiators_len_new' != sf_vag_initiators_len_orig" )
def _perform_add_remove_kvm_host(self, primary_storage_id): sf_vag_id = sf_util.get_vag_id(self.cs_api, self.cluster.id, primary_storage_id, self) kvm_login = self.testdata[TestData.kvm] kvm_hosts = [] kvm_hosts.append(TestData.kvm_1_ip_address) host_iscsi_iqns = self._get_kvm_host_iscsi_iqns( kvm_hosts, kvm_login[TestData.username], kvm_login[TestData.password]) sf_vag = self._get_sf_vag(sf_vag_id) sf_vag_initiators = self._get_sf_vag_initiators(sf_vag) self._verifyVag(host_iscsi_iqns, sf_vag_initiators) sf_vag_initiators_len_orig = len(sf_vag_initiators) host = Host.create(self.apiClient, self.cluster, self.testdata[TestData.newKvmHost], hypervisor="KVM") self.assertTrue(isinstance(host, Host), "'host' is not a 'Host'.") kvm_hosts = [] kvm_hosts.append(TestData.kvm_1_ip_address) kvm_hosts.append(TestData.ip_address_of_new_kvm_host) host_iscsi_iqns = self._get_kvm_host_iscsi_iqns( kvm_hosts, kvm_login[TestData.username], kvm_login[TestData.password]) sf_vag = self._get_sf_vag(sf_vag_id) sf_vag_initiators = self._get_sf_vag_initiators(sf_vag) self._verifyVag(host_iscsi_iqns, sf_vag_initiators) sf_vag_initiators_len_new = len(sf_vag_initiators) self.assertEqual( sf_vag_initiators_len_new, sf_vag_initiators_len_orig + 1, "sf_vag_initiators_len_new' != sf_vag_initiators_len_orig + 1") host.delete(self.apiClient) kvm_hosts = [] kvm_hosts.append(TestData.kvm_1_ip_address) host_iscsi_iqns = self._get_kvm_host_iscsi_iqns( kvm_hosts, kvm_login[TestData.username], kvm_login[TestData.password]) sf_vag = self._get_sf_vag(sf_vag_id) sf_vag_initiators = self._get_sf_vag_initiators(sf_vag) self._verifyVag(host_iscsi_iqns, sf_vag_initiators) sf_vag_initiators_len_new = len(sf_vag_initiators) self.assertEqual( sf_vag_initiators_len_new, sf_vag_initiators_len_orig, "sf_vag_initiators_len_new' != sf_vag_initiators_len_orig")
def test_vag_per_host_5(self): hosts = list_hosts(self.apiClient, clusterid=self.cluster.id) self.assertTrue( len(hosts) >= 2, "There needs to be at least two hosts.") unique_vag_ids = self._get_unique_vag_ids(hosts) self.assertTrue( len(hosts) == len(unique_vag_ids), "To run this test, each host should be in its own VAG.") primarystorage = self.testdata[TestData.primaryStorage] primary_storage = StoragePool.create( self.apiClient, primarystorage, scope=primarystorage[TestData.scope], zoneid=self.zone.id, provider=primarystorage[TestData.provider], tags=primarystorage[TestData.tags], capacityiops=primarystorage[TestData.capacityIops], capacitybytes=primarystorage[TestData.capacityBytes], hypervisor=primarystorage[TestData.hypervisor]) self.cleanup.append(primary_storage) self.virtual_machine = VirtualMachine.create( self.apiClient, self.testdata[TestData.virtualMachine], accountid=self.account.name, zoneid=self.zone.id, serviceofferingid=self.compute_offering.id, templateid=self.template.id, domainid=self.domain.id, startvm=True) root_volume = self._get_root_volume(self.virtual_machine) sf_account_id = sf_util.get_sf_account_id( self.cs_api, self.account.id, primary_storage.id, self, TestAddRemoveHosts._sf_account_id_should_be_non_zero_int_err_msg) sf_volumes = sf_util.get_active_sf_volumes(self.sfe, sf_account_id) sf_volume = sf_util.check_and_get_sf_volume(sf_volumes, root_volume.name, self) sf_vag_ids = sf_util.get_vag_ids(self.cs_api, self.cluster.id, primary_storage.id, self) sf_util.check_vags(sf_volume, sf_vag_ids, self) host = Host(hosts[0].__dict__) host_iqn = self._get_host_iqn(host) all_vags = sf_util.get_all_vags(self.sfe) host_vag = self._get_host_vag(host_iqn, all_vags) self.assertTrue(host_vag != None, "The host should be in a VAG.") host.delete(self.apiClient) sf_volumes = sf_util.get_active_sf_volumes(self.sfe, sf_account_id) sf_volume = sf_util.check_and_get_sf_volume(sf_volumes, root_volume.name, self) sf_util.check_vags(sf_volume, sf_vag_ids, self) all_vags = sf_util.get_all_vags(self.sfe) host_vag = self._get_host_vag(host_iqn, all_vags) self.assertTrue(host_vag == None, "The host should not be in a VAG.") details = { TestData.username: "******", TestData.password: "******", TestData.url: "http://" + host.ipaddress, TestData.podId: host.podid, TestData.zoneId: host.zoneid } host = Host.create(self.apiClient, self.cluster, details, hypervisor=host.hypervisor) self.assertTrue(isinstance(host, Host), "'host' is not a 'Host'.") hosts = list_hosts(self.apiClient, clusterid=self.cluster.id) unique_vag_ids = self._get_unique_vag_ids(hosts) self.assertTrue( len(hosts) == len(unique_vag_ids) + 1, "There should be one more host than unique VAG.")
def test_vag_per_host_5(self): hosts = list_hosts(self.apiClient, clusterid=self.cluster.id) self.assertTrue( len(hosts) >= 2, "There needs to be at least two hosts." ) unique_vag_ids = self._get_unique_vag_ids(hosts) self.assertTrue(len(hosts) == len(unique_vag_ids), "To run this test, each host should be in its own VAG.") primarystorage = self.testdata[TestData.primaryStorage] primary_storage = StoragePool.create( self.apiClient, primarystorage, scope=primarystorage[TestData.scope], zoneid=self.zone.id, provider=primarystorage[TestData.provider], tags=primarystorage[TestData.tags], capacityiops=primarystorage[TestData.capacityIops], capacitybytes=primarystorage[TestData.capacityBytes], hypervisor=primarystorage[TestData.hypervisor] ) self.cleanup.append(primary_storage) self.virtual_machine = VirtualMachine.create( self.apiClient, self.testdata[TestData.virtualMachine], accountid=self.account.name, zoneid=self.zone.id, serviceofferingid=self.compute_offering.id, templateid=self.template.id, domainid=self.domain.id, startvm=True ) root_volume = self._get_root_volume(self.virtual_machine) sf_account_id = sf_util.get_sf_account_id(self.cs_api, self.account.id, primary_storage.id, self, TestAddRemoveHosts._sf_account_id_should_be_non_zero_int_err_msg) sf_volumes = sf_util.get_active_sf_volumes(self.sfe, sf_account_id) sf_volume = sf_util.check_and_get_sf_volume(sf_volumes, root_volume.name, self) sf_vag_ids = sf_util.get_vag_ids(self.cs_api, self.cluster.id, primary_storage.id, self) sf_util.check_vags(sf_volume, sf_vag_ids, self) host = Host(hosts[0].__dict__) host_iqn = self._get_host_iqn(host) all_vags = sf_util.get_all_vags(self.sfe) host_vag = self._get_host_vag(host_iqn, all_vags) self.assertTrue(host_vag != None, "The host should be in a VAG.") host.delete(self.apiClient) sf_volumes = sf_util.get_active_sf_volumes(self.sfe, sf_account_id) sf_volume = sf_util.check_and_get_sf_volume(sf_volumes, root_volume.name, self) sf_util.check_vags(sf_volume, sf_vag_ids, self) all_vags = sf_util.get_all_vags(self.sfe) host_vag = self._get_host_vag(host_iqn, all_vags) self.assertTrue(host_vag == None, "The host should not be in a VAG.") details = { TestData.username: "******", TestData.password: "******", TestData.url: "http://" + host.ipaddress, TestData.podId : host.podid, TestData.zoneId: host.zoneid } host = Host.create( self.apiClient, self.cluster, details, hypervisor=host.hypervisor ) self.assertTrue( isinstance(host, Host), "'host' is not a 'Host'." ) hosts = list_hosts(self.apiClient, clusterid=self.cluster.id) unique_vag_ids = self._get_unique_vag_ids(hosts) self.assertTrue(len(hosts) == len(unique_vag_ids) + 1, "There should be one more host than unique VAG.")