Moved QOS_POLICY_ID into qos_consts.py
Partially-Implements: blueprint quantum-qos-api Change-Id: If789695b4084aed467d5f773c6b6bebea073724d
This commit is contained in:
parent
f69c477dc2
commit
87aa42bc76
|
@ -24,6 +24,7 @@ from neutron.api.v2 import base
|
|||
from neutron.api.v2 import resource_helper
|
||||
from neutron import manager
|
||||
from neutron.plugins.common import constants
|
||||
from neutron.services.qos import qos_consts
|
||||
from neutron.services import service_base
|
||||
|
||||
QOS_PREFIX = "/qos"
|
||||
|
@ -80,19 +81,19 @@ SUB_RESOURCE_ATTRIBUTE_MAP = {
|
|||
}
|
||||
}
|
||||
|
||||
QOS_POLICY_ID = "qos_policy_id"
|
||||
|
||||
EXTENDED_ATTRIBUTES_2_0 = {
|
||||
'ports': {QOS_POLICY_ID: {'allow_post': True,
|
||||
'allow_put': True,
|
||||
'is_visible': True,
|
||||
'default': None,
|
||||
'validate': {'type:uuid_or_none': None}}},
|
||||
'networks': {QOS_POLICY_ID: {'allow_post': True,
|
||||
'allow_put': True,
|
||||
'is_visible': True,
|
||||
'default': None,
|
||||
'validate': {'type:uuid_or_none': None}}}}
|
||||
'ports': {qos_consts.QOS_POLICY_ID: {
|
||||
'allow_post': True,
|
||||
'allow_put': True,
|
||||
'is_visible': True,
|
||||
'default': None,
|
||||
'validate': {'type:uuid_or_none': None}}},
|
||||
'networks': {qos_consts.QOS_POLICY_ID: {
|
||||
'allow_post': True,
|
||||
'allow_put': True,
|
||||
'is_visible': True,
|
||||
'default': None,
|
||||
'validate': {'type:uuid_or_none': None}}}}
|
||||
|
||||
|
||||
class Qos(extensions.ExtensionDescriptor):
|
||||
|
|
|
@ -63,7 +63,6 @@ from neutron.extensions import extra_dhcp_opt as edo_ext
|
|||
from neutron.extensions import portbindings
|
||||
from neutron.extensions import portsecurity as psec
|
||||
from neutron.extensions import providernet as provider
|
||||
from neutron.extensions import qos
|
||||
from neutron.extensions import vlantransparent
|
||||
from neutron.i18n import _LE, _LI, _LW
|
||||
from neutron import manager
|
||||
|
@ -76,6 +75,7 @@ from neutron.plugins.ml2 import driver_context
|
|||
from neutron.plugins.ml2 import managers
|
||||
from neutron.plugins.ml2 import models
|
||||
from neutron.plugins.ml2 import rpc
|
||||
from neutron.services.qos import qos_consts
|
||||
|
||||
LOG = log.getLogger(__name__)
|
||||
|
||||
|
@ -1131,9 +1131,9 @@ class Ml2Plugin(db_base_plugin_v2.NeutronDbPluginV2,
|
|||
need_port_update_notify = True
|
||||
# TODO(QoS): Move out to the extension framework somehow.
|
||||
# Follow https://review.openstack.org/#/c/169223 for a solution.
|
||||
if (qos.QOS_POLICY_ID in attrs and
|
||||
original_port[qos.QOS_POLICY_ID] !=
|
||||
updated_port[qos.QOS_POLICY_ID]):
|
||||
if (qos_consts.QOS_POLICY_ID in attrs and
|
||||
original_port[qos_consts.QOS_POLICY_ID] !=
|
||||
updated_port[qos_consts.QOS_POLICY_ID]):
|
||||
need_port_update_notify = True
|
||||
|
||||
if addr_pair.ADDRESS_PAIRS in attrs:
|
||||
|
|
|
@ -28,11 +28,11 @@ from neutron.common import rpc as n_rpc
|
|||
from neutron.common import topics
|
||||
from neutron.extensions import portbindings
|
||||
from neutron.extensions import portsecurity as psec
|
||||
from neutron.extensions import qos
|
||||
from neutron.i18n import _LW
|
||||
from neutron import manager
|
||||
from neutron.plugins.ml2 import driver_api as api
|
||||
from neutron.plugins.ml2.drivers import type_tunnel
|
||||
from neutron.services.qos import qos_consts
|
||||
# REVISIT(kmestery): Allow the type and mechanism drivers to supply the
|
||||
# mixins and eventually remove the direct dependencies on type_tunnel.
|
||||
|
||||
|
@ -107,8 +107,9 @@ class RpcCallbacks(type_tunnel.TunnelRpcCallbackMixin):
|
|||
host,
|
||||
port_context.network.current)
|
||||
|
||||
qos_profile_id = (port.get(qos.QOS_POLICY_ID) or
|
||||
port_context.network._network.get(qos.QOS_POLICY_ID))
|
||||
qos_policy_id = (port.get(qos_consts.QOS_POLICY_ID) or
|
||||
port_context.network._network.get(
|
||||
qos_consts.QOS_POLICY_ID))
|
||||
entry = {'device': device,
|
||||
'network_id': port['network_id'],
|
||||
'port_id': port['id'],
|
||||
|
@ -121,7 +122,7 @@ class RpcCallbacks(type_tunnel.TunnelRpcCallbackMixin):
|
|||
'device_owner': port['device_owner'],
|
||||
'allowed_address_pairs': port['allowed_address_pairs'],
|
||||
'port_security_enabled': port.get(psec.PORTSECURITY, True),
|
||||
'qos_policy_id': qos_profile_id,
|
||||
'qos_policy_id': qos_policy_id,
|
||||
'profile': port[portbindings.PROFILE]}
|
||||
LOG.debug("Returning: %s", entry)
|
||||
return entry
|
||||
|
|
|
@ -15,3 +15,5 @@
|
|||
|
||||
RULE_TYPE_BANDWIDTH_LIMIT = 'bandwidth_limit'
|
||||
VALID_RULE_TYPES = [RULE_TYPE_BANDWIDTH_LIMIT]
|
||||
|
||||
QOS_POLICY_ID = 'qos_policy_id'
|
||||
|
|
|
@ -13,10 +13,10 @@
|
|||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
from neutron.extensions import qos
|
||||
from neutron import manager
|
||||
from neutron.objects.qos import policy as policy_object
|
||||
from neutron.plugins.common import constants as plugin_constants
|
||||
from neutron.services.qos import qos_consts
|
||||
|
||||
NETWORK = 'network'
|
||||
PORT = 'port'
|
||||
|
@ -46,14 +46,14 @@ class QosResourceExtensionHandler(object):
|
|||
# at db api level automatically within transaction.
|
||||
old_policy.detach_port(port['id'])
|
||||
|
||||
qos_policy_id = port_changes.get(qos.QOS_POLICY_ID)
|
||||
qos_policy_id = port_changes.get(qos_consts.QOS_POLICY_ID)
|
||||
if qos_policy_id is not None:
|
||||
policy = self._get_policy_obj(context, qos_policy_id)
|
||||
#TODO(QoS): If the policy doesn't exist (or if it is not shared and
|
||||
# the tenant id doesn't match the context's), this will
|
||||
# raise an exception (policy is None).
|
||||
policy.attach_port(port['id'])
|
||||
port[qos.QOS_POLICY_ID] = qos_policy_id
|
||||
port[qos_consts.QOS_POLICY_ID] = qos_policy_id
|
||||
|
||||
def _update_network_policy(self, context, network, network_changes):
|
||||
old_policy = policy_object.QosPolicy.get_network_policy(
|
||||
|
@ -61,21 +61,22 @@ class QosResourceExtensionHandler(object):
|
|||
if old_policy:
|
||||
old_policy.detach_network(network['id'])
|
||||
|
||||
qos_policy_id = network_changes.get(qos.QOS_POLICY_ID)
|
||||
qos_policy_id = network_changes.get(qos_consts.QOS_POLICY_ID)
|
||||
if qos_policy_id:
|
||||
policy = self._get_policy_obj(context, qos_policy_id)
|
||||
#TODO(QoS): If the policy doesn't exist (or if it is not shared and
|
||||
# the tenant id doesn't match the context's), this will
|
||||
# raise an exception (policy is None).
|
||||
policy.attach_network(network['id'])
|
||||
network[qos.QOS_POLICY_ID] = qos_policy_id
|
||||
network[qos_consts.QOS_POLICY_ID] = qos_policy_id
|
||||
|
||||
def _exec(self, method_name, context, kwargs):
|
||||
return getattr(self, method_name)(context=context, **kwargs)
|
||||
|
||||
def process_resource(self, context, resource_type, requested_resource,
|
||||
actual_resource):
|
||||
if qos.QOS_POLICY_ID in requested_resource and self.plugin_loaded:
|
||||
if (qos_consts.QOS_POLICY_ID in requested_resource and
|
||||
self.plugin_loaded):
|
||||
self._exec('_update_%s_policy' % resource_type, context,
|
||||
{resource_type: actual_resource,
|
||||
"%s_changes" % resource_type: requested_resource})
|
||||
|
@ -85,4 +86,5 @@ class QosResourceExtensionHandler(object):
|
|||
return {}
|
||||
|
||||
binding = resource['qos_policy_binding']
|
||||
return {qos.QOS_POLICY_ID: binding['policy_id'] if binding else None}
|
||||
qos_policy_id = binding['policy_id'] if binding else None
|
||||
return {qos_consts.QOS_POLICY_ID: qos_policy_id}
|
||||
|
|
|
@ -28,10 +28,10 @@ from neutron.agent import rpc as agent_rpc
|
|||
from neutron.common import constants
|
||||
from neutron.common import exceptions
|
||||
from neutron.common import topics
|
||||
from neutron.extensions import qos
|
||||
from neutron.plugins.ml2.drivers import type_tunnel
|
||||
from neutron.plugins.ml2 import managers
|
||||
from neutron.plugins.ml2 import rpc as plugin_rpc
|
||||
from neutron.services.qos import qos_consts
|
||||
from neutron.tests import base
|
||||
|
||||
|
||||
|
@ -147,16 +147,19 @@ class RpcCallbacksTestCase(base.BaseTestCase):
|
|||
port = collections.defaultdict(lambda: 'fake_port')
|
||||
self.plugin.get_bound_port_context().current = port
|
||||
self.plugin.get_bound_port_context().network._network = (
|
||||
{"id": "fake_network", qos.QOS_POLICY_ID: 'test-policy-id'})
|
||||
{"id": "fake_network",
|
||||
qos_consts.QOS_POLICY_ID: 'test-policy-id'})
|
||||
res = self.callbacks.get_device_details(mock.Mock(), host='fake')
|
||||
self.assertEqual('test-policy-id', res['qos_policy_id'])
|
||||
|
||||
def test_get_device_details_qos_policy_id_taken_from_port(self):
|
||||
port = collections.defaultdict(
|
||||
lambda: 'fake_port', {qos.QOS_POLICY_ID: 'test-port-policy-id'})
|
||||
lambda: 'fake_port',
|
||||
{qos_consts.QOS_POLICY_ID: 'test-port-policy-id'})
|
||||
self.plugin.get_bound_port_context().current = port
|
||||
self.plugin.get_bound_port_context().network._network = (
|
||||
{"id": "fake_network", qos.QOS_POLICY_ID: 'test-net-policy-id'})
|
||||
{"id": "fake_network",
|
||||
qos_consts.QOS_POLICY_ID: 'test-net-policy-id'})
|
||||
res = self.callbacks.get_device_details(mock.Mock(), host='fake')
|
||||
self.assertEqual('test-port-policy-id', res['qos_policy_id'])
|
||||
|
||||
|
|
|
@ -15,8 +15,8 @@
|
|||
|
||||
import mock
|
||||
|
||||
from neutron.extensions import qos
|
||||
from neutron.plugins.common import constants as plugin_constants
|
||||
from neutron.services.qos import qos_consts
|
||||
from neutron.services.qos import qos_extension
|
||||
from neutron.tests import base
|
||||
|
||||
|
@ -47,19 +47,21 @@ class QosResourceExtensionHandlerTestCase(base.BaseTestCase):
|
|||
|
||||
def test_process_resource_no_qos_plugin_loaded(self):
|
||||
with self._mock_plugin_loaded(False):
|
||||
self.ext_handler.process_resource(None, qos_extension.PORT,
|
||||
{qos.QOS_POLICY_ID: None}, None)
|
||||
self.ext_handler.process_resource(
|
||||
None, qos_extension.PORT,
|
||||
{qos_consts.QOS_POLICY_ID: None}, None)
|
||||
self.assertFalse(self.policy_m.called)
|
||||
|
||||
def test_process_resource_port_new_policy(self):
|
||||
with self._mock_plugin_loaded(True):
|
||||
qos_policy_id = mock.Mock()
|
||||
actual_port = {'id': mock.Mock(),
|
||||
qos.QOS_POLICY_ID: qos_policy_id}
|
||||
qos_consts.QOS_POLICY_ID: qos_policy_id}
|
||||
qos_policy = mock.MagicMock()
|
||||
self.policy_m.get_by_id = mock.Mock(return_value=qos_policy)
|
||||
self.ext_handler.process_resource(
|
||||
None, qos_extension.PORT, {qos.QOS_POLICY_ID: qos_policy_id},
|
||||
None, qos_extension.PORT,
|
||||
{qos_consts.QOS_POLICY_ID: qos_policy_id},
|
||||
actual_port)
|
||||
|
||||
qos_policy.attach_port.assert_called_once_with(actual_port['id'])
|
||||
|
@ -69,14 +71,15 @@ class QosResourceExtensionHandlerTestCase(base.BaseTestCase):
|
|||
qos_policy_id = mock.Mock()
|
||||
port_id = mock.Mock()
|
||||
actual_port = {'id': port_id,
|
||||
qos.QOS_POLICY_ID: qos_policy_id}
|
||||
qos_consts.QOS_POLICY_ID: qos_policy_id}
|
||||
old_qos_policy = mock.MagicMock()
|
||||
self.policy_m.get_port_policy = mock.Mock(
|
||||
return_value=old_qos_policy)
|
||||
new_qos_policy = mock.MagicMock()
|
||||
self.policy_m.get_by_id = mock.Mock(return_value=new_qos_policy)
|
||||
self.ext_handler.process_resource(
|
||||
None, qos_extension.PORT, {qos.QOS_POLICY_ID: qos_policy_id},
|
||||
None, qos_extension.PORT,
|
||||
{qos_consts.QOS_POLICY_ID: qos_policy_id},
|
||||
actual_port)
|
||||
|
||||
old_qos_policy.detach_port.assert_called_once_with(port_id)
|
||||
|
@ -86,12 +89,12 @@ class QosResourceExtensionHandlerTestCase(base.BaseTestCase):
|
|||
with self._mock_plugin_loaded(True):
|
||||
qos_policy_id = mock.Mock()
|
||||
actual_network = {'id': mock.Mock(),
|
||||
qos.QOS_POLICY_ID: qos_policy_id}
|
||||
qos_consts.QOS_POLICY_ID: qos_policy_id}
|
||||
qos_policy = mock.MagicMock()
|
||||
self.policy_m.get_by_id = mock.Mock(return_value=qos_policy)
|
||||
self.ext_handler.process_resource(
|
||||
None, qos_extension.NETWORK,
|
||||
{qos.QOS_POLICY_ID: qos_policy_id}, actual_network)
|
||||
{qos_consts.QOS_POLICY_ID: qos_policy_id}, actual_network)
|
||||
|
||||
qos_policy.attach_network.assert_called_once_with(
|
||||
actual_network['id'])
|
||||
|
@ -101,7 +104,7 @@ class QosResourceExtensionHandlerTestCase(base.BaseTestCase):
|
|||
qos_policy_id = mock.Mock()
|
||||
network_id = mock.Mock()
|
||||
actual_network = {'id': network_id,
|
||||
qos.QOS_POLICY_ID: qos_policy_id}
|
||||
qos_consts.QOS_POLICY_ID: qos_policy_id}
|
||||
old_qos_policy = mock.MagicMock()
|
||||
self.policy_m.get_network_policy = mock.Mock(
|
||||
return_value=old_qos_policy)
|
||||
|
@ -109,7 +112,7 @@ class QosResourceExtensionHandlerTestCase(base.BaseTestCase):
|
|||
self.policy_m.get_by_id = mock.Mock(return_value=new_qos_policy)
|
||||
self.ext_handler.process_resource(
|
||||
None, qos_extension.NETWORK,
|
||||
{qos.QOS_POLICY_ID: qos_policy_id}, actual_network)
|
||||
{qos_consts.QOS_POLICY_ID: qos_policy_id}, actual_network)
|
||||
|
||||
old_qos_policy.detach_network.assert_called_once_with(network_id)
|
||||
new_qos_policy.attach_network.assert_called_once_with(network_id)
|
||||
|
@ -123,7 +126,7 @@ class QosResourceExtensionHandlerTestCase(base.BaseTestCase):
|
|||
with self._mock_plugin_loaded(True):
|
||||
fields = self.ext_handler.extract_resource_fields(
|
||||
qos_extension.PORT, _get_test_dbdata(qos_policy_id))
|
||||
self.assertEqual({qos.QOS_POLICY_ID: qos_policy_id}, fields)
|
||||
self.assertEqual({qos_consts.QOS_POLICY_ID: qos_policy_id}, fields)
|
||||
|
||||
def test_extract_resource_fields_no_port_policy(self):
|
||||
self._test_extract_resource_fields_for_port(None)
|
||||
|
@ -136,7 +139,7 @@ class QosResourceExtensionHandlerTestCase(base.BaseTestCase):
|
|||
with self._mock_plugin_loaded(True):
|
||||
fields = self.ext_handler.extract_resource_fields(
|
||||
qos_extension.NETWORK, _get_test_dbdata(qos_policy_id))
|
||||
self.assertEqual({qos.QOS_POLICY_ID: qos_policy_id}, fields)
|
||||
self.assertEqual({qos_consts.QOS_POLICY_ID: qos_policy_id}, fields)
|
||||
|
||||
def test_extract_resource_fields_no_network_policy(self):
|
||||
self._test_extract_resource_fields_for_network(None)
|
||||
|
|
Loading…
Reference in New Issue