From: Adam Israel Date: Mon, 21 Nov 2016 20:19:42 +0000 (-0500) Subject: Fix idempotency issues that could cause install/configuration failures X-Git-Tag: v1.0.3~1^2~6^2 X-Git-Url: https://osm.etsi.org/gitweb/?a=commitdiff_plain;h=942ae4f66349e297106f2e02a7d7776c67c34e38;p=osm%2FRO.git Fix idempotency issues that could cause install/configuration failures Signed-off-by: Adam Israel --- diff --git a/charms/layers/openmano/reactive/layer_openmano.py b/charms/layers/openmano/reactive/layer_openmano.py index cc1b4741..2320e918 100644 --- a/charms/layers/openmano/reactive/layer_openmano.py +++ b/charms/layers/openmano/reactive/layer_openmano.py @@ -32,17 +32,18 @@ INSTALL_PATH = '/opt/openmano' USER = 'openmanod' -@when('openmano.installed') -@when('openmano.available') +@when('openmano.installed', 'openmano.available') def openmano_available(openmano): # TODO make this configurable via charm config openmano.configure(port=9090) -@when('openmano.installed') -@when('db.available', 'db.installed') -@when('openvim-controller.available') -@when('openmano.running') +@when('openvim-controller.available', + 'db.available', + 'db.installed', + 'openmano.installed', + 'openmano.running', + ) def openvim_available(openvim, db): for service in openvim.services(): for endpoint in service['hosts']: @@ -71,9 +72,9 @@ def openvim_available(openvim, db): break -@when('openmano.installed') -@when('db.available', 'db.installed') -@when('openvim-controller.available') +@when('openmano.installed', + 'db.installed', + 'openvim-controller.available') @when_not('openmano.running') def start(*args): # TODO: if the service fails to start, we should raise an error to the op @@ -95,8 +96,7 @@ def start(*args): set_state('openmano.running') -@when('openmano.installed') -@when('db.available') +@when('db.available', 'openmano.installed') @when_not('db.installed') def setup_db(db): """Setup the database @@ -151,6 +151,7 @@ def setup_db(db): status_set('active', 'Database installed.') set_state('db.installed') + @when_not('openvim-controller.available') def need_openvim(): status_set('waiting', 'Waiting for OpenVIM') diff --git a/charms/layers/openmano/scripts/create-datacenter.sh b/charms/layers/openmano/scripts/create-datacenter.sh index 4b192e49..6aafab53 100755 --- a/charms/layers/openmano/scripts/create-datacenter.sh +++ b/charms/layers/openmano/scripts/create-datacenter.sh @@ -4,20 +4,33 @@ OPENMANO=$HOME/bin/openmano export OPENMANO_TENANT=$4 OPENMANO_DATACENTER=`$OPENMANO datacenter-list myov` -if [ $? -ne 0 ]; then +if [ $? -eq 0 ]; then + # If the datacenter exists, the current approach is to delete the existing + # one and create a new one. We may want to change this behavior to retain + # the existing datacenter, but this script will also go away in favour of + # a python API to OpenMano + + # If the datacenter exists, remove all traces of it before continuing + OPENMANO_DATACENTER=`echo $OPENMANO_DATACENTER |gawk '{print $1}'` + + # Delete netmap + $OPENMANO datacenter-netmap-delete --all -f --datacenter $OPENMANO_DATACENTER + + # detach + $OPENMANO datacenter-detach -a $OPENMANO_DATACENTER + # Make sure the datacenter is deleted - $OPENMANO datacenter-delete myov + $OPENMANO datacenter-delete --force myov + OPENMANO_DATACENTER=`$OPENMANO datacenter-create myov http://$1:$2/openvim` fi -export OPENMANO_DATACENTER=`echo $OPENMANO_DATACENTER |gawk '{print $1}'` +OPENMANO_DATACENTER=`echo $OPENMANO_DATACENTER |gawk '{print $1}'` -#export OPENMANO_DATACENTER=`$OPENMANO datacenter-create myov http://$1:$2/openvim |gawk '{print $1}'` -# FIXME: don't add this to .bashrc if it already exists. -if ! grep -q "^export OPENMANO_DATACENTER" $HOME/.bashrc -then - echo "export OPENMANO_DATACENTER=$OPENMANO_DATACENTER " >> $HOME/.bashrc -fi -# TODO: Test idempotency. We may need to check and remove existing data +# if ! grep -q "^export OPENMANO_DATACENTER" $HOME/.bashrc +# then +# echo "export OPENMANO_DATACENTER=$OPENMANO_DATACENTER " >> $HOME/.bashrc +# fi + $OPENMANO datacenter-attach myov --vim-tenant-id $3 $OPENMANO datacenter-netmap-import -f --datacenter $OPENMANO_DATACENTER