Bridge between container framework networking and storage models to OpenStack networking and storage abstractions.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

test_ipvlan.py 2.5KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. # Licensed under the Apache License, Version 2.0 (the "License"); you may
  2. # not use this file except in compliance with the License. You may obtain
  3. # a copy of the License at
  4. #
  5. # http://www.apache.org/licenses/LICENSE-2.0
  6. #
  7. # Unless required by applicable law or agreed to in writing, software
  8. # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  9. # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  10. # License for the specific language governing permissions and limitations
  11. # under the License.
  12. import mock
  13. from oslo_utils import uuidutils
  14. from kuryr.lib.binding.drivers import ipvlan
  15. from kuryr.lib import constants
  16. from kuryr.lib import utils
  17. from kuryr.tests.unit import base
  18. mock_create = mock.MagicMock()
  19. mock_interface = mock.MagicMock()
  20. class TestIpvlanDriver(base.TestCase):
  21. """Unit tests for nested IPVLAN driver"""
  22. @mock.patch('kuryr.lib.binding.drivers.utils._configure_container_iface')
  23. @mock.patch('pyroute2.ipdb.interface.InterfacesDict.__getattribute__',
  24. return_value=mock_create)
  25. @mock.patch('pyroute2.ipdb.interface.InterfacesDict.__getitem__',
  26. return_value=mock_interface)
  27. def test_port_bind(self, mock_getitem, mock_getattribute,
  28. mock_configure_container_iface):
  29. fake_mtu = 1450
  30. fake_docker_endpoint_id = utils.get_hash()
  31. fake_docker_network_id = utils.get_hash()
  32. fake_port_id = uuidutils.generate_uuid()
  33. fake_neutron_v4_subnet_id = uuidutils.generate_uuid()
  34. fake_neutron_v6_subnet_id = uuidutils.generate_uuid()
  35. fake_vif_details = {"port_filter": True, "ovs_hybrid_plug": False}
  36. fake_vif_type = "ovs"
  37. fake_port = self._get_fake_port(
  38. fake_docker_endpoint_id, fake_docker_network_id,
  39. fake_port_id, constants.PORT_STATUS_ACTIVE,
  40. fake_neutron_v4_subnet_id, fake_neutron_v6_subnet_id,
  41. vif_details=fake_vif_details, vif_type=fake_vif_type)
  42. fake_subnets = self._get_fake_subnets(
  43. fake_docker_endpoint_id, fake_docker_network_id,
  44. fake_neutron_v4_subnet_id, fake_neutron_v6_subnet_id)
  45. fake_network = self._get_fake_networks(fake_docker_network_id)
  46. fake_network['networks'][0]['mtu'] = fake_mtu
  47. ipvlan.port_bind(fake_docker_endpoint_id,
  48. fake_port['port'],
  49. fake_subnets['subnets'],
  50. fake_network['networks'][0])
  51. mock_configure_container_iface.assert_called_once()