def test_forbidden_multi_state_set_actions(sdk_client_fs: ADCMClient): """ Check that forbidden caller-context combinations fail as actions and don't affect any ADCM objects """ name = "first" with allure.step(f'Check forbidden from cluster "{name}" context actions'): cluster = sdk_client_fs.cluster(name=name) # missing is used because it should fail for misconfiguration reasons, not because state not set for forbidden_action in ('set_service', 'set_component', 'unset_service_missing', 'unset_component_missing'): with check_objects_multi_state_changed(sdk_client_fs): run_cluster_action_and_assert_result(cluster, forbidden_action, status='failed') with allure.step(f'Check forbidden from service "{name}" context actions'): service = cluster.service(name=name) for forbidden_action in ('set_component', 'unset_component_missing'): with check_objects_multi_state_changed(sdk_client_fs): run_service_action_and_assert_result(service, forbidden_action, status='failed') with allure.step( f'Check forbidden from provider "{name}" context actions'): provider = sdk_client_fs.provider(name=name) for forbidden_action in ('set_host', 'unset_host_missing'): with check_objects_multi_state_changed(sdk_client_fs): run_provider_action_and_assert_result(provider, forbidden_action, status='failed')
def test_forbidden_actions(sdk_client_fs: ADCMClient): """ Check that forbidden caller-context combinations fail as actions and don't affect any ADCM objects """ name = "first" with allure.step(f'Check forbidden from cluster "{name}" context actions'): cluster = sdk_client_fs.cluster(name=name) for forbidden_action in ('change_service', 'change_component'): with check_config_changed(sdk_client_fs): run_cluster_action_and_assert_result(cluster, forbidden_action, status='failed') with allure.step(f'Check forbidden from service "{name}" context actions'): service = cluster.service(name=name) with check_config_changed(sdk_client_fs): run_service_action_and_assert_result(service, 'change_component', status='failed') with allure.step( f'Check forbidden from provider "{name}" context actions'): provider = sdk_client_fs.provider(name=name) with check_config_changed(sdk_client_fs): run_provider_action_and_assert_result(provider, 'change_host', status='failed') first_host, second_host, *_ = provider.host_list() with check_config_changed(sdk_client_fs): run_host_action_and_assert_result( first_host, 'change_host_from_provider', status='failed', config={'host_id': second_host.id})
def test_ansible_set_on_prototype(cluster_obj_venv_9: Cluster, provider_obj_venv_9: Provider): """ Check that we able to change ansible on prototype level, by tweaking venv property for object. """ run_cluster_action_and_assert_result(cluster_obj_venv_9, "obj_venv_9", config=ANSIBLE_9) run_service_action_and_assert_result( cluster_obj_venv_9.service(name="obj_venv_9"), "obj_venv_9", config=ANSIBLE_9) run_component_action_and_assert_result(cluster_obj_venv_9.service( name="obj_venv_9").component(name="obj_venv_9"), "obj_venv_9", config=ANSIBLE_9) run_provider_action_and_assert_result(provider_obj_venv_9, "obj_venv_9", config=ANSIBLE_9) run_host_action_and_assert_result( provider_obj_venv_9.host(fqdn="obj_venv_9"), "obj_venv_9", config=ANSIBLE_9)
def test_provider_action_availability_at_state(provider: Provider): """ Test that provider action is available on specific provider state """ _assert_actions_state_created(provider) run_provider_action_and_assert_result(provider, SWITCH_PROVIDER_STATE) _assert_actions_state_installed(provider) run_provider_action_and_assert_result(provider, ACTION_STATE_INSTALLED)
def test_ansible_set_on_action( cluster_obj_venv_default_action_9: Cluster, cluster_obj_no_venv_action_9: Cluster, provider_obj_venv_default_action_9: Provider, provider_no_venv_action_9: Provider, ): """ Check that we able to change ansible on action. """ run_cluster_action_and_assert_result(cluster_obj_venv_default_action_9, "obj_venv_default_action_9", config=ANSIBLE_9) run_service_action_and_assert_result( cluster_obj_venv_default_action_9.service( name="obj_venv_default_action_9"), "obj_venv_default_action_9", config=ANSIBLE_9, ) run_component_action_and_assert_result( cluster_obj_venv_default_action_9.service( name="obj_venv_default_action_9").component( name="obj_venv_default_action_9"), "obj_venv_default_action_9", config=ANSIBLE_9, ) run_cluster_action_and_assert_result(cluster_obj_no_venv_action_9, "obj_no_venv_action_9", config=ANSIBLE_9) run_service_action_and_assert_result( cluster_obj_no_venv_action_9.service(name="obj_no_venv_action_9"), "obj_no_venv_action_9", config=ANSIBLE_9) run_component_action_and_assert_result( cluster_obj_no_venv_action_9.service( name="obj_no_venv_action_9").component( name="obj_no_venv_action_9"), "obj_no_venv_action_9", config=ANSIBLE_9, ) run_provider_action_and_assert_result(provider_no_venv_action_9, "no_venv_action_9", config=ANSIBLE_9) run_host_action_and_assert_result( provider_no_venv_action_9.host(fqdn="no_venv_action_9"), "no_venv_action_9", config=ANSIBLE_9) run_provider_action_and_assert_result(provider_obj_venv_default_action_9, "obj_venv_default_action_9", config=ANSIBLE_9) run_host_action_and_assert_result( provider_obj_venv_default_action_9.host( fqdn="obj_venv_default_action_9"), "obj_venv_default_action_9", config=ANSIBLE_9, )
def test_missing_ok_multi_state_unset(two_providers: Tuple[Provider, Provider], two_clusters: Tuple[Cluster, Cluster], sdk_client_fs: ADCMClient): """ Checking behaviour of flag "missing_ok": - Job fails when flag is "false" and state is not in multi_state - Job succeed when flag is "true" and state is not in multi_state """ host = (provider := two_providers[0]).host() component = (service := (cluster := two_clusters[0]).service()).component() with allure.step( 'Check job fails with "missing_ok: false" and state not in multi_state' ): for forbidden_action in ('unset_provider', 'unset_host'): with check_objects_multi_state_changed(sdk_client_fs): run_host_action_and_assert_result(host, forbidden_action, 'failed') with check_objects_multi_state_changed(sdk_client_fs): run_provider_action_and_assert_result(provider, 'unset_host_from_provider', status='failed', config={'host_id': host.id}) with check_objects_multi_state_changed(sdk_client_fs): run_cluster_action_and_assert_result(cluster, 'unset_cluster', status='failed') with check_objects_multi_state_changed(sdk_client_fs): run_service_action_and_assert_result(service, 'unset_service', status='failed') with check_objects_multi_state_changed(sdk_client_fs): run_component_action_and_assert_result(component, 'unset_component', status='failed') with allure.step( 'Check job succeed with "missing_ok: true" without changing multi_state of any object' ): for allowed_action in ('unset_provider_missing', 'unset_host_missing'): with check_objects_multi_state_changed(sdk_client_fs): run_host_action_and_assert_result(host, allowed_action) with check_objects_multi_state_changed(sdk_client_fs): run_provider_action_and_assert_result( provider, 'unset_host_from_provider_missing', config={'host_id': host.id}) with check_objects_multi_state_changed(sdk_client_fs): run_cluster_action_and_assert_result(cluster, 'unset_cluster_missing') with check_objects_multi_state_changed(sdk_client_fs): run_service_action_and_assert_result(service, 'unset_service_missing') with check_objects_multi_state_changed(sdk_client_fs): run_component_action_and_assert_result(component, 'unset_component_missing')
def test_host_from_provider(two_providers: Tuple[Provider, Provider], sdk_client_fs: ADCMClient): """Change host state from provider""" provider = two_providers[0] host = provider.host_list()[0] provider_name = compose_name(provider) host_name = compose_name(host) with check_objects_state_changed(sdk_client_fs, {host}), allure.step( f'Set state of {host_name} with action from {provider_name}'): run_provider_action_and_assert_result(provider, 'set_host_from_provider', config={'host_id': host.id})
def run_actions_after_upgrade( self, cluster_all_services: Cluster, cluster_config_history: Cluster, simple_provider: Provider ) -> None: """ Run successful actions on: cluster, service, component. Run failed action on provider. """ sauce_service = cluster_config_history.service(name=self.SAUCE_SERVICE) run_cluster_action_and_assert_result(cluster_all_services, 'eat_sandwich') run_service_action_and_assert_result(sauce_service, 'put_on_bread') run_component_action_and_assert_result(sauce_service.component(name=self.SPICE_COMPONENT), 'add_more') run_provider_action_and_assert_result(simple_provider, 'validate', status='failed')
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_default_ansible( cluster_no_venv: Cluster, cluster_obj_venv_default: Cluster, provider_no_venv: Provider, provider_obj_venv_default: Provider, ): """ Check that by default (if developer write nothing) we have Ansible 2.8. """ run_cluster_action_and_assert_result(cluster_no_venv, "no_venv", config=DEFAULT_ANSIBLE_VER) run_service_action_and_assert_result( cluster_no_venv.service(name="no_venv"), "no_venv", config=DEFAULT_ANSIBLE_VER) run_component_action_and_assert_result( cluster_no_venv.service(name="no_venv").component(name="no_venv"), "no_venv", config=DEFAULT_ANSIBLE_VER) run_cluster_action_and_assert_result(cluster_obj_venv_default, "obj_venv_default", config=DEFAULT_ANSIBLE_VER) run_service_action_and_assert_result( cluster_obj_venv_default.service(name="obj_venv_default"), "obj_venv_default", config=DEFAULT_ANSIBLE_VER) run_component_action_and_assert_result( cluster_obj_venv_default.service(name="obj_venv_default").component( name="obj_venv_default"), "obj_venv_default", config=DEFAULT_ANSIBLE_VER, ) run_provider_action_and_assert_result(provider_no_venv, "no_venv", config=DEFAULT_ANSIBLE_VER) run_host_action_and_assert_result(provider_no_venv.host(fqdn="no_venv"), "no_venv", config=DEFAULT_ANSIBLE_VER) run_provider_action_and_assert_result(provider_obj_venv_default, "obj_venv_default", config=DEFAULT_ANSIBLE_VER) run_host_action_and_assert_result( provider_obj_venv_default.host(fqdn="obj_venv_default"), "obj_venv_default", config=DEFAULT_ANSIBLE_VER)
def run_immediate_change_test(self, provider_host: Tuple[Provider, Host], cluster_service_component: Tuple[Cluster, Service, Component]): """ Run the same action (self._action) for cluster, service, component, provider, host and expect them to succeed """ cluster, service, component = cluster_service_component provider, host = provider_host run_cluster_action_and_assert_result(cluster, self._action) run_service_action_and_assert_result(service, self._action) run_component_action_and_assert_result(component, self._action) run_provider_action_and_assert_result(provider, self._action) run_host_action_and_assert_result(host, self._action)
def test_provider_state_after_action(self, sdk_client_fs: ADCMClient, provider_and_states_checker): """Test provider state after action""" provider_obj, check_objects_state_changed = provider_and_states_checker object_to_be_changed = provider_obj with check_objects_state_changed( sdk_client_fs, {object_to_be_changed }), allure.step(f'Run provider action: {ACTION_NAME}'): run_provider_action_and_assert_result( object_to_be_changed, action=ACTION_NAME, status="success" if "fail" not in provider_obj.name else "failed", )
def test_provider_multi_state_plus_state_after_action( self, sdk_client_fs: ADCMClient, provider_and_multi_states_plus_states_checker): """ Test provider and multi states and states after action Before action add multi state that should be unset via action """ provider_obj, check_objects_state_changed = provider_and_multi_states_plus_states_checker object_to_be_changed = provider_obj run_provider_action_and_assert_result(object_to_be_changed, ACTION_SET_MULTISTATE_NAME) with check_objects_state_changed( sdk_client_fs, {object_to_be_changed }), allure.step(f'Run provider action: {ACTION_NAME}'): run_provider_action_and_assert_result( object_to_be_changed, action=ACTION_NAME, status="success" if "fail" not in provider_obj.name else "failed", )
def test_forbidden_state_set_actions(sdk_client_fs: ADCMClient): """ Check that forbidden caller-context combinations fail as actions and don't affect any ADCM objects """ name = "first" first_first_fqdn = "first-first" first_second_fqdn = "first-second" with allure.step(f'Check forbidden from cluster "{name}" context actions'): cluster = sdk_client_fs.cluster(name=name) for forbidden_action in ('set_service', 'set_component'): with check_objects_state_changed(sdk_client_fs): run_cluster_action_and_assert_result(cluster, forbidden_action, status='failed') with allure.step(f'Check forbidden from service "{name}" context actions'): service = cluster.service(name=name) with check_objects_state_changed(sdk_client_fs): run_service_action_and_assert_result(service, 'set_component', status='failed') with allure.step( f'Check forbidden from provider "{name}" context actions'): provider = sdk_client_fs.provider(name=name) with check_objects_state_changed(sdk_client_fs): run_provider_action_and_assert_result(provider, 'set_host', status='failed') with allure.step( f'Check forbidden from host "{first_first_fqdn}" context actions'): host_first = sdk_client_fs.host(fqdn=first_first_fqdn) host_second = sdk_client_fs.host(fqdn=first_second_fqdn) with check_objects_state_changed(sdk_client_fs): run_host_action_and_assert_result( host_first, 'set_host_from_provider', config={'host_id': host_second.id}, status='failed')