Merge "Rename Queue related methods for VMware NSX plugin"

This commit is contained in:
Jenkins 2014-02-13 19:41:13 +00:00 committed by Gerrit Code Review
commit be187679fd
9 changed files with 162 additions and 113 deletions

View File

@ -71,11 +71,12 @@ from neutron.plugins.nicira.dbexts import distributedrouter as dist_rtr
from neutron.plugins.nicira.dbexts import maclearning as mac_db from neutron.plugins.nicira.dbexts import maclearning as mac_db
from neutron.plugins.nicira.dbexts import nicira_db from neutron.plugins.nicira.dbexts import nicira_db
from neutron.plugins.nicira.dbexts import nicira_networkgw_db as networkgw_db from neutron.plugins.nicira.dbexts import nicira_networkgw_db as networkgw_db
from neutron.plugins.nicira.dbexts import nicira_qos_db as qos_db from neutron.plugins.nicira.dbexts import qos_db
from neutron.plugins.nicira import dhcpmeta_modes from neutron.plugins.nicira import dhcpmeta_modes
from neutron.plugins.nicira.extensions import maclearning as mac_ext from neutron.plugins.nicira.extensions import maclearning as mac_ext
from neutron.plugins.nicira.extensions import nvp_networkgw as networkgw from neutron.plugins.nicira.extensions import nvp_networkgw as networkgw
from neutron.plugins.nicira.extensions import nvp_qos as ext_qos from neutron.plugins.nicira.extensions import nvp_qos as ext_qos
from neutron.plugins.nicira.nsxlib import queue as queuelib
from neutron.plugins.nicira import NvpApiClient from neutron.plugins.nicira import NvpApiClient
from neutron.plugins.nicira import nvplib from neutron.plugins.nicira import nvplib
@ -2170,17 +2171,16 @@ class NvpPluginV2(addr_pair_db.AllowedAddressPairsMixin,
def create_qos_queue(self, context, qos_queue, check_policy=True): def create_qos_queue(self, context, qos_queue, check_policy=True):
q = qos_queue.get('qos_queue') q = qos_queue.get('qos_queue')
self._validate_qos_queue(context, q) self._validate_qos_queue(context, q)
q['id'] = nvplib.create_lqueue(self.cluster, q['id'] = queuelib.create_lqueue(self.cluster, q)
self._nvp_lqueue(q))
return super(NvpPluginV2, self).create_qos_queue(context, qos_queue) return super(NvpPluginV2, self).create_qos_queue(context, qos_queue)
def delete_qos_queue(self, context, id, raise_in_use=True): def delete_qos_queue(self, context, queue_id, raise_in_use=True):
filters = {'queue_id': [id]} filters = {'queue_id': [queue_id]}
queues = self._get_port_queue_bindings(context, filters) queues = self._get_port_queue_bindings(context, filters)
if queues: if queues:
if raise_in_use: if raise_in_use:
raise ext_qos.QueueInUseByPort() raise ext_qos.QueueInUseByPort()
else: else:
return return
nvplib.delete_lqueue(self.cluster, id) queuelib.delete_lqueue(self.cluster, queue_id)
return super(NvpPluginV2, self).delete_qos_queue(context, id) return super(NvpPluginV2, self).delete_qos_queue(context, queue_id)

View File

@ -15,6 +15,7 @@
# License for the specific language governing permissions and limitations # License for the specific language governing permissions and limitations
# under the License. # under the License.
from neutron.api.v2.attributes import is_attr_set
from neutron.openstack.common import log from neutron.openstack.common import log
from neutron.version import version_info from neutron.version import version_info
@ -32,7 +33,7 @@ def get_tags(**kwargs):
def check_and_truncate(display_name): def check_and_truncate(display_name):
if display_name and len(display_name) > MAX_DISPLAY_NAME_LEN: if is_attr_set(display_name) and len(display_name) > MAX_DISPLAY_NAME_LEN:
LOG.debug(_("Specified name:'%s' exceeds maximum length. " LOG.debug(_("Specified name:'%s' exceeds maximum length. "
"It will be truncated on NVP"), display_name) "It will be truncated on NVP"), display_name)
return display_name[:MAX_DISPLAY_NAME_LEN] return display_name[:MAX_DISPLAY_NAME_LEN]

View File

@ -1,6 +1,6 @@
# vim: tabstop=4 shiftwidth=4 softtabstop=4 # vim: tabstop=4 shiftwidth=4 softtabstop=4
# #
# Copyright 2013 Nicira Networks, Inc. All rights reserved. # Copyright 2013 VMware, Inc. All rights reserved.
# #
# Licensed under the Apache License, Version 2.0 (the "License"); you may # 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 # not use this file except in compliance with the License. You may obtain
@ -14,7 +14,6 @@
# License for the specific language governing permissions and limitations # License for the specific language governing permissions and limitations
# under the License. # under the License.
# #
# @author: Aaron Rosen, Nicira, Inc
import sqlalchemy as sa import sqlalchemy as sa
from sqlalchemy import orm from sqlalchemy import orm
@ -26,7 +25,6 @@ from neutron.db import model_base
from neutron.db import models_v2 from neutron.db import models_v2
from neutron.openstack.common import log from neutron.openstack.common import log
from neutron.openstack.common import uuidutils from neutron.openstack.common import uuidutils
from neutron.plugins.nicira.common import utils
from neutron.plugins.nicira.extensions import nvp_qos as ext_qos from neutron.plugins.nicira.extensions import nvp_qos as ext_qos
@ -92,23 +90,23 @@ class NVPQoSDbMixin(ext_qos.QueuePluginBase):
context.session.add(qos_queue) context.session.add(qos_queue)
return self._make_qos_queue_dict(qos_queue) return self._make_qos_queue_dict(qos_queue)
def get_qos_queue(self, context, id, fields=None): def get_qos_queue(self, context, queue_id, fields=None):
return self._make_qos_queue_dict( return self._make_qos_queue_dict(
self._get_qos_queue(context, id), fields) self._get_qos_queue(context, queue_id), fields)
def _get_qos_queue(self, context, id): def _get_qos_queue(self, context, queue_id):
try: try:
return self._get_by_id(context, QoSQueue, id) return self._get_by_id(context, QoSQueue, queue_id)
except exc.NoResultFound: except exc.NoResultFound:
raise ext_qos.QueueNotFound(id=id) raise ext_qos.QueueNotFound(id=queue_id)
def get_qos_queues(self, context, filters=None, fields=None): def get_qos_queues(self, context, filters=None, fields=None):
return self._get_collection(context, QoSQueue, return self._get_collection(context, QoSQueue,
self._make_qos_queue_dict, self._make_qos_queue_dict,
filters=filters, fields=fields) filters=filters, fields=fields)
def delete_qos_queue(self, context, id): def delete_qos_queue(self, context, queue_id):
qos_queue = self._get_qos_queue(context, id) qos_queue = self._get_qos_queue(context, queue_id)
with context.session.begin(subtransactions=True): with context.session.begin(subtransactions=True):
context.session.delete(qos_queue) context.session.delete(qos_queue)
@ -294,21 +292,3 @@ class NVPQoSDbMixin(ext_qos.QueuePluginBase):
# Max can be None # Max can be None
if max and min > max: if max and min > max:
raise ext_qos.QueueMinGreaterMax() raise ext_qos.QueueMinGreaterMax()
def _nvp_lqueue(self, queue):
"""Convert fields to nvp fields."""
nvp_queue = {}
params = {'name': 'display_name',
'qos_marking': 'qos_marking',
'min': 'min_bandwidth_rate',
'max': 'max_bandwidth_rate',
'dscp': 'dscp'}
nvp_queue = dict(
(nvp_name, queue.get(api_name))
for api_name, nvp_name in params.iteritems()
if attr.is_attr_set(queue.get(api_name))
)
if 'display_name' in nvp_queue:
nvp_queue['display_name'] = utils.check_and_truncate(
nvp_queue['display_name'])
return nvp_queue

View File

@ -0,0 +1,72 @@
# 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.
from neutron.api.v2 import attributes as attr
from neutron.common import exceptions as exception
from neutron.openstack.common import excutils
from neutron.openstack.common import jsonutils
from neutron.openstack.common import log
from neutron.plugins.nicira.common import utils
from neutron.plugins.nicira import NvpApiClient
from neutron.plugins.nicira.nvplib import _build_uri_path
from neutron.plugins.nicira.nvplib import do_request
HTTP_POST = "POST"
HTTP_DELETE = "DELETE"
LQUEUE_RESOURCE = "lqueue"
LOG = log.getLogger(__name__)
def create_lqueue(cluster, queue_data):
params = {
'name': 'display_name',
'qos_marking': 'qos_marking',
'min': 'min_bandwidth_rate',
'max': 'max_bandwidth_rate',
'dscp': 'dscp'
}
queue_obj = dict(
(nvp_name, queue_data.get(api_name))
for api_name, nvp_name in params.iteritems()
if attr.is_attr_set(queue_data.get(api_name))
)
if 'display_name' in queue_obj:
queue_obj['display_name'] = utils.check_and_truncate(
queue_obj['display_name'])
queue_obj['tags'] = utils.get_tags()
try:
return do_request(HTTP_POST,
_build_uri_path(LQUEUE_RESOURCE),
jsonutils.dumps(queue_obj),
cluster=cluster)['uuid']
except NvpApiClient.NvpApiException:
# FIXME(salv-orlando): This should not raise NeutronException
with excutils.save_and_reraise_exception():
raise exception.NeutronException()
def delete_lqueue(cluster, queue_id):
try:
do_request(HTTP_DELETE,
_build_uri_path(LQUEUE_RESOURCE,
resource_id=queue_id),
cluster=cluster)
except Exception:
# FIXME(salv-orlando): This should not raise NeutronException
with excutils.save_and_reraise_exception():
raise exception.NeutronException()

View File

@ -1408,29 +1408,3 @@ def get_function_by_version(func_name, nvp_ver):
msg = _('NVP version is not set. Unable to complete request ' msg = _('NVP version is not set. Unable to complete request '
'correctly. Check log for NVP communication errors.') 'correctly. Check log for NVP communication errors.')
raise NvpApiClient.ServiceUnavailable(message=msg) raise NvpApiClient.ServiceUnavailable(message=msg)
# -----------------------------------------------------------------------------
# QOS API Calls
# -----------------------------------------------------------------------------
def create_lqueue(cluster, lqueue):
uri = _build_uri_path(LQUEUE_RESOURCE)
lqueue['tags'] = [{'tag': NEUTRON_VERSION, 'scope': 'quantum'}]
try:
return do_request(HTTP_POST, uri, json.dumps(lqueue),
cluster=cluster)['uuid']
except NvpApiClient.NvpApiException:
# FIXME(salv-orlando): This should not raise QauntumException
LOG.exception(_("Failed to create logical queue"))
raise exception.NeutronException()
def delete_lqueue(cluster, id):
try:
do_request(HTTP_DELETE, _build_uri_path(LQUEUE_RESOURCE,
resource_id=id),
cluster=cluster)
except Exception:
# FIXME(salv-orlando): This should not raise QauntumException
LOG.exception(_("Failed to delete logical queue"))
raise exception.NeutronException()

View File

@ -0,0 +1,68 @@
# Copyright (c) 2014 VMware, Inc.
#
# 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 mock
from neutron.common import exceptions
from neutron.plugins.nicira.nsxlib import queue as queuelib
from neutron.plugins.nicira import NvpApiClient
from neutron.tests.unit.nicira.test_nvplib import NvplibTestCase
class TestLogicalQueueLib(NvplibTestCase):
def setUp(self):
super(TestLogicalQueueLib, self).setUp()
self.fake_queue = {
'name': 'fake_queue',
'min': 0, 'max': 256,
'dscp': 0, 'qos_marking': False
}
def test_create_and_get_lqueue(self):
queue_id = queuelib.create_lqueue(
self.fake_cluster, self.fake_queue)
queue_res = queuelib.do_request(
'GET',
queuelib._build_uri_path('lqueue', resource_id=queue_id),
cluster=self.fake_cluster)
self.assertEqual(queue_id, queue_res['uuid'])
self.assertEqual('fake_queue', queue_res['display_name'])
def test_create_lqueue_nsx_error_raises(self):
def raise_nsx_exc(*args, **kwargs):
raise NvpApiClient.NvpApiException()
with mock.patch.object(queuelib, 'do_request', new=raise_nsx_exc):
self.assertRaises(
exceptions.NeutronException, queuelib.create_lqueue,
self.fake_cluster, self.fake_queue)
def test_delete_lqueue(self):
queue_id = queuelib.create_lqueue(
self.fake_cluster, self.fake_queue)
queuelib.delete_lqueue(self.fake_cluster, queue_id)
self.assertRaises(exceptions.NotFound,
queuelib.do_request,
'GET',
queuelib._build_uri_path(
'lqueue', resource_id=queue_id),
cluster=self.fake_cluster)
def test_delete_non_existing_lqueue_raises(self):
self.assertRaises(exceptions.NeutronException,
queuelib.delete_lqueue,
self.fake_cluster, 'whatever')

View File

@ -42,11 +42,12 @@ from neutron.openstack.common import uuidutils
from neutron.plugins.nicira.common import exceptions as nvp_exc from neutron.plugins.nicira.common import exceptions as nvp_exc
from neutron.plugins.nicira.common import sync from neutron.plugins.nicira.common import sync
from neutron.plugins.nicira.dbexts import nicira_db from neutron.plugins.nicira.dbexts import nicira_db
from neutron.plugins.nicira.dbexts import nicira_qos_db as qos_db from neutron.plugins.nicira.dbexts import qos_db
from neutron.plugins.nicira.extensions import distributedrouter as dist_router from neutron.plugins.nicira.extensions import distributedrouter as dist_router
from neutron.plugins.nicira.extensions import nvp_networkgw from neutron.plugins.nicira.extensions import nvp_networkgw
from neutron.plugins.nicira.extensions import nvp_qos as ext_qos from neutron.plugins.nicira.extensions import nvp_qos as ext_qos
from neutron.plugins.nicira import NeutronPlugin from neutron.plugins.nicira import NeutronPlugin
from neutron.plugins.nicira import nsxlib
from neutron.plugins.nicira import NvpApiClient from neutron.plugins.nicira import NvpApiClient
from neutron.plugins.nicira.NvpApiClient import NVPVersion from neutron.plugins.nicira.NvpApiClient import NVPVersion
from neutron.plugins.nicira import nvplib from neutron.plugins.nicira import nvplib
@ -1041,11 +1042,11 @@ class NvpQoSTestExtensionManager(object):
return [] return []
class TestNiciraQoSQueue(NiciraPluginV2TestCase): class TestQoSQueue(NiciraPluginV2TestCase):
def setUp(self, plugin=None): def setUp(self, plugin=None):
cfg.CONF.set_override('api_extensions_path', NVPEXT_PATH) cfg.CONF.set_override('api_extensions_path', NVPEXT_PATH)
super(TestNiciraQoSQueue, self).setUp() super(TestQoSQueue, self).setUp()
ext_mgr = NvpQoSTestExtensionManager() ext_mgr = NvpQoSTestExtensionManager()
self.ext_api = test_extensions.setup_extensions_middleware(ext_mgr) self.ext_api = test_extensions.setup_extensions_middleware(ext_mgr)
@ -1073,7 +1074,6 @@ class TestNiciraQoSQueue(NiciraPluginV2TestCase):
body['qos_queue']['dscp'] = dscp body['qos_queue']['dscp'] = dscp
if default: if default:
body['qos_queue']['default'] = default body['qos_queue']['default'] = default
res = self._create_qos_queue('json', body) res = self._create_qos_queue('json', body)
qos_queue = self.deserialize('json', res) qos_queue = self.deserialize('json', res)
if res.status_int >= 400: if res.status_int >= 400:
@ -1096,7 +1096,7 @@ class TestNiciraQoSQueue(NiciraPluginV2TestCase):
def test_create_trusted_qos_queue(self): def test_create_trusted_qos_queue(self):
with mock.patch.object(qos_db.LOG, 'info') as log: with mock.patch.object(qos_db.LOG, 'info') as log:
with mock.patch.object(nvplib, 'do_request', with mock.patch.object(nsxlib.queue, 'do_request',
return_value={"uuid": "fake_queue"}): return_value={"uuid": "fake_queue"}):
with self.qos_queue(name='fake_lqueue', min=34, max=44, with self.qos_queue(name='fake_lqueue', min=34, max=44,
qos_marking='trusted', default=False) as q: qos_marking='trusted', default=False) as q:

View File

@ -1269,52 +1269,6 @@ class TestNvplibSecurityProfile(NvplibTestCase):
self.fake_cluster, 'whatever') self.fake_cluster, 'whatever')
class TestNvplibLQueue(NvplibTestCase):
def test_create_and_get_lqueue(self):
queue_id = nvplib.create_lqueue(self.fake_cluster,
{'display_name': 'fake_queue',
'min_bandwidth_rate': 0,
'max_bandwidth_rate': 256,
'dscp': 0,
'qos_marking': False})
queue_res = nvplib.do_request(
nvplib.HTTP_GET,
nvplib._build_uri_path('lqueue', resource_id=queue_id),
cluster=self.fake_cluster)
self.assertEqual(queue_id, queue_res['uuid'])
self.assertEqual('fake_queue', queue_res['display_name'])
def test_create_lqueue_nvp_error_raises(self):
def raise_nvp_exc(*args, **kwargs):
raise NvpApiClient.NvpApiException()
with mock.patch.object(nvplib, 'do_request', new=raise_nvp_exc):
self.assertRaises(
exceptions.NeutronException, nvplib.create_lqueue,
self.fake_cluster, {})
def test_delete_lqueue(self):
queue_id = nvplib.create_lqueue(self.fake_cluster,
{'display_name': 'fake_queue',
'min_bandwidth_rate': 0,
'max_bandwidth_rate': 256,
'dscp': 0,
'qos_marking': False})
nvplib.delete_lqueue(self.fake_cluster, queue_id)
self.assertRaises(exceptions.NotFound,
nvplib.do_request,
nvplib.HTTP_GET,
nvplib._build_uri_path(
'lqueue', resource_id=queue_id),
cluster=self.fake_cluster)
def test_delete_non_existing_lqueue_raises(self):
self.assertRaises(exceptions.NeutronException,
nvplib.delete_lqueue,
self.fake_cluster, 'whatever')
class TestNvplibLogicalPorts(NvplibTestCase): class TestNvplibLogicalPorts(NvplibTestCase):
def _create_switch_and_port(self, tenant_id='pippo', def _create_switch_and_port(self, tenant_id='pippo',