summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Beaver <michaelbeaver64@gmail.com>2019-02-01 14:31:35 -0600
committerMichael Beaver <michaelbeaver64@gmail.com>2019-02-21 12:22:32 -0600
commitb458c3f675b7cd8a16916539eb338a729fd84def (patch)
treec42199adb3d18452534c3aa3c3b8e3e0c7cc5a02
parent9a7c1f4006558226997c30af64b0f3bd0c666718 (diff)
Refactor tiller commands to handle methods
This is a refactor to any methods in the api and cli to move tiller operations to a separate handler function to make them uniform with the rest of the code Change-Id: Iddd45f9f979307f54ad5bd54c3ee005547dd0909
Notes
Notes (review): Code-Review+1: Drew Walters <drewwalters96@gmail.com> Code-Review+1: Doug Aaser <da519m@att.com> Code-Review+1: Dan Crank <dan.no@att.com> Code-Review+2: Sean Eagan <sean.eagan@att.com> Code-Review+1: Vladyslav Drok <vdrok@mirantis.com> Code-Review+1: Nishant Kumar <nishant.e.kumar@ericsson.com> Code-Review+2: Bryan Strassner <strassner.bryan@gmail.com> Workflow+1: Sean Eagan <sean.eagan@att.com> Verified+2: Zuul Submitted-by: Zuul Submitted-at: Mon, 04 Mar 2019 22:39:16 +0000 Reviewed-on: https://review.openstack.org/634494 Project: openstack/airship-armada Branch: refs/heads/master
-rw-r--r--armada/api/controller/armada.py34
-rw-r--r--armada/api/controller/rollback.py33
-rw-r--r--armada/api/controller/test.py10
-rw-r--r--armada/api/controller/tiller.py54
-rw-r--r--armada/cli/apply.py31
-rw-r--r--armada/cli/rollback.py17
6 files changed, 95 insertions, 84 deletions
diff --git a/armada/api/controller/armada.py b/armada/api/controller/armada.py
index d21b8f0..73a3e07 100644
--- a/armada/api/controller/armada.py
+++ b/armada/api/controller/armada.py
@@ -69,29 +69,13 @@ class Apply(api.BaseResource):
69 "or application/json") 69 "or application/json")
70 try: 70 try:
71 with self.get_tiller(req, resp) as tiller: 71 with self.get_tiller(req, resp) as tiller:
72 72 msg = self.handle(req, documents, tiller)
73 armada = Armada(
74 documents,
75 disable_update_pre=req.get_param_as_bool(
76 'disable_update_pre'),
77 disable_update_post=req.get_param_as_bool(
78 'disable_update_post'),
79 enable_chart_cleanup=req.get_param_as_bool(
80 'enable_chart_cleanup'),
81 dry_run=req.get_param_as_bool('dry_run'),
82 force_wait=req.get_param_as_bool('wait'),
83 timeout=req.get_param_as_int('timeout'),
84 tiller=tiller,
85 target_manifest=req.get_param('target_manifest'))
86
87 msg = armada.sync()
88
89 resp.body = json.dumps({ 73 resp.body = json.dumps({
90 'message': msg, 74 'message': msg,
91 }) 75 })
92
93 resp.content_type = 'application/json' 76 resp.content_type = 'application/json'
94 resp.status = falcon.HTTP_200 77 resp.status = falcon.HTTP_200
78
95 except exceptions.ManifestException as e: 79 except exceptions.ManifestException as e:
96 self.return_error(resp, falcon.HTTP_400, message=str(e)) 80 self.return_error(resp, falcon.HTTP_400, message=str(e))
97 except Exception as e: 81 except Exception as e:
@@ -99,3 +83,17 @@ class Apply(api.BaseResource):
99 err_message = 'Failed to apply manifest: {}'.format(e) 83 err_message = 'Failed to apply manifest: {}'.format(e)
100 self.error(req.context, err_message) 84 self.error(req.context, err_message)
101 self.return_error(resp, falcon.HTTP_500, message=err_message) 85 self.return_error(resp, falcon.HTTP_500, message=err_message)
86
87 def handle(self, req, documents, tiller):
88 armada = Armada(
89 documents,
90 disable_update_pre=req.get_param_as_bool('disable_update_pre'),
91 disable_update_post=req.get_param_as_bool('disable_update_post'),
92 enable_chart_cleanup=req.get_param_as_bool('enable_chart_cleanup'),
93 dry_run=req.get_param_as_bool('dry_run'),
94 force_wait=req.get_param_as_bool('wait'),
95 timeout=req.get_param_as_int('timeout'),
96 tiller=tiller,
97 target_manifest=req.get_param('target_manifest'))
98
99 return armada.sync()
diff --git a/armada/api/controller/rollback.py b/armada/api/controller/rollback.py
index 38468d9..78bc933 100644
--- a/armada/api/controller/rollback.py
+++ b/armada/api/controller/rollback.py
@@ -30,27 +30,28 @@ class Rollback(api.BaseResource):
30 @policy.enforce('armada:rollback_release') 30 @policy.enforce('armada:rollback_release')
31 def on_post(self, req, resp, release): 31 def on_post(self, req, resp, release):
32 try: 32 try:
33 dry_run = req.get_param_as_bool('dry_run')
34
35 with self.get_tiller(req, resp) as tiller: 33 with self.get_tiller(req, resp) as tiller:
36 34 msg = self.handle(req, release, tiller)
37 tiller.rollback_release(
38 release,
39 req.get_param_as_int('version') or 0,
40 wait=req.get_param_as_bool('wait'),
41 timeout=req.get_param_as_int('timeout') or 0,
42 force=req.get_param_as_bool('force'),
43 recreate_pods=req.get_param_as_bool('recreate_pods'))
44
45 resp.body = json.dumps({ 35 resp.body = json.dumps({
46 'message': ('(dry run) ' if dry_run else '') + 36 'message': msg,
47 'Rollback of {} complete.'.format(release),
48 }) 37 })
49 38 resp.content_type = 'application/json'
50 resp.content_type = 'application/json' 39 resp.status = falcon.HTTP_200
51 resp.status = falcon.HTTP_200
52 except Exception as e: 40 except Exception as e:
53 self.logger.exception('Caught unexpected exception') 41 self.logger.exception('Caught unexpected exception')
54 err_message = 'Failed to rollback release: {}'.format(e) 42 err_message = 'Failed to rollback release: {}'.format(e)
55 self.error(req.context, err_message) 43 self.error(req.context, err_message)
56 self.return_error(resp, falcon.HTTP_500, message=err_message) 44 self.return_error(resp, falcon.HTTP_500, message=err_message)
45
46 def handle(self, req, release, tiller):
47 dry_run = req.get_param_as_bool('dry_run')
48 tiller.rollback_release(
49 release,
50 req.get_param_as_int('version') or 0,
51 wait=req.get_param_as_bool('wait'),
52 timeout=req.get_param_as_int('timeout') or 0,
53 force=req.get_param_as_bool('force'),
54 recreate_pods=req.get_param_as_bool('recreate_pods'))
55
56 return ('(dry run) ' if dry_run else '') + \
57 'Rollback of {} complete.'.format(release)
diff --git a/armada/api/controller/test.py b/armada/api/controller/test.py
index c2467cc..594b6ff 100644
--- a/armada/api/controller/test.py
+++ b/armada/api/controller/test.py
@@ -37,10 +37,7 @@ class TestReleasesReleaseNameController(api.BaseResource):
37 @policy.enforce('armada:test_release') 37 @policy.enforce('armada:test_release')
38 def on_get(self, req, resp, release): 38 def on_get(self, req, resp, release):
39 with self.get_tiller(req, resp) as tiller: 39 with self.get_tiller(req, resp) as tiller:
40 cleanup = req.get_param_as_bool('cleanup') 40 success = self.handle(req, release, tiller)
41
42 test_handler = Test({}, release, tiller, cleanup=cleanup)
43 success = test_handler.test_release_for_success()
44 41
45 if success: 42 if success:
46 msg = { 43 msg = {
@@ -57,6 +54,11 @@ class TestReleasesReleaseNameController(api.BaseResource):
57 resp.status = falcon.HTTP_200 54 resp.status = falcon.HTTP_200
58 resp.content_type = 'application/json' 55 resp.content_type = 'application/json'
59 56
57 def handle(self, req, release, tiller):
58 cleanup = req.get_param_as_bool('cleanup')
59 test_handler = Test({}, release, tiller, cleanup=cleanup)
60 return test_handler.test_release_for_success()
61
60 62
61class TestReleasesManifestController(api.BaseResource): 63class TestReleasesManifestController(api.BaseResource):
62 ''' 64 '''
diff --git a/armada/api/controller/tiller.py b/armada/api/controller/tiller.py
index 631b929..3f9669d 100644
--- a/armada/api/controller/tiller.py
+++ b/armada/api/controller/tiller.py
@@ -34,19 +34,7 @@ class Status(api.BaseResource):
34 ''' 34 '''
35 try: 35 try:
36 with self.get_tiller(req, resp) as tiller: 36 with self.get_tiller(req, resp) as tiller:
37 37 message = self.handle(tiller)
38 LOG.debug(
39 'Tiller (Status) at: %s:%s, namespace=%s, '
40 'timeout=%s', tiller.tiller_host, tiller.tiller_port,
41 tiller.tiller_namespace, tiller.timeout)
42
43 message = {
44 'tiller': {
45 'state': tiller.tiller_status(),
46 'version': tiller.tiller_version()
47 }
48 }
49
50 resp.status = falcon.HTTP_200 38 resp.status = falcon.HTTP_200
51 resp.body = json.dumps(message) 39 resp.body = json.dumps(message)
52 resp.content_type = 'application/json' 40 resp.content_type = 'application/json'
@@ -56,6 +44,19 @@ class Status(api.BaseResource):
56 self.error(req.context, err_message) 44 self.error(req.context, err_message)
57 self.return_error(resp, falcon.HTTP_500, message=err_message) 45 self.return_error(resp, falcon.HTTP_500, message=err_message)
58 46
47 def handle(self, tiller):
48 LOG.debug('Tiller (Status) at: %s:%s, namespace=%s, '
49 'timeout=%s', tiller.tiller_host, tiller.tiller_port,
50 tiller.tiller_namespace, tiller.timeout)
51
52 message = {
53 'tiller': {
54 'state': tiller.tiller_status(),
55 'version': tiller.tiller_version()
56 }
57 }
58 return message
59
59 60
60class Release(api.BaseResource): 61class Release(api.BaseResource):
61 62
@@ -65,18 +66,10 @@ class Release(api.BaseResource):
65 ''' 66 '''
66 try: 67 try:
67 with self.get_tiller(req, resp) as tiller: 68 with self.get_tiller(req, resp) as tiller:
68 69 releases = self.handle(tiller)
69 LOG.debug( 70 resp.body = json.dumps({
70 'Tiller (Release) at: %s:%s, namespace=%s, ' 71 'releases': releases,
71 'timeout=%s', tiller.tiller_host, tiller.tiller_port, 72 })
72 tiller.tiller_namespace, tiller.timeout)
73
74 releases = {}
75 for release in tiller.list_releases():
76 releases.setdefault(release.namespace, [])
77 releases[release.namespace].append(release.name)
78
79 resp.body = json.dumps({'releases': releases})
80 resp.content_type = 'application/json' 73 resp.content_type = 'application/json'
81 resp.status = falcon.HTTP_200 74 resp.status = falcon.HTTP_200
82 75
@@ -84,3 +77,14 @@ class Release(api.BaseResource):
84 err_message = 'Unable to find Tiller Releases: {}'.format(e) 77 err_message = 'Unable to find Tiller Releases: {}'.format(e)
85 self.error(req.context, err_message) 78 self.error(req.context, err_message)
86 self.return_error(resp, falcon.HTTP_500, message=err_message) 79 self.return_error(resp, falcon.HTTP_500, message=err_message)
80
81 def handle(self, tiller):
82 LOG.debug('Tiller (Release) at: %s:%s, namespace=%s, '
83 'timeout=%s', tiller.tiller_host, tiller.tiller_port,
84 tiller.tiller_namespace, tiller.timeout)
85
86 releases = {}
87 for release in tiller.list_releases():
88 releases.setdefault(release.namespace, [])
89 releases[release.namespace].append(release.name)
90 return releases
diff --git a/armada/cli/apply.py b/armada/cli/apply.py
index 209b960..6333cfa 100644
--- a/armada/cli/apply.py
+++ b/armada/cli/apply.py
@@ -204,20 +204,8 @@ class ApplyManifest(CliAction):
204 tiller_port=self.tiller_port, 204 tiller_port=self.tiller_port,
205 tiller_namespace=self.tiller_namespace, 205 tiller_namespace=self.tiller_namespace,
206 dry_run=self.dry_run) as tiller: 206 dry_run=self.dry_run) as tiller:
207 armada = Armada( 207
208 documents, 208 resp = self.handle(documents, tiller)
209 disable_update_pre=self.disable_update_pre,
210 disable_update_post=self.disable_update_post,
211 enable_chart_cleanup=self.enable_chart_cleanup,
212 dry_run=self.dry_run,
213 set_ovr=self.set,
214 force_wait=self.wait,
215 timeout=self.timeout,
216 tiller=tiller,
217 values=self.values,
218 target_manifest=self.target_manifest)
219
220 resp = armada.sync()
221 self.output(resp) 209 self.output(resp)
222 else: 210 else:
223 if len(self.values) > 0: 211 if len(self.values) > 0:
@@ -245,3 +233,18 @@ class ApplyManifest(CliAction):
245 resp = client.post_apply( 233 resp = client.post_apply(
246 manifest=documents, set=self.set, query=query) 234 manifest=documents, set=self.set, query=query)
247 self.output(resp.get('message')) 235 self.output(resp.get('message'))
236
237 def handle(self, documents, tiller):
238 armada = Armada(
239 documents,
240 disable_update_pre=self.disable_update_pre,
241 disable_update_post=self.disable_update_post,
242 enable_chart_cleanup=self.enable_chart_cleanup,
243 dry_run=self.dry_run,
244 set_ovr=self.set,
245 force_wait=self.wait,
246 timeout=self.timeout,
247 tiller=tiller,
248 values=self.values,
249 target_manifest=self.target_manifest)
250 return armada.sync()
diff --git a/armada/cli/rollback.py b/armada/cli/rollback.py
index 89bf9f2..5285e76 100644
--- a/armada/cli/rollback.py
+++ b/armada/cli/rollback.py
@@ -116,16 +116,19 @@ class Rollback(CliAction):
116 tiller_namespace=self.tiller_namespace, 116 tiller_namespace=self.tiller_namespace,
117 dry_run=self.dry_run) as tiller: 117 dry_run=self.dry_run) as tiller:
118 118
119 response = tiller.rollback_release( 119 response = self.handle(tiller)
120 self.release,
121 self.version,
122 wait=self.wait,
123 timeout=self.timeout,
124 force=self.force,
125 recreate_pods=self.recreate_pods)
126 120
127 self.output(response) 121 self.output(response)
128 122
123 def handle(self, tiller):
124 return tiller.rollback_release(
125 self.release,
126 self.version,
127 wait=self.wait,
128 timeout=self.timeout,
129 force=self.force,
130 recreate_pods=self.recreate_pods)
131
129 def output(self, response): 132 def output(self, response):
130 self.logger.info(('(dry run) ' if self.dry_run else '') + 133 self.logger.info(('(dry run) ' if self.dry_run else '') +
131 'Rollback of %s complete.', self.release) 134 'Rollback of %s complete.', self.release)