From a42876c34c8976c99662c0af4d4b72e8bfeca045 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20M=C3=A1gr?= Date: Fri, 27 Oct 2017 16:21:43 +0200 Subject: [PATCH] Fix glance_upload check This patch makes oschecks-check_glance_upload compatible with python-glanceclient-2.8.0+ Change-Id: Ifd41e48b0709e72773de18f571cfad58ea44b37a --- monitoring-for-openstack/oschecks/glance.py | 32 +++++++++++++++------ 1 file changed, 23 insertions(+), 9 deletions(-) diff --git a/monitoring-for-openstack/oschecks/glance.py b/monitoring-for-openstack/oschecks/glance.py index 67f985f..57a2565 100644 --- a/monitoring-for-openstack/oschecks/glance.py +++ b/monitoring-for-openstack/oschecks/glance.py @@ -18,6 +18,9 @@ # License for the specific language governing permissions and limitations # under the License. + +import StringIO + from oschecks import utils @@ -105,6 +108,18 @@ def check_glance_image_exists(): utils.safe_run(_check_glance_image_exists) +def _upload_image(client, name): + data = StringIO.StringIO("X" * 1024 * 1024) + img = client.images.create(name=name, + disk_format='raw', + container_format='bare') + try: + client.images.upload(img.id, data) + except Exception: + client.images.delete(img.id) + raise + return img.id + def _check_glance_upload(): glance = utils.Glance() glance.add_argument('--monitoring-image', dest='image_name', type=str, @@ -112,16 +127,15 @@ def _check_glance_upload(): help='Name of the monitoring image') options, args, client = glance.setup() - data_raw = "X" * 1024 * 1024 - elapsed, res = utils.timeit(client.images.create, - data=data_raw, - disk_format='raw', - container_format='bare', + elapsed, iid = utils.timeit(_upload_image, + client=client, name=options.image_name) - if not res or not res.id or res.status != 'active': - utils.critical("Unable to upload image in Glance") - - res.delete() + try: + res = client.images.get(iid) + if res.status != 'active': + utils.critical("Unable to upload image in Glance") + finally: + client.images.delete(res.id) if elapsed > 20: utils.warning("Upload image in 20 seconds, it's too long")