def test_get_host_info(self, client): host = steps.create_host_w_default_provider(client, utils.random_string()) actual = steps.read_host(client, host['id']) with allure.step('Check created host with the data from the API'): del actual['status'] del host['status'] assert actual == host
def test_shouldnt_create_host_config_when_config_is_number(self, client): """Should not create host configuration when config string is number """ host = steps.create_host_w_default_provider(client, utils.random_string()) config = random.randint(100, 999) with allure.step('Try to create the host configuration with a number'): with pytest.raises(coreapi.exceptions.ErrorMessage) as e: client.host.config.history.create(host_id=host['id'], config=config) with allure.step('Check error should not be just one int or float'): err.JSON_ERROR.equal(e, 'should not be just one int or float')
def test_shouldnt_create_host_config_when_config_not_json_string(self, client): """Should not create host configuration when config string is not json """ host = steps.create_host_w_default_provider(client, utils.random_string()) config = utils.random_string() with allure.step('Try to create the host config from non-json string'): with pytest.raises(coreapi.exceptions.ErrorMessage) as e: client.host.config.history.create(host_id=host['id'], config=config) with allure.step('Check error config should not be just one string'): err.JSON_ERROR.equal(e, 'config should not be just one string')
def test_get_default_host_config(self, client): # Get a default host config and validate it with json schema host = steps.create_host_w_default_provider(client, utils.random_string()) config_json = {} with allure.step('Get default configuration from host'): config = client.host.config.current.list(host_id=host['id']) if config: config_json = json.loads(json.dumps(config)) schema = json.load(open(SCHEMAS + '/config_item_schema.json')) with allure.step('Check config'): assert validate(config_json, schema) is None steps.delete_all_data(client)
def test_config_history_url_must_point_to_the_host_config(self, client): host = steps.create_host_w_default_provider(client, utils.random_string()) config = {"str-key": "{1bbb}", "required": 158, "option": 8080, "sub": {"sub1": 2}, "credentials": {"sample_string": "txt", "read_only_initiated": {}}} i = 0 with allure.step('Create host history'): while i < random.randint(0, 10): client.host.config.history.create(host_id=host['id'], description=utils.random_string(), config=config) i += 1 history = client.host.config.history.list(host_id=host['id']) with allure.step('Check host history'): for conf in history: assert ('host/{0}/config/'.format(host['id']) in conf['url']) is True steps.delete_all_data(client)
def test_get_hostcomponent_list(self, client): # invalid case, random component takes in circle cluster = steps.create_cluster(client) service = steps.read_service(client, get_random_service(client)['id']) cluster_svc = client.cluster.service.create(cluster_id=cluster['id'], prototype_id=service['id']) components = client.cluster.service.component.list(cluster_id=cluster['id'], service_id=cluster_svc['id']) # create mapping between cluster and hosts, then create hostcomponent on host hostcomponent_list = [] for fqdn in utils.random_string_list(): host = steps.create_host_w_default_provider(client, fqdn) steps.add_host_to_cluster(client, host, cluster) component = random.choice(components)['id'] hostcomponent_list.append({"host_id": host['id'], "service_id": cluster_svc['id'], "component_id": component}) expected_hostcomponent_list = client.cluster.hostcomponent.create( cluster_id=cluster['id'], hc=hostcomponent_list) actual_hs_list = client.cluster.hostcomponent.list(cluster_id=cluster['id']) with allure.step('Check created data with data from API'): assert actual_hs_list == expected_hostcomponent_list
def create_host(self, fqdn): steps.create_host_w_default_provider(self._client, fqdn) return fqdn
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')