From 49aac3d607ba6a3399a8cf1cd7724f949617dc5a Mon Sep 17 00:00:00 2001 From: Mehdi Abaakouk Date: Fri, 6 Jan 2017 14:03:10 +0100 Subject: [PATCH] fix the gnocchi resource type upgrade This fixes the upgrade code to return -1 on exception, and the volume updates dict. Change-Id: I3eb2f718428082d4c637cf0f13d503737cfcf1cb --- ceilometer/gnocchi_client.py | 33 +++++++++++++-------------------- devstack/plugin.sh | 4 ---- 2 files changed, 13 insertions(+), 24 deletions(-) diff --git a/ceilometer/gnocchi_client.py b/ceilometer/gnocchi_client.py index 8f7cff8643..8aca6e61c7 100644 --- a/ceilometer/gnocchi_client.py +++ b/ceilometer/gnocchi_client.py @@ -93,15 +93,16 @@ resources_initial = { # NOTE(sileht): Order matter this have to be considered like alembic migration # code, because it updates the resources schema of Gnocchi -resources_update_operation = [ +resources_update_operations = [ {"desc": "add volume_type to volume", "type": "update_attribute_type", "resource_type": "volume", - "data": { + "data": [{ "op": "add", "path": "/attributes/volume_type", "value": {"type": "string", "min_length": 0, "max_length": 255, - "required": False}}}, + "required": False} + }]}, ] @@ -112,23 +113,15 @@ def upgrade_resource_types(conf): gnocchi.resource_type.get(name=name) except gnocchi_exc.ResourceTypeNotFound: rt = {'name': name, 'attributes': attributes} - try: - gnocchi.resource_type.create(resource_type=rt) - except Exception: - LOG.error("Gnocchi resource creation fail", exc_info=True) - return + gnocchi.resource_type.create(resource_type=rt) - for op in resources_update_operation: - if op['type'] == 'update_attribute_type': - rt = gnocchi.resource_type.get(name=op['resource_type']) - attrib = op['data']['path'].replace('/attributes', '') - if op['data']['op'] == 'add' and attrib in rt['attributes']: + for ops in resources_update_operations: + if ops['type'] == 'update_attribute_type': + rt = gnocchi.resource_type.get(name=ops['resource_type']) + first_op = ops['data'][0] + attrib = first_op['path'].replace('/attributes', '') + if first_op['op'] == 'add' and attrib in rt['attributes']: continue - if op['data']['op'] == 'remove' and attrib not in rt['attributes']: + if first_op['op'] == 'remove' and attrib not in rt['attributes']: continue - try: - gnocchi.resource_type.update(op['resource_type'], op['data']) - except Exception: - LOG.error("Gnocchi resource update fail: %s", op['desc'], - exc_info=True) - return + gnocchi.resource_type.update(ops['resource_type'], ops['data']) diff --git a/devstack/plugin.sh b/devstack/plugin.sh index 744adfe8e9..063fee1be9 100644 --- a/devstack/plugin.sh +++ b/devstack/plugin.sh @@ -350,16 +350,12 @@ function init_ceilometer { if is_service_enabled mysql postgresql ; then if [ "$CEILOMETER_BACKEND" = 'mysql' ] || [ "$CEILOMETER_BACKEND" = 'postgresql' ] || [ "$CEILOMETER_BACKEND" = 'es' ] ; then recreate_database ceilometer - set -e $CEILOMETER_BIN_DIR/ceilometer-upgrade --skip-gnocchi-resource-types - set +e fi fi if is_service_enabled gnocchi ; then if [ "$CEILOMETER_BACKEND" = 'gnocchi' ]; then - set -e $CEILOMETER_BIN_DIR/ceilometer-upgrade --skip-metering-database - set +e fi fi fi