Merge "Remove deprecated get_random_mac()"

This commit is contained in:
Jenkins 2017-09-26 02:02:53 +00:00 committed by Gerrit Code Review
commit 0376f8fbf2
5 changed files with 8 additions and 25 deletions

View File

@ -37,7 +37,6 @@ from eventlet.green import subprocess
import netaddr
from neutron_lib import constants as n_const
from neutron_lib.utils import helpers
from neutron_lib.utils import net
from oslo_concurrency import lockutils
from oslo_config import cfg
from oslo_db import exception as db_exc
@ -146,15 +145,6 @@ def log_opt_values(log):
cfg.CONF.log_opt_values(log, logging.DEBUG)
@removals.remove(
message="Use get_random_mac from neutron_lib.utils.net",
version="Pike",
removal_version="Queens"
)
def get_random_mac(base_mac):
return net.get_random_mac(base_mac)
def get_dhcp_agent_device_id(network_id, host):
# Split host so as to always use only the hostname and
# not the domain name. This will guarantee consistency

View File

@ -23,6 +23,7 @@ from neutron_lib import constants
from neutron_lib import exceptions as n_exc
from neutron_lib.objects import exceptions
from neutron_lib.plugins import directory
from neutron_lib.utils import net
from oslo_config import cfg
from oslo_log import helpers as log_helpers
from oslo_log import log as logging
@ -100,7 +101,7 @@ class DVRDbMixin(ext_dvr.DVRMacAddressPluginBase):
@db_api.retry_if_session_inactive()
def _create_dvr_mac_address_retry(self, context, host, base_mac):
with db_api.context_manager.writer.using(context):
mac_address = utils.get_random_mac(base_mac)
mac_address = net.get_random_mac(base_mac)
dvr_mac_binding = router.DVRMacAddress(
context, host=host, mac_address=netaddr.EUI(mac_address))
dvr_mac_binding.create()

View File

@ -20,7 +20,6 @@ import random
import time
import warnings
from debtcollector import removals
import fixtures
import mock
import netaddr
@ -247,16 +246,6 @@ def get_random_cidr(version=4):
return '2001:db8:%x::/%d' % (random.getrandbits(16), 64)
@removals.remove(
message="Use get_random_mac from neutron_lib.utils.net",
version="Pike",
removal_version="Queens"
)
def get_random_mac():
"""Generate a random mac address starting with fe:16:3e"""
return net.get_random_mac(['fe', '16', '3e', '00', '00', '00'])
def get_random_EUI():
return netaddr.EUI(
net.get_random_mac(['fe', '16', '3e', '00', '00', '00'])

View File

@ -21,6 +21,7 @@ from neutron_lib.callbacks import resources
from neutron_lib import constants
from neutron_lib import context
from neutron_lib.plugins import directory
from neutron_lib.utils import net
from neutron.db import dvr_mac_db
from neutron.extensions import dvr
@ -61,7 +62,7 @@ class DvrDbMixinTestCase(test_plugin.Ml2PluginV2TestCase):
def test__create_dvr_mac_address_success(self):
entry = {'host': 'foo_host', 'mac_address': tools.get_random_EUI()}
with mock.patch.object(dvr_mac_db.utils, 'get_random_mac') as f:
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'])
@ -74,7 +75,7 @@ class DvrDbMixinTestCase(test_plugin.Ml2PluginV2TestCase):
non_unique_mac = tools.get_random_EUI()
self._create_dvr_mac_entry('foo_host_1', non_unique_mac)
with mock.patch.object(dvr_mac_db.utils, 'get_random_mac') as f:
with mock.patch.object(net, 'get_random_mac') as f:
f.return_value = non_unique_mac
self.assertRaises(dvr.MacAddressGenerationFailure,
self.mixin._create_dvr_mac_address,

View File

@ -14,6 +14,7 @@ import abc
import netaddr
from neutron_lib import context
from neutron_lib.utils import net
from oslo_db import exception
from oslo_db.tests.sqlalchemy import base as test_base
from oslo_utils import timeutils
@ -216,7 +217,8 @@ class MACAddressTestCase(SqlAlchemyTypesBaseTestCase):
self._add_row(id=uuidutils.generate_uuid(), mac=mac)
obj = self._get_one(mac)
self.assertEqual(mac, obj['mac'])
random_mac = netaddr.EUI(tools.get_random_mac())
random_mac = netaddr.EUI(net.get_random_mac(
['fe', '16', '3e', '00', '00', '00']))
self._update_row(mac, random_mac)
obj = self._get_one(random_mac)
self.assertEqual(random_mac, obj['mac'])