def test_when_delete_host_all_children_cannot_be_deleted(self, client): # Should be faild if random service has not components cluster = steps.create_cluster(client) with allure.step('Create provider'): provider = client.provider.create( prototype_id=client.stack.provider.list()[0]['id'], name=utils.random_string()) with allure.step('Create host'): host = client.host.create( prototype_id=client.stack.host.list()[0]['id'], provider_id=provider['id'], fqdn=utils.random_string()) steps.add_host_to_cluster(client, host, cluster) with allure.step('Create random service'): service = steps.create_random_service(client, cluster['id']) with allure.step('Create random service component'): component = get_random_cluster_service_component( client, cluster, service) with allure.step('Create hostcomponent'): steps.create_hostcomponent_in_cluster(client, cluster, host, service, component) with pytest.raises(coreapi.exceptions.ErrorMessage) as e: client.cluster.host.delete(host_id=host['id'], cluster_id=cluster['id']) with allure.step('Check host conflict'): err.HOST_CONFLICT.equal(e)
def test_config_history_url_must_point_to_the_service_config(self, client): cluster = steps.create_cluster(client) service = steps.create_random_service(client, cluster['id']) config_str = { "ssh-key": "eulav", "integer-key": 23, "required-key": "10", "float-key": 38.5, "zoo.cfg": { "autopurge.purgeInterval": 40, "dataDir": "/opt/data", "port": 80 } } i = 0 while i < random.randint(0, 10): client.cluster.service.config.history.create( cluster_id=cluster['id'], service_id=service['id'], description=utils.random_string(), config=config_str) i += 1 history = client.cluster.service.config.history.list( cluster_id=cluster['id'], service_id=service['id']) with allure.step('Check config history'): for conf in history: assert ('cluster/{0}/service/'.format(cluster['id']) in conf['url']) is True steps.delete_all_data(client)
def test_create_cluster_service_config(self, client): cluster = steps.create_cluster(client) cfg_json = { "ssh-key": "TItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAA", "zoo.cfg": { "autopurge.purgeInterval": 30, "dataDir": "/dev/0", "port": 80 }, "required-key": "value" } with allure.step('Create service'): cluster_svc = client.cluster.service.create( cluster_id=cluster['id'], prototype_id=get_random_service(client)['id']) with allure.step('Create config'): config = client.cluster.service.config.history.create( cluster_id=cluster['id'], service_id=cluster_svc['id'], description='simple desc', config=cfg_json) with allure.step('Check created config'): expected = client.cluster.service.config.history.read( cluster_id=cluster['id'], service_id=cluster_svc['id'], version=config['id']) assert config == expected steps.delete_all_data(client)
def test_shouldnt_create_service_config_when_key_shouldnt_have_any_subkeys( self, client): cluster = steps.create_cluster(client) config_shouldnt_have_subkeys = { "ssh-key": { "key": "value" }, "zoo.cfg": { "autopurge.purgeInterval": "24", "dataDir": "/zookeeper", "port": "http" } } with allure.step('Create service on the cluster'): cluster_svc = client.cluster.service.create( cluster_id=cluster['id'], prototype_id=get_random_service(client)['id']) with allure.step( 'Try to create config where param shouldn\'t have any subkeys' ): with pytest.raises(coreapi.exceptions.ErrorMessage) as e: client.cluster.service.config.history.create( cluster_id=cluster['id'], service_id=cluster_svc['id'], config=config_shouldnt_have_subkeys) with allure.step('Check error about unknown subkey'): err.CONFIG_KEY_ERROR.equal( e, 'input config should not have any subkeys') steps.delete_all_data(client)
def test_shouldnt_create_service_config_when_float_param_less_than_boundary( self, client): cluster = steps.create_cluster(client) config_float_less_boundary = { "ssh-key": "TItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAA", "zoo.cfg": { "autopurge.purgeInterval": 24, "dataDir": "/zookeeper", "port": 80 }, "float-key": 3.3, "required-key": "value" } with allure.step('Create service on the cluster'): cluster_svc = client.cluster.service.create( cluster_id=cluster['id'], prototype_id=get_random_service(client)['id']) with allure.step('Try to create config when float less than boundary'): with pytest.raises(coreapi.exceptions.ErrorMessage) as e: client.cluster.service.config.history.create( cluster_id=cluster['id'], service_id=cluster_svc['id'], config=config_float_less_boundary) with allure.step('Check error that float less than boundary'): err.CONFIG_VALUE_ERROR.equal(e, 'Value', 'should be more than') steps.delete_all_data(client)
def test_shouldnt_create_service_config_when_config_have_unknown_subkey( self, client): cluster = steps.create_cluster(client) config_w_unknown_subkey = { "ssh-key": "TItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAA", "zoo.cfg": { "autopurge.purgeInterval": 24, "dataDir": "/zookeeper", "portium": "http" }, "required-key": "value" } with allure.step('Create service on the cluster'): cluster_svc = client.cluster.service.create( cluster_id=cluster['id'], prototype_id=get_random_service(client)['id']) with allure.step('Try to create config with unknown subkey'): with pytest.raises(coreapi.exceptions.ErrorMessage) as e: client.cluster.service.config.history.create( cluster_id=cluster['id'], service_id=cluster_svc['id'], config=config_w_unknown_subkey) with allure.step('Check error about unknown subkey'): err.CONFIG_KEY_ERROR.equal(e, 'There is unknown subkey') steps.delete_all_data(client)
def test_shouldnt_create_service_config_when_parameter_is_not_in_option_list( self, client): cluster = steps.create_cluster(client) config_w_illegal_param = { "ssh-key": "TItbmlzdHAyNTYAIbmlzdHAyNTYAAA", "float-key": 4.5, "zoo.cfg": { "autopurge.purgeInterval": 30, "dataDir": "/zookeeper", "port": 500 }, "required-key": "value" } with allure.step('Create service on the cluster'): cluster_svc = client.cluster.service.create( cluster_id=cluster['id'], prototype_id=get_random_service(client)['id']) with allure.step('Try to create config has not option in a list'): with pytest.raises(coreapi.exceptions.ErrorMessage) as e: client.cluster.service.config.history.create( cluster_id=cluster['id'], service_id=cluster_svc['id'], config=config_w_illegal_param) with allure.step('Check CONFIG_VALUE_ERROR'): assert e.value.error.title == '400 Bad Request' assert e.value.error['code'] == 'CONFIG_VALUE_ERROR' assert ('not in option list' in e.value.error['desc']) is True steps.delete_all_data(client)
def test_shouldnt_create_service_config_when_parameter_is_not_string( self, client): cluster = steps.create_cluster(client) config_w_illegal_param = { "ssh-key": "TItbmlzdHAyNTYAAAAIbmlzdHAyNTY", "float-key": 5.7, "zoo.cfg": { "autopurge.purgeInterval": 30, "dataDir": "/zookeeper", "port": 80 }, "required-key": 500 } with allure.step('Create service on the cluster'): cluster_svc = client.cluster.service.create( cluster_id=cluster['id'], prototype_id=get_random_service(client)['id']) with allure.step('Try to create config when param is not float'): with pytest.raises(coreapi.exceptions.ErrorMessage) as e: client.cluster.service.config.history.create( cluster_id=cluster['id'], service_id=cluster_svc['id'], config=config_w_illegal_param) with allure.step('Check error that parameter is not string'): err.CONFIG_VALUE_ERROR.equal(e, 'should be string') steps.delete_all_data(client)
def test_shouldnt_create_service_config_when_try_to_put_dictionary_in_flat_key( self, client): cluster = steps.create_cluster(client) config = { "ssh-key": "as32fKj14fT88", "zoo.cfg": { "autopurge.purgeInterval": 24, "dataDir": "/zookeeper", "port": { "foo": "bar" } }, "required-key": "value" } with allure.step('Create service on the cluster'): cluster_svc = client.cluster.service.create( cluster_id=cluster['id'], prototype_id=get_random_service(client)['id']) with allure.step( 'Try to create config where in flat param we put a dictionary' ): with pytest.raises(coreapi.exceptions.ErrorMessage) as e: client.cluster.service.config.history.create( cluster_id=cluster['id'], service_id=cluster_svc['id'], config=config) with allure.step('Check error about flat param'): err.CONFIG_VALUE_ERROR.equal(e, 'should be flat') steps.delete_all_data(client)
def test_get_config_from_nonexistant_cluster_service(self, client): cluster = steps.create_cluster(client) with pytest.raises(coreapi.exceptions.ErrorMessage) as e: client.cluster.service.config.list(cluster_id=cluster['id'], service_id=random.randint( 100, 500)) with allure.step('Check error that service doesn\'t exist'): err.SERVICE_NOT_FOUND.equal(e, "service doesn\'t exist") steps.delete_all_data(client)
def test_should_throws_exception_when_havent_previous_config(self, client): cluster = steps.create_cluster(client) service = steps.create_random_service(client, cluster['id']) with allure.step('Try to get previous version of the service config'): with pytest.raises(coreapi.exceptions.ErrorMessage) as e: client.cluster.service.config.previous.list( cluster_id=cluster['id'], service_id=service['id']) with allure.step('Check error that config version doesn\'t exist'): err.CONFIG_NOT_FOUND.equal(e, 'config version doesn\'t exist') steps.delete_all_data(client)
def test_read_default_cluster_config(self, client): cluster = steps.create_cluster(client) config = client.cluster.config.current.list(cluster_id=cluster['id']) if config: config_json = utils.ordered_dict_to_dict(config) with allure.step('Load schema'): schema = json.load(open(SCHEMAS + '/config_item_schema.json')) with allure.step('Check schema'): assert validate(config_json, schema) is None steps.delete_all_data(client)
def test_action_shouldnt_be_run_while_cluster_has_an_issue(client): with allure.step('Create default cluster and get id'): bundle = utils.get_data_dir(__file__, "cluster") steps.upload_bundle(client, bundle) cluster_id = steps.create_cluster(client)['id'] with allure.step(f'Run action with error for cluster {cluster_id}'): with pytest.raises(coreapi.exceptions.ErrorMessage) as e: client.cluster.action.run.create( cluster_id=cluster_id, action_id=client.cluster.action.list(cluster_id=cluster_id)[0]['id']) with allure.step('Check if cluster action has issues'): TASK_ERROR.equal(e, 'action has issues')
def test_create_new_config_version_with_other_parameters(self, client): cluster = steps.create_cluster(client) cfg = {"required": 99, "str-key": utils.random_string()} with allure.step('Create new config'): new_config = client.cluster.config.history.create( cluster_id=cluster['id'], config=cfg) with allure.step('Create config history'): expected = client.cluster.config.history.read( cluster_id=cluster['id'], version=new_config['id']) with allure.step('Check new config'): assert new_config == expected steps.delete_all_data(client)
def test_create_new_config_version_with_one_req_parameter(self, client): cluster = steps.create_cluster(client) cfg = {"required": random.randint(0, 9)} with allure.step('Create new config'): new_config = client.cluster.config.history.create( cluster_id=cluster['id'], config=cfg) with allure.step('Create config history'): expected = client.cluster.config.history.read( cluster_id=cluster['id'], version=new_config['id']) with allure.step('Check new config'): assert new_config == expected steps.delete_all_data(client)
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 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: ')