def test_cluster_resize_constraint_breaking(self): # Do best-effort resizing when size upper limit is broken kwargs = { 'adj_type': 'CHANGE_IN_CAPACITY', 'number': 1, 'strict': False } utils.cluster_resize(self, self.cluster_id, **kwargs) # Verify resizing result cluster = utils.get_a_cluster(self, self.cluster_id) self.assertEqual('ACTIVE', cluster['status']) self.assertEqual(4, cluster['desired_capacity']) self.assertEqual(4, len(cluster['nodes'])) # Do best-effort resizing when size lower limit is broken kwargs = { 'adj_type': 'CHANGE_IN_CAPACITY', 'number': -5, 'strict': False } utils.cluster_resize(self, self.cluster_id, **kwargs) # Verify resizing result cluster = utils.get_a_cluster(self, self.cluster_id) self.assertEqual('ACTIVE', cluster['status']) self.assertEqual(2, cluster['desired_capacity']) self.assertEqual(2, len(cluster['nodes']))
def test_cluster_resize_basic(self): # Increase cluster size by specifying adjustment count kwargs = {'adj_type': 'CHANGE_IN_CAPACITY', 'number': 2} utils.cluster_resize(self, self.cluster_id, **kwargs) # Verify resizing result cluster = utils.get_a_cluster(self, self.cluster_id) self.assertEqual('ACTIVE', cluster['status']) self.assertEqual(5, cluster['desired_capacity']) self.assertEqual(5, len(cluster['nodes'])) # Decrease cluster size by specifying adjustment percentage kwargs = {'adj_type': 'CHANGE_IN_PERCENTAGE', 'number': -50} utils.cluster_resize(self, self.cluster_id, **kwargs) # Verify resizing result cluster = utils.get_a_cluster(self, self.cluster_id) self.assertEqual('ACTIVE', cluster['status']) self.assertEqual(3, cluster['desired_capacity']) self.assertEqual(3, len(cluster['nodes'])) # Decrease cluster size by specifying exact capacity kwargs = {'adj_type': 'EXACT_CAPACITY', 'number': 2} utils.cluster_resize(self, self.cluster_id, **kwargs) # Verify resizing result cluster = utils.get_a_cluster(self, self.cluster_id) self.assertEqual('ACTIVE', cluster['status']) self.assertEqual(2, cluster['desired_capacity']) self.assertEqual(2, len(cluster['nodes']))
def test_cluster_resize_constraint_adjusting(self): # Increase cluster size with upper limit increased kwargs = {'adj_type': 'CHANGE_IN_CAPACITY', 'number': 3, 'max_size': 7} utils.cluster_resize(self, self.cluster_id, **kwargs) # Verify resizing result cluster = utils.get_a_cluster(self, self.cluster_id) self.assertEqual('ACTIVE', cluster['status']) self.assertEqual(6, cluster['desired_capacity']) self.assertEqual(6, len(cluster['nodes'])) self.assertEqual(7, cluster['max_size']) # Decrease cluster size upper limit with strict set to False kwargs = {'max_size': 4, 'strict': False} utils.cluster_resize(self, self.cluster_id, **kwargs) # Verify resizing result cluster = utils.get_a_cluster(self, self.cluster_id) self.assertEqual('ACTIVE', cluster['status']) self.assertEqual(4, cluster['desired_capacity']) self.assertEqual(4, len(cluster['nodes'])) self.assertEqual(4, cluster['max_size']) # Decrease cluster size with lower limit decreased kwargs = { 'adj_type': 'CHANGE_IN_CAPACITY', 'number': -4, 'min_size': 0 } utils.cluster_resize(self, self.cluster_id, **kwargs) # Verify resizing result cluster = utils.get_a_cluster(self, self.cluster_id) self.assertEqual('ACTIVE', cluster['status']) self.assertEqual(0, cluster['desired_capacity']) self.assertEqual(0, len(cluster['nodes'])) self.assertEqual(0, cluster['min_size']) # Increase cluster size lower limit with strict set to False kwargs = {'min_size': 2, 'strict': False} utils.cluster_resize(self, self.cluster_id, **kwargs) # Verify resizing result cluster = utils.get_a_cluster(self, self.cluster_id) self.assertEqual('ACTIVE', cluster['status']) self.assertEqual(2, cluster['desired_capacity']) self.assertEqual(2, len(cluster['nodes'])) self.assertEqual(2, cluster['min_size'])
def test_cluster_create_list_delete(self): # Create a cluster desired_capacity = 2 min_size = 1 max_size = 3 metadata = {'k1': 'v1'} timeout = 120 cluster_id1 = utils.create_a_cluster( self, self.profile_id, desired_capacity, min_size, max_size, timeout, metadata) # Verify creation result cluster1 = utils.get_a_cluster(self, cluster_id1) self.assertIsNotNone(cluster1) self.assertEqual(desired_capacity, cluster1['desired_capacity']) self.assertEqual(desired_capacity, len(cluster1['nodes'])) self.assertEqual(min_size, cluster1['min_size']) self.assertEqual(max_size, cluster1['max_size']) self.assertEqual(metadata, cluster1['metadata']) self.assertEqual(timeout, cluster1['timeout']) # Create another cluster cluster_id2 = utils.create_a_cluster(self, self.profile_id) # List clusters clusters = utils.list_clusters(self) self.assertIsNotNone(clusters) cluster_ids = [c['id'] for c in clusters] self.assertIn(cluster_id1, cluster_ids) self.assertIn(cluster_id2, cluster_ids) # Delete cluster utils.delete_a_cluster(self, cluster_id1) utils.delete_a_cluster(self, cluster_id2)
def test_cluster_create_delete(self): # Create a cluster desired_capacity = 2 min_size = 1 max_size = 3 metadata = {'k1': 'v1'} timeout = 600 cluster_id = utils.create_a_cluster( self, self.profile_id, desired_capacity, min_size, max_size, timeout, metadata) # Verify creation result cluster = utils.get_a_cluster(self, cluster_id) self.assertIsNotNone(cluster) self.assertEqual(desired_capacity, cluster['desired_capacity']) self.assertEqual(desired_capacity, len(cluster['nodes'])) for nid in cluster['nodes']: node = utils.get_a_node(self, nid, show_details=True) self.assertEqual('ACTIVE', node['status']) self.assertEqual(cluster_id, node['cluster_id']) self.assertIsNotNone(node['details']) self.assertEqual('ACTIVE', node['details']['status']) self.assertEqual(self.spec['properties']['flavor'], node['details']['flavor']) self.assertEqual(self.spec['properties']['name'], node['details']['name']) metadata = { 'cluster_id': cluster['id'], 'cluster_node_id': node['id'], 'cluster_node_index': six.text_type(node['index']) } self.assertEqual(metadata, node['details']['metadata']) # Delete cluster utils.delete_a_cluster(self, cluster_id)
def test_message_receiver(self): # Create a message type of receiver receiver_id = utils.create_a_receiver(self, None, None, r_type='message') self.addCleanup(utils.delete_a_receiver, self, receiver_id) receiver = utils.get_a_receiver(self, receiver_id) queue_name = receiver['channel']['queue_name'] self.assertTrue(queue_name.startswith('senlin-receiver-')) # Trigger cluster_scale_out action message1 = { 'body': { 'cluster': self.cluster_id, 'action': 'CLUSTER_SCALE_OUT' }, 'ttl': 3600 } utils.post_messages(self, queue_name, [message1]) # Wait and verify result timeout = 120 with timeutils.StopWatch(timeout) as timeout_watch: while timeout > 0: time.sleep(5) cluster = utils.get_a_cluster(self, self.cluster_id) if (len(cluster['nodes']) == 2 and cluster['status'] == 'ACTIVE'): break timeout = timeout_watch.leftover(True) if timeout <= 0: raise Exception('Failed in triggering cluster action.')
def setUp(self): super(TestClusterDelNodesNegativeSizeCheckFailed, self).setUp() self.profile_id = utils.create_a_profile(self) self.addCleanup(utils.delete_a_profile, self, self.profile_id) self.cluster_id = utils.create_a_cluster(self, self.profile_id, desired_capacity=1, min_size=1) self.cluster = utils.get_a_cluster(self, self.cluster_id) self.node_id = self.cluster['nodes'][0] self.addCleanup(utils.delete_a_cluster, self, self.cluster_id)
def test_cluster_update_profile(self): # Update cluster utils.update_a_cluster(self, self.cluster_id, profile_id=self.profile_id_new) # Verify update result cluster = utils.get_a_cluster(self, self.cluster_id) self.assertEqual(self.profile_id_new, cluster['profile_id']) nodes = cluster['nodes'] for n in nodes: node = utils.get_a_node(self, n) self.assertEqual(self.profile_id_new, node['profile_id'])
def test_cluster_update_basic_properties(self): name = 'new-name' metadata = {'k1': 'v1'} timeout = 360 # Update cluster utils.update_a_cluster(self, self.cluster_id, name=name, metadata=metadata, timeout=timeout) # Verify update result cluster = utils.get_a_cluster(self, self.cluster_id) self.assertEqual(name, cluster['name']) self.assertEqual(metadata, cluster['metadata']) self.assertEqual(timeout, cluster['timeout'])
def test_lb_policy(self): # Verify there is no lb information in node data cluster = utils.get_a_cluster(self, self.cluster_id) for n in cluster['nodes']: node = utils.get_a_node(self, n) self.assertNotIn('lb_member', node['data']) # Create a lb policy spec = constants.spec_lb_policy policy_id = utils.create_a_policy(self, spec) lb_policy = utils.get_a_policy(self, policy_id) self.addCleanup(utils.delete_a_policy, self, lb_policy['id']) # Attach lb policy to cluster utils.cluster_attach_policy(self, self.cluster_id, lb_policy['id']) # Verify lb information is added into node data cluster = utils.get_a_cluster(self, self.cluster_id) for n in cluster['nodes']: node = utils.get_a_node(self, n) self.assertIn('lb_member', node['data']) # Scale out cluster utils.cluster_scale_out(self, self.cluster_id) # Verify scale out result cluster = utils.get_a_cluster(self, self.cluster_id) self.assertEqual('ACTIVE', cluster['status']) self.assertEqual(3, cluster['desired_capacity']) self.assertEqual(3, len(cluster['nodes'])) # Verify lb information in all nodes' data cluster = utils.get_a_cluster(self, self.cluster_id) for n in cluster['nodes']: node = utils.get_a_node(self, n) self.assertIn('lb_member', node['data']) # Scale in cluster utils.cluster_scale_in(self, self.cluster_id) # Verify scale in result cluster = utils.get_a_cluster(self, self.cluster_id) self.assertEqual('ACTIVE', cluster['status']) self.assertEqual(2, cluster['desired_capacity']) self.assertEqual(2, len(cluster['nodes'])) for n in cluster['nodes']: node = utils.get_a_node(self, n) self.assertIn('lb_member', node['data']) # Detach lb policy from cluster utils.cluster_detach_policy(self, self.cluster_id, lb_policy['id']) # Verify lb information has been removed from node data cluster = utils.get_a_cluster(self, self.cluster_id) for n in cluster['nodes']: node = utils.get_a_node(self, n) self.assertNotIn('lb_member', node['data'])
def test_batch_policy(self): # Create a batch policy targets on CLUSTER_UPDATE action spec = constants.spec_batch_policy policy_id = utils.create_a_policy(self, spec) self.addCleanup(utils.delete_a_policy, self, policy_id) # Attach batch policy to cluster utils.cluster_attach_policy(self, self.cluster_id, policy_id) self.addCleanup(utils.cluster_detach_policy, self, self.cluster_id, policy_id) utils.update_a_cluster(self, self.cluster_id, profile_id=self.new_profile) # Verify cluster update result cluster = utils.get_a_cluster(self, self.cluster_id) self.assertEqual('ACTIVE', cluster['status']) self.assertEqual(2, len(cluster['nodes'])) self.assertEqual(self.new_profile, cluster['profile_id'])
def test_webhook(self): # Create a webhook type of receiver receiver_id = utils.create_a_receiver(self, self.cluster_id, 'CLUSTER_SCALE_OUT', r_type='webhook', params={'count': 2}) self.addCleanup(utils.delete_a_receiver, self, receiver_id) receiver = utils.get_a_receiver(self, receiver_id) webhook_url = receiver['channel']['alarm_url'] # Trigger webhook and wait for action execution res = self.client.trigger_webhook(webhook_url) action_id = res['location'].split('/actions/')[1] self.client.wait_for_status('actions', action_id, 'SUCCEEDED') # Verify action result cluster = utils.get_a_cluster(self, self.cluster_id) self.assertEqual(2, cluster['desired_capacity']) self.assertEqual(2, len(cluster['nodes']))
def test_cluster_create_delete(self): # Create a cluster desired_capacity = 2 min_size = 1 max_size = 3 metadata = {'k1': 'v1'} timeout = 300 cluster_id = utils.create_a_cluster(self, self.profile_id, desired_capacity, min_size, max_size, timeout, metadata) # Verify creation result cluster = utils.get_a_cluster(self, cluster_id) self.assertIsNotNone(cluster) self.assertEqual(desired_capacity, cluster['desired_capacity']) self.assertEqual(desired_capacity, len(cluster['nodes'])) for nid in cluster['nodes']: node = utils.get_a_node(self, nid) self.assertEqual('ACTIVE', node['status']) self.assertEqual(cluster_id, node['cluster_id']) # Delete cluster utils.delete_a_cluster(self, cluster_id)
def test_cluster_scale_in_out(self): # Scale out cluster without count specified utils.cluster_scale_out(self, self.cluster_id) # Verify scale out result cluster = utils.get_a_cluster(self, self.cluster_id) self.assertEqual('ACTIVE', cluster['status']) self.assertEqual(2, cluster['desired_capacity']) self.assertEqual(2, len(cluster['nodes'])) # Scale out cluster with count set to 2 utils.cluster_scale_out(self, self.cluster_id, count=2) # Verify scale out result cluster = utils.get_a_cluster(self, self.cluster_id) self.assertEqual('ACTIVE', cluster['status']) self.assertEqual(4, cluster['desired_capacity']) self.assertEqual(4, len(cluster['nodes'])) # Keep scaling out cluster with count set to 2 res = utils.cluster_scale_out(self, self.cluster_id, count=2, expected_status='FAILED') # Verify action result and action failure reason cluster = utils.get_a_cluster(self, self.cluster_id) self.assertEqual('ACTIVE', cluster['status']) self.assertEqual(4, cluster['desired_capacity']) self.assertEqual(4, len(cluster['nodes'])) reason = ("The target capacity (6) is greater " "than the cluster's max_size (5).") self.assertEqual(reason, res) # Scale in cluster with count set to 2 utils.cluster_scale_in(self, self.cluster_id, count=2) # Verify scale in result cluster = utils.get_a_cluster(self, self.cluster_id) self.assertEqual('ACTIVE', cluster['status']) self.assertEqual(2, cluster['desired_capacity']) self.assertEqual(2, len(cluster['nodes'])) # Scale in cluster without count specified utils.cluster_scale_in(self, self.cluster_id) # Verify scale in result cluster = utils.get_a_cluster(self, self.cluster_id) self.assertEqual('ACTIVE', cluster['status']) self.assertEqual(1, cluster['desired_capacity']) self.assertEqual(1, len(cluster['nodes'])) # Keep scaling in cluster res = utils.cluster_scale_in(self, self.cluster_id, expected_status='FAILED') # Verify action result and action failure reason cluster = utils.get_a_cluster(self, self.cluster_id) self.assertEqual('ACTIVE', cluster['status']) self.assertEqual(1, cluster['desired_capacity']) self.assertEqual(1, len(cluster['nodes'])) reason = _("The target capacity (0) is less " "than the cluster's min_size (1).") self.assertEqual(reason, res)
def test_scaling_policy(self): # Create a scaling policy targets on CLUSTER_SCALE_OUT action spec = constants.spec_scaling_policy spec['properties'] = { 'event': 'CLUSTER_SCALE_OUT', 'adjustment': { 'type': 'CHANGE_IN_CAPACITY', 'number': 2, 'min_step': 1, 'best_effort': True } } policy_id = utils.create_a_policy(self, spec) scaleout_policy = utils.get_a_policy(self, policy_id) self.addCleanup(utils.delete_a_policy, self, scaleout_policy['id']) # Create a scaling policy targets on CLUSTER_SCALE_IN action spec['properties'] = { 'event': 'CLUSTER_SCALE_IN', 'adjustment': { 'type': 'CHANGE_IN_PERCENTAGE', 'number': 50, 'min_step': 2, 'best_effort': False } } policy_id = utils.create_a_policy(self, spec) scalein_policy = utils.get_a_policy(self, policy_id) self.addCleanup(utils.delete_a_policy, self, scalein_policy['id']) # Attach scale in/out policies to cluster for policy in [scaleout_policy, scalein_policy]: utils.cluster_attach_policy(self, self.cluster_id, policy['id']) self.addCleanup(utils.cluster_detach_policy, self, self.cluster_id, policy['id']) # Scale out cluster without count specified utils.cluster_scale_out(self, self.cluster_id) # Verify scale out result cluster = utils.get_a_cluster(self, self.cluster_id) self.assertEqual('ACTIVE', cluster['status']) self.assertEqual(3, cluster['desired_capacity']) self.assertEqual(3, len(cluster['nodes'])) # Scale out cluster with count set to 1 utils.cluster_scale_out(self, self.cluster_id, count=1) # Verify scale out result cluster = utils.get_a_cluster(self, self.cluster_id) self.assertEqual('ACTIVE', cluster['status']) self.assertEqual(4, cluster['desired_capacity']) self.assertEqual(4, len(cluster['nodes'])) # Keep scaling out cluster with count set to 2 to # verify best_effort parameter utils.cluster_scale_out(self, self.cluster_id, count=2) # Verify scale out result cluster = utils.get_a_cluster(self, self.cluster_id) self.assertEqual('ACTIVE', cluster['status']) self.assertEqual(5, cluster['desired_capacity']) self.assertEqual(5, len(cluster['nodes'])) # Scale in cluster without count specified utils.cluster_scale_in(self, self.cluster_id) # Verify scale in result cluster = utils.get_a_cluster(self, self.cluster_id) self.assertEqual('ACTIVE', cluster['status']) self.assertEqual(3, cluster['desired_capacity']) self.assertEqual(3, len(cluster['nodes'])) # Scale in cluster without count specified to # verify min_step parameter utils.cluster_scale_in(self, self.cluster_id) # Verify scale in result cluster = utils.get_a_cluster(self, self.cluster_id) self.assertEqual('ACTIVE', cluster['status']) self.assertEqual(1, cluster['desired_capacity']) self.assertEqual(1, len(cluster['nodes'])) # Keep scaling in cluster with count set to 2 to # verify best_effort parameter res = utils.cluster_scale_in(self, self.cluster_id, count=2, expected_status='FAILED') # Verify action result and action failure reason cluster = utils.get_a_cluster(self, self.cluster_id) self.assertEqual('ACTIVE', cluster['status']) self.assertEqual(1, cluster['desired_capacity']) self.assertEqual(1, len(cluster['nodes'])) reason = ("Policy check failure: Failed policy '%s': The target " "capacity (-1) is less than the cluster's " "min_size (0).") % scalein_policy['name'] self.assertEqual(reason, res)