Remove use of random uuid from unit tests

Closes-Bug: #1340015
Change-Id: I07eb638fc2e11c136cbd124538a5dd7ea6120978
This commit is contained in:
Rohan Kanade
2014-07-21 14:16:52 +02:00
parent b22495e03c
commit 61306daa8e
14 changed files with 58 additions and 67 deletions

View File

@@ -14,7 +14,6 @@
# under the License.
import itertools
import uuid
import mock
@@ -53,7 +52,8 @@ class UserGeneratorTestCase(test.TestCase):
@mock.patch("rally.benchmark.context.users.osclients")
def test_create_tenant_users(self, mock_osclients):
users_num = 5
args = (mock.MagicMock(), users_num, str(uuid.uuid4()), 1)
args = (mock.MagicMock(), users_num,
'ad325aec-f7b4-4a62-832a-bb718e465bb7', 1)
result = users.UserGenerator._create_tenant_users(args)

View File

@@ -14,7 +14,6 @@
# under the License.
import os
import uuid
import mock
@@ -78,7 +77,7 @@ class DeploymentCommandsTestCase(test.TestCase):
@mock.patch('rally.cmd.commands.deployment.api.recreate_deploy')
def test_recreate(self, mock_recreate):
deploy_id = str(uuid.uuid4())
deploy_id = '43924f8b-9371-4152-af9f-4cf02b4eced4'
self.deployment.recreate(deploy_id)
mock_recreate.assert_called_once_with(deploy_id)
@@ -90,7 +89,7 @@ class DeploymentCommandsTestCase(test.TestCase):
@mock.patch('rally.cmd.commands.deployment.api.destroy_deploy')
def test_destroy(self, mock_destroy):
deploy_id = str(uuid.uuid4())
deploy_id = '53fd0273-60ce-42e5-a759-36f1a683103e'
self.deployment.destroy(deploy_id)
mock_destroy.assert_called_once_with(deploy_id)
@@ -107,13 +106,14 @@ class DeploymentCommandsTestCase(test.TestCase):
def test_list_different_deploy_id(self, mock_deployments,
mock_default, mock_struct,
mock_print_list):
current_deploy_id = str(uuid.uuid4())
current_deploy_id = '26a3ce76-0efa-40e4-86e5-514574bd1ff6'
mock_default.return_value = current_deploy_id
fake_deployment_list = [{'uuid': str(uuid.uuid4()),
'created_at': '03-12-2014',
'name': 'dep1',
'status': 'deploy->started',
'active': 'False'}]
fake_deployment_list = [
{'uuid': 'fa34aea2-ae2e-4cf7-a072-b08d67466e3e',
'created_at': '03-12-2014',
'name': 'dep1',
'status': 'deploy->started',
'active': 'False'}]
mock_deployments.return_value = fake_deployment_list
self.deployment.list()
@@ -134,7 +134,7 @@ class DeploymentCommandsTestCase(test.TestCase):
def test_list_current_deploy_id(self, mock_deployments,
mock_default, mock_struct,
mock_print_list):
current_deploy_id = str(uuid.uuid4())
current_deploy_id = '64258e84-ffa1-4011-9e4c-aba07bdbcc6b'
mock_default.return_value = current_deploy_id
fake_deployment_list = [{'uuid': current_deploy_id,
'created_at': '13-12-2014',
@@ -155,7 +155,7 @@ class DeploymentCommandsTestCase(test.TestCase):
@mock.patch('rally.cmd.commands.deployment.db.deployment_get')
def test_config(self, mock_deployment):
deploy_id = str(uuid.uuid4())
deploy_id = 'fa4a423e-f15d-4d83-971a-89574f892999'
value = {'config': 'config'}
mock_deployment.return_value = value
self.deployment.config(deploy_id)
@@ -171,7 +171,7 @@ class DeploymentCommandsTestCase(test.TestCase):
@mock.patch('rally.cmd.commands.deployment.utils.Struct')
@mock.patch('rally.cmd.commands.deployment.db.deployment_get')
def test_endpoint(self, mock_deployment, mock_struct, mock_print_list):
deploy_id = str(uuid.uuid4())
deploy_id = 'b1a6153e-a314-4cb3-b63b-cf08c1a416c3'
value = {'endpoints': [{}]}
mock_deployment.return_value = value
self.deployment.endpoint(deploy_id)

View File

@@ -13,8 +13,6 @@
# License for the specific language governing permissions and limitations
# under the License.
import uuid
import mock
from rally.cmd.commands import show
@@ -31,7 +29,7 @@ class ShowCommandsTestCase(test.TestCase):
'password': 'fake_password',
'tenant_name': 'fake_tenant_name',
'auth_url': 'http://fake.auth.url'}
self.fake_deploy_id = str(uuid.uuid4)
self.fake_deploy_id = '7f6e88e0-897e-45c0-947c-595ce2437bee'
self.fake_clients = fakes.FakeClients()
self.fake_glance_client = fakes.FakeGlanceClient()
self.fake_nova_client = fakes.FakeNovaClient()

View File

@@ -13,8 +13,6 @@
# License for the specific language governing permissions and limitations
# under the License.
import uuid
import mock
from rally.cmd.commands import task
@@ -40,7 +38,7 @@ class TaskCommandsTestCase(test.TestCase):
dict(uuid='fc1a9bbe-1ead-4740-92b5-0feecf421634',
created_at='2014-01-14 09:14:45.395822',
status='init', failed=False, tag=None))
deploy_id = str(uuid.uuid4())
deploy_id = 'e0617de9-77d1-4875-9b49-9d5789e29f20'
self.task.start('path_to_config.json', deploy_id)
mock_api.assert_called_once_with(deploy_id, {u'some': u'json'},
task=mock_create_task.return_value)
@@ -64,7 +62,7 @@ class TaskCommandsTestCase(test.TestCase):
created_at='2014-01-14 09:14:45.395822',
status='init', failed=False, tag=None))
mock_api.start_task.side_effect = KeyboardInterrupt
deploy_id = str(uuid.uuid4())
deploy_id = 'f586dcd7-8473-4c2e-a4d4-22be26371c10'
self.assertRaises(KeyboardInterrupt, self.task.start,
'path_to_config.json', deploy_id)
mock_api.abort_task.assert_called_once_with(
@@ -72,7 +70,7 @@ class TaskCommandsTestCase(test.TestCase):
@mock.patch("rally.cmd.commands.task.api")
def test_abort(self, mock_api):
test_uuid = str(uuid.uuid4())
test_uuid = '17860c43-2274-498d-8669-448eff7b073f'
mock_api.abort_task = mock.MagicMock()
self.task.abort(test_uuid)
task.api.abort_task.assert_called_once_with(test_uuid)
@@ -84,7 +82,7 @@ class TaskCommandsTestCase(test.TestCase):
self.task.abort, None)
def test_status(self):
test_uuid = str(uuid.uuid4())
test_uuid = 'a3e7cefb-bec2-4802-89f6-410cc31f71af'
value = {'task_id': "task", "status": "status"}
with mock.patch("rally.cmd.commands.task.db") as mock_db:
mock_db.task_get = mock.MagicMock(return_value=value)
@@ -99,7 +97,7 @@ class TaskCommandsTestCase(test.TestCase):
@mock.patch('rally.cmd.commands.task.db')
def test_detailed(self, mock_db):
test_uuid = str(uuid.uuid4())
test_uuid = 'c0d874d4-7195-4fd5-8688-abe82bfad36f'
value = {
"id": "task",
"uuid": test_uuid,
@@ -119,14 +117,14 @@ class TaskCommandsTestCase(test.TestCase):
@mock.patch('rally.cmd.commands.task.db')
def test_detailed_wrong_id(self, mock_db):
test_uuid = str(uuid.uuid4())
test_uuid = 'eb290c30-38d8-4c8f-bbcc-fc8f74b004ae'
mock_db.task_get_detailed = mock.MagicMock(return_value=None)
self.task.detailed(test_uuid)
mock_db.task_get_detailed.assert_called_once_with(test_uuid)
@mock.patch('rally.cmd.commands.task.db')
def test_results(self, mock_db):
test_uuid = str(uuid.uuid4())
test_uuid = 'aa808c14-69cc-4faf-a906-97e05f5aebbd'
value = [
{'key': 'key', 'data': {'raw': 'raw'}}
]
@@ -136,7 +134,7 @@ class TaskCommandsTestCase(test.TestCase):
@mock.patch('rally.cmd.commands.task.db')
def test_invalid_results(self, mock_db):
test_uuid = str(uuid.uuid4())
test_uuid = 'd1f58069-d221-4577-b6ba-5c635027765a'
mock_db.task_result_get_all_by_uuid.return_value = []
return_value = self.task.results(test_uuid)
mock_db.task_result_get_all_by_uuid.assert_called_once_with(test_uuid)
@@ -167,7 +165,7 @@ class TaskCommandsTestCase(test.TestCase):
'created_at'))
def test_delete(self):
task_uuid = str(uuid.uuid4())
task_uuid = '8dcb9c5e-d60b-4022-8975-b5987c7833f7'
force = False
with mock.patch("rally.cmd.commands.task.api") as mock_api:
mock_api.delete_task = mock.Mock()
@@ -177,7 +175,11 @@ class TaskCommandsTestCase(test.TestCase):
@mock.patch("rally.cmd.commands.task.api")
def test_delete_multiple_uuid(self, mock_api):
task_uuids = [str(uuid.uuid4()) for _ in range(5)]
task_uuids = ['4bf35b06-5916-484f-9547-12dce94902b7',
'52cad69d-d3e4-47e1-b445-dec9c5858fe8',
'6a3cb11c-ac75-41e7-8ae7-935732bfb48f',
'018af931-0e5a-40d5-9d6f-b13f4a3a09fc',
'1a4d88c9-fb68-4ff6-a246-f9122aec79b0']
force = False
self.task.delete(task_uuids, force=force)
self.assertTrue(mock_api.delete_task.call_count == len(task_uuids))

View File

@@ -14,7 +14,6 @@
# under the License.
import os
import uuid
import mock
@@ -58,7 +57,7 @@ class UseCommandsTestCase(test.TestCase):
@mock.patch(MOD + 'fileutils.update_env_file')
def test_deployment(self, mock_env, mock_path, mock_deployment,
mock_symlink, mock_remove):
deploy_id = str(uuid.uuid4())
deploy_id = '593b683c-4b16-4b2b-a56b-e162bd60f10b'
endpoints = {'endpoints': [{'auth_url': 'fake_auth_url',
'username': 'fake_username',
'password': 'fake_password',
@@ -84,7 +83,7 @@ class UseCommandsTestCase(test.TestCase):
@mock.patch(MOD + 'db.deployment_get')
def test_deployment_not_found(self, mock_deployment):
deploy_id = str(uuid.uuid4())
deploy_id = 'e87e4dca-b515-4477-888d-5f6103f13b42'
mock_deployment.side_effect = exceptions.DeploymentNotFound(
uuid=deploy_id)
self.assertEqual(1, self.use.deployment(deploy_id))
@@ -92,7 +91,7 @@ class UseCommandsTestCase(test.TestCase):
@mock.patch(MOD + 'fileutils._rewrite_env_file')
@mock.patch(MOD + 'db.task_get', return_value=True)
def test_task(self, mock_task, mock_file):
task_id = str(uuid.uuid4())
task_id = '80422553-5774-44bd-98ac-38bd8c7a0feb'
self.use.task(task_id)
mock_file.assert_called_once_with(
os.path.expanduser('~/.rally/globals'),
@@ -100,6 +99,6 @@ class UseCommandsTestCase(test.TestCase):
@mock.patch(MOD + 'db.task_get')
def test_task_not_found(self, mock_task):
task_id = str(uuid.uuid4())
task_id = 'ddc3f8ba-082a-496d-b18f-72cdf5c10a14'
mock_task.side_effect = exceptions.TaskNotFound(uuid=task_id)
self.assertRaises(exceptions.TaskNotFound, self.use.task, task_id)

View File

@@ -13,8 +13,6 @@
# License for the specific language governing permissions and limitations
# under the License.
import uuid
import mock
import six
@@ -50,7 +48,7 @@ class VerifyCommandsTestCase(test.TestCase):
@mock.patch('rally.osclients.Clients')
@mock.patch('rally.orchestrator.api.verify')
def test_start(self, mock_verify, mock_clients):
deploy_id = str(uuid.uuid4())
deploy_id = '0fba91c6-82d5-4ce1-bd00-5d7c989552d9'
mock_clients().glance().images.list.return_value = [
self.image1, self.image2]
mock_clients().nova().flavors.list.return_value = [
@@ -65,7 +63,7 @@ class VerifyCommandsTestCase(test.TestCase):
@mock.patch('rally.orchestrator.api.verify')
def test_start_with_wrong_set_name(self, mock_verify):
deploy_id = str(uuid.uuid4())
deploy_id = 'f2009aae-6ef3-468e-96b2-3c987d584010'
wrong_set_name = 'unexpected_value'

View File

@@ -14,7 +14,6 @@
# under the License.
import sys
import uuid
import mock
@@ -54,7 +53,7 @@ class TempestCommandsTestCase(test.TestCase):
@mock.patch('rally.verification.verifiers.tempest.tempest.Tempest')
def test_install(self, mock_tempest):
deploy_id = str(uuid.uuid4())
deploy_id = 'e24b5af0-0e2a-4a70-9443-b30a88ab152e'
mock_tempest.return_value = self.tempest
self.tempest_commands.install(deploy_id)
self.tempest.install.assert_called_once_with()

View File

@@ -15,8 +15,6 @@
"""Tests for db.api layer."""
import uuid
from rally import consts
from rally import db
from rally import exceptions
@@ -39,7 +37,7 @@ class TasksTestCase(test.DBTestCase):
def test_task_get_not_found(self):
self.assertRaises(exceptions.TaskNotFound,
db.task_get, str(uuid.uuid4()))
db.task_get, 'f885f435-f6ca-4f3e-9b3e-aeb6837080f2')
def test_task_create(self):
task = self._create_task()
@@ -50,7 +48,7 @@ class TasksTestCase(test.DBTestCase):
self.assertFalse(db_task['failed'])
def test_task_create_without_uuid(self):
_uuid = str(uuid.uuid4())
_uuid = '19be8589-48b0-4af1-a369-9bebaaa563ab'
task = self._create_task({'uuid': _uuid})
db_task = self._get_task(task['uuid'])
self.assertEqual(db_task['uuid'], _uuid)
@@ -63,7 +61,8 @@ class TasksTestCase(test.DBTestCase):
def test_task_update_not_found(self):
self.assertRaises(exceptions.TaskNotFound,
db.task_update, str(uuid.uuid4()), {})
db.task_update,
'7ae1da26-feaa-4213-8208-76af2857a5ab', {})
def test_task_update_all_stats(self):
_uuid = self._create_task({})['uuid']
@@ -106,7 +105,8 @@ class TasksTestCase(test.DBTestCase):
def test_task_delete_not_found(self):
self.assertRaises(exceptions.TaskNotFound,
db.task_delete, str(uuid.uuid4()))
db.task_delete,
'da6f820c-b133-4b9f-8534-4c3bcc40724b')
def test_task_delete_with_results(self):
task_id = self._create_task()['uuid']
@@ -138,7 +138,8 @@ class TasksTestCase(test.DBTestCase):
def test_task_delete_by_uuid_and_status_not_found(self):
self.assertRaises(exceptions.TaskNotFound,
db.task_delete, str(uuid.uuid4()),
db.task_delete,
'fcd0483f-a405-44c4-b712-99c9e52254eb',
status=consts.TaskStatus.FINISHED)
def test_task_result_get_all_by_uuid(self):
@@ -260,7 +261,8 @@ class DeploymentTestCase(test.DBTestCase):
def test_deployment_get_not_found(self):
self.assertRaises(exceptions.DeploymentNotFound,
db.deployment_get, str(uuid.uuid4()))
db.deployment_get,
'852e932b-9552-4b2d-89e3-a5915780a5e3')
def test_deployment_list(self):
deploy_one = db.deployment_create({})
@@ -308,7 +310,8 @@ class DeploymentTestCase(test.DBTestCase):
def test_deployment_delete_not_found(self):
self.assertRaises(exceptions.DeploymentNotFound,
db.deployment_delete, str(uuid.uuid4()))
db.deployment_delete,
'5f2883be-46c8-4c4b-a4fe-988ad0c6b20a')
def test_deployment_delete_is_busy(self):
deployment = db.deployment_create({})
@@ -343,7 +346,8 @@ class ResourceTestCase(test.DBTestCase):
def test_delete_not_found(self):
self.assertRaises(exceptions.ResourceNotFound,
db.resource_delete, str(uuid.uuid4()))
db.resource_delete,
'2d02ecb0-d973-4ffd-975d-2f08a906222b')
def test_get_all(self):
deployment0 = db.deployment_create({})

View File

@@ -13,8 +13,6 @@
# License for the specific language governing permissions and limitations
# under the License.
import uuid
import jsonschema
import mock
@@ -41,7 +39,7 @@ class DevstackEngineTestCase(test.TestCase):
def setUp(self):
super(DevstackEngineTestCase, self).setUp()
self.deployment = {
'uuid': str(uuid.uuid4()),
'uuid': 'de641026-dbe3-4abe-844a-ffef930a600a',
'config': SAMPLE_CONFIG,
}
self.engine = devstack.DevstackEngine(self.deployment)

View File

@@ -15,8 +15,6 @@
"""Test for deploy engines."""
import uuid
import mock
from rally import consts
@@ -27,7 +25,7 @@ from tests import test
def make_fake_deployment(**kwargs):
values = dict({
'uuid': uuid.uuid4(),
'uuid': '1359befb-8737-4f4e-bea9-492416106977',
'config': {
'name': 'fake',
},

View File

@@ -14,8 +14,6 @@
# under the License.
import uuid
import mock
from rally import consts
@@ -48,7 +46,7 @@ class TestMultihostEngine(test.TestCase):
]
}
self.deployment = fakes.FakeDeployment(
uuid=str(uuid.uuid4()),
uuid='905b2f16-6453-4b86-8ba5-6d32025fcfa6',
config=self.config,
)
self.engine = deploy.engine.EngineFactory.get_engine('MultihostEngine',

View File

@@ -15,7 +15,6 @@
"""Tests for db.deploy layer."""
import uuid
import mock
@@ -28,7 +27,7 @@ class DeploymentTestCase(test.TestCase):
def setUp(self):
super(DeploymentTestCase, self).setUp()
self.deployment = {
'uuid': str(uuid.uuid4()),
'uuid': 'baa1bfb6-0c38-4f6c-9bd0-45968890e4f4',
'name': '',
'config': {},
'endpoint': {},

View File

@@ -16,7 +16,6 @@
"""Tests for db.task layer."""
import json
import uuid
import mock
@@ -29,7 +28,7 @@ class TaskTestCase(test.TestCase):
def setUp(self):
super(TaskTestCase, self).setUp()
self.task = {
'uuid': str(uuid.uuid4()),
'uuid': '00ef46a2-c5b8-4aea-a5ca-0f54a10cbca1',
'status': consts.TaskStatus.INIT,
'failed': False,
'verification_log': '',

View File

@@ -16,7 +16,6 @@
""" Test for orchestrator. """
import collections
import uuid
import mock
@@ -77,12 +76,12 @@ class APITestCase(test.TestCase):
super(APITestCase, self).setUp()
self.deploy_config = FAKE_DEPLOY_CONFIG
self.task_config = FAKE_TASK_CONFIG
self.deploy_uuid = str(uuid.uuid4())
self.deploy_uuid = '599bdf1d-fe77-461a-a810-d59b1490f4e3'
self.endpoints = [FAKE_DEPLOY_CONFIG['endpoint']]
# TODO(msdubov): Remove this as soon as ExistingCloud requires
# permission on input
self.endpoints[0]["permission"] = consts.EndpointPermission.ADMIN
self.task_uuid = str(uuid.uuid4())
self.task_uuid = 'b0d9cd6c-2c94-4417-a238-35c7019d0257'
self.task = {
'uuid': self.task_uuid,
}
@@ -96,7 +95,7 @@ class APITestCase(test.TestCase):
@mock.patch('rally.objects.Task')
def test_create_task(self, mock_task):
deployment_uuid = uuid.uuid4()
deployment_uuid = 'b0d9cd6c-2c94-4417-a238-35c7019d0257'
tag = "a"
api.create_task(deployment_uuid, tag)
mock_task.assert_called_once_with(deployment_uuid=deployment_uuid,