diff --git a/Pipfile b/Pipfile index 501892d3..23a428a3 100644 --- a/Pipfile +++ b/Pipfile @@ -30,6 +30,7 @@ pyrfc3339 = ">=1.1" directory-tree = ">=0.0.3.1" yaspin = ">=2.3.0" jsonschema = ">=4.0.0" +waiting = ">=1.4.1" [requires] python_version = "3" diff --git a/Pipfile.lock b/Pipfile.lock index 76bed155..3aedb26e 100644 --- a/Pipfile.lock +++ b/Pipfile.lock @@ -1,7 +1,7 @@ { "_meta": { "hash": { - "sha256": "5ee91191cb49d4fa963f6992c9a525dfe1946a4525d618efebdd0a9b52b88bb9" + "sha256": "f730b4ccf4aef49daa882b1d3215dbeff5ee400fa59c9ad853523711d443883d" }, "pipfile-spec": 6, "requires": { @@ -416,7 +416,7 @@ }, "rapyuta-io-cli": { "path": ".", - "version": "==0.6.0" + "version": "==2.0.1" }, "requests": { "hashes": [ @@ -474,6 +474,13 @@ "markers": "python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3, 3.4, 3.5'", "version": "==1.26.15" }, + "waiting": { + "hashes": [ + "sha256:b641ef3a2382e101d3c4e66494da6fc52b82c325dd04ae341e051b0eec6f30cd" + ], + "index": "pypi", + "version": "==1.4.1" + }, "wcwidth": { "hashes": [ "sha256:795b138f6875577cd91bba52baf9e445cd5118fd32723b460e30a0af30ea230e", diff --git a/riocli/project/model.py b/riocli/project/model.py index a3abe466..e7af5df5 100644 --- a/riocli/project/model.py +++ b/riocli/project/model.py @@ -15,11 +15,13 @@ from munch import unmunchify from rapyuta_io import Client +from waiting import wait, TimeoutExpired from riocli.config import new_v2_client, Configuration from riocli.jsonschema.validate import load_schema from riocli.model import Model +PROJECT_READY_TIMEOUT = 150 class Project(Model): @@ -48,6 +50,12 @@ def create_object(self, client: Client) -> typing.Any: 'organization_id'] r = client.create_project(project) + + try: + wait(self.is_ready, timeout_seconds=PROJECT_READY_TIMEOUT, sleep_seconds=(1, 30, 2)) + except TimeoutExpired as e: + raise e + return unmunchify(r) def update_object(self, client: Client, obj: typing.Any) -> typing.Any: @@ -66,6 +74,11 @@ def delete_object(self, client: Client, obj: typing.Any) -> typing.Any: client = new_v2_client() client.delete_project(obj.metadata.guid) + def is_ready(self) -> bool: + client = new_v2_client() + projects = client.list_projects(query={"name": self.metadata.name}) + return projects[0].status.status == 'Success' + @classmethod def pre_process(cls, client: Client, d: typing.Dict) -> None: pass diff --git a/setup.py b/setup.py index ca9b4aad..a7b89bbc 100644 --- a/setup.py +++ b/setup.py @@ -59,6 +59,7 @@ "directory-tree>=0.0.3.1", "yaspin>=2.3.0", "jsonschema>=4.0.0" + "waiting>=1.4.1" ], setup_requires=["flake8"], )