def test_cooldown_inprogress(self): last_op = timeutils.utcnow(True) cp = cpo.ClusterPolicy(cluster_id=CLUSTER_ID, policy_id=POLICY_ID, last_op=last_op) res = cp.cooldown_inprogress(60) self.assertTrue(res) cp.last_op -= timedelta(hours=1) res = cp.cooldown_inprogress(60) self.assertFalse(res)
def test_to_dict(self): PROFILE_ID = '96f4df4b-889e-4184-ba8d-b5ca122f95bb' POLICY1_ID = '2c5139a6-24ba-4a6f-bd53-a268f61536de' POLICY2_ID = '2c5139a6-24ba-4a6f-bd53-a268f61536d3' NODE1_ID = '26f4df4b-889e-4184-ba8d-b5ca122f9566' NODE2_ID = '26f4df4b-889e-4184-ba8d-b5ca122f9567' utils.create_profile(self.ctx, PROFILE_ID) policy_1 = utils.create_policy(self.ctx, POLICY1_ID, 'P1') policy_2 = utils.create_policy(self.ctx, POLICY2_ID, 'P2') values = { 'profile_id': PROFILE_ID, 'name': 'test-cluster', 'desired_capacity': 1, 'status': 'INIT', 'init_at': timeutils.utcnow(True), 'max_size': -1, 'min_size': 0, 'timeout': cfg.CONF.default_action_timeout, 'user': self.ctx.user_id, 'project': self.ctx.project_id, } cluster = co.Cluster.create(self.ctx, values) p1 = cpo.ClusterPolicy(cluster_id=cluster.id, policy_id=policy_1.id, enabled=True, id=uuidutils.generate_uuid(), last_op=None) p2 = cpo.ClusterPolicy(cluster_id=cluster.id, policy_id=policy_2.id, enabled=True, id=uuidutils.generate_uuid(), last_op=None) values = { 'priority': 12, 'enabled': True, } p1.create(self.ctx, cluster.id, POLICY1_ID, values) p2.create(self.ctx, cluster.id, POLICY2_ID, values) utils.create_node(self.ctx, NODE1_ID, PROFILE_ID, cluster.id) utils.create_node(self.ctx, NODE2_ID, PROFILE_ID, cluster.id) cluster = co.Cluster.get(self.ctx, cluster.id) expected = { 'id': cluster.id, 'name': cluster.name, 'profile_id': PROFILE_ID, 'user': cluster.user, 'project': cluster.project, 'domain': cluster.domain, 'init_at': mock.ANY, 'created_at': None, 'updated_at': None, 'min_size': 0, 'max_size': -1, 'desired_capacity': 1, 'timeout': cfg.CONF.default_action_timeout, 'status': six.text_type('INIT'), 'status_reason': None, 'metadata': {}, 'data': {}, 'dependents': {}, 'config': {}, 'nodes': [mock.ANY, mock.ANY], 'policies': [mock.ANY, mock.ANY], 'profile_name': six.text_type('test-profile'), } cluster_dict = cluster.to_dict() self.assertEqual(expected, cluster_dict) self.assertEqual(2, len(cluster_dict['nodes'])) self.assertEqual(2, len(cluster_dict['policies']))
def _create_cp_binding(self, cluster_id, policy_id): return cpo.ClusterPolicy(cluster_id=cluster_id, policy_id=policy_id, enabled=True, id=uuidutils.generate_uuid(), last_op=None)