def test_provider_bundle_shouldnt_load_when_has_export_section(client): with allure.step('Upload cluster bundle'): bundle = utils.get_data_dir(__file__, 'hostprovider_with_export') with pytest.raises(coreapi.exceptions.ErrorMessage) as e: steps.upload_bundle(client, bundle) with allure.step('Check error'): err.INVALID_OBJECT_DEFINITION.equal(e, 'Only cluster or service can have export section')
def test_loading_provider_bundle_must_be_pass(client): with allure.step('Upload cluster bundle'): bundle = utils.get_data_dir(__file__, "hostprovider_loading_pass") steps.upload_bundle(client, bundle) with allure.step('Check that hostprovider loading pass'): host_provider = client.stack.provider.list() assert host_provider is not None
def test_bundle_should_have_any_cluster_definition(client): with allure.step('Upload cluster bundle with no definition'): bundle = utils.get_data_dir(__file__, "bundle_wo_cluster_definition") with pytest.raises(coreapi.exceptions.ErrorMessage) as e: steps.upload_bundle(client, bundle) with allure.step('Check error message'): err.BUNDLE_ERROR.equal(e, "There isn't any cluster or host provider definition in bundle")
def test_load_should_fail_when(client, entity, state, case): with allure.step(f'Upload {entity} bundle with {case}'): bundle = utils.get_data_dir(__file__, 'states', entity, state, case) with pytest.raises(coreapi.exceptions.ErrorMessage) as e: steps.upload_bundle(client, bundle) with allure.step(f'Check if state is {state}'): err.INVALID_ACTION_DEFINITION.equal(e, state, entity, 'should be string')
def test_load_stack_w_empty_config_field(client): stack_dir = utils.get_data_dir(__file__, 'empty_config_field') steps.upload_bundle(client, stack_dir) with allure.step('Get cluster list'): cluster_proto = client.stack.cluster.list()[0] schema = json.load(open(SCHEMAS + '/stack_list_item_schema.json')) with allure.step('Check cluster'): assert validate(cluster_proto, schema) is None
def test_should_create_provider_wo_description(client): steps.upload_bundle(client, BUNDLES + 'hostprovider_bundle') with allure.step('Create provider'): client.provider.create( prototype_id=client.stack.provider.list()[0]['id'], name=utils.random_string()) with allure.step('Check provider list'): assert client.provider.list() is not None
def test_validate_provider_prototype(client): steps.upload_bundle(client, BUNDLES + 'hostprovider_bundle') with allure.step('Load provider prototype'): provider_prototype = json.loads( json.dumps(client.stack.provider.list()[0])) schema = json.load(open(SCHEMAS + '/stack_list_item_schema.json')) with allure.step('Check provider prototype'): assert validate(provider_prototype, schema) is None
def test_host_proto_wo_actions(client): stack_dir = utils.get_data_dir(__file__, 'host_proto_wo_action') steps.upload_bundle(client, stack_dir) with allure.step('Get host without actions'): host_prototype = client.stack.host.list()[0] schema = json.load(open(SCHEMAS + '/stack_list_item_schema.json')) with allure.step('Check host'): assert validate(host_prototype, schema) is None
def test_bundle_can_be_removed_when_no_object_associated_with(client): with allure.step('Upload cluster bundle'): bundle = utils.get_data_dir(__file__, "cluster_inventory_tests") steps.upload_bundle(client, bundle) with allure.step('Remove cluster bundle'): client.stack.bundle.delete(bundle_id=client.stack.bundle.list()[0]['id']) with allure.step('Check cluster bundle is removed'): assert not client.stack.bundle.list()
def test_shouldnt_create_host_with_unknown_prototype(client): steps.upload_bundle(client, BUNDLES + 'hostprovider_bundle') with allure.step('Create host'): with pytest.raises(exceptions.ErrorMessage) as e: client.host.create(prototype_id=client.stack.host.list()[0]['id'], provider_id=random.randint(100, 500), fqdn=utils.random_string()) with allure.step('Check error provider doesnt exist'): errorcodes.PROVIDER_NOT_FOUND.equal(e, "provider doesn't exist")
def test_get_provider_config(client): steps.upload_bundle(client, BUNDLES + 'hostprovider_bundle') with allure.step('Create provider'): provider = client.provider.create( prototype_id=client.stack.provider.list()[0]['id'], name=utils.random_string()) with allure.step('Check provider config'): assert client.provider.config.current.list( provider_id=provider['id'])['config'] is not None
def test_bundle_cant_removed_when_some_object_associated_with(client): with allure.step('Upload cluster bundle'): bundle = utils.get_data_dir(__file__, "cluster_inventory_tests") steps.upload_bundle(client, bundle) with allure.step('Create cluster'): client.cluster.create(prototype_id=client.stack.cluster.list()[0]['id'], name=__file__) with pytest.raises(coreapi.exceptions.ErrorMessage) as e: client.stack.bundle.delete(bundle_id=client.stack.bundle.list()[0]['id']) with allure.step('Check error message'): err.BUNDLE_CONFLICT.equal(e, "There is cluster", "of bundle ")
def test_should_create_provider_w_description(client): steps.upload_bundle(client, BUNDLES + 'hostprovider_bundle') with allure.step('Create provider'): description = utils.random_string() provider = client.provider.create( prototype_id=client.stack.provider.list()[0]['id'], name=utils.random_string(), description=description) with allure.step('Check provider with description'): assert provider['description'] == description
def test_action_shouldnt_be_run_while_hostprovider_has_an_issue(client): with allure.step('Create default hostprovider and get id'): bundle = utils.get_data_dir(__file__, "provider") steps.upload_bundle(client, bundle) provider_id = steps.create_hostprovider(client)['id'] with allure.step(f'Run action with error for provider {provider_id}'): with pytest.raises(coreapi.exceptions.ErrorMessage) as e: client.provider.action.run.create( provider_id=provider_id, action_id=client.provider.action.list(provider_id=provider_id)[0]['id']) with allure.step('Check if provider action has issues'): TASK_ERROR.equal(e, 'action has issues')
def test_when_hostprovider_has_issue_than_upgrade_locked(client): with allure.step('Create hostprovider'): bundledir = utils.get_data_dir(__file__, "provider") upgrade_bundle = utils.get_data_dir(__file__, "upgrade", "provider") steps.upload_bundle(client, bundledir) provider_id = steps.create_hostprovider(client)['id'] steps.upload_bundle(client, upgrade_bundle) with allure.step('Upgrade provider'): with pytest.raises(coreapi.exceptions.ErrorMessage) as e: client.provider.upgrade.do.create( provider_id=provider_id, upgrade_id=client.provider.upgrade.list(provider_id=provider_id)[0]['id']) with allure.step('Check if upgrade locked'): UPGRADE_ERROR.equal(e)
def test_provider_shouldnt_be_deleted_when_it_has_host(client): steps.upload_bundle(client, BUNDLES + 'hostprovider_bundle') with allure.step('Create provider'): provider = steps.create_hostprovider(client) with allure.step('Create host'): client.host.create(prototype_id=client.stack.host.list()[0]['id'], provider_id=provider['id'], fqdn=utils.random_string()) with allure.step('Delete provider'): with pytest.raises(exceptions.ErrorMessage) as e: client.provider.delete(provider_id=provider['id']) with allure.step('Check error'): errorcodes.PROVIDER_CONFLICT.equal(e, 'There is host ', ' of host provider ')
def test_when_cluster_has_issue_than_upgrade_locked(client): with allure.step('Create cluster and upload new one bundle'): bundledir = utils.get_data_dir(__file__, "cluster") upgrade_bundle = utils.get_data_dir(__file__, "upgrade", "cluster") steps.upload_bundle(client, bundledir) cluster = steps.create_cluster(client) steps.upload_bundle(client, upgrade_bundle) with allure.step('Upgrade cluster'): upgrade_list = client.cluster.upgrade.list(cluster_id=cluster['id']) with pytest.raises(coreapi.exceptions.ErrorMessage) as e: client.cluster.upgrade.do.create( cluster_id=cluster['id'], upgrade_id=upgrade_list[0]['id']) with allure.step('Check if cluster has issues'): UPGRADE_ERROR.equal(e, 'cluster ', ' has issue: ')
def test_action_shouldnt_be_run_while_host_has_an_issue(client): with allure.step('Create default host and get id'): bundle = utils.get_data_dir(__file__, "host") steps.upload_bundle(client, bundle) provider_id = steps.create_hostprovider(client)['id'] host_id = client.host.create(prototype_id=client.stack.host.list()[0]['id'], provider_id=provider_id, fqdn=utils.random_string())['id'] with allure.step(f'Run action with error for host {host_id}'): with pytest.raises(coreapi.exceptions.ErrorMessage) as e: client.host.action.run.create( host_id=host_id, action_id=client.host.action.list(host_id=host_id)[0]['id']) with allure.step('Check if host action has issues'): TASK_ERROR.equal(e, 'action has issues')
def test_when_component_hasnt_constraint_then_cluster_doesnt_have_issues(client): with allure.step('Create cluster (component hasnt constraint)'): bundledir = utils.get_data_dir(__file__, "cluster_component_hasnt_constraint") steps.upload_bundle(client, bundledir) cluster = steps.create_cluster(client) with allure.step('Create service'): steps.create_random_service(client, cluster['id']) with allure.step('Run action: lock cluster'): action = get_action_by_name(client, cluster, 'lock-cluster') wait_until( client, task=client.cluster.action.run.create(cluster_id=cluster['id'], action_id=action['id']) ) with allure.step('Check if state is always-locked'): assert client.cluster.read(cluster_id=cluster['id'])['state'] == 'always-locked'
def adcm(image, request, adcm_credentials): repo, tag = image dw = DockerWrapper() adcm = dw.run_adcm(image=repo, tag=tag, pull=False) adcm.api.auth(**adcm_credentials) cluster_bundle = os.path.join(DATADIR, 'cluster_bundle') provider_bundle = os.path.join(DATADIR, 'hostprovider') steps.upload_bundle(adcm.api.objects, cluster_bundle) steps.upload_bundle(adcm.api.objects, provider_bundle) def fin(): adcm.stop() request.addfinalizer(fin) return adcm
def test_check_cluster_state_after_run_action_when_empty(cluster_bundle, state, client): with allure.step(f'Upload cluster bundle: {cluster_bundle}'): bundle = utils.get_data_dir(__file__, "empty_states", cluster_bundle) steps.upload_bundle(client, bundle) with allure.step('Create cluster'): cluster = client.cluster.create(prototype_id=client.stack.cluster.list()[0]['id'], name=utils.random_string()) with allure.step('Run cluster'): action = client.cluster.action.run.create( action_id=filter_action_by_name( client.cluster.action.list(cluster_id=cluster['id']), 'install')[0]['id'], cluster_id=cluster['id']) wait_until(client, action) with allure.step(f'Check if cluster state is {state}'): assert client.cluster.read(cluster_id=cluster['id'])['state'] == state
def test_run_parametrized_action_must_be_runned(client): with allure.step('Upload cluster bundle'): bundle = utils.get_data_dir(__file__, "run_parametrized_action") steps.upload_bundle(client, bundle) with allure.step('Create cluster'): cluster = client.cluster.create(prototype_id=client.stack.cluster.list()[0]['id'], name=utils.random_string()) with allure.step('Run cluster'): action = client.cluster.action.run.create( action_id=filter_action_by_name( client.cluster.action.list(cluster_id=cluster['id']), 'install')[0]['id'], cluster_id=cluster['id'], config={"param": "test test test test test"}) wait_until(client, action) with allure.step('Check if state is success'): assert client.job.read(job_id=client.job.list()[0]['id'])['status'] == 'success'
def test_check_host_state_after_run_action_when_empty(host_bundle, state, client): with allure.step(f'Upload cluster bundle: {host_bundle}'): bundle = utils.get_data_dir(__file__, "empty_states", host_bundle) steps.upload_bundle(client, bundle) with allure.step('Create provider and host'): provider = client.provider.create(prototype_id=client.stack.provider.list()[0]['id'], name=utils.random_string()) host = client.host.create(prototype_id=client.stack.host.list()[0]['id'], provider_id=provider['id'], fqdn=utils.random_string()) with allure.step('Run host'): action = client.host.action.run.create( action_id=filter_action_by_name( client.host.action.list(host_id=host['id']), 'init')[0]['id'], host_id=host['id']) wait_until(client, action) with allure.step(f'Check if host state is {state}'): assert client.host.read(host_id=host['id'])['state'] == state
def test_check_inventories_file(adcm, client): bundledir = utils.get_data_dir(__file__, 'cluster_inventory_tests') steps.upload_bundle(client, bundledir) with allure.step('Create cluster'): cluster = prepare(client) client.cluster.action.run.create( cluster_id=cluster['id'], action_id=random.choice( client.cluster.action.list(cluster_id=cluster['id']))['id']) time.sleep(5) with allure.step('Get inventory file from container'): text = get_file_from_container(adcm, '/adcm/data/run/1/', 'inventory.json') inventory = json.loads(text.read().decode('utf8')) with allure.step('Check inventory file'): template = open(utils.get_data_dir(__file__, 'cluster-inventory.json'), 'rb') expected = json.loads(template.read().decode('utf8')) assert inventory == expected
def prepared_cluster(client): bundle = utils.get_data_dir(__file__, 'locked_when_action_running') steps.upload_bundle(client, bundle) return client.cluster.create(prototype_id=client.stack.cluster.list()[0]['id'], name=utils.random_string())
def client(adcm): steps.upload_bundle(adcm.api.objects, BUNDLES + "cluster_bundle") steps.upload_bundle(adcm.api.objects, BUNDLES + "hostprovider_bundle") return adcm.api.objects
def host(client): host_bundle = utils.get_data_dir(__file__, 'host_bundle_on_any_level') steps.upload_bundle(client, host_bundle) return steps.create_host_w_default_provider(client, 'localhost')
def hostprovider(client): steps.upload_bundle(client, utils.get_data_dir(__file__, 'host_bundle_on_any_level')) return steps.create_hostprovider(client)
def test_that_check_empty_field_is(empty_fields, client): with allure.step('Upload cluster bundle'): bundle = utils.get_data_dir(__file__, "empty_states", empty_fields) steps.upload_bundle(client, bundle) with allure.step('Check cluster bundle'): assert client.stack.bundle.list() is not None
def test_load_host_provider(client): steps.upload_bundle(client, BUNDLES + 'hostprovider_bundle') with allure.step('Check bundle list'): assert client.stack.bundle.list() is not None