From f6ca3a1fd382c6e0c03bd226bf411abffb977b6c Mon Sep 17 00:00:00 2001 From: mohankumar_n Date: Wed, 19 Aug 2015 18:49:54 +0530 Subject: [PATCH] Adding registration interface for non_admin_status_resources By default, admin_state_up is set to True in _test_create_resource. If a resource doesn't need to package admin_state_up then it's resource name should be mentioned in "non_admin_status_resources" explicitly. The current logic doesn't work for the extension project/s which are developed outside the tree but depends upon the existing test framework for running their unit test-cases. To address this issue, the patch adds a new registration interface for non_admin_status_resources using which one can add their resource to non_admin_status_resources and avoid admin_state_up packaging. Change-Id: I2abf3bd038f7e444818bfebfed37713ba536f1b5 --- neutronclient/tests/unit/test_cli20.py | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/neutronclient/tests/unit/test_cli20.py b/neutronclient/tests/unit/test_cli20.py index efee1ae..448a48a 100644 --- a/neutronclient/tests/unit/test_cli20.py +++ b/neutronclient/tests/unit/test_cli20.py @@ -15,6 +15,7 @@ # import contextlib +import copy import itertools import sys @@ -38,6 +39,16 @@ FORMAT = 'json' TOKEN = 'testtoken' ENDURL = 'localurl' +non_admin_status_resources = ['subnet', 'floatingip', 'security_group', + 'security_group_rule', 'qos_queue', + 'network_gateway', 'gateway_device', + 'credential', 'network_profile', + 'policy_profile', 'ikepolicy', + 'ipsecpolicy', 'metering_label', + 'metering_label_rule', 'net_partition', + 'fox_socket', 'subnetpool', + 'rbac_policy', 'address_scope'] + @contextlib.contextmanager def capture_std_streams(): @@ -186,6 +197,7 @@ class CLITestV20Base(base.BaseTestCase): """Prepare the test environment.""" super(CLITestV20Base, self).setUp() client.Client.EXTED_PLURALS.update(constants.PLURALS) + self.non_admin_status_resources = copy.copy(non_admin_status_resources) if plurals is not None: client.Client.EXTED_PLURALS.update(plurals) self.metadata = {'plurals': client.Client.EXTED_PLURALS, @@ -207,6 +219,9 @@ class CLITestV20Base(base.BaseTestCase): self._get_attr_metadata)) self.client = client.Client(token=TOKEN, endpoint_url=self.endurl) + def register_non_admin_status_resource(self, resource_name): + self.non_admin_status_resources.append(resource_name) + def _test_create_resource(self, resource, cmd, name, myid, args, position_names, position_values, tenant_id=None, tags=None, admin_state_up=True, @@ -217,18 +232,9 @@ class CLITestV20Base(base.BaseTestCase): self.mox.StubOutWithMock(cmd, "get_client") self.mox.StubOutWithMock(self.client.httpclient, "request") cmd.get_client().MultipleTimes().AndReturn(self.client) - non_admin_status_resources = ['subnet', 'floatingip', 'security_group', - 'security_group_rule', 'qos_queue', - 'network_gateway', 'gateway_device', - 'credential', 'network_profile', - 'policy_profile', 'ikepolicy', - 'ipsecpolicy', 'metering_label', - 'metering_label_rule', 'net_partition', - 'fox_socket', 'subnetpool', - 'rbac_policy', 'address_scope'] if not cmd_resource: cmd_resource = resource - if (resource in non_admin_status_resources): + if (resource in self.non_admin_status_resources): body = {resource: {}, } else: body = {resource: {'admin_state_up': admin_state_up, }, }