From 9dfed63d574ad68e7a22c98ef9aac1f2a3bd172b Mon Sep 17 00:00:00 2001 From: Sam Thursfield Date: Thu, 18 Jun 2015 16:56:07 +0000 Subject: Raise exception if show-build-log doesn't find the build log Previously it would print nothing and then exit with success. Better to tell the user that an error occurred. Example of the new error: ERROR: No build log for artifact 6fb39673b8f9a1c9848063f5132aa958ffa75f2be61a8dde68ebb11f5a3c4a5f found on cache server http://cache.baserock.org:8080/ Change-Id: Icf8ceef60eb497ff90e00391d442a394e3d76f10 --- morphlib/plugins/show_build_log_plugin.py | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) (limited to 'morphlib/plugins') diff --git a/morphlib/plugins/show_build_log_plugin.py b/morphlib/plugins/show_build_log_plugin.py index 6f22036a..38b62540 100644 --- a/morphlib/plugins/show_build_log_plugin.py +++ b/morphlib/plugins/show_build_log_plugin.py @@ -86,11 +86,20 @@ class ShowBuildLog(cliapp.Plugin): if cache_key: url = urlparse.urljoin(artifact_cache_server, '/1.0/artifacts?filename=%s.build-log' % source.cache_key) - build_log = urllib.urlopen(url) - build_output = [] - for line in build_log: - build_output.append(str(line)) - self.app.output.write(''.join(build_output)) + response = urllib.urlopen(url) + if response.getcode() == 200: + build_output = [] + for line in response: + build_output.append(str(line)) + self.app.output.write(''.join(build_output)) + elif response.getcode() == 404: + raise cliapp.AppException( + 'No build log for artifact %s found on cache server %s' % + (source.cache_key, artifact_cache_server)) + else: + raise cliapp.AppException( + 'Error connecting to cache server %s: %s' % + (artifact_cache_server, response.getcode())) else: raise cliapp.AppException('Component not found in the given ' 'system.') -- cgit v1.2.1