def test_cluster_policy_load(self): ex = self.assertRaises(exception.PolicyNotAttached, cpm.ClusterPolicy.load, self.context, 'some-cluster', 'any-policy') self.assertEqual('The policy (any-policy) is not attached to the ' 'specified cluster (some-cluster).', six.text_type(ex)) cluster = utils.create_cluster(self.context, CLUSTER_ID, PROFILE_ID) policy = utils.create_policy(self.context, POLICY_ID) values = { 'priority': 12, 'enabled': True, } cp = cpm.ClusterPolicy(cluster.id, policy.id, **values) cp_id = cp.store(self.context) result = cpm.ClusterPolicy.load(self.context, CLUSTER_ID, POLICY_ID) self.assertEqual(cp_id, result.id) self.assertEqual(cluster.id, result.cluster_id) self.assertEqual(policy.id, result.policy_id) self.assertTrue(True, result.enabled) self.assertEqual(12, result.priority) self.assertEqual({}, result.data) self.assertIsNone(result.last_op) self.assertEqual('test-cluster', result.cluster_name) self.assertEqual('senlin.policy.dummy-1.0', result.policy_type) self.assertEqual('test_policy', result.policy_name)
def test_cluster_policy_load(self): ex = self.assertRaises(exception.PolicyNotAttached, cpm.ClusterPolicy.load, self.context, 'some-cluster', 'any-policy') self.assertEqual( "The policy 'any-policy' is not attached to the " "specified cluster 'some-cluster'.", six.text_type(ex)) cluster = utils.create_cluster(self.context, CLUSTER_ID, PROFILE_ID) policy = utils.create_policy(self.context, POLICY_ID) values = { 'priority': 12, 'enabled': True, } cp = cpm.ClusterPolicy(cluster.id, policy.id, **values) cp_id = cp.store(self.context) result = cpm.ClusterPolicy.load(self.context, CLUSTER_ID, POLICY_ID) self.assertEqual(cp_id, result.id) self.assertEqual(cluster.id, result.cluster_id) self.assertEqual(policy.id, result.policy_id) self.assertTrue(True, result.enabled) self.assertEqual(12, result.priority) self.assertEqual({}, result.data) self.assertIsNone(result.last_op) self.assertEqual('test-cluster', result.cluster_name) self.assertEqual('senlin.policy.dummy-1.0', result.policy_type) self.assertEqual('test_policy', result.policy_name)
def setUp(self): super(TestScalingPolicy, self).setUp() self.context = utils.dummy_context() self.spec = { 'type': 'senlin.policy.scaling', 'version': '1.0', 'properties': { 'event': 'CLUSTER_SCALE_IN', 'adjustment': { 'type': 'CHANGE_IN_CAPACITY', 'number': 1, 'min_step': 1, 'best_effort': False, 'cooldown': 3, } } } self.profile = utils.create_profile(self.context, PROFILE_ID) self.cluster = utils.create_cluster(self.context, CLUSTER_ID, PROFILE_ID) self.cluster_no_maxsize = utils.create_cluster(self.context, CLUSTER_NOMAXSIZE_ID, PROFILE_ID, max_size=-1)
def setUp(self): super(TestScalingPolicy, self).setUp() self.context = utils.dummy_context() self.spec = { 'type': 'senlin.policy.scaling', 'version': '1.0', 'properties': { 'event': 'CLUSTER_SCALE_IN', 'adjustment': { 'type': 'CHANGE_IN_CAPACITY', 'number': 1, 'min_step': 1, 'best_effort': False, 'cooldown': 3, } } } self.profile = utils.create_profile(self.context, PROFILE_ID) self.cluster = utils.create_cluster(self.context, CLUSTER_ID, PROFILE_ID)
def test_cluster_policy_load_all(self): result = cpm.ClusterPolicy.load_all(self.context, 'non-existent') self.assertEqual([], result) cluster = utils.create_cluster(self.context, CLUSTER_ID, PROFILE_ID) policy1 = utils.create_policy(self.context, 'd752f3e4-7be5-41a6-8a36-85bbbdbd7d4a') policy2 = utils.create_policy(self.context, '0a2e1240-d34f-4c96-8034-37388cdcdb7b') b1 = cpm.ClusterPolicy(cluster.id, policy1.id, enabled=True, priority=10) b1.store(self.context) b2 = cpm.ClusterPolicy(cluster.id, policy2.id, enabled=False, priority=20) b2.store(self.context) # NOTE: we don't test all other parameters because the db api tests # already covered that result = cpm.ClusterPolicy.load_all(self.context, CLUSTER_ID) self.assertEqual(2, len(result))
def test_cluster_policy_store(self): utils.create_profile(self.context, PROFILE_ID) cluster = utils.create_cluster(self.context, CLUSTER_ID, PROFILE_ID) policy = utils.create_policy(self.context, POLICY_ID) values = { 'priority': 12, 'enabled': True, } cp = cpm.ClusterPolicy(cluster.id, policy.id, **values) self.assertIsNone(cp.id) cp_id = cp.store(self.context) self.assertIsNotNone(cp_id) result = cpo.ClusterPolicy.get(self.context, CLUSTER_ID, POLICY_ID) self.assertIsNotNone(result) self.assertEqual(12, result.priority) self.assertTrue(result.enabled) self.assertEqual({}, result.data) self.assertIsNone(result.last_op) # do an update cp.enabled = False cp.priority = 60 cp.data = {'foo': 'bar'} timestamp = timeutils.utcnow(True) cp.last_op = timestamp new_id = cp.store(self.context) self.assertEqual(cp_id, new_id) result = cpo.ClusterPolicy.get(self.context, CLUSTER_ID, POLICY_ID) self.assertIsNotNone(result) self.assertFalse(result.enabled) self.assertEqual(60, result.priority) self.assertEqual({'foo': 'bar'}, result.data) self.assertEqual(common_utils.isotime(timestamp), common_utils.isotime(result.last_op))
def test_cluster_policy_store(self): cluster = utils.create_cluster(self.context, CLUSTER_ID, PROFILE_ID) policy = utils.create_policy(self.context, POLICY_ID) values = { 'priority': 12, 'enabled': True, } cp = cpm.ClusterPolicy(cluster.id, policy.id, **values) self.assertIsNone(cp.id) cp_id = cp.store(self.context) self.assertIsNotNone(cp_id) result = cpo.ClusterPolicy.get(self.context, CLUSTER_ID, POLICY_ID) self.assertIsNotNone(result) self.assertEqual(12, result.priority) self.assertTrue(result.enabled) self.assertEqual({}, result.data) self.assertIsNone(result.last_op) # do an update cp.enabled = False cp.priority = 60 cp.data = {'foo': 'bar'} timestamp = timeutils.utcnow(True) cp.last_op = timestamp new_id = cp.store(self.context) self.assertEqual(cp_id, new_id) result = cpo.ClusterPolicy.get(self.context, CLUSTER_ID, POLICY_ID) self.assertIsNotNone(result) self.assertFalse(result.enabled) self.assertEqual(60, result.priority) self.assertEqual({'foo': 'bar'}, result.data) self.assertEqual(common_utils.isotime(timestamp), common_utils.isotime(result.last_op))
def setUp(self): super(TestNode, self).setUp() self.context = utils.dummy_context(project='node_test_project') self.profile = utils.create_profile(self.context, PROFILE_ID) self.cluster = utils.create_cluster(self.context, CLUSTER_ID, PROFILE_ID)
def setUp(self): super(TestNode, self).setUp() self.context = utils.dummy_context(project='node_test_project') self.profile = utils.create_profile(self.context, PROFILE_ID) self.cluster = utils.create_cluster(self.context, CLUSTER_ID, PROFILE_ID)