-
Notifications
You must be signed in to change notification settings - Fork 77
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Neutron gateway actions #611
Changes from 7 commits
988efd6
5f0c43d
6fb2f3c
74959de
cbc9c84
837bfad
12afecc
a5e5d9e
15ed2ab
b6f6db3
00742d5
728c9fc
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,6 +21,7 @@ | |
|
||
|
||
import copy | ||
import json | ||
import logging | ||
import tenacity | ||
|
||
|
@@ -248,6 +249,141 @@ def _get_services(cls): | |
return services | ||
|
||
|
||
class NeutronGatewayStatusActionsTest(test_utils.OpenStackBaseTest): | ||
"""Test status actions of Neutron Gateway Charm. | ||
|
||
actions: | ||
* get-status-routers | ||
* get-status-dhcp | ||
* get-status-lb | ||
""" | ||
|
||
SKIP_LBAAS_TESTS = True | ||
|
||
@classmethod | ||
def setUpClass(cls, application_name='neutron-gateway', model_alias=None): | ||
"""Run class setup for running Neutron Gateway tests.""" | ||
super(NeutronGatewayStatusActionsTest, cls).setUpClass( | ||
application_name, model_alias) | ||
# set up clients | ||
cls.neutron_client = ( | ||
openstack_utils.get_neutron_session_client(cls.keystone_session)) | ||
|
||
# Loadbalancer tests not supported on Train and above and on | ||
# releases Mitaka and below | ||
current_release = openstack_utils.get_os_release() | ||
bionic_train = openstack_utils.get_os_release('bionic_train') | ||
xenial_mitaka = openstack_utils.get_os_release('xenial_mitaka') | ||
cls.SKIP_LBAAS_TESTS = (current_release <= xenial_mitaka or | ||
current_release >= bionic_train) | ||
|
||
def _assert_result_match(self, action_result, resource_list, | ||
resource_name): | ||
"""Assert that action_result contains same data as resource_list.""" | ||
# make sure that action completed successfully | ||
self.assertEqual(action_result.status, 'completed') | ||
|
||
# extract data from juju action | ||
action_data = action_result.data.get('results', {}).get(resource_name) | ||
resources_from_action = json.loads(action_data) | ||
|
||
# pull resource IDs from expected resource list and juju action data | ||
expected_resource_ids = {resource['id'] for resource in resource_list} | ||
result_resource_ids = {resource['id'] for resource in | ||
resources_from_action} | ||
|
||
# assert that juju action returned expected resources | ||
self.assertEqual(result_resource_ids, expected_resource_ids) | ||
|
||
def test_get_status_routers(self): | ||
"""Test that get-status-routers reports correct neutron routers.""" | ||
# fetch neutron routers using neutron client | ||
ngw_unit = zaza.model.get_units(self.application_name, | ||
model_name=self.model_name)[0] | ||
routers_from_client = self.neutron_client.list_routers().get( | ||
'routers', []) | ||
|
||
if not routers_from_client: | ||
self.fail('At least one router must be configured for this test ' | ||
'to pass.') | ||
|
||
# fetch neutron routers using juju-action | ||
result = zaza.model.run_action(ngw_unit.entity_id, | ||
'get-status-routers', | ||
model_name=self.model_name, | ||
action_params={"format": "json"}) | ||
|
||
# assert that data from neutron client match data from juju action | ||
self._assert_result_match(result, routers_from_client, 'router-list') | ||
|
||
def test_get_status_dhcp(self): | ||
"""Test that get-status-dhcp reports correct DHCP networks.""" | ||
# fetch DHCP networks using neutron client | ||
ngw_unit = zaza.model.get_units(self.application_name, | ||
model_name=self.model_name)[0] | ||
networks_from_client = self.neutron_client.list_networks().get( | ||
'networks', []) | ||
|
||
if not networks_from_client: | ||
self.fail('At least one network must be configured for this test ' | ||
'to pass.') | ||
Comment on lines
+325
to
+327
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As above; should this test be skipped if there is no resource to test against rather than failing? |
||
|
||
# fetch DHCP networks using juju-action | ||
result = zaza.model.run_action(ngw_unit.entity_id, | ||
'get-status-dhcp', | ||
model_name=self.model_name, | ||
action_params={"format": "json"}) | ||
|
||
# assert that data from neutron client match data from juju action | ||
self._assert_result_match(result, networks_from_client, | ||
'dhcp-networks') | ||
|
||
def test_get_status_load_balancers(self): | ||
"""Test that get-status-lb reports correct loadbalancers.""" | ||
if self.SKIP_LBAAS_TESTS: | ||
self.skipTest('LBaasV2 is not supported in this version.') | ||
|
||
loadbalancer_id = None | ||
|
||
try: | ||
# create LBaasV2 for the purpose of this test | ||
lbaas_name = 'test_lbaas' | ||
subnet_list = self.neutron_client.list_subnets( | ||
name='private_subnet').get('subnets', []) | ||
|
||
if not subnet_list: | ||
raise RuntimeError('Expected subnet "private_subnet" is not ' | ||
'configured.') | ||
|
||
subnet = subnet_list[0] | ||
loadbalancer_data = {'loadbalancer': {'name': lbaas_name, | ||
'vip_subnet_id': subnet['id'] | ||
} | ||
} | ||
loadbalancer = self.neutron_client.create_loadbalancer( | ||
body=loadbalancer_data) | ||
loadbalancer_id = loadbalancer['loadbalancer']['id'] | ||
|
||
# test that client and action report same data | ||
ngw_unit = zaza.model.get_units(self.application_name, | ||
model_name=self.model_name)[0] | ||
lbaas_from_client = self.neutron_client.list_loadbalancers().get( | ||
'loadbalancers', []) | ||
|
||
result = zaza.model.run_action(ngw_unit.entity_id, | ||
'get-status-lb', | ||
model_name=self.model_name, | ||
action_params={"format": "json"}) | ||
|
||
self._assert_result_match(result, lbaas_from_client, | ||
'load-balancers') | ||
except Exception as exc: | ||
raise exc | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This isn't needed; the exception with happen if no exceptions are caught which is essentially the same thing. |
||
finally: | ||
if loadbalancer_id: | ||
self.neutron_client.delete_loadbalancer(loadbalancer_id) | ||
|
||
|
||
class NeutronCreateNetworkTest(test_utils.OpenStackBaseTest): | ||
"""Test creating a Neutron network through the API. | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you want the test to fail, or just to be skipped?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Intention was for tests to fail because the model is not properly configured. Unless there's a reason for some test models to not have routers. But none of the func test models had problem with this so far.
Edit: My reasoning was that without the proper resources present on the neutron agents (routers, networks, loadbalancers), we can not verify that these actions return correct data. If we skip these tests, errors may silently creep in, in the future.