def test_env_get(self): env1 = db.env_create("name", "STATUS42", "descr", {}, {}, {}, []) env2 = db.env_create("name2", "STATUS42", "descr", {}, {}, {}, []) self.assertEqual(env1, db.env_get(env1["uuid"])) self.assertEqual(env1, db.env_get(env1["name"])) self.assertEqual(env2, db.env_get(env2["uuid"])) self.assertEqual(env2, db.env_get(env2["name"]))
def test_env_list(self): for i in range(3): db.env_create("name %s" % i, "STATUS42", "descr", {}, {}, {}, []) self.assertEqual(i + 1, len(db.env_list())) all_ = db.env_list() self.assertIsInstance(all_, list) for env in all_: self.assertIsInstance(env, dict) self.assertEqual(set("name %s" % i for i in range(3)), set(e["name"] for e in db.env_list()))
def setUp(self): super(PlatformTestCase, self).setUp() platforms = [{ "status": "ANY", "plugin_name": "plugin_%s@plugin" % i, "plugin_spec": {}, "platform_name": "plugin" } for i in range(5)] self.env1 = db.env_create("env1", "init", "", {}, {}, {}, platforms[:2]) self.env2 = db.env_create("env2", "init", "", {}, {}, {}, platforms[2:])
def setUp(self): super(PlatformTestCase, self).setUp() platforms = [ { "status": "ANY", "plugin_name": "plugin_%s@plugin" % i, "plugin_spec": {}, "platform_name": "plugin" } for i in range(5) ] self.env1 = db.env_create( "env1", "init", "", {}, {}, {}, platforms[:2]) self.env2 = db.env_create( "env2", "init", "", {}, {}, {}, platforms[2:])
def setUp(self): super(WorkloadTestCase, self).setUp() self.env = db.env_create(self.id(), "INIT", "", {}, {}, {}, []) self.task = db.task_create({"env_uuid": self.env["uuid"]}) self.task_uuid = self.task["uuid"] self.subtask = db.subtask_create(self.task_uuid, title="foo") self.subtask_uuid = self.subtask["uuid"]
def _validate_and_create_env(cls, name, spec): """Validated and create env and platforms DB records. Do NOT use this method directly. Call create() method instead. - Restore full name of plugin. If only platform name is specified plugin with name existing@<platform_name> is going to be used - Validates spec using standard plugin validation mechanism - Creates env and platforms DB records in DB :returns: dict that contains env record stored in DB """ try: jsonschema.validate(spec, SPEC_SCHEMA) except jsonschema.ValidationError as err: raise exceptions.ManagerInvalidSpec( mgr="Env", spec=spec, errors=[str(err)]) spec.pop("!version", None) config = spec.pop("!config", {}) extras = spec.pop("!extras", {}) description = spec.pop("!description", "") existing_platforms = {} for p_name, p_spec in spec.items(): if "@" not in p_name: spec["existing@%s" % p_name] = p_spec spec.pop(p_name) platform_name = p_name.split("@")[1] if "@" in p_name else p_name if platform_name in existing_platforms: raise exceptions.ManagerInvalidSpec( mgr="Env", spec=spec, errors=["Using multiple plugins [%s, %s] with the same " "platform in single Env is not supported: " % (p_name, existing_platforms[platform_name])] ) existing_platforms[platform_name] = p_name errors = [] for p_name, p_spec in spec.items(): errors.extend(platform.Platform.validate(p_name, {}, spec, p_spec)) if errors: raise exceptions.ManagerInvalidSpec( mgr="Env", spec=spec, errors=errors) _platforms = [] for p_name, p_spec in spec.items(): _platforms.append({ "status": platform.STATUS.INIT, "plugin_name": p_name, "plugin_spec": p_spec, "platform_name": p_name.split("@")[1] }) return cls(db.env_create(name, STATUS.INIT, description, extras, config, spec, _platforms))
def _validate_and_create_env(cls, name, spec): """Validated and create env and platforms DB records. Do NOT use this method directly. Call create() method instead. - Restore full name of plugin. If only platform name is specified plugin with name existing@<platform_name> is going to be used - Validates spec using standard plugin validation mechanism - Creates env and platforms DB records in DB :returns: dict that contains env record stored in DB """ try: jsonschema.validate(spec, SPEC_SCHEMA) except jsonschema.ValidationError as err: raise exceptions.ManagerInvalidSpec( mgr="Env", spec=spec, errors=[str(err)]) spec.pop("!version", None) config = spec.pop("!config", {}) extras = spec.pop("!extras", {}) description = spec.pop("!description", "") existing_platforms = {} for p_name, p_spec in list(spec.items()): if "@" not in p_name: spec["existing@%s" % p_name] = p_spec spec.pop(p_name) platform_name = p_name.split("@")[1] if "@" in p_name else p_name if platform_name in existing_platforms: raise exceptions.ManagerInvalidSpec( mgr="Env", spec=spec, errors=["Using multiple plugins [%s, %s] with the same " "platform in single Env is not supported: " % (p_name, existing_platforms[platform_name])] ) existing_platforms[platform_name] = p_name errors = [] for p_name, p_spec in spec.items(): errors.extend(platform.Platform.validate(p_name, {}, spec, p_spec)) if errors: raise exceptions.ManagerInvalidSpec( mgr="Env", spec=spec, errors=errors) _platforms = [] for p_name, p_spec in spec.items(): _platforms.append({ "status": platform.STATUS.INIT, "plugin_name": p_name, "plugin_spec": p_spec, "platform_name": p_name.split("@")[1] }) return cls(db.env_create(name, STATUS.INIT, description, extras, config, spec, _platforms))
def test_env_update(self): env = db.env_create("name", "status", "descr", {}, {}, {}, []) self.assertTrue(db.env_update(env["uuid"])) self.assertTrue( db.env_update(env["uuid"], "another_descr", {"e": 123}, {"c": 1})) env = db.env_get(env["uuid"]) self.assertEqual("another_descr", env["description"]) self.assertEqual({"e": 123}, env["extras"]) self.assertEqual({"c": 1}, env["config"])
def teet_env_create_with_platforms(self): platforms = [{ "status": "ANY", "plugin_name": "plugin_%s@plugin" % i, "plugin_spec": {}, "platform_name": "plugin" } for i in range(3)] env = db.env_create("name", "status", "descr", {}, {}, {}, platforms) db_platforms = db.platforms_list(env["uuid"]) self.assertEqual(3, len(db_platforms))
def setUp(self): super(WorkloadDataTestCase, self).setUp() self.env = db.env_create(self.id(), "INIT", "", {}, {}, {}, []) self.task = db.task_create({"env_uuid": self.env["uuid"]}) self.task_uuid = self.task["uuid"] self.subtask = db.subtask_create(self.task_uuid, title="foo") self.subtask_uuid = self.subtask["uuid"] self.workload = db.workload_create( self.task_uuid, self.subtask_uuid, name="atata", description="foo", position=0, args={}, contexts={}, sla={}, runner={}, runner_type="r", hooks={}) self.workload_uuid = self.workload["uuid"]
def test_env_delete_cascade(self): platforms = [{ "status": "ANY", "plugin_name": "plugin_%s@plugin" % i, "plugin_spec": {}, "platform_name": "plugin" } for i in range(3)] env = db.env_create("name", "status", "descr", {}, {}, {}, platforms) db.env_delete_cascade(env["uuid"]) self.assertEqual(0, len(db.env_list())) self.assertEqual(0, len(db.platforms_list(env["uuid"])))
def test_evn_set_status(self): env = db.env_create("name", "status", "descr", {}, {}, {}, []) self.assertRaises(exceptions.DBConflict, db.env_set_status, env["uuid"], "wrong_old_status", "new_status") env = db.env_get(env["uuid"]) self.assertEqual("status", env["status"]) self.assertTrue(db.env_set_status(env["uuid"], "status", "new_status")) env = db.env_get(env["uuid"]) self.assertEqual("new_status", env["status"])
def test_env_create(self): env = db.env_create("name", "status", "descr", {"extra": "test"}, {"conf": "c1"}, {"spec": "spec"}, []) self.assertIsInstance(env, dict) self.assertIsNotNone(env["uuid"]) self.assertEqual(env, db.env_get(env["uuid"])) self.assertEqual("name", env["name"]) self.assertEqual("status", env["status"]) self.assertEqual("descr", env["description"]) self.assertEqual({"conf": "c1"}, env["config"]) self.assertEqual({"extra": "test"}, env["extras"]) self.assertEqual({"spec": "spec"}, env["spec"])
def teet_env_create_with_platforms(self): platforms = [ { "status": "ANY", "plugin_name": "plugin_%s@plugin" % i, "plugin_spec": {}, "platform_name": "plugin" } for i in range(3) ] env = db.env_create("name", "status", "descr", {}, {}, {}, platforms) db_platforms = db.platforms_list(env["uuid"]) self.assertEqual(3, len(db_platforms))
def test_env_create(self): env = db.env_create( "name", "status", "descr", {"extra": "test"}, {"conf": "c1"}, {"spec": "spec"}, []) self.assertIsInstance(env, dict) self.assertIsNotNone(env["uuid"]) self.assertEqual(env, db.env_get(env["uuid"])) self.assertEqual("name", env["name"]) self.assertEqual("status", env["status"]) self.assertEqual("descr", env["description"]) self.assertEqual({"conf": "c1"}, env["config"]) self.assertEqual({"extra": "test"}, env["extras"]) self.assertEqual({"spec": "spec"}, env["spec"])
def test_evn_set_status(self): env = db.env_create("name", "status", "descr", {}, {}, {}, []) self.assertRaises( exceptions.DBConflict, db.env_set_status, env["uuid"], "wrong_old_status", "new_status") env = db.env_get(env["uuid"]) self.assertEqual("status", env["status"]) self.assertTrue( db.env_set_status(env["uuid"], "status", "new_status")) env = db.env_get(env["uuid"]) self.assertEqual("new_status", env["status"])
def test_env_delete_cascade(self): platforms = [ { "status": "ANY", "plugin_name": "plugin_%s@plugin" % i, "plugin_spec": {}, "platform_name": "plugin" } for i in range(3) ] env = db.env_create("name", "status", "descr", {}, {}, {}, platforms) db.env_delete_cascade(env["uuid"]) self.assertEqual(0, len(db.env_list())) self.assertEqual(0, len(db.platforms_list(env["uuid"])))
def test_env_list_filter_by_status(self): db.env_create("name 1", "STATUS42", "descr", {}, {}, {}, []) db.env_create("name 2", "STATUS42", "descr", {}, {}, {}, []) db.env_create("name 3", "STATUS43", "descr", {}, {}, {}, []) result = db.env_list("STATUS42") self.assertEqual(2, len(result)) self.assertEqual(set(["name 1", "name 2"]), set(r["name"] for r in result)) result = db.env_list("STATUS43") self.assertEqual(1, len(result)) self.assertEqual("name 3", result[0]["name"])
def setUp(self): super(WorkloadDataTestCase, self).setUp() self.env = db.env_create(self.id(), "INIT", "", {}, {}, {}, []) self.task = db.task_create({"env_uuid": self.env["uuid"]}) self.task_uuid = self.task["uuid"] self.subtask = db.subtask_create(self.task_uuid, title="foo") self.subtask_uuid = self.subtask["uuid"] self.workload = db.workload_create(self.task_uuid, self.subtask_uuid, name="atata", description="foo", position=0, args={}, contexts={}, sla={}, runner={}, runner_type="r", hooks={}) self.workload_uuid = self.workload["uuid"]
def test_verification_list(self): another_env = db.env_create(self.id() + "2", "INIT", "", {}, {}, {}, []) v1 = self._create_verification(tags=["foo", "bar"], env_uuid=another_env["uuid"]) v2 = self._create_verification() vs = db.verification_list(self.verifier["uuid"]) self.assertEqual(sorted([v1["uuid"], v2["uuid"]]), sorted([v["uuid"] for v in vs])) vs = db.verification_list(self.verifier["uuid"], another_env["uuid"]) self.assertEqual(1, len(vs)) self.assertEqual(v1["uuid"], vs[0]["uuid"]) vs = db.verification_list(tags=["bar"]) self.assertEqual(1, len(vs)) self.assertEqual(v1["uuid"], vs[0]["uuid"]) v2 = db.verification_update(v2["uuid"], status="foo") vs = db.verification_list(status="foo") self.assertEqual(1, len(vs)) self.assertEqual(v2["uuid"], vs[0]["uuid"])
def test_verification_list(self): another_env = db.env_create( self.id() + "2", "INIT", "", {}, {}, {}, []) v1 = self._create_verification(tags=["foo", "bar"], env_uuid=another_env["uuid"]) v2 = self._create_verification() vs = db.verification_list(self.verifier["uuid"]) self.assertEqual(sorted([v1["uuid"], v2["uuid"]]), sorted([v["uuid"] for v in vs])) vs = db.verification_list(self.verifier["uuid"], another_env["uuid"]) self.assertEqual(1, len(vs)) self.assertEqual(v1["uuid"], vs[0]["uuid"]) vs = db.verification_list(tags=["bar"]) self.assertEqual(1, len(vs)) self.assertEqual(v1["uuid"], vs[0]["uuid"]) v2 = db.verification_update(v2["uuid"], status="foo") vs = db.verification_list(status="foo") self.assertEqual(1, len(vs)) self.assertEqual(v2["uuid"], vs[0]["uuid"])
def _validate_and_create_env(cls, name, description, extras, spec): """Validated and create env and platforms DB records. Do NOT use this method directly. Call create() method instead. - Restore full name of plugin. If only platform name is specified plugin with name existing@<platform_name> is going to be used - Validates spec using standard plugin validation mechanism - Creates env and platforms DB records in DB :returns: dict that contains env record stored in DB """ for p_name, p_spec in spec.items(): if "@" not in p_name: spec["existing@%s" % p_name] = p_spec spec.pop(p_name) errors = [] for p_name, p_spec in spec.items(): errors.extend(platform.Platform.validate(p_name, {}, spec, p_spec)) if errors: raise exceptions.ManagerInvalidSpec(mgr="Env", spec=spec, errors=errors) _platforms = [] for p_name, p_spec in spec.items(): _platforms.append({ "status": platform.STATUS.INIT, "plugin_name": p_name, "plugin_spec": p_spec, "platform_name": p_name.split("@")[1] }) return cls( db.env_create(name, STATUS.INIT, description, extras, spec, _platforms))
def setUp(self): super(SubtaskTestCase, self).setUp() self.env = db.env_create(self.id(), "INIT", "", {}, {}, {}, []) self.task = db.task_create({"env_uuid": self.env["uuid"]})
def test_env_create_duplicate_env(self): db.env_create("name", "status", "descr", {}, {}, {}, []) self.assertRaises( exceptions.DBRecordExists, db.env_create, "name", "status", "descr", {}, {}, {}, [])
def test_env_get_status(self): env = db.env_create("name", "STATUS42", "descr", {}, {}, {}, []) self.assertEqual("STATUS42", db.env_get_status(env["uuid"]))
def test_env_rename_duplicate(self): env1 = db.env_create("name", "status", "descr", {}, {}, {}, []) env2 = db.env_create("name2", "status", "descr", {}, {}, {}, []) self.assertRaises( exceptions.DBRecordExists, db.env_rename, env1["uuid"], env1["name"], env2["name"])
def test_env_rename(self): env = db.env_create("name", "status", "descr", {"extra": "test"}, {"spec": "spec"}, {}, []) self.assertTrue(db.env_rename(env["uuid"], env["name"], "name2")) self.assertEqual("name2", db.env_get(env["uuid"])["name"])
def test_env_rename_duplicate(self): env1 = db.env_create("name", "status", "descr", {}, {}, {}, []) env2 = db.env_create("name2", "status", "descr", {}, {}, {}, []) self.assertRaises(exceptions.DBRecordExists, db.env_rename, env1["uuid"], env1["name"], env2["name"])
def test_env_create_duplicate_env(self): db.env_create("name", "status", "descr", {}, {}, {}, []) self.assertRaises(exceptions.DBRecordExists, db.env_create, "name", "status", "descr", {}, {}, {}, [])
def setUp(self): super(VerificationTestCase, self).setUp() self.verifier = db.verifier_create("a", "b", "c", "d", "e", False) self.env = db.env_create(self.id(), "INIT", "", {}, {}, {}, [])
def setUp(self): super(TasksTestCase, self).setUp() self.env = db.env_create(self.id(), "INIT", "", {}, {}, {}, [])