Add task file validate command
* Remove the redundant users context setup from benchmark.engine * Add task_validate to orchestrator api * Add verify command to validate the task file: rally task validate --deploy-id <deployment> --task <TASK FILE PATH> Change-Id: I6cccf55cb390ae8bb95716db779a0c6daf965f99
This commit is contained in:
parent
5920f947b6
commit
30c0624821
@ -40,6 +40,27 @@ from rally import utils as rutils
|
||||
|
||||
class TaskCommands(object):
|
||||
|
||||
@cliutils.args('--deploy-id', type=str, dest='deploy_id', required=False,
|
||||
help='UUID of the deployment')
|
||||
@cliutils.args('--task', '--filename',
|
||||
help='Path to the file with full configuration of task')
|
||||
@envutils.with_default_deploy_id
|
||||
def validate(self, task, deploy_id=None):
|
||||
"""Validate a task file.
|
||||
|
||||
:param task: a file with yaml/json configration
|
||||
:param deploy_id: a UUID of a deployment
|
||||
"""
|
||||
|
||||
with open(task, "rb") as task_file:
|
||||
config_dict = yaml.safe_load(task_file.read())
|
||||
try:
|
||||
api.task_validate(deploy_id, config_dict)
|
||||
print("Task config is valid :)")
|
||||
except exceptions.InvalidTaskException as e:
|
||||
print("Task config is invalid: \n")
|
||||
print(e)
|
||||
|
||||
@cliutils.args('--deploy-id', type=str, dest='deploy_id', required=False,
|
||||
help='UUID of the deployment')
|
||||
@cliutils.args('--task', '--filename',
|
||||
|
@ -84,6 +84,20 @@ def create_task(deploy_uuid, tag):
|
||||
return objects.Task(deployment_uuid=deploy_uuid, tag=tag)
|
||||
|
||||
|
||||
def task_validate(deploy_uuid, config):
|
||||
"""Validate a task config against specified deployment.
|
||||
|
||||
:param deploy_uuid: UUID of the deployment
|
||||
:param config: a dict with a task configuration
|
||||
"""
|
||||
deployment = objects.Deployment.get(deploy_uuid)
|
||||
task = objects.Task(deployment_uuid=deploy_uuid)
|
||||
benchmark_engine = engine.BenchmarkEngine(config, task)
|
||||
benchmark_engine.bind(admin=deployment["admin"],
|
||||
users=deployment["users"])
|
||||
benchmark_engine.validate()
|
||||
|
||||
|
||||
def start_task(deploy_uuid, config, task=None):
|
||||
"""Start a task.
|
||||
|
||||
|
@ -245,3 +245,11 @@ class TaskCommandsTestCase(test.TestCase):
|
||||
retval = self.task.sla_check(task_id='fake_task_id')
|
||||
self.assertEqual(1, retval)
|
||||
mock_sla.SLA.check_all.assert_called_once_with('fake_task')
|
||||
|
||||
@mock.patch('rally.cmd.commands.task.open',
|
||||
mock.mock_open(read_data='{"some": "json"}'),
|
||||
create=True)
|
||||
@mock.patch('rally.orchestrator.api.task_validate')
|
||||
def test_verify(self, mock_validate):
|
||||
self.task.validate('path_to_config.json', 'fake_id')
|
||||
mock_validate.assert_called_once_with('fake_id', {"some": "json"})
|
||||
|
@ -67,6 +67,25 @@ class APITestCase(test.TestCase):
|
||||
}
|
||||
self.tempest = mock.Mock()
|
||||
|
||||
@mock.patch("rally.orchestrator.api.objects.Task")
|
||||
@mock.patch("rally.orchestrator.api.objects.Deployment.get",
|
||||
return_value={"uuid": "deploy_uuid",
|
||||
"admin": mock.MagicMock(),
|
||||
"users": []})
|
||||
@mock.patch("rally.orchestrator.api.engine.BenchmarkEngine")
|
||||
def test_task_validate(self, mock_engine, mock_deployment_get, mock_task):
|
||||
api.task_validate(self.deploy_uuid, "config")
|
||||
|
||||
mock_engine.assert_has_calls([
|
||||
mock.call("config", mock_task.return_value),
|
||||
mock.call().bind(admin=mock_deployment_get.return_value["admin"],
|
||||
users=[]),
|
||||
mock.call().validate(),
|
||||
])
|
||||
|
||||
mock_task.assert_called_once_with(deployment_uuid=self.deploy_uuid)
|
||||
mock_deployment_get.assert_called_once_with(self.deploy_uuid)
|
||||
|
||||
@mock.patch("rally.objects.Task")
|
||||
def test_create_task(self, mock_task):
|
||||
deployment_uuid = "b0d9cd6c-2c94-4417-a238-35c7019d0257"
|
||||
|
Loading…
x
Reference in New Issue
Block a user