def vf_management_supported():
+ is_supported = True
required_caps = (
ip_link_support.IpLinkConstants.IP_LINK_CAPABILITY_STATE,
- ip_link_support.IpLinkConstants.IP_LINK_CAPABILITY_SPOOFCHK)
++ ip_link_support.IpLinkConstants.IP_LINK_CAPABILITY_SPOOFCHK,
+ ip_link_support.IpLinkConstants.IP_LINK_CAPABILITY_RATE)
try:
vf_section = ip_link_support.IpLinkSupport.get_vf_mgmt_section()
for cap in required_caps:
--- /dev/null
-Revises: 8675309a5c4f
+ # Copyright 2015 Huawei Technologies India Pvt Ltd, 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.
+ #
+
+ """qos db changes
+
+ Revision ID: 48153cb5f051
-down_revision = '8675309a5c4f'
++Revises: 1c844d1677f7
+ Create Date: 2015-06-24 17:03:34.965101
+
+ """
+
+ # revision identifiers, used by Alembic.
+ revision = '48153cb5f051'
++down_revision = '1c844d1677f7'
+
+ from alembic import op
+ import sqlalchemy as sa
+
+ from neutron.api.v2 import attributes as attrs
+
+
+ def upgrade():
+ op.create_table(
+ 'qos_policies',
+ sa.Column('id', sa.String(length=36), primary_key=True),
+ sa.Column('name', sa.String(length=attrs.NAME_MAX_LEN)),
+ sa.Column('description', sa.String(length=attrs.DESCRIPTION_MAX_LEN)),
+ sa.Column('shared', sa.Boolean(), nullable=False),
+ sa.Column('tenant_id', sa.String(length=attrs.TENANT_ID_MAX_LEN),
+ index=True))
+
+ op.create_table(
+ 'qos_network_policy_bindings',
+ sa.Column('policy_id', sa.String(length=36),
+ sa.ForeignKey('qos_policies.id', ondelete='CASCADE'),
+ nullable=False),
+ sa.Column('network_id', sa.String(length=36),
+ sa.ForeignKey('networks.id', ondelete='CASCADE'),
+ nullable=False, unique=True))
+
+ op.create_table(
+ 'qos_port_policy_bindings',
+ sa.Column('policy_id', sa.String(length=36),
+ sa.ForeignKey('qos_policies.id', ondelete='CASCADE'),
+ nullable=False),
+ sa.Column('port_id', sa.String(length=36),
+ sa.ForeignKey('ports.id', ondelete='CASCADE'),
+ nullable=False, unique=True))
+
+ op.create_table(
+ 'qos_bandwidth_limit_rules',
+ sa.Column('id', sa.String(length=36), primary_key=True),
+ sa.Column('qos_policy_id', sa.String(length=36),
+ sa.ForeignKey('qos_policies.id', ondelete='CASCADE'),
+ nullable=False, unique=True),
+ sa.Column('max_kbps', sa.Integer()),
+ sa.Column('max_burst_kbps', sa.Integer()))
from neutron.db import models_v2 # noqa
from neutron.db import portbindings_db # noqa
from neutron.db import portsecurity_db # noqa
-from neutron.db import quota_db # noqa
+ from neutron.db.qos import models as qos_models # noqa
+from neutron.db.quota import models # noqa
from neutron.db import rbac_db_models # noqa
from neutron.db import securitygroups_db # noqa
from neutron.db import servicetype_db # noqa
raise exc.IpCommandError(dev_name=self.dev_name,
reason=e)
+ def set_vf_spoofcheck(self, vf_index, enabled):
+ """sets vf spoofcheck
+
+ @param vf_index: vf index
+ @param enabled: True to enable spoof checking,
+ False to disable
+ """
+ setting = "on" if enabled else "off"
+
+ try:
+ self._as_root('', "link", ("set", self.dev_name, "vf",
+ str(vf_index), "spoofchk", setting))
+ except Exception as e:
+ raise exc.IpCommandError(dev_name=self.dev_name,
+ reason=str(e))
+
+ def set_vf_max_rate(self, vf_index, max_tx_rate):
+ """sets vf max rate.
+
+ @param vf_index: vf index
+ @param max_tx_rate: vf max tx rate
+ """
+ try:
+ self._as_root([], "link", ("set", self.dev_name, "vf",
+ str(vf_index), "rate",
+ str(max_tx_rate)))
+ except Exception as e:
+ LOG.exception(_LE("Failed executing ip command"))
+ raise exc.IpCommandError(dev_name=self.dev_name,
+ reason=e)
+
def _get_vf_link_show(self, vf_list, link_show_out):
"""Get link show output for VFs
from neutron.plugins.ml2 import managers
from neutron.plugins.ml2 import models
from neutron.plugins.ml2 import rpc
+from neutron.quota import resource_registry
+ from neutron.services.qos import qos_consts
LOG = log.getLogger(__name__)
cls.metering_label_rules = []
cls.fw_rules = []
cls.fw_policies = []
- cls.ipsecpolicies = []
+ cls.qos_rules = []
+ cls.qos_policies = []
cls.ethertype = "IPv" + str(cls._ip_version)
cls.address_scopes = []
cls.admin_address_scopes = []
for fw_rule in cls.fw_rules:
cls._try_delete_resource(cls.client.delete_firewall_rule,
fw_rule['id'])
- # Clean up ike policies
- for ikepolicy in cls.ikepolicies:
- cls._try_delete_resource(cls.client.delete_ikepolicy,
- ikepolicy['id'])
- # Clean up vpn services
- for vpnservice in cls.vpnservices:
- cls._try_delete_resource(cls.client.delete_vpnservice,
- vpnservice['id'])
+ # Clean up QoS policies
+ for qos_policy in cls.qos_policies:
+ cls._try_delete_resource(cls.admin_client.delete_qos_policy,
+ qos_policy['id'])
+ # Clean up QoS rules
+ for qos_rule in cls.qos_rules:
+ cls._try_delete_resource(cls.admin_client.delete_qos_rule,
+ qos_rule['id'])
# Clean up floating IPs
for floating_ip in cls.floating_ips:
cls._try_delete_resource(cls.client.delete_floatingip,
"_execute") as mock_exec:
mock_exec.side_effect = Exception()
self.assertRaises(exc.IpCommandError,
- self.pci_wrapper.set_vf_state,
+ self.pci_wrapper.set_vf_spoofcheck,
self.VF_INDEX,
True)
+
+ def test_set_vf_max_rate(self):
+ with mock.patch.object(self.pci_wrapper, "_as_root") \
+ as mock_as_root:
+ result = self.pci_wrapper.set_vf_max_rate(self.VF_INDEX, 1000)
+ self.assertIsNone(result)
+ mock_as_root.assert_called_once_with([], "link",
+ ("set", self.DEV_NAME, "vf", str(self.VF_INDEX), "rate", '1000'))
+
+ def test_set_vf_max_rate_fail(self):
+ with mock.patch.object(self.pci_wrapper,
+ "_execute") as mock_exec:
+ mock_exec.side_effect = Exception()
+ self.assertRaises(exc.IpCommandError,
+ self.pci_wrapper.set_vf_max_rate,
+ self.VF_INDEX,
+ 1000)
self.assertTrue(self._mock_treat_devices_added_updated(
details, mock.Mock(), 'treat_vif_port'))
- 'get_devices_details_list',
- return_value=[details]),\
+ def test_treat_devices_added_updated_sends_vif_port_into_extension_manager(
+ self, *args):
+ details = mock.MagicMock()
+ details.__contains__.side_effect = lambda x: True
+ port = mock.MagicMock()
+
+ def fake_handle_port(context, port):
+ self.assertIn('vif_port', port)
+
+ with mock.patch.object(self.agent.plugin_rpc,
++ 'get_devices_details_list_and_failed_devices',
++ return_value={'devices': [details],
++ 'failed_devices': None}),\
+ mock.patch.object(self.agent.agent_extensions_mgr,
+ 'handle_port', new=fake_handle_port),\
+ mock.patch.object(self.agent.int_br,
+ 'get_vifs_by_ids',
+ return_value={details['device']: port}),\
+ mock.patch.object(self.agent, 'treat_vif_port',
+ return_value=False):
+
+ self.agent.treat_devices_added_or_updated([{}], False)
+
def test_treat_devices_added_updated_skips_if_port_not_found(self):
dev_mock = mock.MagicMock()
dev_mock.__getitem__.return_value = 'the_skipped_one'
self.callbacks.get_device_details(mock.Mock())
self.assertTrue(self.plugin.update_port_status.called)
- def test_get_devices_details_list(self):
+ def test_get_device_details_qos_policy_id_none(self):
+ 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"})
+ res = self.callbacks.get_device_details(mock.Mock(), host='fake')
+ self.assertIsNone(res['qos_policy_id'])
+
+ def test_get_device_details_qos_policy_id_inherited_from_network(self):
+ 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_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_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_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'])
+
+ def _test_get_devices_list(self, callback, side_effect, expected):
devices = [1, 2, 3, 4, 5]
kwargs = {'host': 'fake_host', 'agent_id': 'fake_agent_id'}
with mock.patch.object(self.callbacks, 'get_device_details',
test = neutron.tests.unit.plugins.ml2.drivers.ext_test:TestExtensionDriver
testdb = neutron.tests.unit.plugins.ml2.drivers.ext_test:TestDBExtensionDriver
port_security = neutron.plugins.ml2.extensions.port_security:PortSecurityExtensionDriver
- cisco_n1kv_ext = neutron.plugins.ml2.drivers.cisco.n1kv.n1kv_ext_driver:CiscoN1kvExtensionDriver
+ qos = neutron.plugins.ml2.extensions.qos:QosExtensionDriver
neutron.openstack.common.cache.backends =
memory = neutron.openstack.common.cache._backends.memory:MemoryBackend
neutron.ipam_drivers =