NSX|V3+P: Support QoS on ENS networks

Depending on the backend version

Change-Id: I33af8879a519a896b1d19e3dbbc0f007e3110235
This commit is contained in:
Adit Sarfaty 2019-06-10 11:28:04 +03:00
parent f58b71ce73
commit 48821d139c
5 changed files with 40 additions and 14 deletions

View File

@ -545,6 +545,9 @@ class NsxPluginV3Base(agentschedulers_db.AZDhcpAgentSchedulerDbMixin,
raise n_exc.InvalidInput(error_message=err_msg)
def _validate_ens_create_port(self, context, port_data):
if self._ens_qos_supported():
return
qos_selected = validators.is_attr_set(port_data.get(
qos_consts.QOS_POLICY_ID))
if qos_selected:
@ -716,7 +719,7 @@ class NsxPluginV3Base(agentschedulers_db.AZDhcpAgentSchedulerDbMixin,
raise nsx_exc.QoSOnExternalNet()
self._assert_on_illegal_port_with_qos(device_owner)
is_ens_tz_port = self._is_ens_tz_port(context, original_port)
if is_ens_tz_port:
if is_ens_tz_port and not self._ens_qos_supported():
err_msg = _("Cannot configure QOS on ENS networks")
raise n_exc.InvalidInput(error_message=err_msg)
@ -833,6 +836,8 @@ class NsxPluginV3Base(agentschedulers_db.AZDhcpAgentSchedulerDbMixin,
fields) for network in networks])
def _assert_on_ens_with_qos(self, net_data):
if self._ens_qos_supported():
return
qos_id = net_data.get(qos_consts.QOS_POLICY_ID)
if validators.is_attr_set(qos_id):
err_msg = _("Cannot configure QOS on ENS networks")
@ -880,6 +885,10 @@ class NsxPluginV3Base(agentschedulers_db.AZDhcpAgentSchedulerDbMixin,
"""Should be implemented by each plugin"""
pass
def _ens_qos_supported(self):
"""Should be implemented by each plugin"""
pass
def _has_native_dhcp_metadata(self):
"""Should be implemented by each plugin"""
pass

View File

@ -598,6 +598,10 @@ class NsxPolicyPlugin(nsx_plugin_common.NsxPluginV3Base):
"""
return True
def _ens_qos_supported(self):
return self.nsxpolicy.feature_supported(
nsxlib_consts.FEATURE_ENS_WITH_QOS)
def _validate_ens_net_portsecurity(self, net_data):
"""ENS security features are always enabled on NSX versions which
the policy plugin supports.

View File

@ -1021,6 +1021,10 @@ class NsxV3Plugin(nsx_plugin_common.NsxPluginV3Base,
return self.nsxlib.feature_supported(
nsxlib_consts.FEATURE_ENS_WITH_SEC)
def _ens_qos_supported(self):
return self.nsxlib.feature_supported(
nsxlib_consts.FEATURE_ENS_WITH_QOS)
def _validate_ens_net_portsecurity(self, net_data):
"""Validate/Update the port security of the new network for ENS TZ"""
if not self._ens_psec_supported():

View File

@ -550,13 +550,14 @@ class NsxPTestNetworks(test_db_base_plugin_v2.TestNetworksV2,
'tenant_id': 'some_tenant',
'provider:network_type': 'flat',
'provider:physical_network': 'xxx',
'admin_state_up': True,
'shared': False,
'qos_policy_id': policy_id,
'port_security_enabled': False}}
with mock_ens, mock_tz, mock_tt, mock.patch.object(
self.plugin, '_validate_qos_policy_id'):
self.assertRaises(n_exc.InvalidInput,
self.plugin.create_network,
context.get_admin_context(), data)
res = self.plugin.create_network(context.get_admin_context(), data)
self.assertEqual(policy_id, res['qos_policy_id'])
def test_update_ens_network_with_qos(self):
cfg.CONF.set_override('ens_support', True, 'nsx_v3')
@ -589,10 +590,10 @@ class NsxPTestNetworks(test_db_base_plugin_v2.TestNetworksV2,
'port_security_enabled': False,
'tenant_id': 'some_tenant',
'qos_policy_id': policy_id}}
self.assertRaises(n_exc.InvalidInput,
self.plugin.update_network,
context.get_admin_context(),
network['id'], data)
res = self.plugin.update_network(
context.get_admin_context(),
network['id'], data)
self.assertEqual(policy_id, res['qos_policy_id'])
class NsxPTestPorts(common_v3.NsxV3TestPorts,
@ -787,8 +788,8 @@ class NsxPTestPorts(common_v3.NsxV3TestPorts,
# Cannot add qos policy to this type of port
with mock_ens, mock_tz, mock_tt, \
mock.patch.object(self.plugin, '_validate_qos_policy_id'):
self.assertRaises(n_exc.InvalidInput,
self.plugin.create_port, self.ctx, data)
res = self.plugin.create_port(self.ctx, data)
self.assertEqual(policy_id, res['qos_policy_id'])
def test_create_port_with_mac_learning_true(self):
plugin = directory.get_plugin()

View File

@ -582,6 +582,8 @@ class TestNetworksV2(test_plugin.TestNetworksV2, NsxV3PluginTestCaseMixin):
mock_tt = mock.patch('vmware_nsxlib.v3'
'.core_resources.NsxLibTransportZone'
'.get_transport_type', return_value='VLAN')
mock_ver = mock.patch("vmware_nsxlib.v3.NsxLib.get_version",
return_value='2.4.0')
policy_id = uuidutils.generate_uuid()
data = {'network': {
'name': 'qos_net',
@ -590,7 +592,7 @@ class TestNetworksV2(test_plugin.TestNetworksV2, NsxV3PluginTestCaseMixin):
'provider:physical_network': 'xxx',
'qos_policy_id': policy_id,
'port_security_enabled': False}}
with mock_ens, mock_tz, mock_tt, mock.patch.object(
with mock_ens, mock_tz, mock_tt, mock_ver, mock.patch.object(
self.plugin, '_validate_qos_policy_id'):
self.assertRaises(n_exc.InvalidInput,
self.plugin.create_network,
@ -607,6 +609,8 @@ class TestNetworksV2(test_plugin.TestNetworksV2, NsxV3PluginTestCaseMixin):
mock_tt = mock.patch('vmware_nsxlib.v3'
'.core_resources.NsxLibTransportZone'
'.get_transport_type', return_value='VLAN')
mock_ver = mock.patch("vmware_nsxlib.v3.NsxLib.get_version",
return_value='2.4.0')
data = {'network': {
'name': 'qos_net',
'tenant_id': 'some_tenant',
@ -615,7 +619,7 @@ class TestNetworksV2(test_plugin.TestNetworksV2, NsxV3PluginTestCaseMixin):
'admin_state_up': True,
'shared': False,
'port_security_enabled': False}}
with mock_ens, mock_tz, mock_tt,\
with mock_ens, mock_tz, mock_tt, mock_ver,\
mock.patch.object(self.plugin, '_validate_qos_policy_id'):
network = self.plugin.create_network(context.get_admin_context(),
data)
@ -1207,6 +1211,8 @@ class TestPortsV2(common_v3.NsxV3SubnetMixin,
'.core_resources.NsxLibTransportZone'
'.get_transport_type',
return_value='VLAN')
mock_ver = mock.patch("vmware_nsxlib.v3.NsxLib.get_version",
return_value='2.4.0')
data = {'port': {
'network_id': network['network']['id'],
'tenant_id': self._tenant_id,
@ -1220,7 +1226,7 @@ class TestPortsV2(common_v3.NsxV3SubnetMixin,
'qos_policy_id': policy_id}
}
# Cannot add qos policy to this type of port
with mock_ens, mock_tz, mock_tt,\
with mock_ens, mock_tz, mock_tt, mock_ver,\
mock.patch.object(self.plugin, '_validate_qos_policy_id'):
self.assertRaises(n_exc.InvalidInput,
self.plugin.create_port, self.ctx, data)
@ -1273,6 +1279,8 @@ class TestPortsV2(common_v3.NsxV3SubnetMixin,
'.core_resources.NsxLibTransportZone'
'.get_transport_type',
return_value='VLAN')
mock_ver = mock.patch("vmware_nsxlib.v3.NsxLib.get_version",
return_value='2.4.0')
data = {'port': {
'network_id': network['network']['id'],
'tenant_id': self._tenant_id,
@ -1284,7 +1292,7 @@ class TestPortsV2(common_v3.NsxV3SubnetMixin,
'port_security_enabled': False,
'mac_address': '00:00:00:00:00:01'}
}
with mock_ens, mock_tz, mock_tt,\
with mock_ens, mock_tz, mock_tt, mock_ver,\
mock.patch.object(self.plugin, '_validate_qos_policy_id'):
port = self.plugin.create_port(self.ctx, data)
data['port'] = {'qos_policy_id': policy_id}