Example #1
0
 def test_get_dvr_mac_address_list(self):
     mac_1 = tools.get_random_EUI()
     mac_2 = tools.get_random_EUI()
     self._create_dvr_mac_entry('host_1', mac_1)
     self._create_dvr_mac_entry('host_2', mac_2)
     mac_list = self.mixin.get_dvr_mac_address_list(self.ctx)
     self.assertEqual(2, len(mac_list))
     for mac in mac_list:
         self.assertIsInstance(mac, dict)
Example #2
0
 def test_get_dvr_mac_address_list(self):
     mac_1 = tools.get_random_EUI()
     mac_2 = tools.get_random_EUI()
     self._create_dvr_mac_entry('host_1', mac_1)
     self._create_dvr_mac_entry('host_2', mac_2)
     mac_list = self.mixin.get_dvr_mac_address_list(self.ctx)
     self.assertEqual(2, len(mac_list))
     for mac in mac_list:
         self.assertIsInstance(mac, dict)
Example #3
0
 def setUp(self):
     super(MACAddressFieldTest, self).setUp()
     self.field = common_types.MACAddressField()
     mac1 = tools.get_random_EUI()
     mac2 = tools.get_random_EUI()
     self.coerce_good_values = [(mac1, mac1), (mac2, mac2)]
     self.coerce_bad_values = [
         'XXXX', 'ypp', 'g3:vvv',
         # the field type is strict and does not allow to pass strings, even
         # if they represent a valid MAC address
         tools.get_random_mac(),
     ]
     self.to_primitive_values = self.coerce_good_values
     self.from_primitive_values = self.coerce_good_values
Example #4
0
 def setUp(self):
     super(MACAddressFieldTest, self).setUp()
     self.field = common_types.MACAddressField()
     mac1 = tools.get_random_EUI()
     mac2 = tools.get_random_EUI()
     self.coerce_good_values = [(mac1, mac1), (mac2, mac2)]
     self.coerce_bad_values = [
         'XXXX', 'ypp', 'g3:vvv',
         # the field type is strict and does not allow to pass strings, even
         # if they represent a valid MAC address
         tools.get_random_mac(),
     ]
     self.to_primitive_values = self.coerce_good_values
     self.from_primitive_values = self.coerce_good_values
Example #5
0
 def test__create_dvr_mac_address_success(self):
     entry = {'host': 'foo_host', 'mac_address': tools.get_random_EUI()}
     with mock.patch.object(net, 'get_random_mac') as f:
         f.return_value = entry['mac_address']
         expected = self.mixin._create_dvr_mac_address(
             self.ctx, entry['host'])
     self.assertEqual(expected, entry)
Example #6
0
 def test__get_dvr_mac_address_by_host(self):
     entry = router.DVRMacAddress(
         self.ctx, host='foo_host',
         mac_address=tools.get_random_EUI())
     entry.create()
     result = self.mixin._get_dvr_mac_address_by_host(self.ctx, 'foo_host')
     self.assertEqual(entry.to_dict(), result)
Example #7
0
 def test__get_dvr_mac_address_by_host(self):
     entry = router.DVRMacAddress(self.ctx,
                                  host='foo_host',
                                  mac_address=tools.get_random_EUI())
     entry.create()
     result = self.mixin._get_dvr_mac_address_by_host(self.ctx, 'foo_host')
     self.assertEqual(entry.to_dict(), result)
Example #8
0
 def test__create_dvr_mac_address_success(self):
     entry = {'host': 'foo_host', 'mac_address': tools.get_random_EUI()}
     with mock.patch.object(net, 'get_random_mac') as f:
         f.return_value = entry['mac_address']
         expected = self.mixin._create_dvr_mac_address(
             self.ctx, entry['host'])
     self.assertEqual(expected, entry)
Example #9
0
 def setUp(self):
     super(MACAddressFieldTest, self).setUp()
     self.field = common_types.MACAddressField()
     mac1 = tools.get_random_EUI()
     mac2 = tools.get_random_EUI()
     self.coerce_good_values = [(mac1, mac1), (mac2, mac2)]
     self.coerce_bad_values = [
         'XXXX', 'ypp', 'g3:vvv',
         # the field type is strict and does not allow to pass strings, even
         # if they represent a valid MAC address
         net.get_random_mac('fe:16:3e:00:00:00'.split(':')),
     ]
     self.to_primitive_values = ((a1, str(a2))
                                 for a1, a2 in self.coerce_good_values)
     self.from_primitive_values = ((a2, a1)
                                   for a1, a2 in self.to_primitive_values)
Example #10
0
 def test_mac_not_cleared_on_agent_delete_event_with_remaining_agents(self):
     plugin = directory.get_plugin()
     mac_1 = tools.get_random_EUI()
     mac_2 = tools.get_random_EUI()
     self._create_dvr_mac_entry('host_1', mac_1)
     self._create_dvr_mac_entry('host_2', mac_2)
     agent1 = {'host': 'host_1', 'id': 'a1'}
     agent2 = {'host': 'host_1', 'id': 'a2'}
     with mock.patch.object(plugin, 'get_agents', return_value=[agent2]):
         with mock.patch.object(plugin, 'notifier') as notifier:
             registry.notify(resources.AGENT, events.BEFORE_DELETE, self,
                             context=self.ctx, agent=agent1)
     mac_list = self.mixin.get_dvr_mac_address_list(self.ctx)
     for mac in mac_list:
         self.assertIsInstance(mac, dict)
     self.assertEqual(2, len(mac_list))
     self.assertFalse(notifier.dvr_mac_address_update.called)
Example #11
0
 def test_mac_cleared_on_agent_delete_event(self):
     plugin = directory.get_plugin()
     mac_1 = tools.get_random_EUI()
     mac_2 = tools.get_random_EUI()
     self._create_dvr_mac_entry('host_1', mac_1)
     self._create_dvr_mac_entry('host_2', mac_2)
     agent = {'host': 'host_1', 'id': 'a1'}
     with mock.patch.object(plugin, 'notifier') as notifier:
         registry.notify(resources.AGENT, events.BEFORE_DELETE, self,
                         context=self.ctx, agent=agent)
     mac_list = self.mixin.get_dvr_mac_address_list(self.ctx)
     self.assertEqual(1, len(mac_list))
     for mac in mac_list:
         self.assertIsInstance(mac, dict)
     self.assertEqual('host_2', mac_list[0]['host'])
     notifier.dvr_mac_address_update.assert_called_once_with(
         self.ctx, mac_list)
Example #12
0
 def test_mac_not_cleared_on_agent_delete_event_with_remaining_agents(self):
     plugin = directory.get_plugin()
     mac_1 = tools.get_random_EUI()
     mac_2 = tools.get_random_EUI()
     self._create_dvr_mac_entry('host_1', mac_1)
     self._create_dvr_mac_entry('host_2', mac_2)
     agent1 = {'host': 'host_1', 'id': 'a1'}
     agent2 = {'host': 'host_1', 'id': 'a2'}
     with mock.patch.object(plugin, 'get_agents', return_value=[agent2]):
         with mock.patch.object(plugin, 'notifier') as notifier:
             registry.notify(resources.AGENT, events.BEFORE_DELETE, self,
                             context=self.ctx, agent=agent1)
     mac_list = self.mixin.get_dvr_mac_address_list(self.ctx)
     for mac in mac_list:
         self.assertIsInstance(mac, dict)
     self.assertEqual(2, len(mac_list))
     self.assertFalse(notifier.dvr_mac_address_update.called)
Example #13
0
 def test_mac_cleared_on_agent_delete_event(self):
     plugin = directory.get_plugin()
     mac_1 = tools.get_random_EUI()
     mac_2 = tools.get_random_EUI()
     self._create_dvr_mac_entry('host_1', mac_1)
     self._create_dvr_mac_entry('host_2', mac_2)
     agent = {'host': 'host_1', 'id': 'a1'}
     with mock.patch.object(plugin, 'notifier') as notifier:
         registry.notify(resources.AGENT, events.BEFORE_DELETE, self,
                         context=self.ctx, agent=agent)
     mac_list = self.mixin.get_dvr_mac_address_list(self.ctx)
     self.assertEqual(1, len(mac_list))
     for mac in mac_list:
         self.assertIsInstance(mac, dict)
     self.assertEqual('host_2', mac_list[0]['host'])
     notifier.dvr_mac_address_update.assert_called_once_with(
         self.ctx, mac_list)
Example #14
0
 def _create_port(self, **port_attrs):
     attrs = {'project_id': uuidutils.generate_uuid(),
              'admin_state_up': True,
              'status': 'ACTIVE',
              'device_id': 'fake_device',
              'device_owner': 'fake_owner',
              'mac_address': tools.get_random_EUI()}
     attrs.update(port_attrs)
     port = ports.Port(self.context, **attrs)
     port.create()
     return port
Example #15
0
 def _create_port(self, **port_attrs):
     attrs = {'project_id': uuidutils.generate_uuid(),
              'admin_state_up': True,
              'status': 'ACTIVE',
              'device_id': 'fake_device',
              'device_owner': 'fake_owner',
              'mac_address': tools.get_random_EUI()}
     attrs.update(port_attrs)
     port = ports.Port(self.context, **attrs)
     port.create()
     return port
Example #16
0
    def test__create_dvr_mac_address_retries_exceeded_retry_logic(self):
        # limit retries so test doesn't take 40 seconds
        mock.patch('neutron.db.api._retry_db_errors.max_retries',
                   new=2).start()

        non_unique_mac = tools.get_random_EUI()
        self._create_dvr_mac_entry('foo_host_1', non_unique_mac)
        with mock.patch.object(net, 'get_random_mac') as f:
            f.return_value = non_unique_mac
            self.assertRaises(lib_exc.HostMacAddressGenerationFailure,
                              self.mixin._create_dvr_mac_address,
                              self.ctx, "foo_host_2")
Example #17
0
    def test__create_dvr_mac_address_retries_exceeded_retry_logic(self):
        # limit retries so test doesn't take 40 seconds
        mock.patch('neutron.db.api._retry_db_errors.max_retries',
                   new=2).start()

        non_unique_mac = tools.get_random_EUI()
        self._create_dvr_mac_entry('foo_host_1', non_unique_mac)
        with mock.patch.object(net, 'get_random_mac') as f:
            f.return_value = non_unique_mac
            self.assertRaises(lib_exc.HostMacAddressGenerationFailure,
                              self.mixin._create_dvr_mac_address, self.ctx,
                              "foo_host_2")
Example #18
0
 def _create_port(self, **port_attrs):
     attrs = {
         "project_id": uuidutils.generate_uuid(),
         "admin_state_up": True,
         "status": "ACTIVE",
         "device_id": "fake_device",
         "device_owner": "fake_owner",
         "mac_address": tools.get_random_EUI(),
     }
     attrs.update(port_attrs)
     port = ports.Port(self.context, **attrs)
     port.create()
     return port
Example #19
0
    def test__create_dvr_mac_address_retries_exceeded_retry_logic(self):
        # limit retries so test doesn't take 40 seconds
        retry_fixture = fixture.DBRetryErrorsFixture(max_retries=2)
        retry_fixture.setUp()

        non_unique_mac = tools.get_random_EUI()
        self._create_dvr_mac_entry('foo_host_1', non_unique_mac)
        with mock.patch.object(net, 'get_random_mac') as f:
            f.return_value = non_unique_mac
            self.assertRaises(lib_exc.HostMacAddressGenerationFailure,
                              self.mixin._create_dvr_mac_address,
                              self.ctx, "foo_host_2")
        retry_fixture.cleanUp()
Example #20
0
    def test__create_dvr_mac_address_retries_exceeded_retry_logic(self):
        # limit retries so test doesn't take 40 seconds
        retry_fixture = fixture.DBRetryErrorsFixture(max_retries=2)
        retry_fixture.setUp()

        non_unique_mac = tools.get_random_EUI()
        self._create_dvr_mac_entry('foo_host_1', non_unique_mac)
        with mock.patch.object(net, 'get_random_mac') as f:
            f.return_value = non_unique_mac
            self.assertRaises(lib_exc.HostMacAddressGenerationFailure,
                              self.mixin._create_dvr_mac_address, self.ctx,
                              "foo_host_2")
        retry_fixture.cleanUp()
Example #21
0
def _create_port(context, device_id, ip_address):
    network_id = 'd339eb89-3b7c-4a29-8c02-83ed329ea6d5'
    subnet_id = '1f9206e1-0872-4bc1-a600-3efed860ee64'
    fixed_ips = {
        'subnet_id': subnet_id,
        'network_id': network_id,
        'ip_address': ip_address}
    ip_allocation = ports.IPAllocation(context, **fixed_ips)
    port_attrs = {
        'network_id': network_id,
        'fixed_ips': [ip_allocation]
    }
    attrs = {'project_id': 'fake',
             'admin_state_up': True,
             'status': 'ACTIVE',
             'device_id': device_id,
             'device_owner': 'compute:nova',
             'mac_address': tools.get_random_EUI()}
    attrs.update(**port_attrs)
    port = ports.Port(context, **attrs)
    return port
Example #22
0
 def test_get_dvr_mac_address_by_host_existing_host(self):
     self._create_dvr_mac_entry('foo_host', tools.get_random_EUI())
     with mock.patch.object(self.mixin,
                            '_get_dvr_mac_address_by_host') as f:
         self.mixin.get_dvr_mac_address_by_host(self.ctx, 'foo_host')
         self.assertEqual(1, f.call_count)
Example #23
0
 def test_get_dvr_mac_address_by_host_existing_host(self):
     self._create_dvr_mac_entry('foo_host', tools.get_random_EUI())
     with mock.patch.object(self.mixin,
                            '_get_dvr_mac_address_by_host') as f:
         self.mixin.get_dvr_mac_address_by_host(self.ctx, 'foo_host')
         self.assertEqual(1, f.call_count)