def test_two_clusters(self, action_name, cluster_with_components: Cluster, provider: Provider): """ Test that component actions on host works fine on two clusters """ second_cluster = cluster_with_components.bundle().cluster_prototype( ).cluster_create(name="Second cluster") service_on_first_cluster = cluster_with_components.service_add( name=FIRST_SERVICE) component_on_first_cluster = service_on_first_cluster.component( name=FIRST_COMPONENT) service_on_second_cluster = second_cluster.service_add( name=FIRST_SERVICE) component_on_second_cluster = service_on_second_cluster.component( name=FIRST_COMPONENT) first_host = provider.host_create("host_in_first_cluster") second_host = provider.host_create("host_in_second_cluster") cluster_with_components.host_add(first_host) second_cluster.host_add(second_host) cluster_with_components.hostcomponent_set( (first_host, component_on_first_cluster)) second_cluster.hostcomponent_set( (second_host, component_on_second_cluster)) action_in_object_is_present(action_name, first_host) action_in_object_is_present(action_name, second_host) run_host_action_and_assert_result(first_host, action_name, status="success") run_host_action_and_assert_result(second_host, action_name, status="success")
def test_availability(self, cluster: Cluster, provider: Provider, action_name): """ Test that cluster host action is available on cluster host and is absent on cluster """ host1 = provider.host_create("host_in_cluster") host2 = provider.host_create("host_not_in_cluster") cluster.host_add(host1) action_in_object_is_present(action_name, host1) action_in_object_is_absent(action_name, host2) action_in_object_is_absent(action_name, cluster) run_host_action_and_assert_result(host1, action_name, status="success")
def test_get_host_list(self, sdk_client_fs: ADCMClient, provider: Provider): """ Create multiple hosts and check that all hosts was created """ actual, expected = [], [] for fqdn in utils.random_string_list(): provider.host_create(fqdn) expected.append(fqdn) for host in sdk_client_fs.host_list(): actual.append(host.fqdn) with allure.step("Check created hosts with the data from the API"): assert all(expected_host in actual for expected_host in expected)
def test_invoker_object_url(self, cluster: Cluster, provider: Provider, page: JobListPage): """Check link to object that invoked action is correct""" host_fqdn = 'run-on-me' host_job_link = f'{provider.name}/{host_fqdn}' component_link = f'{CLUSTER_NAME}/{SERVICE_NAME}/{COMPONENT_NAME}' host_component_link = f'{component_link}/{host_fqdn}' with allure.step('Run action on component and check job link to it'): service: Service = cluster.service(name=SERVICE_NAME) component: Component = service.component(name=COMPONENT_NAME) component_action = component.action( display_name=COMPONENT_ACTION_DISPLAY_NAME) _check_link_to_invoker_object(component_link, page, component_action) with allure.step( 'Create host, run action on host and check job link to it'): host = provider.host_create(host_fqdn) host_action = host.action(display_name=FAIL_ACTION_DISPLAY_NAME) _check_link_to_invoker_object(host_job_link, page, host_action) with allure.step('Add host to the cluster, assign component on it'): cluster.host_add(host) cluster.hostcomponent_set((host, component)) with allure.step( 'Run component host action on host and check job link to it'): host_action = _wait_and_get_action_on_host( host, ON_HOST_ACTION_DISPLAY_NAME) _check_link_to_invoker_object(host_component_link, page, host_action)
def test_availability_at_state(self, cluster_with_components: Cluster, provider: Provider): """ Test that component host action is available on specify service state """ service = cluster_with_components.service_add(name=FIRST_SERVICE) component = service.component(name=FIRST_COMPONENT) adjacent_component = service.component(name=SECOND_COMPONENT) host = provider.host_create("host_in_cluster") cluster_with_components.host_add(host) cluster_with_components.hostcomponent_set((host, component)) action_in_object_is_absent(ACTION_ON_HOST_STATE_REQUIRED, host) run_cluster_action_and_assert_result(cluster_with_components, SWITCH_CLUSTER_STATE) action_in_object_is_absent(ACTION_ON_HOST_STATE_REQUIRED, host) run_service_action_and_assert_result(service, SWITCH_SERVICE_STATE) action_in_object_is_absent(ACTION_ON_HOST_STATE_REQUIRED, host) run_host_action_and_assert_result(host, SWITCH_HOST_STATE) action_in_object_is_absent(ACTION_ON_HOST_STATE_REQUIRED, host) run_component_action_and_assert_result(adjacent_component, SWITCH_COMPONENT_STATE) action_in_object_is_absent(ACTION_ON_HOST_STATE_REQUIRED, host) run_component_action_and_assert_result(component, SWITCH_COMPONENT_STATE) action_in_object_is_present(ACTION_ON_HOST_STATE_REQUIRED, host) run_host_action_and_assert_result(host, ACTION_ON_HOST_STATE_REQUIRED)
def test_no_horizontal_lock(self, host_provider: Provider, host: Host, lock_action): """ Test that no horizontal lock when host locked """ second_host = host_provider.host_create(fqdn=random_string()) _lock_obj(host, lock_action) is_free(second_host)
def cluster_with_two_hosts(cluster: Cluster, host_provider: Provider) -> Tuple[Cluster, List[Host]]: """Add service, component and host to cluster twice""" hosts = [] for i in range(2): host = host_provider.host_create(f"host_{i}") hosts.append(host) cluster.host_add(host) return cluster, hosts
def test_availability(self, cluster_with_service: Cluster, provider: Provider, action_name): """ Test that service host action is available on a service host and is absent on cluster """ service = cluster_with_service.service_add(name=FIRST_SERVICE) second_service = cluster_with_service.service_add(name=SECOND_SERVICE) host_with_two_components = provider.host_create( "host_with_two_components") host_with_one_component = provider.host_create( "host_with_one_component") host_without_component = provider.host_create("host_without_component") host_with_different_services = provider.host_create( "host_with_different_services") host_outside_cluster = provider.host_create("host_outside_cluster") for host in [ host_with_two_components, host_with_one_component, host_without_component, host_with_different_services, ]: cluster_with_service.host_add(host) cluster_with_service.hostcomponent_set( (host_with_two_components, service.component(name=FIRST_COMPONENT)), (host_with_two_components, service.component(name=SECOND_COMPONENT)), (host_with_one_component, service.component(name=FIRST_COMPONENT)), (host_with_different_services, service.component(name=SECOND_COMPONENT)), (host_with_different_services, second_service.component(name=FIRST_COMPONENT)), ) action_in_object_is_present(action_name, host_with_one_component) action_in_object_is_present(action_name, host_with_two_components) action_in_object_is_present(action_name, host_with_different_services) action_in_object_is_absent(action_name, host_without_component) action_in_object_is_absent(action_name, host_outside_cluster) action_in_object_is_absent(action_name, cluster_with_service) action_in_object_is_absent(action_name, service) run_host_action_and_assert_result(host_with_one_component, action_name) run_host_action_and_assert_result(host_with_two_components, action_name) run_host_action_and_assert_result(host_with_different_services, action_name)
def test_host_belong_to_cluster_should_not_deleted(self, cluster: Cluster, provider: Provider): """Test that we should be unable to delete host bounded to cluster""" host = provider.host_create(utils.random_string()) cluster.host_add(host) with pytest.raises(coreapi.exceptions.ErrorMessage) as e: host.delete() with allure.step("Check error host belong to cluster"): err.HOST_CONFLICT.equal(e, "Host", "belong to cluster")
def test_get_cluster_host_info(self, cluster: Cluster, provider: Provider): """Test get cluster host info""" host = provider.host_create(utils.random_string()) with allure.step("Create mapping between cluster and host"): expected = cluster.host_add(host) with allure.step("Get cluster host info"): host.reread() with allure.step("Check test results"): _check_hosts(host, expected)
def test_adding_host_to_cluster(self, cluster: Cluster, provider: Provider): """Test add host to cluster""" host = provider.host_create(utils.random_string()) expected = cluster.host_add(host) with allure.step("Get cluster host info"): host_list = cluster.host_list() assert len(host_list) == 1 actual = host_list[0] with allure.step("Check mapping"): _check_hosts(actual, expected)
def test_two_clusters(self, action_name, cluster: Cluster, provider: Provider): """ Test that cluster actions on host works fine on two clusters """ second_cluster = cluster.bundle().cluster_prototype().cluster_create( name="Second cluster") first_host = provider.host_create("host_in_first_cluster") second_host = provider.host_create("host_in_second_cluster") cluster.host_add(first_host) second_cluster.host_add(second_host) action_in_object_is_present(action_name, first_host) action_in_object_is_present(action_name, second_host) run_host_action_and_assert_result(first_host, action_name, status="success") run_host_action_and_assert_result(second_host, action_name, status="success")
def test_availability_at_state(self, cluster: Cluster, provider: Provider): """ Test that cluster host action is available on specify cluster state """ host = provider.host_create("host_in_cluster") cluster.host_add(host) action_in_object_is_absent(ACTION_ON_HOST_STATE_REQUIRED, host) run_cluster_action_and_assert_result(cluster, SWITCH_CLUSTER_STATE) action_in_object_is_present(ACTION_ON_HOST_STATE_REQUIRED, host) run_host_action_and_assert_result(host, ACTION_ON_HOST_STATE_REQUIRED)
def test_delete_host_from_cluster(self, cluster: Cluster, provider: Provider): """Test delete host from cluster""" host = provider.host_create(utils.random_string()) expected = cluster.host_list() with allure.step("Create mapping between cluster and host"): cluster.host_add(host) with allure.step("Deleting host from cluster"): cluster.host_delete(host) actual = cluster.host_list() with allure.step("Check host removed from cluster"): assert actual == expected
def test_availability(self, cluster_with_components: Cluster, provider: Provider, action_name): """ Test that component host action is available on a component host """ service = cluster_with_components.service_add(name=FIRST_SERVICE) component_with_action = service.component(name=FIRST_COMPONENT) component_without_action = service.component(name=SECOND_COMPONENT) host_single_component = provider.host_create( "host_with_single_component") host_two_components = provider.host_create("host_with_two_components") host_component_without_action = provider.host_create( "host_component_without_action") host_without_components = provider.host_create( "host_without_components") host_outside_cluster = provider.host_create("host_outside_cluster") for host in [ host_single_component, host_two_components, host_component_without_action, host_without_components, ]: cluster_with_components.host_add(host) cluster_with_components.hostcomponent_set( (host_single_component, component_with_action), (host_two_components, component_with_action), (host_two_components, component_without_action), (host_component_without_action, component_without_action), ) action_in_object_is_present(action_name, host_single_component) action_in_object_is_present(action_name, host_two_components) action_in_object_is_absent(action_name, host_component_without_action) action_in_object_is_absent(action_name, host_without_components) action_in_object_is_absent(action_name, host_outside_cluster) action_in_object_is_absent(action_name, cluster_with_components) action_in_object_is_absent(action_name, service) action_in_object_is_absent(action_name, component_with_action) action_in_object_is_absent(action_name, component_without_action) run_host_action_and_assert_result(host_single_component, action_name) run_host_action_and_assert_result(host_two_components, action_name)
def test_get_cluster_hosts_list(self, cluster: Cluster, provider: Provider): """Test get cluster hosts list""" actual, expected = [], [] with allure.step("Create host list in cluster"): for fqdn in utils.random_string_list(): host = provider.host_create(fqdn) cluster.host_add(host) expected.append(host.id) for host in cluster.host_list(): actual.append(host.id) with allure.step("Check test data"): assert actual == expected
def test_target_group_in_inventory(cluster_with_target_group_action: Cluster, provider: Provider, sdk_client_fs): """ Test that target group action has inventory_hostname info """ hostname = "host_in_cluster" host = provider.host_create(hostname) cluster_with_target_group_action.host_add(host) action_in_object_is_present(ACTION_ON_HOST, host) run_host_action_and_assert_result(host, ACTION_ON_HOST) with allure.step("Assert that hostname in job log is present"): assert (f"We are on host: {hostname}" in sdk_client_fs.job().log( type="stdout").content), "No hostname info in the job log"
def test_host_action_availability_at_state(provider: Provider): """ Test that host action is available on specific host state """ host_1 = provider.host_create("host-1-fqdn") host_2 = provider.host_create("host-2-fqdn") _assert_actions_state_created(host_1) run_provider_action_and_assert_result(provider, SWITCH_PROVIDER_STATE) _assert_actions_state_created(host_1) run_host_action_and_assert_result(host_1, SWITCH_HOST_STATE) _assert_actions_state_installed(host_1) _assert_actions_state_created(host_2) run_host_action_and_assert_result(host_1, ACTION_STATE_INSTALLED)
def test_host_should_be_unlocked_after_host_action( cluster: Cluster, host_provider: Provider, adcm_object: str, host_action_postfix: str, run_on_host: str, ): """Test that host is unlocked after host action""" action_name = f"{adcm_object}_{host_action_postfix}" first_service = cluster.service_add(name="first_service") second_service = cluster.service_add(name="second_service") host_with_two_components = host_provider.host_create("host_with_two_components") host_with_one_component = host_provider.host_create("host_with_one_component") host_with_different_services = host_provider.host_create("host_with_different_services") cluster_hosts = [ host_with_two_components, host_with_one_component, host_with_different_services, ] for host in cluster_hosts: cluster.host_add(host) cluster.hostcomponent_set( (host_with_two_components, second_service.component(name="second_service_component_1")), (host_with_two_components, second_service.component(name="second_service_component_2")), (host_with_one_component, second_service.component(name="second_service_component_1")), (host_with_different_services, first_service.component(name="first_service_component_2")), (host_with_different_services, second_service.component(name="second_service_component_1")), ) host = cluster.host(fqdn=run_on_host) with allure.step(f"Run action {action_name} on {host}"): host.action(name=action_name).run().wait(timeout=30) for host in cluster_hosts: is_free(host)
def test_create_hostcomponent(self, sdk_client_fs: ADCMClient, provider: Provider): """ Check that hostcomponent is set """ bundle = sdk_client_fs.upload_from_fs(get_data_dir(__file__, "cluster_service_hostcomponent")) cluster = bundle.cluster_create(utils.random_string()) host = provider.host_create(utils.random_string()) cluster.host_add(host) service = cluster.service_add(name="ZOOKEEPER") component = service.component(name="ZOOKEEPER_CLIENT") cluster.hostcomponent_set((host, component)) with allure.step("Check host component map"): hc_map = cluster.hostcomponent() assert len(hc_map) == 1 assert hc_map[0]["host_id"] == host.id assert hc_map[0]["component_id"] == component.id
def test_get_hostcomponent_list(self, cluster: Cluster, provider: Provider): """ Check that hostcomponent map retrieved successfully """ service = cluster.service_add(name="ZOOKEEPER") components = service.component_list() hc_map_temp = [] for fqdn in utils.random_string_list(): host = provider.host_create(fqdn=fqdn) cluster.host_add(host) component = random.choice(components) hc_map_temp.append((host, component)) hc_map_expected = cluster.hostcomponent_set(*hc_map_temp) with allure.step("Check created data with data from API"): hc_map_actual = cluster.hostcomponent() assert hc_map_actual == hc_map_expected
def test_availability_at_host_state(self, cluster_with_service: Cluster, provider: Provider): """ Test that service host action isn't available on specify host state """ service = cluster_with_service.service_add(name=FIRST_SERVICE) host = provider.host_create("host_in_cluster") cluster_with_service.host_add(host) cluster_with_service.hostcomponent_set( (host, service.component(name=FIRST_COMPONENT))) action_in_object_is_absent(ACTION_ON_HOST_STATE_REQUIRED, host) run_host_action_and_assert_result(host, SWITCH_HOST_STATE) action_in_object_is_absent(ACTION_ON_HOST_STATE_REQUIRED, host) run_service_action_and_assert_result(service, SWITCH_SERVICE_STATE) action_in_object_is_present(ACTION_ON_HOST_STATE_REQUIRED, host) run_host_action_and_assert_result(host, ACTION_ON_HOST_STATE_REQUIRED)
def test_check_inventories_file(cluster: Cluster, provider: Provider, adcm_fs: ADCM, request: SubRequest): """Assert inventory file contents for the action""" host = provider.host_create(fqdn=HOST_FQDN) with allure.step('Configure cluster'): service = cluster.service_add(name="zookeeper") cluster.host_add(host) component = service.component(name=GROUP_COMPONENT_NAME) cluster.hostcomponent_set((host, component)) with allure.step( f'Create config group with {GROUP_COMPONENT_NAME} and change it'): config_group = create_config_group_and_add_host( 'group_name', component, host) config_group.config_set(CONFIG_TO_CHANGE) with allure.step('Run actions on cluster'): run_cluster_action_and_assert_result(cluster, "set_multi_states") run_cluster_action_and_assert_result(cluster, "install") with allure.step('Get inventory file from container'): text = get_file_from_container(adcm_fs, '/adcm/data/run/2/', 'inventory.json') inventory_content = text.read().decode('utf8') inventory = json.loads(inventory_content) _attach_inventory_file(request, inventory_content, 'Actual content of inventory.json') with allure.step('Get expected inventory file'): with open(utils.get_data_dir(__file__, 'cluster-inventory.json'), 'rb') as template: expected_content = template.read().decode('utf8') expected = json.loads(expected_content) _attach_inventory_file(request, expected_content, 'Expected content of inventory.json') with allure.step('Compare actual and expected config'): assert ( inventory == expected ), "Content of file inventory.json doesn't match expected. See attachments for more info." with allure.step( 'Check that object attributes are available in ansible script'): run_cluster_action_and_assert_result(cluster, 'check')
def host(provider: Provider) -> Host: """Create host""" return provider.host_create(utils.random_string())
def test_host_action_job(self, provider: Provider, page: JobListPage): """Run action on host and validate job in table and popup""" host = provider.host_create('some-fqdn') _test_run_action(page, host, f'{provider.name}/{host.fqdn}')
def created_hosts(provider: Provider) -> List[Host]: """Create 11 hosts for "parallel" actions execution""" return [provider.host_create(f'host-{i}') for i in range(11)]
def host_with_actions(provider_with_actions: Provider): """Create host with actions""" return provider_with_actions.host_create(fqdn='host.with.actions')
def hosts_with_actions(host_with_actions: Host, provider_with_actions: Provider): """Create hosts with actions""" hosts = [host_with_actions] for i in range(9): hosts.append(provider_with_actions.host_create(fqdn=f'host.with.actions.{i}')) return hosts
def host(host_provider: Provider) -> Host: """Create host""" return host_provider.host_create(random_string())
def host_with_actions(provider_with_actions: Provider): return provider_with_actions.host_create(fqdn='host.with.actions')