Skip to content

Commit

Permalink
Issue #4: Add Task.instance_status computed property
Browse files Browse the repository at this point in the history
  • Loading branch information
machristie committed Mar 30, 2018
1 parent e0a7f7a commit c7306b6
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 25 deletions.
9 changes: 8 additions & 1 deletion cloudlaunch_cli/api/resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,4 +109,11 @@ def run_delete(self):


class Task(APIResource):
pass

@property
def instance_status(self):
"""Return HEALTH_CHECK instance_status otherwise None."""
if self.action == 'HEALTH_CHECK' and self.status == 'SUCCESS':
return self.result['instance_status']
else:
return None
6 changes: 2 additions & 4 deletions cloudlaunch_cli/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,10 +90,8 @@ def _print_deployments(deployments):
for deployment in deployments:
created_date = arrow.get(deployment.added)
latest_task = deployment.latest_task
latest_task_status = latest_task.status
if latest_task.action == 'HEALTH_CHECK' \
and latest_task.status == 'SUCCESS':
latest_task_status = latest_task.result['instance_status']
latest_task_status = latest_task.instance_status \
if latest_task.instance_status else latest_task.status
latest_task_display = "{action}:{latest_task_status}".format(
action=latest_task.action,
latest_task_status=latest_task_status)
Expand Down
35 changes: 15 additions & 20 deletions tests/api/test_resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,31 +55,17 @@ class TestDeployment(unittest.TestCase):
},
"tasks": "http://127.0.0.1:4200/api/v1/deployments/26/tasks/",
"latest_task": {
"id": 215,
"url": "http://127.0.0.1:4200/api/v1/deployments/26/tasks/215/",
"id": 216,
"url": "http://127.0.0.1:4200/api/v1/deployments/26/tasks/216/",
"celery_id": None,
"action": "LAUNCH",
"action": "HEALTH_CHECK",
"status": "SUCCESS",
"result": {
"cloudLaunch": {
"keyPair": {
"id": "cloudlaunch_key_pair",
"name": "cloudlaunch_key_pair",
"material": None
},
"securityGroup": {
"id": "sg-ec40da9e",
"name": "cloudlaunch-vm"
},
"instance": {
"id": "i-043d1b4d61e9065b8"
},
"publicIP": "34.233.71.64"
}
"instance_status": "running"
},
"traceback": None,
"added": "2018-03-28T13:09:50.638217-04:00",
"updated": "2018-03-28T14:10:15.831364-04:00",
"added": "2018-03-28T13:16:58.675260-04:00",
"updated": "2018-03-28T13:17:01.329800-04:00",
"deployment": 26
},
"launch_task": {
Expand Down Expand Up @@ -173,3 +159,12 @@ def test_update(self):
def test_public_ip(self):
"""Test public_ip computed property."""
self.assertEqual(self.deployment.public_ip, "34.233.71.64")


class TestTask(TestDeployment):

def test_instance_status(self):
self.assertEqual(self.deployment.latest_task.instance_status,
"running")
self.assertEqual(self.deployment.launch_task.instance_status,
None)

0 comments on commit c7306b6

Please sign in to comment.