def test_task(self): cfg = { "Dummy.dummy_random_fail_in_atomic": [ { "runner": { "type": "constant", "times": 100, "concurrency": 5 } } ] } with mock.patch.dict("os.environ", utils.TEST_ENV): deployment_id = envutils.get_global("RALLY_DEPLOYMENT") config = utils.TaskConfig(cfg) output = self.rally(("task start --task %(task_file)s " "--deployment %(deployment_id)s") % {"task_file": config.filename, "deployment_id": deployment_id}) result = re.search( r"(?P<uuid>[0-9a-f\-]{36}): started", output) uuid = result.group("uuid") self.rally("use task --uuid %s" % uuid) current_task = envutils.get_global("RALLY_TASK") self.assertEqual(uuid, current_task)
def test_use(self): rally = utils.Rally() with mock.patch.dict("os.environ", utils.TEST_ENV): deployment_id = envutils.get_global("RALLY_DEPLOYMENT") config = utils.TaskConfig(self._get_sample_task_config()) output = rally(("task start --task %(task_file)s " "--deployment %(deployment_id)s") % {"task_file": config.filename, "deployment_id": deployment_id}) result = re.search( r"(?P<uuid>[0-9a-f\-]{36}): started", output) uuid = result.group("uuid") rally("task use --task %s" % uuid) current_task = envutils.get_global("RALLY_TASK") self.assertEqual(uuid, current_task)
def test_deployment(self): with mock.patch.dict("os.environ", utils.TEST_ENV): output = self.rally( "deployment create --name t_create_env1 --fromenv") uuid = self._get_deployment_uuid(output) self.rally("deployment create --name t_create_env2 --fromenv") self.rally("use deployment --deployment %s" % uuid) current_deployment = envutils.get_global("RALLY_DEPLOYMENT") self.assertEqual(uuid, current_deployment)
def test_use(self): with mock.patch.dict("os.environ", utils.TEST_ENV): output = self.rally( "deployment create --name t_create_env1 --fromenv") uuid = re.search(r"Using deployment: (?P<uuid>[0-9a-f\-]{36})", output).group("uuid") self.rally("deployment create --name t_create_env2 --fromenv") self.rally("deployment use --deployment %s" % uuid) current_deployment = envutils.get_global("RALLY_DEPLOYMENT") self.assertEqual(uuid, current_deployment)
def _test_start_abort_on_sla_failure(self, cfg, times): rally = utils.Rally() with mock.patch.dict("os.environ", utils.TEST_ENV): deployment_id = envutils.get_global("RALLY_DEPLOYMENT") config = utils.TaskConfig(cfg) rally(("task start --task %(task_file)s " "--deployment %(deployment_id)s --abort-on-sla-failure") % {"task_file": config.filename, "deployment_id": deployment_id}) results = json.loads(rally("task results")) iterations_completed = len(results[0]["result"]) self.assertTrue(iterations_completed < times)
def test_validate_is_invalid(self): rally = utils.Rally() with mock.patch.dict("os.environ", utils.TEST_ENV): deployment_id = envutils.get_global("RALLY_DEPLOYMENT") cfg = {"invalid": "config"} config = utils.TaskConfig(cfg) self.assertRaises(utils.RallyCmdError, rally, ("task validate --task %(task_file)s " "--deployment %(deployment_id)s") % {"task_file": config.filename, "deployment_id": deployment_id})
def test_start(self): rally = utils.Rally() with mock.patch.dict("os.environ", utils.TEST_ENV): deployment_id = envutils.get_global("RALLY_DEPLOYMENT") cfg = self._get_sample_task_config() config = utils.TaskConfig(cfg) output = rally(("task start --task %(task_file)s " "--deployment %(deployment_id)s") % {"task_file": config.filename, "deployment_id": deployment_id}) result = re.search( r"(?P<task_id>[0-9a-f\-]{36}): started", output) self.assertIsNotNone(result)
def test_task(self): cfg = { "Dummy.dummy_random_fail_in_atomic": [{ "runner": { "type": "constant", "times": 100, "concurrency": 5 } }] } with mock.patch.dict("os.environ", utils.TEST_ENV): deployment_id = envutils.get_global("RALLY_DEPLOYMENT") config = utils.TaskConfig(cfg) output = self.rally(("task start --task %(task_file)s " "--deployment %(deployment_id)s") % { "task_file": config.filename, "deployment_id": deployment_id }) result = re.search(r"(?P<uuid>[0-9a-f\-]{36}): started", output) uuid = result.group("uuid") self.rally("use task --uuid %s" % uuid) current_task = envutils.get_global("RALLY_TASK") self.assertEqual(uuid, current_task)
def list(self, deployment_list=None): """Print list of deployments.""" headers = ['uuid', 'created_at', 'name', 'status', 'active'] current_deploy_id = envutils.get_global('RALLY_DEPLOYMENT') deployment_list = deployment_list or db.deployment_list() table_rows = [] if deployment_list: for t in deployment_list: r = [str(t[column]) for column in headers[:-1]] r.append("" if t["uuid"] != current_deploy_id else "*") table_rows.append(utils.Struct(**dict(zip(headers, r)))) common_cliutils.print_list(table_rows, headers) else: print(_("There are no deployments. " "To create a new deployment, use:" "\nrally deployment create"))
def list(self, deployment_list=None): """Print list of deployments.""" headers = ['uuid', 'created_at', 'name', 'status', 'active'] current_deploy_id = envutils.get_global('RALLY_DEPLOYMENT') deployment_list = deployment_list or db.deployment_list() if deployment_list: table = prettytable.PrettyTable(headers) for t in deployment_list: r = [str(t[column]) for column in headers[:-1]] r.append("" if t["uuid"] != current_deploy_id else "*") table.add_row(r) print(table) else: print(_("There are no deployments. " "To create a new deployment, use:" "\nrally deployment create"))
def list(self, deployment_list=None): """Print list of deployments.""" headers = ['uuid', 'created_at', 'name', 'status', 'active'] current_deploy_id = envutils.get_global('RALLY_DEPLOYMENT') deployment_list = deployment_list or db.deployment_list() table_rows = [] if deployment_list: for t in deployment_list: r = [str(t[column]) for column in headers[:-1]] r.append("" if t["uuid"] != current_deploy_id else "*") table_rows.append(utils.Struct(**dict(zip(headers, r)))) common_cliutils.print_list(table_rows, headers) else: print( _("There are no deployments. " "To create a new deployment, use:" "\nrally deployment create"))
def list(self, deployment_list=None): """List existing deployments.""" headers = ["uuid", "created_at", "name", "status", "active"] current_deployment = envutils.get_global("RALLY_DEPLOYMENT") deployment_list = deployment_list or db.deployment_list() table_rows = [] if deployment_list: for t in deployment_list: r = [str(t[column]) for column in headers[:-1]] r.append("" if t["uuid"] != current_deployment else "*") table_rows.append(utils.Struct(**dict(zip(headers, r)))) cliutils.print_list(table_rows, headers, sortby_index=headers.index("created_at")) else: print(_("There are no deployments. " "To create a new deployment, use:" "\nrally deployment create"))
def list(self, deployment_list=None): """List existing deployments.""" headers = ["uuid", "created_at", "name", "status", "active"] current_deployment = envutils.get_global("RALLY_DEPLOYMENT") deployment_list = deployment_list or db.deployment_list() table_rows = [] if deployment_list: for t in deployment_list: r = [str(t[column]) for column in headers[:-1]] r.append("" if t["uuid"] != current_deployment else "*") table_rows.append(utils.Struct(**dict(zip(headers, r)))) cliutils.print_list(table_rows, headers, sortby_index=headers.index("created_at")) else: print( _("There are no deployments. " "To create a new deployment, use:" "\nrally deployment create"))
def test_get_deployment_id_in_env(self): deployment_id = envutils.get_global(envutils.ENV_DEPLOYMENT) self.assertEqual("my_deployment_id", deployment_id)
def test_get_task_id_in_env(self): self.assertEqual('my_task_id', envutils.get_global('RALLY_TASK'))
def test_get_task_id_with_none(self, mock_file): self.assertIsNone(envutils.get_global("RALLY_TASK")) mock_file.assert_called_once_with(os.path.expanduser("~/.rally/globals"))
def test_get_deployment_id_with_none(self, mock_file): self.assertIsNone(envutils.get_global(envutils.ENV_DEPLOYMENT)) mock_file.assert_called_once_with(os.path.expanduser("~/.rally/globals"))
def test_get_deployment_id_in_env(self): deploy_id = envutils.get_global('RALLY_DEPLOYMENT') self.assertEqual('my_deploy_id', deploy_id)
def test_get_task_id_in_env(self): self.assertEqual('my_task_id', envutils.get_global(envutils.ENV_TASK))
def test_get_task_id_with_none(self, mock_file): self.assertEqual(None, envutils.get_global('RALLY_TASK')) mock_file.assert_called_once_with(os.path.expanduser( '~/.rally/globals'))
def test_get_deployment_id_with_none(self, mock_file): self.assertEqual(None, envutils.get_global('RALLY_DEPLOYMENT')) mock_file.assert_called_once_with(os.path.expanduser( '~/.rally/globals'))
def test_get_task_id_with_none(self, mock_file): self.assertIsNone(envutils.get_global("RALLY_TASK")) mock_file.assert_called_once_with( os.path.expanduser("~/.rally/globals"))
def test_get_task_id_in_env(self): self.assertEqual("my_task_id", envutils.get_global(envutils.ENV_TASK))
def test_get_deployment_id_with_none(self, mock_file): self.assertIsNone(envutils.get_global(envutils.ENV_DEPLOYMENT)) mock_file.assert_called_once_with( os.path.expanduser("~/.rally/globals"))
def test_get_task_id_with_none(self, mock_file): self.assertEqual(None, envutils.get_global('RALLY_TASK')) mock_file.assert_called_once_with( os.path.expanduser('~/.rally/globals'))