def test_change_service_state_by_name(cluster_bundle: Bundle): expected_state = copy.deepcopy(INITIAL_CLUSTERS_STATE) assert_cluster_service_states(cluster_bundle, expected_state) with allure.step('Run action: set first service'): cluster_bundle.cluster(name='first').action( name='set_first_service').run().try_wait() expected_state['first']['services']['First'] = 'bimba!' assert_cluster_service_states(cluster_bundle, expected_state) with allure.step('Run action: set second service'): cluster_bundle.cluster(name='third').action( name='set_second_service').run().try_wait() expected_state['third']['services']['Second'] = 'state2' assert_cluster_service_states(cluster_bundle, expected_state)
def assert_cluster_service_states(bundle: Bundle, statemap: dict): for cname, clv in statemap.items(): cstate = bundle.cluster(name=cname).state cstate_expected = clv['state'] expect( cstate == cstate_expected, f"Cluster \"{cname}\" is \"{cstate}\" while expected \"{cstate_expected}\"" ) for sname, sstate_expected in clv['services'].items(): sstate = bundle.cluster(name=cname).service(name=sname).state expect(sstate == sstate_expected, (f"Cluster \"{cname}\" service \"{sname}\" state is " f"\"{sstate}\" while expected \"{sstate_expected}\"")) assert_expectations()
def test_cluster_config(cluster_bundle: Bundle, keys_clusters): expected_state = copy.deepcopy(INITIAL_CLUSTERS_CONFIG) assert_cluster_config(cluster_bundle, expected_state) with allure.step('Check cluster keys'): for key, cname in keys_clusters: cluster = cluster_bundle.cluster(name=cname) cluster.action(name='cluster_' + key).run().try_wait() expected_state[cname]["config"][key] = NEW_VALUES[key] assert_cluster_config(cluster_bundle, expected_state)
def test_change_service_state_by_name_from_another_service( cluster_bundle: Bundle): expected_state = copy.deepcopy(INITIAL_CLUSTERS_STATE) assert_cluster_service_states(cluster_bundle, expected_state) with allure.step('Run action: set first service'): second = cluster_bundle.cluster(name='first').service(name='Second') result = second.action(name='set_first_service').run().wait() with allure.step('Check job state'): assert result == "failed", "Job expected to be failed" assert_cluster_service_states(cluster_bundle, expected_state)
def assert_cluster_config(bundle: Bundle, statemap: dict): for cname, clv in statemap.items(): actual_cnf = bundle.cluster(name=cname).config() expected_cnf = clv['config'] for k, v in expected_cnf.items(): expect( v == actual_cnf[k], 'Cluster {} config "{}" is "{}" while expected "{}"'.format( cname, k, str(actual_cnf[k]), str(v))) for sname, service_expected_cnf in clv['services'].items(): service_actual_cnf = bundle.cluster(name=cname).service( name=sname).config() for k, v in service_expected_cnf.items(): expect( v == service_actual_cnf[k], 'Cluster {} service {} config {} is {} while expected {}'. format(cname, sname, k, str(service_actual_cnf[k]), str(v))) assert_expectations()
def test_service_config(cluster_bundle: Bundle, keys_clusters_services): expected_state = copy.deepcopy(INITIAL_CLUSTERS_CONFIG) assert_cluster_config(cluster_bundle, expected_state) with allure.step('Check service keys'): for key, cname, sname in keys_clusters_services: cluster = cluster_bundle.cluster(name=cname) service = cluster.service(name=sname) service.action(name='service_' + key).run().try_wait() expected_state[cname]["services"][sname][key] = NEW_VALUES[key] assert_cluster_config(cluster_bundle, expected_state)
def test_change_cluster_state(cluster_bundle: Bundle): expected_state = copy.deepcopy(INITIAL_CLUSTERS_STATE) assert_cluster_service_states(cluster_bundle, expected_state) first = cluster_bundle.cluster(name='first') second = cluster_bundle.cluster(name='second') third = cluster_bundle.cluster(name='third') with allure.step('Run second cluster action: set cluster'): second.action(name='set_cluster').run().try_wait() with allure.step('Check cluster state'): expected_state['second']['state'] = 'statey' assert_cluster_service_states(cluster_bundle, expected_state) with allure.step('Run first service action: set cluster'): first.service(name='First').action(name='set_cluster').run().try_wait() expected_state['first']['state'] = 'statey' assert_cluster_service_states(cluster_bundle, expected_state) with allure.step('Run second service action: set cluster'): third.service(name='Second').action( name='set_cluster').run().try_wait() expected_state['third']['state'] = 'statey' assert_cluster_service_states(cluster_bundle, expected_state)
def test_another_service_from_service_by_name(cluster_bundle: Bundle, keys_clusters_services): expected_state = copy.deepcopy(INITIAL_CLUSTERS_CONFIG) assert_cluster_config(cluster_bundle, expected_state) with allure.step('Check another service from service by name'): for key, cname, sname in keys_clusters_services: if sname == "Second": continue second = cluster_bundle.cluster(name=cname).service(name='Second') result = second.action(name='service_name_' + sname + '_' + key).run().wait() assert result == "failed", "Job expected to be failed" assert_cluster_config(cluster_bundle, expected_state)