Browse Source

Remove the oslo-utils dependency

Change-Id: I34357d5a594330d07f5cad372859d98efb5d3fde
(cherry picked from commit 5044279f58)
tags/0.10.4^0
Miguel Duarte Barroso Maciej Józefczyk 1 year ago
parent
commit
ad9b9fc64e
5 changed files with 55 additions and 6 deletions
  1. +1
    -2
      ovsdbapp/schema/ovn_northbound/commands.py
  2. +2
    -3
      ovsdbapp/tests/functional/schema/ovn_northbound/test_impl_idl.py
  3. +18
    -0
      ovsdbapp/tests/unit/test_utils.py
  4. +34
    -0
      ovsdbapp/utils.py
  5. +0
    -1
      requirements.txt

+ 1
- 2
ovsdbapp/schema/ovn_northbound/commands.py View File

@@ -12,7 +12,6 @@
import re

import netaddr
from oslo_utils import uuidutils

from ovsdbapp.backend.ovs_idl import command as cmd
from ovsdbapp.backend.ovs_idl import idlutils
@@ -1160,7 +1159,7 @@ class _PgUpdatePortsHelper(cmd.BaseCommand):

if isinstance(port, cmd.BaseCommand):
port = port.result
elif uuidutils.is_uuid_like(port):
elif utils.is_uuid_like(port):
try:
port = self.api.lookup('Logical_Switch_Port', port)
except idlutils.RowNotFound:


+ 2
- 3
ovsdbapp/tests/functional/schema/ovn_northbound/test_impl_idl.py View File

@@ -11,7 +11,6 @@
# under the License.

import netaddr
from oslo_utils import uuidutils
import testscenarios

from ovsdbapp.backend.ovs_idl import idlutils
@@ -1243,7 +1242,7 @@ class TestPortGroup(OvnNorthboundTest):
def setUp(self):
super(TestPortGroup, self).setUp()
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):
# Assert the Port Group was added
@@ -1297,7 +1296,7 @@ class TestPortGroup(OvnNorthboundTest):

def test_pg_del_ports_if_exists(self):
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
self.assertRaises(RuntimeError, self.api.pg_del_ports(self.pg_name,


+ 18
- 0
ovsdbapp/tests/unit/test_utils.py View File

@@ -11,6 +11,7 @@
# under the License.

import netaddr
import uuid

from ovsdbapp.tests import base
from ovsdbapp import utils
@@ -51,3 +52,20 @@ class TestUtils(base.TestCase):
for val in bad:
self.assertRaises(netaddr.AddrFormatError,
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'))

+ 34
- 0
ovsdbapp/utils.py View File

@@ -11,6 +11,7 @@
# under the License.

import netaddr
import uuid

# NOTE(twilson) Clearly these are silly, but they are good enough for now
# 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:
raise netaddr.AddrFormatError("Invalid 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

+ 0
- 1
requirements.txt View File

@@ -4,7 +4,6 @@

fixtures>=3.0.0 # Apache-2.0/BSD
netaddr>=0.7.18 # BSD
oslo.utils>=3.33.0 # Apache-2.0
ovs>=2.8.0 # Apache-2.0
pbr!=2.1.0,>=2.0.0 # Apache-2.0
six>=1.10.0 # MIT

Loading…
Cancel
Save