Replace uuid.uuid4() with uuidutils.generate_uuid()
Openstack common has a wrapper for generating uuids. We should use that function to generate uuids for consistency. Change-Id: Ia40c301868d7034c4af34848e15aef2744404ff8
This commit is contained in:
parent
392f3859ff
commit
ca4df61ca9
|
@ -24,10 +24,10 @@ Create Date: 2014-09-18 12:44:28.327312
|
|||
revision = '1b1d4016375d'
|
||||
down_revision = '52924111f7d8'
|
||||
|
||||
import uuid
|
||||
|
||||
from alembic import op
|
||||
from oslo_serialization import jsonutils
|
||||
from oslo_utils import uuidutils
|
||||
import sqlalchemy as sa
|
||||
from sqlalchemy.sql import text
|
||||
|
||||
|
@ -301,7 +301,7 @@ def dump_master_node_settings(connection):
|
|||
connection - a database connection
|
||||
"""
|
||||
|
||||
generated_uuid = str(uuid.uuid4())
|
||||
generated_uuid = uuidutils.generate_uuid()
|
||||
settings = jsonutils.dumps(_master_node_settings)
|
||||
|
||||
update = text(
|
||||
|
|
|
@ -13,7 +13,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.
|
||||
import uuid
|
||||
|
||||
from sqlalchemy import Boolean
|
||||
from sqlalchemy import Column
|
||||
|
@ -36,6 +35,8 @@ from nailgun.db.sqlalchemy.models.mutable import MutableDict
|
|||
from nailgun.db.sqlalchemy.models.mutable import MutableList
|
||||
from nailgun.logger import logger
|
||||
|
||||
from oslo_utils import uuidutils
|
||||
|
||||
|
||||
class NodeGroup(Base):
|
||||
__tablename__ = 'nodegroups'
|
||||
|
@ -63,7 +64,7 @@ class Node(Base):
|
|||
)
|
||||
id = Column(Integer, primary_key=True)
|
||||
uuid = Column(String(36), nullable=False,
|
||||
default=lambda: str(uuid.uuid4()), unique=True)
|
||||
default=lambda: uuidutils.generate_uuid(), unique=True)
|
||||
cluster_id = Column(Integer, ForeignKey('clusters.id', ondelete='CASCADE'))
|
||||
group_id = Column(
|
||||
Integer,
|
||||
|
|
|
@ -14,8 +14,6 @@
|
|||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
import uuid
|
||||
|
||||
from sqlalchemy import Boolean
|
||||
from sqlalchemy import Column
|
||||
from sqlalchemy import DateTime
|
||||
|
@ -36,6 +34,8 @@ from nailgun.db.sqlalchemy.models.fields import JSON
|
|||
from nailgun.db.sqlalchemy.models.mutable import MutableDict
|
||||
from nailgun.db.sqlalchemy.models.mutable import MutableList
|
||||
|
||||
from oslo_utils import uuidutils
|
||||
|
||||
|
||||
class Task(Base):
|
||||
__tablename__ = 'tasks'
|
||||
|
@ -46,7 +46,7 @@ class Task(Base):
|
|||
id = Column(Integer, primary_key=True)
|
||||
cluster_id = Column(Integer, ForeignKey('clusters.id', ondelete='CASCADE'))
|
||||
uuid = Column(String(36), nullable=False,
|
||||
default=lambda: str(uuid.uuid4()))
|
||||
default=lambda: uuidutils.generate_uuid())
|
||||
name = Column(
|
||||
Enum(*consts.TASK_NAMES, name='task_name'),
|
||||
nullable=False,
|
||||
|
|
|
@ -26,7 +26,6 @@ import os
|
|||
import re
|
||||
import six
|
||||
from six.moves import range
|
||||
import uuid
|
||||
|
||||
from datetime import datetime
|
||||
import functools
|
||||
|
@ -35,6 +34,7 @@ from netaddr import IPNetwork
|
|||
from random import randint
|
||||
|
||||
from oslo_serialization import jsonutils
|
||||
from oslo_utils import uuidutils
|
||||
|
||||
import sqlalchemy as sa
|
||||
import web
|
||||
|
@ -1895,7 +1895,7 @@ class BaseMasterNodeSettignsTest(BaseIntegrationTest):
|
|||
|
||||
def create_master_node_settings(self):
|
||||
self.master_node_settings = {
|
||||
'master_node_uid': str(uuid.uuid4()),
|
||||
'master_node_uid': uuidutils.generate_uuid(),
|
||||
}
|
||||
self.master_node_settings.update(self.master_node_settings_template)
|
||||
MasterNodeSettings.create(self.master_node_settings)
|
||||
|
|
|
@ -14,8 +14,6 @@
|
|||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
import uuid
|
||||
|
||||
from oslo_serialization import jsonutils
|
||||
|
||||
from nailgun import consts
|
||||
|
@ -27,6 +25,8 @@ from nailgun.rpc import receiver as rcvr
|
|||
from nailgun.test.base import BaseIntegrationTest
|
||||
from nailgun.utils import reverse
|
||||
|
||||
from oslo_utils import uuidutils
|
||||
|
||||
|
||||
class TestNotification(BaseIntegrationTest):
|
||||
|
||||
|
@ -35,7 +35,7 @@ class TestNotification(BaseIntegrationTest):
|
|||
receiver = rcvr.NailgunReceiver()
|
||||
|
||||
task = Task(
|
||||
uuid=str(uuid.uuid4()),
|
||||
uuid=uuidutils.generate_uuid(),
|
||||
name="super",
|
||||
cluster_id=cluster.id
|
||||
)
|
||||
|
@ -68,7 +68,7 @@ class TestNotification(BaseIntegrationTest):
|
|||
receiver = rcvr.NailgunReceiver()
|
||||
|
||||
task = Task(
|
||||
uuid=str(uuid.uuid4()),
|
||||
uuid=uuidutils.generate_uuid(),
|
||||
name="super",
|
||||
cluster_id=cluster.id
|
||||
)
|
||||
|
@ -98,7 +98,7 @@ class TestNotification(BaseIntegrationTest):
|
|||
receiver = rcvr.NailgunReceiver()
|
||||
|
||||
task = Task(
|
||||
uuid=str(uuid.uuid4()),
|
||||
uuid=uuidutils.generate_uuid(),
|
||||
name="super",
|
||||
cluster_id=cluster.id
|
||||
)
|
||||
|
@ -140,7 +140,7 @@ class TestNotification(BaseIntegrationTest):
|
|||
receiver = rcvr.NailgunReceiver()
|
||||
|
||||
task = Task(
|
||||
uuid=str(uuid.uuid4()),
|
||||
uuid=uuidutils.generate_uuid(),
|
||||
name="cluster_deletion",
|
||||
cluster_id=cluster.id
|
||||
)
|
||||
|
@ -168,7 +168,7 @@ class TestNotification(BaseIntegrationTest):
|
|||
receiver = rcvr.NailgunReceiver()
|
||||
|
||||
task = Task(
|
||||
uuid=str(uuid.uuid4()),
|
||||
uuid=uuidutils.generate_uuid(),
|
||||
name="cluster_deletion",
|
||||
cluster_id=cluster.id
|
||||
)
|
||||
|
|
|
@ -17,7 +17,6 @@
|
|||
import datetime
|
||||
import mock
|
||||
import random
|
||||
import uuid
|
||||
|
||||
from nailgun.db.sqlalchemy.models import Attributes
|
||||
from nailgun.db.sqlalchemy.models import Cluster
|
||||
|
@ -35,6 +34,7 @@ from nailgun.utils import reverse
|
|||
from nailgun import consts
|
||||
|
||||
from nailgun import objects
|
||||
from oslo_utils import uuidutils
|
||||
|
||||
|
||||
class BaseReciverTestCase(BaseIntegrationTest):
|
||||
|
@ -894,7 +894,7 @@ class TestConsumer(BaseReciverTestCase):
|
|||
node, node2 = self.env.nodes
|
||||
|
||||
task = Task(
|
||||
uuid=str(uuid.uuid4()),
|
||||
uuid=uuidutils.generate_uuid(),
|
||||
name="deploy",
|
||||
cluster_id=cluster.id
|
||||
)
|
||||
|
@ -927,7 +927,7 @@ class TestConsumer(BaseReciverTestCase):
|
|||
cluster.status = consts.CLUSTER_STATUSES.operational
|
||||
|
||||
task = Task(
|
||||
uuid=str(uuid.uuid4()),
|
||||
uuid=uuidutils.generate_uuid(),
|
||||
name="dry_run_deployment",
|
||||
cluster_id=cluster.id
|
||||
)
|
||||
|
@ -1061,7 +1061,7 @@ class TestConsumer(BaseReciverTestCase):
|
|||
cluster = self.env.create_cluster()
|
||||
|
||||
task = Task(
|
||||
uuid=str(uuid.uuid4()),
|
||||
uuid=uuidutils.generate_uuid(),
|
||||
name="super",
|
||||
status="running",
|
||||
cluster_id=cluster.id
|
||||
|
@ -1076,7 +1076,7 @@ class TestConsumer(BaseReciverTestCase):
|
|||
|
||||
def test_node_deletion_subtask_progress(self):
|
||||
supertask = Task(
|
||||
uuid=str(uuid.uuid4()),
|
||||
uuid=uuidutils.generate_uuid(),
|
||||
name="super",
|
||||
status="running"
|
||||
)
|
||||
|
@ -1139,7 +1139,7 @@ class TestConsumer(BaseReciverTestCase):
|
|||
|
||||
def test_proper_progress_calculation(self):
|
||||
supertask = Task(
|
||||
uuid=str(uuid.uuid4()),
|
||||
uuid=uuidutils.generate_uuid(),
|
||||
name="super",
|
||||
status="running"
|
||||
)
|
||||
|
@ -1187,7 +1187,7 @@ class TestConsumer(BaseReciverTestCase):
|
|||
]
|
||||
)
|
||||
task = Task(
|
||||
uuid=str(uuid.uuid4()),
|
||||
uuid=uuidutils.generate_uuid(),
|
||||
name=name,
|
||||
status=consts.TASK_STATUSES.running,
|
||||
cluster_id=cluster.id
|
||||
|
@ -1199,7 +1199,7 @@ class TestConsumer(BaseReciverTestCase):
|
|||
def _prepare_sub_task(self, name):
|
||||
task = self._prepare_task(consts.TASK_NAMES.super)
|
||||
sub_task = Task(
|
||||
uuid=str(uuid.uuid4()),
|
||||
uuid=uuidutils.generate_uuid(),
|
||||
name=name,
|
||||
status=consts.TASK_STATUSES.running,
|
||||
cluster_id=self.env.clusters[0].id,
|
||||
|
@ -1337,7 +1337,7 @@ class TestConsumer(BaseReciverTestCase):
|
|||
node1, node2 = self.env.nodes
|
||||
|
||||
task = Task(
|
||||
uuid=str(uuid.uuid4()),
|
||||
uuid=uuidutils.generate_uuid(),
|
||||
name="super",
|
||||
cluster_id=cluster_db.id
|
||||
)
|
||||
|
@ -1375,7 +1375,7 @@ class TestConsumer(BaseReciverTestCase):
|
|||
node1, node2 = self.env.nodes
|
||||
|
||||
task = Task(
|
||||
uuid=str(uuid.uuid4()),
|
||||
uuid=uuidutils.generate_uuid(),
|
||||
name="super",
|
||||
cluster_id=cluster_db.id
|
||||
)
|
||||
|
@ -1416,7 +1416,7 @@ class TestConsumer(BaseReciverTestCase):
|
|||
group_id = objects.Cluster.get_default_group(cluster_db).id
|
||||
|
||||
task = Task(
|
||||
uuid=str(uuid.uuid4()),
|
||||
uuid=uuidutils.generate_uuid(),
|
||||
name="cluster_deletion",
|
||||
cluster_id=cluster_id
|
||||
)
|
||||
|
@ -1518,7 +1518,7 @@ class TestConsumer(BaseReciverTestCase):
|
|||
)
|
||||
|
||||
task = Task(
|
||||
uuid=str(uuid.uuid4()),
|
||||
uuid=uuidutils.generate_uuid(),
|
||||
name="cluster_deletion",
|
||||
cluster_id=cluster_db.id
|
||||
)
|
||||
|
@ -1567,7 +1567,7 @@ class TestConsumer(BaseReciverTestCase):
|
|||
node1, node2 = self.env.nodes
|
||||
|
||||
task = Task(
|
||||
uuid=str(uuid.uuid4()),
|
||||
uuid=uuidutils.generate_uuid(),
|
||||
name=consts.TASK_NAMES.provision,
|
||||
cluster_id=cluster.id)
|
||||
self.db.add(task)
|
||||
|
@ -1606,7 +1606,7 @@ class TestConsumer(BaseReciverTestCase):
|
|||
nodes = self.env.nodes
|
||||
|
||||
task = Task(
|
||||
uuid=str(uuid.uuid4()),
|
||||
uuid=uuidutils.generate_uuid(),
|
||||
name=consts.TASK_NAMES.deployment,
|
||||
cluster_id=cluster.id
|
||||
)
|
||||
|
@ -1640,7 +1640,7 @@ class TestConsumer(BaseReciverTestCase):
|
|||
nodes = self.env.nodes
|
||||
task_title = task_name.title()
|
||||
task = Task(
|
||||
uuid=str(uuid.uuid4()),
|
||||
uuid=uuidutils.generate_uuid(),
|
||||
name=task_name,
|
||||
cluster_id=cluster.id
|
||||
)
|
||||
|
@ -1710,7 +1710,7 @@ class TestResetEnvironment(BaseReciverTestCase):
|
|||
node = self.env.nodes[0]
|
||||
|
||||
task = Task(
|
||||
uuid=str(uuid.uuid4()),
|
||||
uuid=uuidutils.generate_uuid(),
|
||||
name=consts.TASK_NAMES.reset_environment,
|
||||
cluster_id=cluster.id)
|
||||
self.db.add(task)
|
||||
|
@ -1737,7 +1737,7 @@ class TestResetEnvironment(BaseReciverTestCase):
|
|||
node = self.env.nodes[0]
|
||||
|
||||
reset_environment = Task(
|
||||
uuid=str(uuid.uuid4()),
|
||||
uuid=uuidutils.generate_uuid(),
|
||||
name=consts.TASK_NAMES.reset_environment,
|
||||
cluster_id=cluster.id)
|
||||
self.db.add(reset_environment)
|
||||
|
|
|
@ -12,11 +12,10 @@
|
|||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
import uuid
|
||||
|
||||
import alembic
|
||||
from datetime import datetime
|
||||
from oslo_serialization import jsonutils
|
||||
from oslo_utils import uuidutils
|
||||
import six
|
||||
import sqlalchemy as sa
|
||||
from sqlalchemy.exc import DataError
|
||||
|
@ -244,7 +243,7 @@ class TestNodeGroupsMigration(base.BaseAlembicMigrationTest):
|
|||
self.meta.tables['nodegroups'].c.name])).fetchone()
|
||||
db.execute(self.meta.tables['nodegroups'].insert(),
|
||||
[{'cluster_id': nodegroup['cluster_id'],
|
||||
'name': six.text_type(uuid.uuid4())}])
|
||||
'name': six.text_type(uuidutils.generate_uuid())}])
|
||||
|
||||
def test_node_group_has_default_field(self):
|
||||
nodegroup = db.execute(
|
||||
|
@ -314,14 +313,14 @@ class TestTaskNameMigration(base.BaseAlembicMigrationTest):
|
|||
for name in added_task_names:
|
||||
insert_table_row(tasks_table,
|
||||
{'name': name,
|
||||
'uuid': str(uuid.uuid4()),
|
||||
'uuid': uuidutils.genrate_uuid(),
|
||||
'status': 'running'})
|
||||
|
||||
with self.assertRaisesRegexp(DataError, 'invalid input value for '
|
||||
'enum task_name'):
|
||||
insert_table_row(tasks_table,
|
||||
{'name': 'wrong_task_name',
|
||||
'uuid': str(uuid.uuid4()),
|
||||
'uuid': uuidutils.genrate_uuid(),
|
||||
'status': 'running'})
|
||||
|
||||
|
||||
|
@ -335,7 +334,7 @@ class TestNodeErrorTypeMigration(base.BaseAlembicMigrationTest):
|
|||
{'name': 'node1',
|
||||
'status': 'error',
|
||||
'error_type': error_type,
|
||||
'uuid': str(uuid.uuid4()),
|
||||
'uuid': uuidutils.genrate_uuid(),
|
||||
'mac': '00:00:00:00:00:00',
|
||||
'timestamp': datetime.now()})
|
||||
inserted_count = db.execute(
|
||||
|
@ -350,7 +349,7 @@ class TestNodeErrorTypeMigration(base.BaseAlembicMigrationTest):
|
|||
{'name': 'node1',
|
||||
'status': 'error',
|
||||
'error_type': 'wrong_error_type',
|
||||
'uuid': str(uuid.uuid4()),
|
||||
'uuid': uuidutils.genrate_uuid(),
|
||||
'mac': '00:00:00:00:00:00',
|
||||
'timestamp': datetime.now()})
|
||||
|
||||
|
|
|
@ -24,13 +24,13 @@ from itertools import ifilter
|
|||
|
||||
from nailgun.db import db
|
||||
from nailgun.db.sqlalchemy import models
|
||||
import uuid
|
||||
|
||||
from sqlalchemy import inspect as sqlalchemy_inspect
|
||||
from sqlalchemy.orm import Query
|
||||
|
||||
import jsonschema
|
||||
from oslo_serialization import jsonutils
|
||||
from oslo_utils import uuidutils
|
||||
import six
|
||||
from six.moves import range
|
||||
|
||||
|
@ -1051,7 +1051,7 @@ class TestActionLogObject(BaseIntegrationTest):
|
|||
'additional_info': {},
|
||||
'is_sent': False,
|
||||
'cluster_id': 1,
|
||||
'task_uuid': str(uuid.uuid4())
|
||||
'task_uuid': uuidutils.generate_uuid()
|
||||
}
|
||||
|
||||
al = self._create_log_entry(object_data)
|
||||
|
@ -1075,7 +1075,7 @@ class TestActionLogObject(BaseIntegrationTest):
|
|||
'additional_info': {'already_present_data': None},
|
||||
'is_sent': False,
|
||||
'cluster_id': 1,
|
||||
'task_uuid': str(uuid.uuid4())
|
||||
'task_uuid': uuidutils.generate_uuid()
|
||||
}
|
||||
|
||||
al = self._create_log_entry(object_data)
|
||||
|
@ -1755,7 +1755,7 @@ class TestClusterObjectGetRoles(BaseTestCase):
|
|||
|
||||
def create_plugin(self, roles_metadata):
|
||||
plugin = objects.Plugin.create(self.env.get_default_plugin_metadata(
|
||||
name=uuid.uuid4().get_hex(),
|
||||
name=uuidutils.generate_uuid(dashed=False),
|
||||
roles_metadata=roles_metadata,
|
||||
))
|
||||
self.cluster.plugins.append(plugin)
|
||||
|
|
Loading…
Reference in New Issue