Don't create task db record during validation
Do not create database task record during 'rally task validate' command. Change-Id: I1792b444aedcf2719b12708c221e317af6ac7e8c
This commit is contained in:
parent
fb4058f7cf
commit
58154be332
@ -162,7 +162,7 @@ class Task(object):
|
||||
:param config: a dict with a task configuration
|
||||
"""
|
||||
deployment = objects.Deployment.get(deployment)
|
||||
task = objects.Task(deployment_uuid=deployment["uuid"])
|
||||
task = objects.Task(deployment_uuid=deployment["uuid"], fake=True)
|
||||
benchmark_engine = engine.BenchmarkEngine(
|
||||
config, task, admin=deployment["admin"], users=deployment["users"])
|
||||
benchmark_engine.validate()
|
||||
|
@ -14,6 +14,7 @@
|
||||
# under the License.
|
||||
|
||||
import json
|
||||
import uuid
|
||||
|
||||
from rally import consts
|
||||
from rally import db
|
||||
@ -106,11 +107,21 @@ TASK_RESULT_SCHEMA = {
|
||||
class Task(object):
|
||||
"""Represents a task object."""
|
||||
|
||||
def __init__(self, task=None, **attributes):
|
||||
if task:
|
||||
self.task = task
|
||||
def __init__(self, task=None, fake=False, **attributes):
|
||||
"""Task object init
|
||||
|
||||
:param task: dictionary like object, that represents a task
|
||||
:param fake: if True, will be created task object with random UUID and
|
||||
parameters, passed in 'attributes'. Does not create database
|
||||
record. Used for special purposes, like task config validation.
|
||||
"""
|
||||
|
||||
self.fake = fake
|
||||
if fake:
|
||||
self.task = task or {"uuid": str(uuid.uuid4())}
|
||||
self.task.update(attributes)
|
||||
else:
|
||||
self.task = db.task_create(attributes)
|
||||
self.task = task or db.task_create(attributes)
|
||||
|
||||
def __getitem__(self, key):
|
||||
return self.task[key]
|
||||
@ -134,7 +145,8 @@ class Task(object):
|
||||
db.task_delete(uuid, status=status)
|
||||
|
||||
def _update(self, values):
|
||||
self.task = db.task_update(self.task["uuid"], values)
|
||||
if not self.fake:
|
||||
self.task = db.task_update(self.task["uuid"], values)
|
||||
|
||||
def update_status(self, status):
|
||||
self._update({"status": status})
|
||||
|
@ -47,6 +47,14 @@ class TaskTestCase(test.TestCase):
|
||||
self.assertFalse(mock_create.called)
|
||||
self.assertEqual(task["uuid"], self.task["uuid"])
|
||||
|
||||
@mock.patch("rally.objects.task.uuid.uuid4", return_value="some_uuid")
|
||||
@mock.patch("rally.objects.task.db.task_create")
|
||||
def test_init_with_fake_true(self, mock_create, mock_uuid):
|
||||
task = objects.Task(fake=True)
|
||||
self.assertFalse(mock_create.called)
|
||||
self.assertTrue(mock_uuid.called)
|
||||
self.assertEqual(task["uuid"], mock_uuid.return_value)
|
||||
|
||||
@mock.patch("rally.objects.task.db.task_get")
|
||||
def test_get(self, mock_get):
|
||||
mock_get.return_value = self.task
|
||||
|
@ -69,6 +69,7 @@ class TaskAPITestCase(test.TestCase):
|
||||
])
|
||||
|
||||
mock_task.assert_called_once_with(
|
||||
fake=True,
|
||||
deployment_uuid=mock_deployment_get.return_value["uuid"])
|
||||
mock_deployment_get.assert_called_once_with(
|
||||
mock_deployment_get.return_value["uuid"])
|
||||
|
Loading…
x
Reference in New Issue
Block a user