Fix inconsistencies in use of IPAddr and UUID instances.

We no longer use instances of either class, allowing us to be confident if we
are dealing with a string rather than a string OR UUID/IPAddr instance.

Change-Id: I602e9f2e6bc63d692b4dfc0bcffd30b923286576
This commit is contained in:
Kiall Mac Innes 2012-11-30 13:53:12 +00:00
parent 6228e0c59d
commit 52c7dd4fb3
5 changed files with 12 additions and 24 deletions

View File

@ -38,8 +38,6 @@ import inspect
import itertools
import json
import xmlrpclib
import uuid
import ipaddr
from moniker.openstack.common import timeutils
@ -106,10 +104,6 @@ def to_primitive(value, convert_instances=False, level=0):
return o
elif isinstance(value, datetime.datetime):
return timeutils.strtime(value)
elif isinstance(value, uuid.UUID):
return str(value)
elif isinstance(value, ipaddr.IPAddress):
return str(value)
elif hasattr(value, 'iteritems'):
return to_primitive(dict(value.iteritems()),
convert_instances=convert_instances,

View File

@ -52,7 +52,7 @@ class UUID(TypeDecorator):
if value is None:
return value
else:
return uuid.UUID(value)
return str(uuid.UUID(value))
class Inet(TypeDecorator):
@ -69,9 +69,3 @@ class Inet(TypeDecorator):
return value
else:
return str(value)
def process_result_value(self, value, dialect):
if value is None:
return value
else:
return ipaddr.IPAddress(value)

View File

@ -18,10 +18,10 @@
# under the License.
# should this be in schema.py?
from uuid import uuid4
from sqlalchemy import ForeignKey, Enum, Integer, String, DateTime, Text
from sqlalchemy.schema import Column, MetaData
from moniker.openstack.common import timeutils
from moniker.openstack.common.uuidutils import generate_uuid
from moniker.storage.impl_sqlalchemy.migrate_repo.utils import (
Table, create_tables, drop_tables)
from moniker.sqlalchemy.types import Inet, UUID
@ -31,7 +31,7 @@ meta = MetaData()
RECORD_TYPES = ['A', 'AAAA', 'CNAME', 'MX', 'SRV', 'TXT', 'NS']
servers = Table('servers', meta,
Column('id', UUID(), default=uuid4, primary_key=True),
Column('id', UUID(), default=generate_uuid, primary_key=True),
Column('created_at', DateTime(), default=timeutils.utcnow),
Column('updated_at', DateTime(), onupdate=timeutils.utcnow),
Column('version', Integer(), default=1, nullable=False),
@ -40,7 +40,7 @@ servers = Table('servers', meta,
Column('ipv6', Inet(), default=None, unique=True))
domains = Table('domains', meta,
Column('id', UUID(), default=uuid4, primary_key=True),
Column('id', UUID(), default=generate_uuid, primary_key=True),
Column('created_at', DateTime(), default=timeutils.utcnow),
Column('updated_at', DateTime(), onupdate=timeutils.utcnow),
Column('version', Integer(), default=1, nullable=False),
@ -54,7 +54,7 @@ domains = Table('domains', meta,
Column('minimum', Integer(), default=3600, nullable=False))
records = Table('records', meta,
Column('id', UUID(), default=uuid4, primary_key=True),
Column('id', UUID(), default=generate_uuid, primary_key=True),
Column('created_at', DateTime(), default=timeutils.utcnow),
Column('updated_at', DateTime(), onupdate=timeutils.utcnow),
Column('version', Integer(), default=1, nullable=False),

View File

@ -15,7 +15,6 @@
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
from uuid import uuid4
from urlparse import urlparse
from sqlalchemy import (Column, DateTime, String, Text, Integer, ForeignKey,
Enum, Boolean, Unicode)
@ -26,6 +25,7 @@ from sqlalchemy.ext.hybrid import hybrid_property
from moniker.openstack.common import cfg
from moniker.openstack.common import log as logging
from moniker.openstack.common import timeutils
from moniker.openstack.common.uuidutils import generate_uuid
from moniker import exceptions
from moniker.sqlalchemy.types import UUID, Inet
@ -50,7 +50,7 @@ def table_args():
class Base(object):
__abstract__ = True
id = Column(UUID, default=uuid4, primary_key=True)
id = Column(UUID, default=generate_uuid, primary_key=True)
created_at = Column(DateTime, default=timeutils.utcnow)
updated_at = Column(DateTime, onupdate=timeutils.utcnow)

View File

@ -44,8 +44,8 @@ class CentralServiceTest(CentralTestCase):
# Ensure all values have been set correctly
self.assertIsNotNone(server['id'])
self.assertEqual(server['name'], values['name'])
self.assertEqual(str(server['ipv4']), values['ipv4'])
self.assertEqual(str(server['ipv6']), values['ipv6'])
self.assertEqual(server['ipv4'], values['ipv4'])
self.assertEqual(server['ipv6'], values['ipv6'])
def test_get_servers(self):
context = self.get_admin_context()
@ -84,8 +84,8 @@ class CentralServiceTest(CentralTestCase):
expected_server['id'])
self.assertEqual(server['id'], expected_server['id'])
self.assertEqual(server['name'], expected_server['name'])
self.assertEqual(str(server['ipv4']), expected_server['ipv4'])
self.assertEqual(str(server['ipv6']), expected_server['ipv6'])
self.assertEqual(server['ipv4'], expected_server['ipv4'])
self.assertEqual(server['ipv6'], expected_server['ipv6'])
def test_update_server(self):
context = self.get_admin_context()
@ -103,7 +103,7 @@ class CentralServiceTest(CentralTestCase):
expected_server['id'])
# Ensure the server was updated correctly
self.assertEqual(str(server['ipv4']), '127.0.0.1')
self.assertEqual(server['ipv4'], '127.0.0.1')
def test_delete_server(self):
context = self.get_admin_context()