summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZuul <zuul@review.openstack.org>2019-03-04 22:39:16 +0000
committerGerrit Code Review <review@openstack.org>2019-03-04 22:39:16 +0000
commit24867f34db3fcc2283ea353560b141ce7da41089 (patch)
treee075d2f7b0c1a987863add35e54220f02c133b00
parente7c7a86f48f0403a81f2cf78b656a92be3d47874 (diff)
parentb458c3f675b7cd8a16916539eb338a729fd84def (diff)
Merge "Refactor tiller commands to handle methods"
-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 41fa771..62f8d70 100644
--- a/armada/cli/apply.py
+++ b/armada/cli/apply.py
@@ -207,20 +207,8 @@ class ApplyManifest(CliAction):
207 tiller_namespace=self.tiller_namespace, 207 tiller_namespace=self.tiller_namespace,
208 bearer_token=self.bearer_token, 208 bearer_token=self.bearer_token,
209 dry_run=self.dry_run) as tiller: 209 dry_run=self.dry_run) as tiller:
210 armada = Armada( 210
211 documents, 211 resp = self.handle(documents, tiller)
212 disable_update_pre=self.disable_update_pre,
213 disable_update_post=self.disable_update_post,
214 enable_chart_cleanup=self.enable_chart_cleanup,
215 dry_run=self.dry_run,
216 set_ovr=self.set,
217 force_wait=self.wait,
218 timeout=self.timeout,
219 tiller=tiller,
220 values=self.values,
221 target_manifest=self.target_manifest)
222
223 resp = armada.sync()
224 self.output(resp) 212 self.output(resp)
225 else: 213 else:
226 if len(self.values) > 0: 214 if len(self.values) > 0:
@@ -248,3 +236,18 @@ class ApplyManifest(CliAction):
248 resp = client.post_apply( 236 resp = client.post_apply(
249 manifest=documents, set=self.set, query=query) 237 manifest=documents, set=self.set, query=query)
250 self.output(resp.get('message')) 238 self.output(resp.get('message'))
239
240 def handle(self, documents, tiller):
241 armada = Armada(
242 documents,
243 disable_update_pre=self.disable_update_pre,
244 disable_update_post=self.disable_update_post,
245 enable_chart_cleanup=self.enable_chart_cleanup,
246 dry_run=self.dry_run,
247 set_ovr=self.set,
248 force_wait=self.wait,
249 timeout=self.timeout,
250 tiller=tiller,
251 values=self.values,
252 target_manifest=self.target_manifest)
253 return armada.sync()
diff --git a/armada/cli/rollback.py b/armada/cli/rollback.py
index f3bc5e8..8923544 100644
--- a/armada/cli/rollback.py
+++ b/armada/cli/rollback.py
@@ -119,16 +119,19 @@ class Rollback(CliAction):
119 bearer_token=self.bearer_token, 119 bearer_token=self.bearer_token,
120 dry_run=self.dry_run) as tiller: 120 dry_run=self.dry_run) as tiller:
121 121
122 response = tiller.rollback_release( 122 response = self.handle(tiller)
123 self.release,
124 self.version,
125 wait=self.wait,
126 timeout=self.timeout,
127 force=self.force,
128 recreate_pods=self.recreate_pods)
129 123
130 self.output(response) 124 self.output(response)
131 125
126 def handle(self, tiller):
127 return tiller.rollback_release(
128 self.release,
129 self.version,
130 wait=self.wait,
131 timeout=self.timeout,
132 force=self.force,
133 recreate_pods=self.recreate_pods)
134
132 def output(self, response): 135 def output(self, response):
133 self.logger.info(('(dry run) ' if self.dry_run else '') + 136 self.logger.info(('(dry run) ' if self.dry_run else '') +
134 'Rollback of %s complete.', self.release) 137 'Rollback of %s complete.', self.release)