Add functional test for cluster scale in/out
Change-Id: If98bc5d36331b445def7ac18cd91ec9f8dfefb1f
This commit is contained in:
parent
c0c5d737be
commit
16b21cddf3
|
@ -51,6 +51,19 @@ def list_clusters(client, **query):
|
|||
return resp.body['clusters']
|
||||
|
||||
|
||||
def action_cluster(client, cluster_id, action_name, params=None):
|
||||
rel_url = 'clusters/%(id)s/action' % {'id': cluster_id}
|
||||
status = [200]
|
||||
data = {
|
||||
action_name: {} if params is None else params
|
||||
}
|
||||
body = jsonutils.dumps(data)
|
||||
resp = client.api_request('PUT', rel_url, body=body,
|
||||
resp_status=status)
|
||||
action_id = resp.body['action']
|
||||
return action_id
|
||||
|
||||
|
||||
def delete_cluster(client, cluster_id):
|
||||
rel_url = 'clusters/%(id)s' % {'id': cluster_id}
|
||||
status = [204]
|
||||
|
@ -88,3 +101,10 @@ def list_policy_types(client, **query):
|
|||
status = [200]
|
||||
resp = client.api_request('GET', rel_url, resp_status=status)
|
||||
return resp.body['policy_types']
|
||||
|
||||
|
||||
def get_action(client, action_id, ignore_missing=False):
|
||||
rel_url = 'actions/%(id)s' % {'id': action_id}
|
||||
status = [200, 404] if ignore_missing else [200]
|
||||
resp = client.api_request('GET', rel_url, resp_status=status)
|
||||
return resp if ignore_missing else resp.body['action']
|
||||
|
|
|
@ -10,12 +10,11 @@
|
|||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
import time
|
||||
|
||||
from oslo_log import log as logging
|
||||
|
||||
from senlin.tests.functional import api as test_api
|
||||
from senlin.tests.functional import base
|
||||
from senlin.tests.functional.utils import test_utils
|
||||
|
||||
LOG = logging.getLogger(__name__)
|
||||
|
||||
|
@ -24,22 +23,8 @@ class TestCluster(base.SenlinFunctionalTest):
|
|||
def setUp(self):
|
||||
super(TestCluster, self).setUp()
|
||||
# Create profile
|
||||
test_nova_spec = {
|
||||
"type": "os.nova.server",
|
||||
"version": "1.0",
|
||||
"properties": {
|
||||
# TODO(Yanyan Hu): Use flavor name rather than ID in
|
||||
# nova server spec file after sdk support is done.
|
||||
"flavor": 1,
|
||||
"name": "new-server-test",
|
||||
"image": "cirros-0.3.2-x86_64-uec",
|
||||
"networks": [
|
||||
{"network": "private-net"}
|
||||
]
|
||||
}
|
||||
}
|
||||
self.profile = test_api.create_profile(self.client, 'test-profile',
|
||||
test_nova_spec)
|
||||
test_utils.spec_nova_server)
|
||||
|
||||
def tearDown(self):
|
||||
# Delete profile
|
||||
|
@ -61,19 +46,8 @@ class TestCluster(base.SenlinFunctionalTest):
|
|||
min_size, max_size)
|
||||
|
||||
# Wait and verify cluster creation result
|
||||
# TODO(Yanyan Hu): Put timeout option into test configure file
|
||||
timeout = 60
|
||||
ready = False
|
||||
while timeout > 0:
|
||||
cluster = test_api.get_cluster(self.client, cluster['id'])
|
||||
if cluster['status'] == 'ACTIVE':
|
||||
ready = True
|
||||
break
|
||||
time.sleep(5)
|
||||
timeout -= 5
|
||||
if not ready:
|
||||
raise Exception('Cluster creation timeout.')
|
||||
|
||||
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'])
|
||||
|
@ -82,14 +56,6 @@ class TestCluster(base.SenlinFunctionalTest):
|
|||
|
||||
# Delete cluster
|
||||
test_api.delete_cluster(self.client, cluster['id'])
|
||||
timeout = 60
|
||||
ready = False
|
||||
while timeout > 0:
|
||||
res = test_api.get_cluster(self.client, cluster['id'], True)
|
||||
if res.status == 404:
|
||||
ready = True
|
||||
break
|
||||
time.sleep(5)
|
||||
timeout -= 5
|
||||
if not ready:
|
||||
raise Exception('Cluster deletion timeout.')
|
||||
test_utils.wait_for_status(test_api.get_cluster, self.client,
|
||||
cluster['id'], 'ACTIVE',
|
||||
ignore_missing=True)
|
|
@ -0,0 +1,132 @@
|
|||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
# not use this file except in compliance with the License. You may obtain
|
||||
# a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
from oslo_log import log as logging
|
||||
|
||||
from senlin.common.i18n import _
|
||||
from senlin.tests.functional import api as test_api
|
||||
from senlin.tests.functional import base
|
||||
from senlin.tests.functional.utils import test_utils
|
||||
|
||||
LOG = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class TestCluster(base.SenlinFunctionalTest):
|
||||
def setUp(self):
|
||||
super(TestCluster, self).setUp()
|
||||
# Create profile
|
||||
self.profile = test_api.create_profile(self.client, 'test-profile',
|
||||
test_utils.spec_nova_server)
|
||||
|
||||
def tearDown(self):
|
||||
# Delete profile
|
||||
test_api.delete_profile(self.client, self.profile['id'])
|
||||
super(TestCluster, self).tearDown()
|
||||
|
||||
def test_cluster_scale_in_out(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']))
|
||||
|
||||
# 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 2
|
||||
action_id = test_api.action_cluster(self.client, cluster['id'],
|
||||
'scale_out', {'count': 2})
|
||||
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']))
|
||||
|
||||
# Keep scaling out and break the size constraint
|
||||
action_id = test_api.action_cluster(self.client, cluster['id'],
|
||||
'scale_out')
|
||||
|
||||
# Wait for cluster scale out action failed
|
||||
action = test_utils.wait_for_status(test_api.get_action, self.client,
|
||||
action_id, 'FAILED')
|
||||
reason = _("The target capacity (6) is greater "
|
||||
"than the cluster's max_size (5).")
|
||||
self.assertEqual(reason, action['status_reason'])
|
||||
|
||||
# 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(4, len(cluster['nodes']))
|
||||
|
||||
# Scale in with count set to 3
|
||||
action_id = test_api.action_cluster(self.client, cluster['id'],
|
||||
'scale_in', {'count': 3})
|
||||
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']))
|
||||
|
||||
# Keep scaling in and break the size constraint
|
||||
action_id = test_api.action_cluster(self.client, cluster['id'],
|
||||
'scale_in')
|
||||
action = test_utils.wait_for_status(test_api.get_action, self.client,
|
||||
action_id, 'FAILED')
|
||||
|
||||
reason = _("The target capacity (0) is less "
|
||||
"than the cluster's min_size (1).")
|
||||
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']))
|
||||
|
||||
# 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)
|
|
@ -0,0 +1,46 @@
|
|||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
# not use this file except in compliance with the License. You may obtain
|
||||
# a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
import time
|
||||
|
||||
|
||||
spec_nova_server = {
|
||||
"type": "os.nova.server",
|
||||
"version": "1.0",
|
||||
"properties": {
|
||||
# TODO(Yanyan Hu): Use flavor name rather than ID in
|
||||
# nova server spec file after sdk support is done.
|
||||
"flavor": 1,
|
||||
"name": "new-server-test",
|
||||
"image": "cirros-0.3.2-x86_64-uec",
|
||||
"networks": [
|
||||
{"network": "private-net"}
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
def wait_for_status(func, client, obj_id, expected_status, timeout=60,
|
||||
ignore_missing=False):
|
||||
# TODO(Yanyan Hu): Put timeout option into test configure file
|
||||
while timeout > 0:
|
||||
res = func(client, obj_id, ignore_missing)
|
||||
if not ignore_missing:
|
||||
if res['status'] == expected_status:
|
||||
return res
|
||||
else:
|
||||
if res.status == 404:
|
||||
return res
|
||||
time.sleep(5)
|
||||
timeout -= 5
|
||||
|
||||
raise Exception('Waiting for status timeout.')
|
Loading…
Reference in New Issue