]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
Remove nvplib and move utility methods into nsxlib
authorSalvatore Orlando <salv.orlando@gmail.com>
Fri, 14 Feb 2014 00:55:13 +0000 (16:55 -0800)
committerThomas Goirand <thomas@goirand.fr>
Thu, 13 Mar 2014 07:20:42 +0000 (15:20 +0800)
This patch completes the process of moving code from nvplib
to nsxlib. Utility methods such as do_request and get_all_query_pages
are transferred into nsxlib, so that nvplib can be safely removed.

Partially implements blueprint nicira-plugin-renaming

Change-Id: I43be18c89ac908ebae32b39a8508a7006b5fe328

16 files changed:
neutron/plugins/vmware/check_nsx_config.py
neutron/plugins/vmware/common/sync.py
neutron/plugins/vmware/nsxlib/__init__.py
neutron/plugins/vmware/nsxlib/l2gateway.py
neutron/plugins/vmware/nsxlib/lsn.py
neutron/plugins/vmware/nsxlib/queue.py
neutron/plugins/vmware/nsxlib/router.py
neutron/plugins/vmware/nsxlib/secgroup.py
neutron/plugins/vmware/nsxlib/switch.py
neutron/plugins/vmware/nvplib.py [deleted file]
neutron/tests/unit/vmware/__init__.py
neutron/tests/unit/vmware/nsxlib/test_l2gateway.py
neutron/tests/unit/vmware/nsxlib/test_router.py
neutron/tests/unit/vmware/nsxlib/test_secgroup.py
neutron/tests/unit/vmware/test_nsx_sync.py
neutron/tests/unit/vmware/test_nsx_utils.py

index 7b2fbd34383adab255cee308ec1c8e5ba28e6188..4fdcdc7ecdae07f0d6d983f4e27077c063b76ae9 100644 (file)
@@ -24,7 +24,7 @@ from oslo.config import cfg
 from neutron.common import config
 from neutron.plugins.vmware.common import config as nsx_config  # noqa
 from neutron.plugins.vmware.common import nsx_utils
-from neutron.plugins.vmware import nvplib
+from neutron.plugins.vmware import nsxlib
 
 config.setup_logging(cfg.CONF)
 
@@ -40,7 +40,7 @@ def get_nsx_controllers(cluster):
 
 def config_helper(config_entity, cluster):
     try:
-        return nvplib.do_request('GET',
+        return nsxlib.do_request('GET',
                                  "/ws.v1/%s?fields=uuid" % config_entity,
                                  cluster=cluster).get('results', [])
     except Exception as e:
@@ -75,7 +75,7 @@ def get_transport_nodes(cluster):
 
 def is_transport_node_connected(cluster, node_uuid):
     try:
-        return nvplib.do_request('GET',
+        return nsxlib.do_request('GET',
                                  "/ws.v1/transport-node/%s/status" % node_uuid,
                                  cluster=cluster)['connection']['connected']
     except Exception as e:
index c4ac707e001cdfea5ace5ed85d8014eaaf1c7265..0a57f0c2115a434ee5f0fd2f87a2e55935a9bd2f 100644 (file)
@@ -28,9 +28,9 @@ from neutron.openstack.common import timeutils
 from neutron.plugins.vmware.api_client import exception as api_exc
 from neutron.plugins.vmware.common import exceptions as nsx_exc
 from neutron.plugins.vmware.common import nsx_utils
+from neutron.plugins.vmware import nsxlib
 from neutron.plugins.vmware.nsxlib import router as routerlib
 from neutron.plugins.vmware.nsxlib import switch as switchlib
-from neutron.plugins.vmware import nvplib
 
 # Maximum page size for a single request
 # NOTE(salv-orlando): This might become a version-dependent map should the
@@ -194,14 +194,14 @@ def _start_loopingcall(min_chunk_size, state_sync_interval, func):
 
 class NvpSynchronizer():
 
-    LS_URI = nvplib._build_uri_path(
-        nvplib.LSWITCH_RESOURCE, fields='uuid,tags,fabric_status',
+    LS_URI = nsxlib._build_uri_path(
+        switchlib.LSWITCH_RESOURCE, fields='uuid,tags,fabric_status',
         relations='LogicalSwitchStatus')
-    LR_URI = nvplib._build_uri_path(
+    LR_URI = nsxlib._build_uri_path(
         routerlib.LROUTER_RESOURCE, fields='uuid,tags,fabric_status',
         relations='LogicalRouterStatus')
-    LP_URI = nvplib._build_uri_path(
-        nvplib.LSWITCHPORT_RESOURCE,
+    LP_URI = nsxlib._build_uri_path(
+        switchlib.LSWITCHPORT_RESOURCE,
         parent_resource_id='*',
         fields='uuid,tags,fabric_status_up',
         relations='LogicalPortStatus')
@@ -494,7 +494,7 @@ class NvpSynchronizer():
                           'max_page_size': MAX_PAGE_SIZE})
             # Only the first request might return the total size,
             # subsequent requests will definetely not
-            results, cursor, total_size = nvplib.get_single_query_page(
+            results, cursor, total_size = nsxlib.get_single_query_page(
                 uri, self._cluster, cursor,
                 min(page_size, MAX_PAGE_SIZE))
             for _req in range(num_requests - 1):
@@ -505,7 +505,7 @@ class NvpSynchronizer():
                 # resource type is below this threshold
                 if not cursor:
                     break
-                req_results, cursor = nvplib.get_single_query_page(
+                req_results, cursor = nsxlib.get_single_query_page(
                     uri, self._cluster, cursor,
                     min(page_size, MAX_PAGE_SIZE))[:2]
                 results.extend(req_results)
index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..8f5bd4830bb37201ef5dc71f52157637f2cea125 100644 (file)
@@ -0,0 +1,144 @@
+# vim: tabstop=4 shiftwidth=4 softtabstop=4
+
+# Copyright 2014 VMware, Inc.
+# All Rights Reserved
+#
+#    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 json
+
+from neutron.common import exceptions as exception
+from neutron.openstack.common import log
+from neutron.plugins.vmware.api_client import exception as api_exc
+from neutron.plugins.vmware.common import exceptions as nsx_exc
+from neutron.version import version_info
+
+HTTP_GET = "GET"
+HTTP_POST = "POST"
+HTTP_DELETE = "DELETE"
+HTTP_PUT = "PUT"
+# Prefix to be used for all NVP API calls
+URI_PREFIX = "/ws.v1"
+NEUTRON_VERSION = version_info.release_string()
+
+LOG = log.getLogger(__name__)
+
+
+def _build_uri_path(resource,
+                    resource_id=None,
+                    parent_resource_id=None,
+                    fields=None,
+                    relations=None,
+                    filters=None,
+                    types=None,
+                    is_attachment=False,
+                    extra_action=None):
+    resources = resource.split('/')
+    res_path = resources[0] + (resource_id and "/%s" % resource_id or '')
+    if len(resources) > 1:
+        # There is also a parent resource to account for in the uri
+        res_path = "%s/%s/%s" % (resources[1],
+                                 parent_resource_id,
+                                 res_path)
+    if is_attachment:
+        res_path = "%s/attachment" % res_path
+    elif extra_action:
+        res_path = "%s/%s" % (res_path, extra_action)
+    params = []
+    params.append(fields and "fields=%s" % fields)
+    params.append(relations and "relations=%s" % relations)
+    params.append(types and "types=%s" % types)
+    if filters:
+        params.extend(['%s=%s' % (k, v) for (k, v) in filters.iteritems()])
+    uri_path = "%s/%s" % (URI_PREFIX, res_path)
+    non_empty_params = [x for x in params if x is not None]
+    if non_empty_params:
+        query_string = '&'.join(non_empty_params)
+        if query_string:
+            uri_path += "?%s" % query_string
+    return uri_path
+
+
+def format_exception(etype, e, exception_locals):
+    """Consistent formatting for exceptions.
+
+    :param etype: a string describing the exception type.
+    :param e: the exception.
+    :param execption_locals: calling context local variable dict.
+    :returns: a formatted string.
+    """
+    msg = [_("Error. %(type)s exception: %(exc)s.") %
+           {'type': etype, 'exc': e}]
+    l = dict((k, v) for k, v in exception_locals.iteritems()
+             if k != 'request')
+    msg.append(_("locals=[%s]") % str(l))
+    return ' '.join(msg)
+
+
+def do_request(*args, **kwargs):
+    """Issue a request to the cluster specified in kwargs.
+
+    :param args: a list of positional arguments.
+    :param kwargs: a list of keyworkds arguments.
+    :returns: the result of the operation loaded into a python
+        object or None.
+    """
+    cluster = kwargs["cluster"]
+    try:
+        res = cluster.api_client.request(*args)
+        if res:
+            return json.loads(res)
+    except api_exc.ResourceNotFound:
+        raise exception.NotFound()
+    except api_exc.ReadOnlyMode:
+        raise nsx_exc.MaintenanceInProgress()
+
+
+def get_single_query_page(path, cluster, page_cursor=None,
+                          page_length=1000, neutron_only=True):
+    params = []
+    if page_cursor:
+        params.append("_page_cursor=%s" % page_cursor)
+    params.append("_page_length=%s" % page_length)
+    # NOTE(salv-orlando): On the NSX backend the 'Quantum' tag is still
+    # used for marking Neutron entities in order to preserve compatibility
+    if neutron_only:
+        params.append("tag_scope=quantum")
+    query_params = "&".join(params)
+    path = "%s%s%s" % (path, "&" if (path.find("?") != -1) else "?",
+                       query_params)
+    body = do_request(HTTP_GET, path, cluster=cluster)
+    # Result_count won't be returned if _page_cursor is supplied
+    return body['results'], body.get('page_cursor'), body.get('result_count')
+
+
+def get_all_query_pages(path, cluster):
+    need_more_results = True
+    result_list = []
+    page_cursor = None
+    while need_more_results:
+        results, page_cursor = get_single_query_page(
+            path, cluster, page_cursor)[:2]
+        if not page_cursor:
+            need_more_results = False
+        result_list.extend(results)
+    return result_list
+
+
+def mk_body(**kwargs):
+    """Convenience function creates and dumps dictionary to string.
+
+    :param kwargs: the key/value pirs to be dumped into a json string.
+    :returns: a json string.
+    """
+    return json.dumps(kwargs, ensure_ascii=False)
index c48353ccf5ad6306c93bb41a22fc2302fceeb5e3..46128acbead28098e44cc9ff01e4f487c5525876 100644 (file)
@@ -18,10 +18,10 @@ import json
 
 from neutron.openstack.common import log
 from neutron.plugins.vmware.common import utils
+from neutron.plugins.vmware.nsxlib import _build_uri_path
+from neutron.plugins.vmware.nsxlib import do_request
+from neutron.plugins.vmware.nsxlib import get_all_query_pages
 from neutron.plugins.vmware.nsxlib import switch
-from neutron.plugins.vmware.nvplib import _build_uri_path
-from neutron.plugins.vmware.nvplib import do_request
-from neutron.plugins.vmware.nvplib import get_all_query_pages
 
 HTTP_GET = "GET"
 HTTP_POST = "POST"
index bec5567fd421318b98b030be6799c40616465817..de73bf88ea6b9074a2c211bb2424fb256591e3e0 100644 (file)
@@ -22,8 +22,8 @@ from neutron.openstack.common import log
 from neutron.plugins.vmware.api_client import exception as api_exc
 from neutron.plugins.vmware.common import exceptions as nsx_exc
 from neutron.plugins.vmware.common import utils
-from neutron.plugins.vmware.nvplib import _build_uri_path
-from neutron.plugins.vmware.nvplib import do_request
+from neutron.plugins.vmware.nsxlib import _build_uri_path
+from neutron.plugins.vmware.nsxlib import do_request
 
 HTTP_GET = "GET"
 HTTP_POST = "POST"
index 8e92124b857c1c11da776e5a6c77f6b0546a6fa0..db393c392b58f1252d4ad390e7897efa5a7eab7d 100644 (file)
@@ -20,8 +20,8 @@ from neutron.openstack.common import jsonutils
 from neutron.openstack.common import log
 from neutron.plugins.vmware.api_client import exception as api_exc
 from neutron.plugins.vmware.common import utils
-from neutron.plugins.vmware.nvplib import _build_uri_path
-from neutron.plugins.vmware.nvplib import do_request
+from neutron.plugins.vmware.nsxlib import _build_uri_path
+from neutron.plugins.vmware.nsxlib import do_request
 
 HTTP_POST = "POST"
 HTTP_DELETE = "DELETE"
index 3f39e36e7383c9c15797b6181432a7850ee20e80..75c432911d74f42edb02b91a137347c32e3813c9 100644 (file)
@@ -20,12 +20,12 @@ from neutron.openstack.common import log
 from neutron.plugins.vmware.api_client import exception as api_exc
 from neutron.plugins.vmware.common import exceptions as nsx_exc
 from neutron.plugins.vmware.common import utils
+from neutron.plugins.vmware.nsxlib import _build_uri_path
+from neutron.plugins.vmware.nsxlib import do_request
+from neutron.plugins.vmware.nsxlib import get_all_query_pages
 from neutron.plugins.vmware.nsxlib.switch import get_port
 from neutron.plugins.vmware.nsxlib.versioning import DEFAULT_VERSION
 from neutron.plugins.vmware.nsxlib.versioning import versioned
-from neutron.plugins.vmware.nvplib import _build_uri_path
-from neutron.plugins.vmware.nvplib import do_request
-from neutron.plugins.vmware.nvplib import get_all_query_pages
 
 HTTP_GET = "GET"
 HTTP_POST = "POST"
index ef34458c3659a981f26c90fa60d48d5b096a3bb0..c7dac80f2a5fb32773d4b70dfd08d1c63760ac0d 100644 (file)
@@ -19,10 +19,10 @@ from neutron.common import constants
 from neutron.common import exceptions
 from neutron.openstack.common import log
 from neutron.plugins.vmware.common import utils
-from neutron.plugins.vmware.nvplib import _build_uri_path
-from neutron.plugins.vmware.nvplib import do_request
-from neutron.plugins.vmware.nvplib import format_exception
-from neutron.plugins.vmware.nvplib import get_all_query_pages
+from neutron.plugins.vmware.nsxlib import _build_uri_path
+from neutron.plugins.vmware.nsxlib import do_request
+from neutron.plugins.vmware.nsxlib import format_exception
+from neutron.plugins.vmware.nsxlib import get_all_query_pages
 
 HTTP_GET = "GET"
 HTTP_POST = "POST"
index 391635adcc073d15f5ade28562966fb3cf96dbd7..a451add2a551d359d0b5498e59aaecffd2c3b04d 100644 (file)
@@ -22,9 +22,9 @@ from neutron.openstack.common import log
 from neutron.plugins.vmware.api_client import exception as api_exc
 from neutron.plugins.vmware.common import exceptions as nsx_exc
 from neutron.plugins.vmware.common import utils
-from neutron.plugins.vmware.nvplib import _build_uri_path
-from neutron.plugins.vmware.nvplib import do_request
-from neutron.plugins.vmware.nvplib import get_all_query_pages
+from neutron.plugins.vmware.nsxlib import _build_uri_path
+from neutron.plugins.vmware.nsxlib import do_request
+from neutron.plugins.vmware.nsxlib import get_all_query_pages
 
 HTTP_GET = "GET"
 HTTP_POST = "POST"
diff --git a/neutron/plugins/vmware/nvplib.py b/neutron/plugins/vmware/nvplib.py
deleted file mode 100644 (file)
index e851dd6..0000000
+++ /dev/null
@@ -1,141 +0,0 @@
-# Copyright 2012 VMware, Inc.
-# All Rights Reserved
-#
-#    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 json
-
-
-from neutron.common import exceptions as exception
-from neutron.openstack.common import log
-from neutron.plugins.vmware.api_client import exception as api_exc
-from neutron.plugins.vmware.common import exceptions as nsx_exc
-
-
-LOG = log.getLogger(__name__)
-# HTTP METHODS CONSTANTS
-HTTP_GET = "GET"
-HTTP_POST = "POST"
-HTTP_DELETE = "DELETE"
-HTTP_PUT = "PUT"
-# Prefix to be used for all NSX API calls
-URI_PREFIX = "/ws.v1"
-
-LSWITCH_RESOURCE = "lswitch"
-LSWITCHPORT_RESOURCE = "lport/%s" % LSWITCH_RESOURCE
-
-# Maximum page size for a single request
-# NOTE(salv-orlando): This might become a version-dependent map should the
-# limit be raised in future versions
-MAX_PAGE_SIZE = 5000
-
-
-def _build_uri_path(resource,
-                    resource_id=None,
-                    parent_resource_id=None,
-                    fields=None,
-                    relations=None,
-                    filters=None,
-                    types=None,
-                    is_attachment=False,
-                    extra_action=None):
-    resources = resource.split('/')
-    res_path = resources[0] + (resource_id and "/%s" % resource_id or '')
-    if len(resources) > 1:
-        # There is also a parent resource to account for in the uri
-        res_path = "%s/%s/%s" % (resources[1],
-                                 parent_resource_id,
-                                 res_path)
-    if is_attachment:
-        res_path = "%s/attachment" % res_path
-    elif extra_action:
-        res_path = "%s/%s" % (res_path, extra_action)
-    params = []
-    params.append(fields and "fields=%s" % fields)
-    params.append(relations and "relations=%s" % relations)
-    params.append(types and "types=%s" % types)
-    if filters:
-        params.extend(['%s=%s' % (k, v) for (k, v) in filters.iteritems()])
-    uri_path = "%s/%s" % (URI_PREFIX, res_path)
-    non_empty_params = [x for x in params if x is not None]
-    if non_empty_params:
-        query_string = '&'.join(non_empty_params)
-        if query_string:
-            uri_path += "?%s" % query_string
-    return uri_path
-
-
-def get_single_query_page(path, cluster, page_cursor=None,
-                          page_length=1000, neutron_only=True):
-    params = []
-    if page_cursor:
-        params.append("_page_cursor=%s" % page_cursor)
-    params.append("_page_length=%s" % page_length)
-    # NOTE(salv-orlando): On the NSX backend the 'Quantum' tag is still
-    # used for marking Neutron entities in order to preserve compatibility
-    if neutron_only:
-        params.append("tag_scope=quantum")
-    query_params = "&".join(params)
-    path = "%s%s%s" % (path, "&" if (path.find("?") != -1) else "?",
-                       query_params)
-    body = do_request(HTTP_GET, path, cluster=cluster)
-    # Result_count won't be returned if _page_cursor is supplied
-    return body['results'], body.get('page_cursor'), body.get('result_count')
-
-
-def get_all_query_pages(path, c):
-    need_more_results = True
-    result_list = []
-    page_cursor = None
-    while need_more_results:
-        results, page_cursor = get_single_query_page(
-            path, c, page_cursor)[:2]
-        if not page_cursor:
-            need_more_results = False
-        result_list.extend(results)
-    return result_list
-
-
-def format_exception(etype, e, exception_locals):
-    """Consistent formatting for exceptions.
-
-    :param etype: a string describing the exception type.
-    :param e: the exception.
-    :param execption_locals: calling context local variable dict.
-    :returns: a formatted string.
-    """
-    msg = [_("Error. %(type)s exception: %(exc)s.") %
-           {'type': etype, 'exc': e}]
-    l = dict((k, v) for k, v in exception_locals.iteritems()
-             if k != 'request')
-    msg.append(_("locals=[%s]") % str(l))
-    return ' '.join(msg)
-
-
-def do_request(*args, **kwargs):
-    """Issue a request to the cluster specified in kwargs.
-
-    :param args: a list of positional arguments.
-    :param kwargs: a list of keyworkds arguments.
-    :returns: the result of the operation loaded into a python
-        object or None.
-    """
-    cluster = kwargs["cluster"]
-    try:
-        res = cluster.api_client.request(*args)
-        if res:
-            return json.loads(res)
-    except api_exc.ResourceNotFound:
-        raise exception.NotFound()
-    except api_exc.ReadOnlyMode:
-        raise nsx_exc.MaintenanceInProgress()
index 31a212256d72c85951db308c88fc34e2dced9680..df966786039d7f23e45fc41909c5a76b8ce9c400 100644 (file)
@@ -19,7 +19,6 @@ import os
 from neutron.plugins.vmware.api_client import client as nsx_client
 from neutron.plugins.vmware.api_client import eventlet_client
 from neutron.plugins.vmware import extensions
-from neutron.plugins.vmware import nvplib
 import neutron.plugins.vmware.plugin as neutron_plugin
 from neutron.plugins.vmware.vshield.common import VcnsApiClient as vcnsapi
 from neutron.plugins.vmware.vshield import vcns
@@ -37,7 +36,6 @@ vcns_api_helper = vcnsapi.VcnsApiHelper
 STUBS_PATH = os.path.join(os.path.dirname(__file__), 'etc')
 NSXEXT_PATH = os.path.dirname(extensions.__file__)
 NSXAPI_NAME = '%s.%s' % (api_client.__module__, api_client.__name__)
-NSXLIB_NAME = nvplib.__name__
 PLUGIN_NAME = '%s.%s' % (plugin.__module__, plugin.__name__)
 SERVICE_PLUGIN_NAME = '%s.%s' % (service_plugin.__module__,
                                  service_plugin.__name__)
@@ -51,5 +49,5 @@ def get_fake_conf(filename):
     return os.path.join(STUBS_PATH, filename)
 
 
-def nsx_method(method_name, module_name='nvplib'):
+def nsx_method(method_name, module_name='nsxlib'):
     return '%s.%s.%s' % ('neutron.plugins.vmware', module_name, method_name)
index 4d2ac853e6d709c7bb01125768395c4125ca438f..d122ad05104b9bae1367a8f9827fd31e00c319aa 100644 (file)
@@ -15,6 +15,7 @@
 #
 
 from neutron.plugins.vmware.api_client import exception
+from neutron.plugins.vmware import nsxlib
 from neutron.plugins.vmware.nsxlib import l2gateway as l2gwlib
 from neutron.plugins.vmware.nsxlib import switch as switchlib
 from neutron.tests.unit import test_api_v2
@@ -135,12 +136,12 @@ class L2GatewayTestCase(base.NsxlibTestCase):
         l2gwlib.plug_l2_gw_service(
             self.fake_cluster, lswitch['uuid'],
             lport['uuid'], gw_id)
-        uri = l2gwlib._build_uri_path(switchlib.LSWITCHPORT_RESOURCE,
-                                      lport['uuid'],
-                                      lswitch['uuid'],
-                                      is_attachment=True)
-        resp_obj = l2gwlib.do_request("GET", uri,
-                                      cluster=self.fake_cluster)
+        uri = nsxlib._build_uri_path(switchlib.LSWITCHPORT_RESOURCE,
+                                     lport['uuid'],
+                                     lswitch['uuid'],
+                                     is_attachment=True)
+        resp_obj = nsxlib.do_request("GET", uri,
+                                     cluster=self.fake_cluster)
         self.assertIn('LogicalPortAttachment', resp_obj)
         self.assertEqual(resp_obj['LogicalPortAttachment']['type'],
                          'L2GatewayAttachment')
index 4f62ab48801c7d344fd7d21c6e23bc893ae4ddb1..c2384400ceff8859aa57f7dee288d7c8c4b90c69 100644 (file)
@@ -22,6 +22,7 @@ from neutron.plugins.vmware.api_client import exception as api_exc
 from neutron.plugins.vmware.api_client.version import Version
 from neutron.plugins.vmware.common import exceptions as nsx_exc
 from neutron.plugins.vmware.common import utils
+from neutron.plugins.vmware import nsxlib
 from neutron.plugins.vmware.nsxlib import router as routerlib
 from neutron.plugins.vmware.nsxlib import switch as switchlib
 from neutron.tests.unit import test_api_v2
@@ -46,11 +47,10 @@ class TestNatRules(base.NsxlibTestCase):
                 self.fake_cluster, lrouter['uuid'], '10.0.0.99',
                 match_criteria={'destination_ip_addresses':
                                 '192.168.0.5'})
-            uri = routerlib._build_uri_path(routerlib.LROUTERNAT_RESOURCE,
-                                            nat_rule['uuid'],
-                                            lrouter['uuid'])
-            resp_obj = routerlib.do_request(
-                "GET", uri, cluster=self.fake_cluster)
+            uri = nsxlib._build_uri_path(routerlib.LROUTERNAT_RESOURCE,
+                                         nat_rule['uuid'],
+                                         lrouter['uuid'])
+            resp_obj = nsxlib.do_request("GET", uri, cluster=self.fake_cluster)
             self.assertEqual('DestinationNatRule', resp_obj['type'])
             self.assertEqual('192.168.0.5',
                              resp_obj['match']['destination_ip_addresses'])
index 66e9a2e3dc9d95a4b988ade681d17be3b29f5cf5..b5020100ef9d7d957156acdff4657054194c9f7d 100644 (file)
@@ -15,8 +15,8 @@
 #
 
 from neutron.common import exceptions
+from neutron.plugins.vmware import nsxlib
 from neutron.plugins.vmware.nsxlib import secgroup as secgrouplib
-from neutron.plugins.vmware import nvplib as nsx_utils
 from neutron.tests.unit import test_api_v2
 from neutron.tests.unit.vmware.nsxlib import base
 
@@ -28,10 +28,10 @@ class SecurityProfileTestCase(base.NsxlibTestCase):
     def test_create_and_get_security_profile(self):
         sec_prof = secgrouplib.create_security_profile(
             self.fake_cluster, _uuid(), 'pippo', {'name': 'test'})
-        sec_prof_res = secgrouplib.do_request(
+        sec_prof_res = nsxlib.do_request(
             secgrouplib.HTTP_GET,
-            nsx_utils._build_uri_path('security-profile',
-                                      resource_id=sec_prof['uuid']),
+            nsxlib._build_uri_path('security-profile',
+                                   resource_id=sec_prof['uuid']),
             cluster=self.fake_cluster)
         self.assertEqual(sec_prof['uuid'], sec_prof_res['uuid'])
         # Check for builtin rules
@@ -41,10 +41,10 @@ class SecurityProfileTestCase(base.NsxlibTestCase):
     def test_create_and_get_default_security_profile(self):
         sec_prof = secgrouplib.create_security_profile(
             self.fake_cluster, _uuid(), 'pippo', {'name': 'default'})
-        sec_prof_res = nsx_utils.do_request(
+        sec_prof_res = nsxlib.do_request(
             secgrouplib.HTTP_GET,
-            nsx_utils._build_uri_path('security-profile',
-                                      resource_id=sec_prof['uuid']),
+            nsxlib._build_uri_path('security-profile',
+                                   resource_id=sec_prof['uuid']),
             cluster=self.fake_cluster)
         self.assertEqual(sec_prof['uuid'], sec_prof_res['uuid'])
         # Check for builtin rules
@@ -60,10 +60,10 @@ class SecurityProfileTestCase(base.NsxlibTestCase):
                      'logical_port_ingress_rules': [ingress_rule]}
         secgrouplib.update_security_group_rules(
             self.fake_cluster, sec_prof['uuid'], new_rules)
-        sec_prof_res = nsx_utils.do_request(
-            secgrouplib.HTTP_GET,
-            nsx_utils._build_uri_path('security-profile',
-                                      resource_id=sec_prof['uuid']),
+        sec_prof_res = nsxlib.do_request(
+            nsxlib.HTTP_GET,
+            nsxlib._build_uri_path('security-profile',
+                                   resource_id=sec_prof['uuid']),
             cluster=self.fake_cluster)
         self.assertEqual(sec_prof['uuid'], sec_prof_res['uuid'])
         # Check for builtin rules
@@ -84,10 +84,10 @@ class SecurityProfileTestCase(base.NsxlibTestCase):
                      'logical_port_ingress_rules': []}
         secgrouplib.update_security_group_rules(
             self.fake_cluster, sec_prof['uuid'], new_rules)
-        sec_prof_res = nsx_utils.do_request(
-            nsx_utils.HTTP_GET,
-            nsx_utils._build_uri_path('security-profile',
-                                      resource_id=sec_prof['uuid']),
+        sec_prof_res = nsxlib.do_request(
+            nsxlib.HTTP_GET,
+            nsxlib._build_uri_path('security-profile',
+                                   resource_id=sec_prof['uuid']),
             cluster=self.fake_cluster)
         self.assertEqual(sec_prof['uuid'], sec_prof_res['uuid'])
         # Check for builtin rules
@@ -111,9 +111,9 @@ class SecurityProfileTestCase(base.NsxlibTestCase):
         secgrouplib.delete_security_profile(
             self.fake_cluster, sec_prof['uuid'])
         self.assertRaises(exceptions.NotFound,
-                          secgrouplib.do_request,
-                          secgrouplib.HTTP_GET,
-                          nsx_utils._build_uri_path(
+                          nsxlib.do_request,
+                          nsxlib.HTTP_GET,
+                          nsxlib._build_uri_path(
                               'security-profile',
                               resource_id=sec_prof['uuid']),
                           cluster=self.fake_cluster)
index 12a36a535b819dfadcef040a5344fef7c9322314..cd4fc1d538979e1c2919dfe80e4c95c25144fc24 100644 (file)
@@ -31,7 +31,7 @@ from neutron.plugins.vmware.api_client import exception as api_exc
 from neutron.plugins.vmware.api_client import version
 from neutron.plugins.vmware.common import sync
 from neutron.plugins.vmware import nsx_cluster as cluster
-from neutron.plugins.vmware import nvplib as nsx_utils
+from neutron.plugins.vmware import nsxlib
 from neutron.plugins.vmware import plugin
 from neutron.tests import base
 from neutron.tests.unit import test_api_v2
@@ -461,7 +461,7 @@ class SyncTestCase(base.BaseTestCase):
     def _test_sync_with_chunk_larger_maxpagesize(
         self, net_size, port_size, router_size, chunk_size, exp_calls):
         ctx = context.get_admin_context()
-        real_func = nsx_utils.get_single_query_page
+        real_func = nsxlib.get_single_query_page
         sp = sync.SyncParameters(chunk_size)
         with self._populate_data(ctx, net_size=net_size,
                                  port_size=port_size,
@@ -470,7 +470,7 @@ class SyncTestCase(base.BaseTestCase):
                 # The following mock is just for counting calls,
                 # but we will still run the actual function
                 with mock.patch.object(
-                    nsx_utils, 'get_single_query_page',
+                    nsxlib, 'get_single_query_page',
                     side_effect=real_func) as mock_get_page:
                     self._test_sync(
                         constants.NET_STATUS_ACTIVE,
index 001af0e4ac6fc87acad65b84f016ce2370e9ec32..3b8dc4fd5d009311a9222304956ca2d914633c04 100644 (file)
@@ -21,7 +21,7 @@ from neutron.plugins.vmware.api_client import exception as api_exc
 from neutron.plugins.vmware.common import exceptions as nsx_exc
 from neutron.plugins.vmware.common import nsx_utils
 from neutron.plugins.vmware.common import utils
-from neutron.plugins.vmware import nvplib
+from neutron.plugins.vmware import nsxlib
 from neutron.tests import base
 from neutron.tests.unit.vmware import nsx_method
 from neutron.tests.unit.vmware.nsxlib import base as nsx_base
@@ -66,7 +66,7 @@ class NsxUtilsTestCase(base.BaseTestCase):
                               module_name='dbexts.db')).start()
 
     def _verify_get_nsx_switch_and_port_id(self, exp_ls_uuid, exp_lp_uuid):
-        # The nvplib and db calls are  mocked, therefore the cluster
+        # The nsxlib and db calls are mocked, therefore the cluster
         # and the neutron_port_id parameters can be set to None
         ls_uuid, lp_uuid = nsx_utils.get_nsx_switch_and_port_id(
             db_api.get_session(), None, None)
@@ -74,7 +74,7 @@ class NsxUtilsTestCase(base.BaseTestCase):
         self.assertEqual(exp_lp_uuid, lp_uuid)
 
     def _verify_get_nsx_switch_ids(self, exp_ls_uuids):
-        # The nvplib and db calls are  mocked, therefore the cluster
+        # The nsxlib and db calls are mocked, therefore the cluster
         # and the neutron_router_id parameters can be set to None
         ls_uuids = nsx_utils.get_nsx_switch_ids(
             db_api.get_session(), None, None)
@@ -209,27 +209,27 @@ class NsxUtilsTestCase(base.BaseTestCase):
         self.assertEqual(len(result), utils.MAX_DISPLAY_NAME_LEN)
 
     def test_build_uri_path_plain(self):
-        result = nvplib._build_uri_path('RESOURCE')
-        self.assertEqual("%s/%s" % (nvplib.URI_PREFIX, 'RESOURCE'), result)
+        result = nsxlib._build_uri_path('RESOURCE')
+        self.assertEqual("%s/%s" % (nsxlib.URI_PREFIX, 'RESOURCE'), result)
 
     def test_build_uri_path_with_field(self):
-        result = nvplib._build_uri_path('RESOURCE', fields='uuid')
-        expected = "%s/%s?fields=uuid" % (nvplib.URI_PREFIX, 'RESOURCE')
+        result = nsxlib._build_uri_path('RESOURCE', fields='uuid')
+        expected = "%s/%s?fields=uuid" % (nsxlib.URI_PREFIX, 'RESOURCE')
         self.assertEqual(expected, result)
 
     def test_build_uri_path_with_filters(self):
         filters = {"tag": 'foo', "tag_scope": "scope_foo"}
-        result = nvplib._build_uri_path('RESOURCE', filters=filters)
+        result = nsxlib._build_uri_path('RESOURCE', filters=filters)
         expected = (
             "%s/%s?tag_scope=scope_foo&tag=foo" %
-            (nvplib.URI_PREFIX, 'RESOURCE'))
+            (nsxlib.URI_PREFIX, 'RESOURCE'))
         self.assertEqual(expected, result)
 
     def test_build_uri_path_with_resource_id(self):
         res = 'RESOURCE'
         res_id = 'resource_id'
-        result = nvplib._build_uri_path(res, resource_id=res_id)
-        expected = "%s/%s/%s" % (nvplib.URI_PREFIX, res, res_id)
+        result = nsxlib._build_uri_path(res, resource_id=res_id)
+        expected = "%s/%s/%s" % (nsxlib.URI_PREFIX, res, res_id)
         self.assertEqual(expected, result)
 
     def test_build_uri_path_with_parent_and_resource_id(self):
@@ -238,10 +238,10 @@ class NsxUtilsTestCase(base.BaseTestCase):
         res = '%s/%s' % (child_res, parent_res)
         par_id = 'parent_resource_id'
         res_id = 'resource_id'
-        result = nvplib._build_uri_path(
+        result = nsxlib._build_uri_path(
             res, parent_resource_id=par_id, resource_id=res_id)
         expected = ("%s/%s/%s/%s/%s" %
-                    (nvplib.URI_PREFIX, parent_res, par_id, child_res, res_id))
+                    (nsxlib.URI_PREFIX, parent_res, par_id, child_res, res_id))
         self.assertEqual(expected, result)
 
     def test_build_uri_path_with_attachment(self):
@@ -250,10 +250,10 @@ class NsxUtilsTestCase(base.BaseTestCase):
         res = '%s/%s' % (child_res, parent_res)
         par_id = 'parent_resource_id'
         res_id = 'resource_id'
-        result = nvplib._build_uri_path(res, parent_resource_id=par_id,
+        result = nsxlib._build_uri_path(res, parent_resource_id=par_id,
                                         resource_id=res_id, is_attachment=True)
         expected = ("%s/%s/%s/%s/%s/%s" %
-                    (nvplib.URI_PREFIX, parent_res,
+                    (nsxlib.URI_PREFIX, parent_res,
                      par_id, child_res, res_id, 'attachment'))
         self.assertEqual(expected, result)
 
@@ -263,10 +263,10 @@ class NsxUtilsTestCase(base.BaseTestCase):
         res = '%s/%s' % (child_res, parent_res)
         par_id = 'parent_resource_id'
         res_id = 'resource_id'
-        result = nvplib._build_uri_path(res, parent_resource_id=par_id,
+        result = nsxlib._build_uri_path(res, parent_resource_id=par_id,
                                         resource_id=res_id, extra_action='doh')
         expected = ("%s/%s/%s/%s/%s/%s" %
-                    (nvplib.URI_PREFIX, parent_res,
+                    (nsxlib.URI_PREFIX, parent_res,
                      par_id, child_res, res_id, 'doh'))
         self.assertEqual(expected, result)
 
@@ -319,12 +319,12 @@ class ClusterManagementTestCase(nsx_base.NsxlibTestCase):
                                'request',
                                side_effect=api_exc.ReadOnlyMode):
             self.assertRaises(nsx_exc.MaintenanceInProgress,
-                              nvplib.do_request, cluster=self.fake_cluster)
+                              nsxlib.do_request, cluster=self.fake_cluster)
 
     def test_cluster_method_not_implemented(self):
         self.assertRaises(api_exc.NsxApiException,
-                          nvplib.do_request,
-                          nvplib.HTTP_GET,
-                          nvplib._build_uri_path('MY_FAKE_RESOURCE',
+                          nsxlib.do_request,
+                          nsxlib.HTTP_GET,
+                          nsxlib._build_uri_path('MY_FAKE_RESOURCE',
                                                  resource_id='foo'),
                           cluster=self.fake_cluster)