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_macvlan.py 3.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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 macvlan
  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 TestMacvlanDriver(base.TestCase):
  21. """Unit tests for nested MACVLAN 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_nova_instance_port_id = uuidutils.generate_uuid()
  34. fake_neutron_v4_subnet_id = uuidutils.generate_uuid()
  35. fake_neutron_v6_subnet_id = uuidutils.generate_uuid()
  36. fake_vif_details = {"port_filter": True, "ovs_hybrid_plug": False}
  37. fake_vif_type = "ovs"
  38. fake_neutron_port = self._get_fake_port(
  39. fake_docker_endpoint_id, fake_docker_network_id,
  40. fake_port_id, constants.PORT_STATUS_ACTIVE,
  41. fake_neutron_v4_subnet_id, fake_neutron_v6_subnet_id,
  42. vif_details=fake_vif_details, vif_type=fake_vif_type)
  43. fake_nova_instance_port = self._get_fake_port(
  44. "nova-port", fake_docker_network_id,
  45. fake_nova_instance_port_id, constants.PORT_STATUS_ACTIVE,
  46. fake_neutron_v4_subnet_id, fake_neutron_v6_subnet_id,
  47. "192.168.1.3", "fe80::f816:3eff:fe20:57c5",
  48. vif_details=fake_vif_details, vif_type=fake_vif_type)
  49. fake_subnets = self._get_fake_subnets(
  50. fake_docker_endpoint_id, fake_docker_network_id,
  51. fake_neutron_v4_subnet_id, fake_neutron_v6_subnet_id)
  52. fake_network = self._get_fake_networks(fake_docker_network_id)
  53. fake_network['networks'][0]['mtu'] = fake_mtu
  54. macvlan.port_bind(fake_docker_endpoint_id,
  55. fake_neutron_port['port'],
  56. fake_subnets['subnets'],
  57. fake_network['networks'][0],
  58. fake_nova_instance_port['port'])
  59. mock_configure_container_iface.assert_called_once()