def update_default_dc(api): dc_service = test_utils.data_center_service(api.system_service(), 'Default') dc_service.update( data_center=sdk4.types.DataCenter( local=True ) )
def _add_storage_domain(api, p): system_service = api.system_service() sds_service = system_service.storage_domains_service() with test_utils.TestEvent(system_service, 956): # USER_ADD_STORAGE_DOMAIN(956) sd = sds_service.add(p) sd_service = sds_service.storage_domain_service(sd.id) testlib.assert_true_within_long( lambda: sd_service.get().status == sdk4.types.StorageDomainStatus.UNATTACHED ) dc_service = test_utils.data_center_service(system_service, DC_NAME) attached_sds_service = dc_service.storage_domains_service() with test_utils.TestEvent(system_service, [966, 962]): # USER_ACTIVATED_STORAGE_DOMAIN(966) # USER_ATTACH_STORAGE_DOMAIN_TO_POOL(962) attached_sds_service.add( sdk4.types.StorageDomain( id=sd.id, ), ) attached_sd_service = attached_sds_service.storage_domain_service(sd.id) testlib.assert_true_within_long( lambda: attached_sd_service.get().status == sdk4.types.StorageDomainStatus.ACTIVE )
def deactivate_storage_domain(connection): dc = test_utils.data_center_service(connection.system_service(), DC_NAME) _get_storage_domain(dc, SD_SECOND_NFS_NAME, service=True).deactivate() testlib.assert_equals_within_short( lambda: _get_storage_domain(dc, SD_SECOND_NFS_NAME).status, ovirtsdk4.types.StorageDomainStatus.MAINTENANCE)
def get_network_attachment(engine, host, network_name, dc_name): dc = test_utils.data_center_service(engine, dc_name) # CAVEAT: .list(search='name=Migration_Network') is ignored, and the first # network returned happened to be VM_Network in my case network = next(net for net in dc.networks_service().list() if net.name == network_name) return _get_attachment_by_id(host, network.id)
def deactivate_storage_domain(connection): raise SkipTest('skipping until reattach test fixed. Jira OVIRT-2264') dc = test_utils.data_center_service(connection.system_service(), DC_NAME) _get_storage_domain(dc, SD_SECOND_NFS_NAME, service=True).deactivate() testlib.assert_equals_within_short( lambda: _get_storage_domain(dc, SD_SECOND_NFS_NAME).status, ovirtsdk4.types.StorageDomainStatus.MAINTENANCE)
def test_detach_storage_domain(engine_api): engine = engine_api.system_service() dc = test_utils.data_center_service(engine, DC_NAME) _get_storage_domain(dc, SD_SECOND_NFS_NAME, service=True).remove() assertions.assert_equals_within_short( lambda: _get_storage_domain(engine, SD_SECOND_NFS_NAME).status, ovirtsdk4.types.StorageDomainStatus.UNATTACHED)
def get_network_attachment(engine, host, network_name, dc_name): dc = test_utils.data_center_service(engine, dc_name) # CAVEAT: .list(search='name=Migration_Network') is ignored, and the first # network returned happened to be VM_Network in my case network = next(net for net in dc.networks_service().list() if netname_to_text(net.name) == network_name) return _get_attachment_by_id(host, network.id)
def reattach_storage_domain(connection): engine = connection.system_service() dc = test_utils.data_center_service(engine, DC_NAME) sd = _get_storage_domain(engine, SD_SECOND_NFS_NAME) dc.storage_domains_service().add(sd) testlib.assert_equals_within_short( lambda: _get_storage_domain(dc, SD_SECOND_NFS_NAME).status, ovirtsdk4.types.StorageDomainStatus.ACTIVE)
def detach_storage_domain(connection): raise SkipTest('skipping until reattach test fixed. Jira OVIRT-2264') engine = connection.system_service() dc = test_utils.data_center_service(engine, DC_NAME) _get_storage_domain(dc, SD_SECOND_NFS_NAME, service=True).remove() testlib.assert_equals_within_short( lambda: _get_storage_domain(engine, SD_SECOND_NFS_NAME).status, ovirtsdk4.types.StorageDomainStatus.UNATTACHED)
def set_network_mtu(engine, network_name, dc_name, mtu): dc = test_utils.data_center_service(engine, dc_name) network = next(net for net in dc.networks_service().list() if net.name == network_name) network_service = dc.networks_service().network_service(id=network.id) network.mtu = mtu return network_service.update(network)
def reattach_storage_domain(connection): raise SkipTest('skipping until reattach test fixed. Jira OVIRT-2264') engine = connection.system_service() dc = test_utils.data_center_service(engine, DC_NAME) sd = _get_storage_domain(engine, SD_SECOND_NFS_NAME) dc.storage_domains_service().add(sd) testlib.assert_equals_within_short( lambda: _get_storage_domain(dc, SD_SECOND_NFS_NAME).status, ovirtsdk4.types.StorageDomainStatus.ACTIVE)
def reattach_storage_domain(connection): raise SkipTest('skipping until reattach test fixed. Jira OVIRT-2264') VnicSetup.vnic_setup().remove_some_profiles_and_networks() engine = connection.system_service() dc = test_utils.data_center_service(engine, DC_NAME) sd = _get_storage_domain(engine, SD_SECOND_NFS_NAME) dc.storage_domains_service().add(sd) testlib.assert_equals_within_short( lambda: _get_storage_domain(dc, SD_SECOND_NFS_NAME).status, ovirtsdk4.types.StorageDomainStatus.ACTIVE)
def test_reattach_storage_domain(engine_api): # TODO: uncomment once VnicSetup checks are fixed. # VnicSetup.vnic_setup().remove_some_profiles_and_networks() engine = engine_api.system_service() dc = test_utils.data_center_service(engine, DC_NAME) sd = _get_storage_domain(engine, SD_SECOND_NFS_NAME) dc.storage_domains_service().add(sd) assertions.assert_equals_within_short( lambda: _get_storage_domain(dc, SD_SECOND_NFS_NAME).status, ovirtsdk4.types.StorageDomainStatus.ACTIVE)
def test_deactivate_storage_domain(engine_api): # TODO: uncomment once VnicSetup checks are fixed. # TODO: this also seems to leave running tasks behind which break the deactivation. # TODO: it should be tested in multiple runs or properly waited for. # VnicSetup.vnic_setup().init(engine_api.system_service(), # VM2_NAME, DC_NAME, CLUSTER_NAME) dc = test_utils.data_center_service(engine_api.system_service(), DC_NAME) _get_storage_domain(dc, SD_SECOND_NFS_NAME, service=True).deactivate() assertions.assert_equals_within_short( lambda: _get_storage_domain(dc, SD_SECOND_NFS_NAME).status, ovirtsdk4.types.StorageDomainStatus.MAINTENANCE)
def add_disk_profile(api): engine = api.system_service() disk_profiles_service = engine.disk_profiles_service() dc_service = test_utils.data_center_service(engine, DC_NAME) attached_sds_service = dc_service.storage_domains_service() attached_sd = attached_sds_service.list()[0] nt.assert_true( disk_profiles_service.add( sdk4.types.DiskProfile( name='my_disk_profile', storage_domain=sdk4.types.StorageDomain(id=attached_sd.id, ), ), ))
def test_import_floating_disk(engine_api): engine = engine_api.system_service() dc_service = test_utils.data_center_service(engine, DC_NAME) attached_sds_service = dc_service.storage_domains_service() sd_service = test_utils.get_attached_storage_domain( engine, SD_SECOND_NFS_NAME, service=False) attached_domain = attached_sds_service.storage_domain_service( sd_service.id) disk = test_utils.get_attached_storage_domain_disk_service( attached_domain, FLOATING_DISK_NAME, query={'unregistered': True}) disk.register() registered_disk = test_utils.get_attached_storage_domain_disk_service( attached_domain, FLOATING_DISK_NAME) assert registered_disk.get().name == FLOATING_DISK_NAME
def test_reconstruct_master_domain(api_v4): pytest.skip('TODO:Handle case where tasks are running') system_service = api_v4.system_service() dc_service = test_utils.data_center_service(system_service, DC_NAME) attached_sds_service = dc_service.storage_domains_service() master_sd = next(sd for sd in attached_sds_service.list() if sd.master) attached_sd_service = attached_sds_service.storage_domain_service( master_sd.id) attached_sd_service.deactivate() testlib.assert_true_within_long(lambda: attached_sd_service.get().status == types.StorageDomainStatus.MAINTENANCE) new_master_sd = next(sd for sd in attached_sds_service.list() if sd.master) assert new_master_sd.id != master_sd.id attached_sd_service.activate() testlib.assert_true_within_long(lambda: attached_sd_service.get().status == types.StorageDomainStatus.ACTIVE)
def _add_storage_domain_4(api, p): system_service = api.system_service() sds_service = system_service.storage_domains_service() sd = sds_service.add(p) sd_service = sds_service.storage_domain_service(sd.id) testlib.assert_true_within_long(lambda: sd_service.get().status == sdk4. types.StorageDomainStatus.UNATTACHED) dc_service = test_utils.data_center_service(system_service, DC_NAME) attached_sds_service = dc_service.storage_domains_service() attached_sds_service.add(sdk4.types.StorageDomain(id=sd.id, ), ) attached_sd_service = attached_sds_service.storage_domain_service(sd.id) testlib.assert_true_within_long(lambda: attached_sd_service.get().status == sdk4.types.StorageDomainStatus.ACTIVE)
def add_disk_profile(api): engine = api.system_service() disk_profiles_service = engine.disk_profiles_service() dc_service = test_utils.data_center_service(engine, DC_NAME) attached_sds_service = dc_service.storage_domains_service() attached_sd = attached_sds_service.list()[0] nt.assert_true( disk_profiles_service.add( sdk4.types.DiskProfile( name='my_disk_profile', storage_domain=sdk4.types.StorageDomain( id=attached_sd.id, ), ), ) )
def add_qos(api): engine = api.system_service() dc_service = test_utils.data_center_service(engine, DC_NAME) qoss = dc_service.qoss_service() nt.assert_true( qoss.add( sdk4.types.Qos( name='my_cpu_qos', type=sdk4.types.QosType.CPU, cpu_limit=99, ), )) nt.assert_true( qoss.add( sdk4.types.Qos( name='my_storage_qos', type=sdk4.types.QosType.STORAGE, max_iops=999999, description='max_iops_qos', ), ))
def reconstruct_master_domain(api): raise SkipTest('TODO:Handle case where tasks are running') system_service = api.system_service() dc_service = test_utils.data_center_service(system_service, DC_NAME) attached_sds_service = dc_service.storage_domains_service() master_sd = next(sd for sd in attached_sds_service.list() if sd.master) attached_sd_service = attached_sds_service.storage_domain_service(master_sd.id) attached_sd_service.deactivate() testlib.assert_true_within_long( lambda: attached_sd_service.get().status == types.StorageDomainStatus.MAINTENANCE ) new_master_sd = next(sd for sd in attached_sds_service.list() if sd.master) nt.assert_true(new_master_sd.id != master_sd.id) attached_sd_service.activate() testlib.assert_true_within_long( lambda: attached_sd_service.get().status == types.StorageDomainStatus.ACTIVE )
def _add_storage_domain(api, p): system_service = api.system_service() sds_service = system_service.storage_domains_service() with test_utils.TestEvent(system_service, 956): # USER_ADD_STORAGE_DOMAIN(956) sd = sds_service.add(p) sd_service = sds_service.storage_domain_service(sd.id) testlib.assert_true_within_long(lambda: sd_service.get().status == sdk4 .types.StorageDomainStatus.UNATTACHED) dc_service = test_utils.data_center_service(system_service, DC_NAME) attached_sds_service = dc_service.storage_domains_service() with test_utils.TestEvent(system_service, [966, 962]): # USER_ACTIVATED_STORAGE_DOMAIN(966) # USER_ATTACH_STORAGE_DOMAIN_TO_POOL(962) attached_sds_service.add(sdk4.types.StorageDomain(id=sd.id, ), ) attached_sd_service = attached_sds_service.storage_domain_service( sd.id) testlib.assert_true_within_long(lambda: attached_sd_service.get( ).status == sdk4.types.StorageDomainStatus.ACTIVE)
def _add_storage_domain_4(api, p): system_service = api.system_service() sds_service = system_service.storage_domains_service() sd = sds_service.add(p) sd_service = sds_service.storage_domain_service(sd.id) testlib.assert_true_within_long( lambda: sd_service.get().status == sdk4.types.StorageDomainStatus.UNATTACHED ) dc_service = test_utils.data_center_service(system_service, DC_NAME) attached_sds_service = dc_service.storage_domains_service() attached_sds_service.add( sdk4.types.StorageDomain( id=sd.id, ), ) attached_sd_service = attached_sds_service.storage_domain_service(sd.id) testlib.assert_true_within_long( lambda: attached_sd_service.get().status == sdk4.types.StorageDomainStatus.ACTIVE )
def add_qos(api): engine = api.system_service() dc_service = test_utils.data_center_service(engine, DC_NAME) qoss = dc_service.qoss_service() nt.assert_true( qoss.add( sdk4.types.Qos( name='my_cpu_qos', type=sdk4.types.QosType.CPU, cpu_limit=99, ), ) ) nt.assert_true( qoss.add( sdk4.types.Qos( name='my_storage_qos', type=sdk4.types.QosType.STORAGE, max_iops=999999, description='max_iops_qos', ), ) )
def test_deactivate_storage_domain(engine_api): # TODO: uncomment once VnicSetup checks are fixed. # TODO: this also seems to leave running tasks behind which break the deactivation. # TODO: it should be tested in multiple runs or properly waited for. # VnicSetup.vnic_setup().init(engine_api.system_service(), # VM2_NAME, DC_NAME, CLUSTER_NAME) engine = engine_api.system_service() dc = test_utils.data_center_service(engine_api.system_service(), DC_NAME) correlation_id = 'deactivate_storage_domain' def _deactivate_with_running_ovf_update_task(): try: test_utils.get_attached_storage_domain( dc, SD_SECOND_NFS_NAME, service=True).deactivate( query={'correlation_id': correlation_id}) return True except ovirtsdk4.Error as err: # The storage domain's deactivation may fail if it has running tasks. # In case of updating ovf_store disks task (UploadStream), # ignore. Otherwise, raise the exception. if not (('UploadStream' in err.args[0]) or ('OVF' in err.args[0])): raise return False assertions.assert_true_within_short( _deactivate_with_running_ovf_update_task) # Wait for the storage deactivation to be finished. # TODO Fix the code on engine, so the status will be changed once the operation finished (BZ 1949101). assertions.assert_true_within_short( lambda: test_utils.all_jobs_finished(engine, correlation_id) ) assertions.assert_true_within_short( lambda: test_utils.get_attached_storage_domain( dc, SD_SECOND_NFS_NAME).status == ovirtsdk4.types.StorageDomainStatus.MAINTENANCE )
def remove_default_dc_4(api): dc_service = test_utils.data_center_service(api.system_service(), 'Default') dc_service.remove()