Esempio n. 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)
Esempio n. 2
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)
Esempio n. 3
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)
Esempio n. 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
         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)
Esempio n. 5
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
Esempio n. 6
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.publish(resources.AGENT,
                              events.BEFORE_DELETE,
                              self,
                              payload=events.DBEventPayload(
                                  self.ctx, states=(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)
Esempio n. 7
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.publish(resources.AGENT,
                          events.BEFORE_DELETE,
                          self,
                          payload=events.DBEventPayload(self.ctx,
                                                        states=(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)
Esempio n. 8
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()
Esempio n. 9
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)