Add functional test for lb_policy

This patch adds functional test for lb_policy. Since all lbaas
driver interfaces are faked in this patch, integration test is
needed for more complete verification.

Change-Id: I7e9317796725ac4b939355946568b2e665723cba
This commit is contained in:
yanyanhu 2015-09-25 03:45:40 -04:00
parent a2dd82a596
commit 1637957040
5 changed files with 194 additions and 1 deletions

View File

@ -72,6 +72,13 @@ def delete_cluster(client, cluster_id):
return
def get_node(client, node_id, ignore_missing=False):
rel_url = 'nodes/%(id)s' % {'id': node_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['node']
def create_profile(client, name, spec, permission=None, metadata={}):
rel_url = 'profiles'
status = [200]

View File

@ -13,7 +13,7 @@
from senlin.drivers.openstack import ceilometer_v2
from senlin.drivers.openstack import heat_v1
from senlin.drivers.openstack import keystone_v3
from senlin.drivers.openstack import lbaas
from senlin.tests.functional.drivers.openstack import lbaas
from senlin.tests.functional.drivers.openstack import neutron_v2
from senlin.tests.functional.drivers.openstack import nova_v2

View File

@ -0,0 +1,36 @@
# 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 senlin.drivers import base
class LoadBalancerDriver(base.DriverBase):
def __init__(self, params):
self.lb_result = {
"loadbalancer": "a36c20d0-18e9-42ce-88fd-82a35977ee8c",
"listener": "35cb8516-1173-4035-8dae-0dae3453f37f",
"pool": "4c0a0a5f-cf8f-44b7-b912-957daa8ce5e5"
}
self.member_id = "9a7aff27-fd41-4ec1-ba4c-3eb92c629313"
def lb_create(self, vip, pool):
return True, self.lb_result
def lb_delete(self, **kwargs):
return True, 'LB deletion succeeded'
def member_add(self, node, lb_id, pool_id, port, subnet):
return self.member_id
def member_remove(self, lb_id, pool_id, member_id):
return True

View File

@ -0,0 +1,127 @@
# 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.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 TestLBPolicy(base.SenlinFunctionalTest):
def setUp(self):
super(TestLBPolicy, 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(TestLBPolicy, self).tearDown()
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)

View File

@ -43,6 +43,29 @@ spec_scaling_policy = {
}
}
spec_lb_policy = {
"type": "senlin.policy.loadbalance",
"version": "1.0",
"properties": {
"pool": {
"protocol": "HTTP",
"protocol_port": 80,
"subnet": "private-subnet",
"lb_method": "ROUND_ROBIN",
"session_persistence": {
"type": "SOURCE_IP",
"cookie_name": "test-cookie"
}
},
"vip": {
"subnet": "private-subnet",
"connection_limit": 100,
"protocol": "HTTP",
"protocol_port": 80
}
}
}
def wait_for_status(func, client, obj_id, expected_status, timeout=60,
ignore_missing=False):