Use get_random_string from neutron-lib

Use the method provided by neutron-lib and delete the duplicated
neutron one.

NeutronLibImpact

Change-Id: I3a62d8f58862ab978102ac205b1359424e225eeb
This commit is contained in:
Gary Kotton 2016-12-01 04:52:02 -08:00
parent 4238c20f2a
commit 71fac629e2
7 changed files with 13 additions and 31 deletions

View File

@ -150,12 +150,6 @@ def get_random_mac(base_mac):
return ':'.join(["%02x" % x for x in mac])
@removals.remove(
message="Use get_random_string from neutron_lib.utils.helpers")
def get_random_string(length):
return helpers.get_random_string(length)
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

@ -16,6 +16,7 @@
import mock
from neutron_lib import constants as n_consts
from neutron_lib.utils import helpers
from oslo_utils import uuidutils
from neutron.agent.common import ovs_lib
@ -27,7 +28,7 @@ from neutron.tests.functional.agent.l2 import base
def generate_tap_device_name():
return n_consts.TAP_DEVICE_PREFIX + common_utils.get_random_string(
return n_consts.TAP_DEVICE_PREFIX + helpers.get_random_string(
n_consts.DEVICE_NAME_MAX_LEN - len(n_consts.TAP_DEVICE_PREFIX))

View File

@ -14,9 +14,9 @@
import os
from neutron_lib.utils import helpers
import testtools
from neutron.common import utils
from neutron.tests.common.exclusive_resources import resource_allocator
from neutron.tests.functional import base
@ -32,7 +32,7 @@ class TestResourceAllocator(base.BaseLoggingTestCase):
def setUp(self):
super(TestResourceAllocator, self).setUp()
self.ra = resource_allocator.ResourceAllocator(
utils.get_random_string(6), lambda: 42)
helpers.get_random_string(6), lambda: 42)
self.addCleanup(safe_remove_file, self.ra._state_file_path)
def test_allocate_and_release(self):

View File

@ -18,7 +18,6 @@ import datetime
import os
import platform
import random
import string
import time
import warnings
@ -202,12 +201,8 @@ class UnorderedList(list):
return not self == other
def get_random_string(n=10):
return ''.join(random.choice(string.ascii_lowercase) for _ in range(n))
def get_random_string_list(i=3, n=5):
return [get_random_string(n) for _ in range(0, i)]
return [helpers.get_random_string(n) for _ in range(0, i)]
def get_random_boolean():

View File

@ -14,7 +14,6 @@
import os.path
import random
import re
import sys
import eventlet
@ -689,15 +688,6 @@ class TestRoundVal(base.BaseTestCase):
self.assertEqual(expected, utils.round_val(value))
class TestGetRandomString(base.BaseTestCase):
def test_get_random_string(self):
length = 127
random_string = utils.get_random_string(length)
self.assertEqual(length, len(random_string))
regex = re.compile('^[0-9a-fA-F]+$')
self.assertIsNotNone(regex.match(random_string))
class TestSafeDecodeUtf8(base.BaseTestCase):
@helpers.requires_py2

View File

@ -25,6 +25,7 @@ from alembic.operations import ops as alembic_ops
from alembic import script as alembic_script
import fixtures
import mock
from neutron_lib.utils import helpers
from oslo_utils import fileutils
import pkg_resources
import sqlalchemy as sa
@ -51,7 +52,7 @@ class FakeRevision(object):
self.branch_labels = labels
self.down_revision = down_revision
self.is_branch_point = is_branch_point
self.revision = tools.get_random_string()
self.revision = helpers.get_random_string(10)
self.module = mock.MagicMock()

View File

@ -19,6 +19,7 @@ import random
import mock
import netaddr
from neutron_lib import exceptions as n_exc
from neutron_lib.utils import helpers
from oslo_db import exception as obj_exc
from oslo_db.sqlalchemy import utils as db_utils
from oslo_utils import timeutils
@ -374,14 +375,14 @@ def get_list_of_random_networks(num=10):
def get_random_domain_name():
return '.'.join([
tools.get_random_string(62)[:random.choice(range(63))]
helpers.get_random_string(62)[:random.choice(range(63))]
for i in range(4)
])
def get_random_dict_of_strings():
return {
tools.get_random_string(): tools.get_random_string()
helpers.get_random_string(10): helpers.get_random_string(10)
for i in range(10)
}
@ -397,7 +398,7 @@ FIELD_TYPE_VALUE_GENERATOR_MAP = {
obj_fields.BooleanField: tools.get_random_boolean,
obj_fields.DateTimeField: tools.get_random_datetime,
obj_fields.IntegerField: tools.get_random_integer,
obj_fields.StringField: tools.get_random_string,
obj_fields.StringField: lambda: helpers.get_random_string(10),
obj_fields.ListOfStringsField: tools.get_random_string_list,
common_types.UUIDField: uuidutils.generate_uuid,
obj_fields.ObjectField: lambda: None,
@ -1217,7 +1218,7 @@ class BaseDbObjectTestCase(_BaseObjectTestCase,
self._network.create()
def _create_network(self):
name = "test-network-%s" % tools.get_random_string(4)
name = "test-network-%s" % helpers.get_random_string(4)
_network = net_obj.Network(self.context,
name=name)
_network.create()
@ -1309,7 +1310,7 @@ class BaseDbObjectTestCase(_BaseObjectTestCase,
def _create_test_standard_attribute(self):
attrs = {
'id': tools.get_random_integer(),
'resource_type': tools.get_random_string(4),
'resource_type': helpers.get_random_string(4),
'revision_number': tools.get_random_integer()
}
self._standard_attribute = obj_db_api.create_object(