Example #1
0
    def test_lb_policy(self):
        # Create cluster
        desired_capacity = 2
        min_size = 1
        max_size = 5
        cluster = test_api.create_cluster(self.client,
                                          test_utils.random_name('cluster'),
                                          self.profile['id'], desired_capacity,
                                          min_size, max_size)
        cluster = test_utils.wait_for_status(test_api.get_cluster, self.client,
                                             cluster['id'], 'ACTIVE')

        # Verify there is no lb information in node data
        cluster = test_api.get_cluster(self.client, cluster['id'])
        for n in cluster['nodes']:
            node = test_api.get_node(self.client, n)
            self.assertNotIn('lb_member', node['data'])

        # Create a lb policy
        spec = test_utils.spec_lb_policy
        lb_policy = test_api.create_policy(self.client,
                                           test_utils.random_name('lb-policy'),
                                           spec)

        # Attach scaling in/out policies to cluster
        params = {"enabled": True, "policy_id": lb_policy['id']}
        action_id = test_api.action_cluster(self.client, cluster['id'],
                                            'policy_attach', params)
        test_utils.wait_for_status(test_api.get_action, self.client, action_id,
                                   'SUCCEEDED')

        # Verify lb information recorded in node data
        cluster = test_api.get_cluster(self.client, cluster['id'])
        for n in cluster['nodes']:
            node = test_api.get_node(self.client, n)
            self.assertIn('lb_member', node['data'])

        # Scale out cluster
        action_id = test_api.action_cluster(self.client, cluster['id'],
                                            'scale_out')
        test_utils.wait_for_status(test_api.get_action, self.client, action_id,
                                   'SUCCEEDED')

        # Verify cluster scale out result
        cluster = test_api.get_cluster(self.client, cluster['id'])
        self.assertEqual('ACTIVE', cluster['status'])
        self.assertEqual(3, len(cluster['nodes']))

        # Verify lb information recorded in node data
        cluster = test_api.get_cluster(self.client, cluster['id'])
        for n in cluster['nodes']:
            node = test_api.get_node(self.client, n)
            self.assertIn('lb_member', node['data'])

        # Scale in cluster
        action_id = test_api.action_cluster(self.client, cluster['id'],
                                            'scale_in')
        test_utils.wait_for_status(test_api.get_action, self.client, action_id,
                                   'SUCCEEDED')

        # Detach scaling lb policy from cluster
        params = {"policy_id": lb_policy['id']}
        action_id = test_api.action_cluster(self.client, cluster['id'],
                                            'policy_detach', params)
        test_utils.wait_for_status(test_api.get_action, self.client, action_id,
                                   'SUCCEEDED')

        # Verify lb information recorded in node data
        cluster = test_api.get_cluster(self.client, cluster['id'])
        for n in cluster['nodes']:
            node = test_api.get_node(self.client, n)
            self.assertNotIn('lb_member', node['data'])

        # Delete policies
        test_api.delete_policy(self.client, lb_policy['id'])

        # Delete cluster
        test_api.delete_cluster(self.client, cluster['id'])
        cluster = test_utils.wait_for_delete(test_api.get_cluster, self.client,
                                             cluster['id'])
Example #2
0
    def test_scaling_policy(self):
        # Create cluster
        desired_capacity = 1
        min_size = 0
        max_size = 5
        cluster = test_api.create_cluster(self.client, 'test-cluster',
                                          self.profile['id'], desired_capacity,
                                          min_size, max_size)
        cluster = test_utils.wait_for_status(test_api.get_cluster, self.client,
                                             cluster['id'], 'ACTIVE')

        # Create a scaling policy targets on CLUSTER_SCALE_OUT action
        spec = test_utils.spec_scaling_policy
        spec['properties'] = {
            'event': 'CLUSTER_SCALE_OUT',
            'adjustment': {
                'type': 'CHANGE_IN_CAPACITY',
                'number': 2,
                'min_step': 1,
                'best_effort': True
            }
        }
        scaling_out_policy = test_api.create_policy(self.client,
                                                    'scaling-out-policy',
                                                    spec, 0, 0)

        # 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
            }
        }
        scaling_in_policy = test_api.create_policy(self.client,
                                                   'scaling-in-policy',
                                                   spec, 0, 0)

        # Attach scaling in/out policies to cluster
        for policy in [scaling_in_policy, scaling_out_policy]:
            params = {
                "priority": 50,
                "level": 50,
                "enabled": True,
                "cooldown": 0,
                "policy_id": policy['id']
            }
            action_id = test_api.action_cluster(self.client, cluster['id'],
                                                'policy_attach', params)
            test_utils.wait_for_status(test_api.get_action, self.client,
                                       action_id, 'SUCCEEDED')

        # Scale out cluster without params
        action_id = test_api.action_cluster(self.client, cluster['id'],
                                            'scale_out')
        test_utils.wait_for_status(test_api.get_action, self.client,
                                   action_id, 'SUCCEEDED')

        # Verify cluster scale out result
        cluster = test_api.get_cluster(self.client, cluster['id'])
        self.assertEqual('ACTIVE', cluster['status'])
        self.assertEqual(3, len(cluster['nodes']))

        # Scale out with count set to 1
        action_id = test_api.action_cluster(self.client, cluster['id'],
                                            'scale_out', {'count': 1})
        test_utils.wait_for_status(test_api.get_action, self.client,
                                   action_id, 'SUCCEEDED')

        # Verify cluster scale out result
        cluster = test_api.get_cluster(self.client, cluster['id'])
        self.assertEqual('ACTIVE', cluster['status'])
        self.assertEqual(4, len(cluster['nodes']))

        # Scale out with count set to 3 to verify best_effort param
        action_id = test_api.action_cluster(self.client, cluster['id'],
                                            'scale_out', {'count': 3})
        test_utils.wait_for_status(test_api.get_action, self.client,
                                   action_id, 'SUCCEEDED')

        # Verify cluster scale out result
        cluster = test_api.get_cluster(self.client, cluster['id'])
        self.assertEqual('ACTIVE', cluster['status'])
        self.assertEqual(5, len(cluster['nodes']))

        # Scale in cluster without params
        action_id = test_api.action_cluster(self.client, cluster['id'],
                                            'scale_in')
        test_utils.wait_for_status(test_api.get_action, self.client,
                                   action_id, 'SUCCEEDED')

        # Verify cluster scale in result
        cluster = test_api.get_cluster(self.client, cluster['id'])
        self.assertEqual('ACTIVE', cluster['status'])
        self.assertEqual(3, len(cluster['nodes']))

        # Scale in without param to verify min_step param
        action_id = test_api.action_cluster(self.client, cluster['id'],
                                            'scale_in')
        test_utils.wait_for_status(test_api.get_action, self.client,
                                   action_id, 'SUCCEEDED')

        # Verify cluster scale in result
        cluster = test_api.get_cluster(self.client, cluster['id'])
        self.assertEqual('ACTIVE', cluster['status'])
        self.assertEqual(1, len(cluster['nodes']))

        # Scale in with count set to 2 to verify best_effort param
        action_id = test_api.action_cluster(self.client, cluster['id'],
                                            'scale_in', {'count': 2})
        action = test_utils.wait_for_status(test_api.get_action, self.client,
                                            action_id, 'FAILED')

        reason = _("Policy check failure: Attempted scaling below minimum "
                   "size.")
        self.assertEqual(reason, action['status_reason'])

        # Verify cluster scale in result
        cluster = test_api.get_cluster(self.client, cluster['id'])
        self.assertEqual('ACTIVE', cluster['status'])
        self.assertEqual(1, len(cluster['nodes']))

        # Detach scaling in/out policies from cluster
        for policy in [scaling_in_policy, scaling_out_policy]:
            params = {
                "policy_id": policy['id']
            }
            action_id = test_api.action_cluster(self.client, cluster['id'],
                                                'policy_detach', params)
            test_utils.wait_for_status(test_api.get_action, self.client,
                                       action_id, 'SUCCEEDED')

        # Delete policies
        test_api.delete_policy(self.client, scaling_in_policy['id'])
        test_api.delete_policy(self.client, scaling_out_policy['id'])

        # Delete cluster
        test_api.delete_cluster(self.client, cluster['id'])
        cluster = test_utils.wait_for_status(test_api.get_cluster, self.client,
                                             cluster['id'], 'DELETED',
                                             ignore_missing=True)
Example #3
0
    def test_scaling_policy(self):
        # Create cluster
        desired_capacity = 1
        min_size = 0
        max_size = 5
        cluster = test_api.create_cluster(self.client, 'test-cluster',
                                          self.profile['id'], desired_capacity,
                                          min_size, max_size)
        cluster = test_utils.wait_for_status(test_api.get_cluster, self.client,
                                             cluster['id'], 'ACTIVE')

        # Create a scaling policy targets on CLUSTER_SCALE_OUT action
        spec = test_utils.spec_scaling_policy
        spec['properties'] = {
            'event': 'CLUSTER_SCALE_OUT',
            'adjustment': {
                'type': 'CHANGE_IN_CAPACITY',
                'number': 2,
                'min_step': 1,
                'best_effort': True
            }
        }
        scaling_out_policy = test_api.create_policy(self.client,
                                                    'scaling-out-policy', spec,
                                                    0, 0)

        # 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
            }
        }
        scaling_in_policy = test_api.create_policy(self.client,
                                                   'scaling-in-policy', spec,
                                                   0, 0)

        # Attach scaling in/out policies to cluster
        for policy in [scaling_in_policy, scaling_out_policy]:
            params = {
                "priority": 50,
                "level": 50,
                "enabled": True,
                "cooldown": 0,
                "policy_id": policy['id']
            }
            action_id = test_api.action_cluster(self.client, cluster['id'],
                                                'policy_attach', params)
            test_utils.wait_for_status(test_api.get_action, self.client,
                                       action_id, 'SUCCEEDED')

        # Scale out cluster without params
        action_id = test_api.action_cluster(self.client, cluster['id'],
                                            'scale_out')
        test_utils.wait_for_status(test_api.get_action, self.client, action_id,
                                   'SUCCEEDED')

        # Verify cluster scale out result
        cluster = test_api.get_cluster(self.client, cluster['id'])
        self.assertEqual('ACTIVE', cluster['status'])
        self.assertEqual(3, len(cluster['nodes']))

        # Scale out with count set to 1
        action_id = test_api.action_cluster(self.client, cluster['id'],
                                            'scale_out', {'count': 1})
        test_utils.wait_for_status(test_api.get_action, self.client, action_id,
                                   'SUCCEEDED')

        # Verify cluster scale out result
        cluster = test_api.get_cluster(self.client, cluster['id'])
        self.assertEqual('ACTIVE', cluster['status'])
        self.assertEqual(4, len(cluster['nodes']))

        # Scale out with count set to 3 to verify best_effort param
        action_id = test_api.action_cluster(self.client, cluster['id'],
                                            'scale_out', {'count': 3})
        test_utils.wait_for_status(test_api.get_action, self.client, action_id,
                                   'SUCCEEDED')

        # Verify cluster scale out result
        cluster = test_api.get_cluster(self.client, cluster['id'])
        self.assertEqual('ACTIVE', cluster['status'])
        self.assertEqual(5, len(cluster['nodes']))

        # Scale in cluster without params
        action_id = test_api.action_cluster(self.client, cluster['id'],
                                            'scale_in')
        test_utils.wait_for_status(test_api.get_action, self.client, action_id,
                                   'SUCCEEDED')

        # Verify cluster scale in result
        cluster = test_api.get_cluster(self.client, cluster['id'])
        self.assertEqual('ACTIVE', cluster['status'])
        self.assertEqual(3, len(cluster['nodes']))

        # Scale in without param to verify min_step param
        action_id = test_api.action_cluster(self.client, cluster['id'],
                                            'scale_in')
        test_utils.wait_for_status(test_api.get_action, self.client, action_id,
                                   'SUCCEEDED')

        # Verify cluster scale in result
        cluster = test_api.get_cluster(self.client, cluster['id'])
        self.assertEqual('ACTIVE', cluster['status'])
        self.assertEqual(1, len(cluster['nodes']))

        # Scale in with count set to 2 to verify best_effort param
        action_id = test_api.action_cluster(self.client, cluster['id'],
                                            'scale_in', {'count': 2})
        action = test_utils.wait_for_status(test_api.get_action, self.client,
                                            action_id, 'FAILED')

        reason = _("Policy check failure: Attempted scaling below minimum "
                   "size.")
        self.assertEqual(reason, action['status_reason'])

        # Verify cluster scale in result
        cluster = test_api.get_cluster(self.client, cluster['id'])
        self.assertEqual('ACTIVE', cluster['status'])
        self.assertEqual(1, len(cluster['nodes']))

        # Detach scaling in/out policies from cluster
        for policy in [scaling_in_policy, scaling_out_policy]:
            params = {"policy_id": policy['id']}
            action_id = test_api.action_cluster(self.client, cluster['id'],
                                                'policy_detach', params)
            test_utils.wait_for_status(test_api.get_action, self.client,
                                       action_id, 'SUCCEEDED')

        # Delete policies
        test_api.delete_policy(self.client, scaling_in_policy['id'])
        test_api.delete_policy(self.client, scaling_out_policy['id'])

        # Delete cluster
        test_api.delete_cluster(self.client, cluster['id'])
        cluster = test_utils.wait_for_status(test_api.get_cluster,
                                             self.client,
                                             cluster['id'],
                                             'DELETED',
                                             ignore_missing=True)
Example #4
0
    def test_lb_policy(self):
        # Create cluster
        desired_capacity = 2
        min_size = 1
        max_size = 5
        cluster = test_api.create_cluster(self.client, 'test-cluster',
                                          self.profile['id'], desired_capacity,
                                          min_size, max_size)

        # Wait and verify cluster creation result
        cluster = test_utils.wait_for_status(test_api.get_cluster, self.client,
                                             cluster['id'], 'ACTIVE')
        self.assertEqual('test-cluster', cluster['name'])
        self.assertEqual(desired_capacity, cluster['desired_capacity'])
        self.assertEqual(min_size, cluster['min_size'])
        self.assertEqual(max_size, cluster['max_size'])
        self.assertEqual(desired_capacity, len(cluster['nodes']))

        # Verify there is no lb information in node data
        cluster = test_api.get_cluster(self.client, cluster['id'])
        for n in cluster['nodes']:
            node = test_api.get_node(self.client, n)
            self.assertNotIn('lb_member', node['data'])

        # Create a lb policy
        spec = test_utils.spec_lb_policy
        lb_policy = test_api.create_policy(self.client, 'test-lb-policy', spec,
                                           0, 0)

        # Attach scaling in/out policies to cluster
        params = {
            "priority": 50,
            "level": 50,
            "enabled": True,
            "cooldown": 0,
            "policy_id": lb_policy['id']
        }
        action_id = test_api.action_cluster(self.client, cluster['id'],
                                            'policy_attach', params)
        test_utils.wait_for_status(test_api.get_action, self.client,
                                   action_id, 'SUCCEEDED')

        # Verify lb information recorded in node data
        cluster = test_api.get_cluster(self.client, cluster['id'])
        for n in cluster['nodes']:
            node = test_api.get_node(self.client, n)
            self.assertIn('lb_member', node['data'])

        # Scale out cluster
        action_id = test_api.action_cluster(self.client, cluster['id'],
                                            'scale_out')
        test_utils.wait_for_status(test_api.get_action, self.client,
                                   action_id, 'SUCCEEDED')

        # Verify cluster scale out result
        cluster = test_api.get_cluster(self.client, cluster['id'])
        self.assertEqual('ACTIVE', cluster['status'])
        self.assertEqual(3, len(cluster['nodes']))

        # Verify lb information recorded in node data
        cluster = test_api.get_cluster(self.client, cluster['id'])
        for n in cluster['nodes']:
            node = test_api.get_node(self.client, n)
            self.assertIn('lb_member', node['data'])

        # Scale in cluster
        action_id = test_api.action_cluster(self.client, cluster['id'],
                                            'scale_in')
        test_utils.wait_for_status(test_api.get_action, self.client,
                                   action_id, 'SUCCEEDED')

        # Detach scaling lb policy from cluster
        params = {
            "policy_id": lb_policy['id']
        }
        action_id = test_api.action_cluster(self.client, cluster['id'],
                                            'policy_detach', params)
        test_utils.wait_for_status(test_api.get_action, self.client,
                                   action_id, 'SUCCEEDED')

        # Verify lb information recorded in node data
        cluster = test_api.get_cluster(self.client, cluster['id'])
        for n in cluster['nodes']:
            node = test_api.get_node(self.client, n)
            self.assertNotIn('lb_member', node['data'])

        # Delete policies
        test_api.delete_policy(self.client, lb_policy['id'])

        # Delete cluster
        test_api.delete_cluster(self.client, cluster['id'])
        cluster = test_utils.wait_for_status(test_api.get_cluster, self.client,
                                             cluster['id'], 'DELETED',
                                             ignore_missing=True)
Example #5
0
    def test_lb_policy(self):
        # Create cluster
        desired_capacity = 2
        min_size = 1
        max_size = 5
        cluster = test_api.create_cluster(self.client,
                                          test_utils.random_name('cluster'),
                                          self.profile['id'], desired_capacity,
                                          min_size, max_size)
        cluster = test_utils.wait_for_status(test_api.get_cluster, self.client,
                                             cluster['id'], 'ACTIVE')

        # Verify there is no lb information in node data
        cluster = test_api.get_cluster(self.client, cluster['id'])
        for n in cluster['nodes']:
            node = test_api.get_node(self.client, n)
            self.assertNotIn('lb_member', node['data'])

        # Create a lb policy
        spec = test_utils.spec_lb_policy
        lb_policy = test_api.create_policy(self.client,
                                           test_utils.random_name('lb-policy'),
                                           spec)

        # Attach scaling in/out policies to cluster
        params = {
            "enabled": True,
            "policy_id": lb_policy['id']
        }
        action_id = test_api.action_cluster(self.client, cluster['id'],
                                            'policy_attach', params)
        test_utils.wait_for_status(test_api.get_action, self.client,
                                   action_id, 'SUCCEEDED')

        # Verify lb information recorded in node data
        cluster = test_api.get_cluster(self.client, cluster['id'])
        for n in cluster['nodes']:
            node = test_api.get_node(self.client, n)
            self.assertIn('lb_member', node['data'])

        # Scale out cluster
        action_id = test_api.action_cluster(self.client, cluster['id'],
                                            'scale_out')
        test_utils.wait_for_status(test_api.get_action, self.client,
                                   action_id, 'SUCCEEDED')

        # Verify cluster scale out result
        cluster = test_api.get_cluster(self.client, cluster['id'])
        self.assertEqual('ACTIVE', cluster['status'])
        self.assertEqual(3, len(cluster['nodes']))

        # Verify lb information recorded in node data
        cluster = test_api.get_cluster(self.client, cluster['id'])
        for n in cluster['nodes']:
            node = test_api.get_node(self.client, n)
            self.assertIn('lb_member', node['data'])

        # Scale in cluster
        action_id = test_api.action_cluster(self.client, cluster['id'],
                                            'scale_in')
        test_utils.wait_for_status(test_api.get_action, self.client,
                                   action_id, 'SUCCEEDED')

        # Detach scaling lb policy from cluster
        params = {
            "policy_id": lb_policy['id']
        }
        action_id = test_api.action_cluster(self.client, cluster['id'],
                                            'policy_detach', params)
        test_utils.wait_for_status(test_api.get_action, self.client,
                                   action_id, 'SUCCEEDED')

        # Verify lb information recorded in node data
        cluster = test_api.get_cluster(self.client, cluster['id'])
        for n in cluster['nodes']:
            node = test_api.get_node(self.client, n)
            self.assertNotIn('lb_member', node['data'])

        # Delete policies
        test_api.delete_policy(self.client, lb_policy['id'])

        # Delete cluster
        test_api.delete_cluster(self.client, cluster['id'])
        cluster = test_utils.wait_for_delete(test_api.get_cluster, self.client,
                                             cluster['id'])