Remove the oslo-utils dependency
Change-Id: I34357d5a594330d07f5cad372859d98efb5d3fde
(cherry picked from commit 5044279f58
)
This commit is contained in:
parent
d151372081
commit
912a3a9b0e
|
@ -12,7 +12,6 @@
|
||||||
import re
|
import re
|
||||||
|
|
||||||
import netaddr
|
import netaddr
|
||||||
from oslo_utils import uuidutils
|
|
||||||
|
|
||||||
from ovsdbapp.backend.ovs_idl import command as cmd
|
from ovsdbapp.backend.ovs_idl import command as cmd
|
||||||
from ovsdbapp.backend.ovs_idl import idlutils
|
from ovsdbapp.backend.ovs_idl import idlutils
|
||||||
|
@ -1260,7 +1259,7 @@ class _PgUpdatePortsHelper(cmd.BaseCommand):
|
||||||
|
|
||||||
if isinstance(port, cmd.BaseCommand):
|
if isinstance(port, cmd.BaseCommand):
|
||||||
port = port.result
|
port = port.result
|
||||||
elif uuidutils.is_uuid_like(port):
|
elif utils.is_uuid_like(port):
|
||||||
try:
|
try:
|
||||||
port = self.api.lookup('Logical_Switch_Port', port)
|
port = self.api.lookup('Logical_Switch_Port', port)
|
||||||
except idlutils.RowNotFound:
|
except idlutils.RowNotFound:
|
||||||
|
|
|
@ -11,7 +11,6 @@
|
||||||
# under the License.
|
# under the License.
|
||||||
|
|
||||||
import netaddr
|
import netaddr
|
||||||
from oslo_utils import uuidutils
|
|
||||||
import testscenarios
|
import testscenarios
|
||||||
|
|
||||||
from ovsdbapp.backend.ovs_idl import idlutils
|
from ovsdbapp.backend.ovs_idl import idlutils
|
||||||
|
@ -1343,7 +1342,7 @@ class TestPortGroup(OvnNorthboundTest):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
super(TestPortGroup, self).setUp()
|
super(TestPortGroup, self).setUp()
|
||||||
self.switch = self.useFixture(fixtures.LogicalSwitchFixture()).obj
|
self.switch = self.useFixture(fixtures.LogicalSwitchFixture()).obj
|
||||||
self.pg_name = 'testpg-%s' % uuidutils.generate_uuid()
|
self.pg_name = 'testpg-%s' % ovsdb_utils.generate_uuid()
|
||||||
|
|
||||||
def test_port_group(self):
|
def test_port_group(self):
|
||||||
# Assert the Port Group was added
|
# Assert the Port Group was added
|
||||||
|
@ -1397,7 +1396,7 @@ class TestPortGroup(OvnNorthboundTest):
|
||||||
|
|
||||||
def test_pg_del_ports_if_exists(self):
|
def test_pg_del_ports_if_exists(self):
|
||||||
self.api.pg_add(self.pg_name).execute(check_error=True)
|
self.api.pg_add(self.pg_name).execute(check_error=True)
|
||||||
non_existent_res = uuidutils.generate_uuid()
|
non_existent_res = ovsdb_utils.generate_uuid()
|
||||||
|
|
||||||
# Assert that if if_exists is False (default) it will raise an error
|
# Assert that if if_exists is False (default) it will raise an error
|
||||||
self.assertRaises(RuntimeError, self.api.pg_del_ports(self.pg_name,
|
self.assertRaises(RuntimeError, self.api.pg_del_ports(self.pg_name,
|
||||||
|
|
|
@ -11,6 +11,7 @@
|
||||||
# under the License.
|
# under the License.
|
||||||
|
|
||||||
import netaddr
|
import netaddr
|
||||||
|
import uuid
|
||||||
|
|
||||||
from ovsdbapp.tests import base
|
from ovsdbapp.tests import base
|
||||||
from ovsdbapp import utils
|
from ovsdbapp import utils
|
||||||
|
@ -51,3 +52,20 @@ class TestUtils(base.TestCase):
|
||||||
for val in bad:
|
for val in bad:
|
||||||
self.assertRaises(netaddr.AddrFormatError,
|
self.assertRaises(netaddr.AddrFormatError,
|
||||||
utils.normalize_ip_port, val)
|
utils.normalize_ip_port, val)
|
||||||
|
|
||||||
|
def test_is_uuid_like(self):
|
||||||
|
self.assertTrue(utils.is_uuid_like(str(uuid.uuid4())))
|
||||||
|
self.assertTrue(utils.is_uuid_like(
|
||||||
|
'{12345678-1234-1234-1234-123456781234}'))
|
||||||
|
self.assertTrue(utils.is_uuid_like(
|
||||||
|
'12345678123412341234123456781234'))
|
||||||
|
self.assertTrue(utils.is_uuid_like(
|
||||||
|
'urn:uuid:12345678-1234-1234-1234-123456781234'))
|
||||||
|
self.assertTrue(utils.is_uuid_like(
|
||||||
|
'urn:bbbaaaaa-aaaa-aaaa-aabb-bbbbbbbbbbbb'))
|
||||||
|
self.assertTrue(utils.is_uuid_like(
|
||||||
|
'uuid:bbbaaaaa-aaaa-aaaa-aabb-bbbbbbbbbbbb'))
|
||||||
|
self.assertFalse(utils.is_uuid_like(
|
||||||
|
'uuid:batrdbaa-aaaa-aaaa-aabb-bbbbbbbbbbbb'))
|
||||||
|
self.assertFalse(utils.is_uuid_like(
|
||||||
|
'123456781234123412341234567812345678'))
|
||||||
|
|
|
@ -11,6 +11,7 @@
|
||||||
# under the License.
|
# under the License.
|
||||||
|
|
||||||
import netaddr
|
import netaddr
|
||||||
|
import uuid
|
||||||
|
|
||||||
# NOTE(twilson) Clearly these are silly, but they are good enough for now
|
# NOTE(twilson) Clearly these are silly, but they are good enough for now
|
||||||
# I'm happy for someone to replace them with better parsing
|
# I'm happy for someone to replace them with better parsing
|
||||||
|
@ -41,3 +42,36 @@ def normalize_ip_port(ipport):
|
||||||
if int(port) <= 0 or int(port) > 65535:
|
if int(port) <= 0 or int(port) > 65535:
|
||||||
raise netaddr.AddrFormatError("Invalid port")
|
raise netaddr.AddrFormatError("Invalid port")
|
||||||
return "%s:%s" % (ip, port)
|
return "%s:%s" % (ip, port)
|
||||||
|
|
||||||
|
|
||||||
|
def generate_uuid(dashed=True):
|
||||||
|
"""Create a random uuid string.
|
||||||
|
|
||||||
|
:param dashed: Generate uuid with dashes or not
|
||||||
|
:type dashed: bool
|
||||||
|
:returns: string
|
||||||
|
"""
|
||||||
|
if dashed:
|
||||||
|
return str(uuid.uuid4())
|
||||||
|
return uuid.uuid4().hex
|
||||||
|
|
||||||
|
|
||||||
|
def _format_uuid_string(string):
|
||||||
|
return (string.replace('urn:', '')
|
||||||
|
.replace('uuid:', '')
|
||||||
|
.strip('{}')
|
||||||
|
.replace('-', '')
|
||||||
|
.lower())
|
||||||
|
|
||||||
|
|
||||||
|
def is_uuid_like(val):
|
||||||
|
"""Return validation of a value as a UUID.
|
||||||
|
|
||||||
|
:param val: Value to verify
|
||||||
|
:type val: string
|
||||||
|
:returns: bool
|
||||||
|
"""
|
||||||
|
try:
|
||||||
|
return str(uuid.UUID(val)).replace('-', '') == _format_uuid_string(val)
|
||||||
|
except (TypeError, ValueError, AttributeError):
|
||||||
|
return False
|
||||||
|
|
|
@ -4,7 +4,6 @@
|
||||||
|
|
||||||
fixtures>=3.0.0 # Apache-2.0/BSD
|
fixtures>=3.0.0 # Apache-2.0/BSD
|
||||||
netaddr>=0.7.18 # BSD
|
netaddr>=0.7.18 # BSD
|
||||||
oslo.utils>=3.33.0 # Apache-2.0
|
|
||||||
ovs>=2.8.0 # Apache-2.0
|
ovs>=2.8.0 # Apache-2.0
|
||||||
pbr!=2.1.0,>=2.0.0 # Apache-2.0
|
pbr!=2.1.0,>=2.0.0 # Apache-2.0
|
||||||
six>=1.10.0 # MIT
|
six>=1.10.0 # MIT
|
||||||
|
|
Loading…
Reference in New Issue