def test_get_state_single_job(self): bundle = utils.gen_bundle() cluster_proto = utils.gen_prototype(bundle, 'cluster') cluster = utils.gen_cluster(prototype=cluster_proto) action = utils.gen_action(prototype=cluster_proto) action.state_on_success = 'success' action.state_on_fail = 'fail' action.multi_state_on_success_set = ['success'] action.multi_state_on_success_unset = ['success unset'] action.multi_state_on_fail_set = ['fail'] action.multi_state_on_fail_unset = ['fail unset'] action.save() task = utils.gen_task_log(cluster, action) job = utils.gen_job_log(task) # status: expected state, expected multi_state set, expected multi_state unset test_data = [ [config.Job.SUCCESS, 'success', ['success'], ['success unset']], [config.Job.FAILED, 'fail', ['fail'], ['fail unset']], [config.Job.ABORTED, None, [], []], ] for status, exp_state, exp_m_state_set, exp_m_state_unset in test_data: state, m_state_set, m_state_unset = job_module.get_state( action, job, status) self.assertEqual(state, exp_state) self.assertListEqual(m_state_set, exp_m_state_set) self.assertListEqual(m_state_unset, exp_m_state_unset)
def test_unlock_affected(self): cluster = utils.gen_cluster() task = utils.gen_task_log(cluster) utils.gen_job_log(task) task.lock_affected([cluster]) task.unlock_affected() self.assertFalse(cluster.locked) self.assertIsNone(task.lock)
def test_lock_affected(self): cluster = utils.gen_cluster() task = utils.gen_task_log(cluster) utils.gen_job_log(task) task.lock_affected([cluster]) self.assertTrue(cluster.locked) task.refresh_from_db() self.assertIsNotNone(task.lock)
def test_lock_affected__lock_is_single(self): cluster = utils.gen_cluster() task = utils.gen_task_log(cluster) utils.gen_job_log(task) task.lock = utils.gen_concern_item(models.ConcernType.Lock) task.save() task.lock_affected([cluster]) self.assertFalse(cluster.locked)
def test_state(self): obj = utils.gen_cluster() upgrade = self.cook_upgrade() upgrade.state_available = ["installed", "any"] obj.prototype.version = "1.5" obj.state = "created" self.check_upgrade(obj, upgrade, False) obj.state = "installed" self.check_upgrade(obj, upgrade, True)
def test_version(self): obj = utils.gen_cluster() upgrade = self.cook_upgrade() obj.prototype.version = "1.5" self.check_upgrade(obj, upgrade, True) obj.prototype.version = "2.5" self.check_upgrade(obj, upgrade, False) obj.prototype.version = "2.0" self.check_upgrade(obj, upgrade, True) obj.prototype.version = "1.0" self.check_upgrade(obj, upgrade, True)
def test_variants(self): bundle = utils.gen_bundle() prototype = utils.gen_prototype(bundle, 'cluster') cluster = utils.gen_cluster(bundle=bundle, prototype=prototype) action = utils.gen_action(bundle=bundle, prototype=prototype) for state_name, cluster_states in cluster_variants.items(): for cl_attr, cl_value in cluster_states.items(): setattr(cluster, cl_attr, cl_value) cluster.save() for req_name, req_states in plausible_action_variants.items(): for act_attr, act_value in req_states.items(): setattr(action, act_attr, act_value) action.save() self.assertIs(action.allowed(cluster), expected_results[state_name][req_name])
def setUp(self) -> None: self.cluster_config = { 'group': { 'string': 'string' }, 'activatable_group': { 'integer': 1 } } self.cluster_attr = {'activatable_group': {'active': True}} self.cluster = utils.gen_cluster() utils.gen_prototype_config(prototype=self.cluster.prototype, name='group', field_type='group', display_name='group') utils.gen_prototype_config( prototype=self.cluster.prototype, name='group', field_type='string', subname='string', display_name='string', ) utils.gen_prototype_config( prototype=self.cluster.prototype, name='activatable_group', field_type='group', display_name='activatable_group', ) utils.gen_prototype_config( prototype=self.cluster.prototype, name='activatable_group', field_type='integer', subname='integer', display_name='integer', ) self.cluster.config = utils.gen_config(config=self.cluster_config, attr=self.cluster_attr) self.cluster.save()
def test_issue(self): obj = utils.gen_cluster() issue.create_issue(obj, ConcernCause.Config) upgrade = self.cook_upgrade() self.check_upgrade(obj, upgrade, False)
def generate_hierarchy(): # pylint: disable=too-many-locals,too-many-statements """ Generates two hierarchies: cluster_1 - service_11 - component_111 - host_11 - provider_1 - host_12 - provider_1 - component_112 - host_11 - provider_1 - host_12 - provider_1 - service_12 - component_121 - host_11 - provider_1 - host_12 - provider_1 - host_31 - provider_3 - component_122 - host_11 - provider_1 - host_12 - provider_1 - host_31 - provider_3 cluster_2 - service_21 - component_211 - host_21 - provider_2 - host_22 - provider_2 - component_212 - host_21 - provider_2 - host_22 - provider_2 - service_22 - component_221 - host_21 - provider_2 - host_22 - provider_2 - host_32 - provider_3 - component_222 - host_21 - provider_2 - host_22 - provider_2 - host_32 - provider_3 """ cluster_bundle = utils.gen_bundle() cluster_pt = utils.gen_prototype(cluster_bundle, 'cluster') service_pt_1 = utils.gen_prototype(cluster_bundle, 'service') service_pt_2 = utils.gen_prototype(cluster_bundle, 'service') component_pt_11 = utils.gen_prototype(cluster_bundle, 'component') component_pt_12 = utils.gen_prototype(cluster_bundle, 'component') component_pt_21 = utils.gen_prototype(cluster_bundle, 'component') component_pt_22 = utils.gen_prototype(cluster_bundle, 'component') cluster_1 = utils.gen_cluster(prototype=cluster_pt) service_11 = utils.gen_service(cluster_1, prototype=service_pt_1) service_12 = utils.gen_service(cluster_1, prototype=service_pt_2) component_111 = utils.gen_component(service_11, prototype=component_pt_11) component_112 = utils.gen_component(service_11, prototype=component_pt_12) component_121 = utils.gen_component(service_12, prototype=component_pt_21) component_122 = utils.gen_component(service_12, prototype=component_pt_22) cluster_2 = utils.gen_cluster(prototype=cluster_pt) service_21 = utils.gen_service(cluster_2, prototype=service_pt_1) service_22 = utils.gen_service(cluster_2, prototype=service_pt_2) component_211 = utils.gen_component(service_21, prototype=component_pt_11) component_212 = utils.gen_component(service_21, prototype=component_pt_12) component_221 = utils.gen_component(service_22, prototype=component_pt_21) component_222 = utils.gen_component(service_22, prototype=component_pt_22) provider_bundle = utils.gen_bundle() provider_pt = utils.gen_prototype(provider_bundle, 'provider') host_pt = utils.gen_prototype(provider_bundle, 'host') provider_1 = utils.gen_provider(prototype=provider_pt) host_11 = utils.gen_host(provider_1, prototype=host_pt) host_12 = utils.gen_host(provider_1, prototype=host_pt) provider_2 = utils.gen_provider(prototype=provider_pt) host_21 = utils.gen_host(provider_2, prototype=host_pt) host_22 = utils.gen_host(provider_2, prototype=host_pt) provider_3 = utils.gen_provider(prototype=provider_pt) host_31 = utils.gen_host(provider_3, prototype=host_pt) host_32 = utils.gen_host(provider_3, prototype=host_pt) utils.gen_host_component(component_111, host_11) utils.gen_host_component(component_112, host_11) utils.gen_host_component(component_121, host_11) utils.gen_host_component(component_122, host_11) utils.gen_host_component(component_111, host_12) utils.gen_host_component(component_112, host_12) utils.gen_host_component(component_121, host_12) utils.gen_host_component(component_122, host_12) utils.gen_host_component(component_121, host_31) utils.gen_host_component(component_122, host_31) utils.gen_host_component(component_211, host_21) utils.gen_host_component(component_212, host_21) utils.gen_host_component(component_221, host_21) utils.gen_host_component(component_222, host_21) utils.gen_host_component(component_211, host_22) utils.gen_host_component(component_212, host_22) utils.gen_host_component(component_221, host_22) utils.gen_host_component(component_222, host_22) utils.gen_host_component(component_221, host_32) utils.gen_host_component(component_222, host_32) return dict( cluster_1=cluster_1, service_11=service_11, service_12=service_12, component_111=component_111, component_112=component_112, component_121=component_121, component_122=component_122, cluster_2=cluster_2, service_21=service_21, service_22=service_22, component_211=component_211, component_212=component_212, component_221=component_221, component_222=component_222, provider_1=provider_1, host_11=host_11, host_12=host_12, provider_2=provider_2, host_21=host_21, host_22=host_22, provider_3=provider_3, host_31=host_31, host_32=host_32, )