From a72ab76593d30adc877273599fc98f091b414c25 Mon Sep 17 00:00:00 2001 From: Eric Kao Date: Fri, 11 Aug 2017 15:46:50 -0700 Subject: [PATCH] add tempest test to activate library policies Test activating library policies in dsvm job. Helpful for testing contributions to policy library. Ideally the test would be done in local unit tests, but with the way policy creation works right now, a functioning datasource (eg. nova) is required. It may be helpful in the future to add a new way of validating library policies without the running datasource. Change-Id: I36d78a7f2764386a1fc251dedd4ecfa696000ec1 --- services/policy/policy_client.py | 12 ++++++++++-- tests/scenario/test_congress_basic_ops.py | 20 ++++++++++++++++++++ 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/services/policy/policy_client.py b/services/policy/policy_client.py index 4921d08..6cb9495 100644 --- a/services/policy/policy_client.py +++ b/services/policy/policy_client.py @@ -45,15 +45,23 @@ class PolicyClient(rest_client.RestClient): driver = '/v1/system/drivers' driver_path = '/v1/system/drivers/%s' + def _add_params_to_url(self, url, params): + for key in params: + url = url + '?{param_name}={param_value}'.format( + param_name=key, param_value=params[key]) + return url + def _resp_helper(self, resp, body=None): if body: body = json.loads(body) return rest_client.ResponseBody(resp, body) - def create_policy(self, body): + def create_policy(self, body, params=None): + if params is None: + params = {} body = json.dumps(body) resp, body = self.post( - self.policy, body=body) + self._add_params_to_url(self.policy, params), body=body) return self._resp_helper(resp, body) def delete_policy(self, policy): diff --git a/tests/scenario/test_congress_basic_ops.py b/tests/scenario/test_congress_basic_ops.py index 3fbaf3c..245d252 100644 --- a/tests/scenario/test_congress_basic_ops.py +++ b/tests/scenario/test_congress_basic_ops.py @@ -241,6 +241,26 @@ class TestPolicyLibraryBasicOps(manager_congress.ScenarioPolicyBase): self.assertNotIn(test_policy, new_state, 'library policy delete not reflected in list results') + @decorators.attr(type='smoke') + def test_create_library_policies(self): + '''test the library policies by loading into policy engine''' + + # list library policies (by name) to skip in this test, perhaps + # because it depends on datasources not available in gate + skip_names_list = [] + + response = self.admin_manager.congress_client.list_library_policy() + library_policies = response['results'] + + for library_policy in library_policies: + if library_policy['name'] not in skip_names_list: + resp = self.admin_manager.congress_client.create_policy( + body=None, params={'library_policy': library_policy['id']}) + self.assertEqual(resp.response['status'], '201', + 'Policy activation failed') + self.addCleanup(self.os_admin.congress_client.delete_policy, + resp['id']) + class TestCongressDataSources(manager_congress.ScenarioPolicyBase):