From cea279c3acfbe2aa2bbd22db62b15fbd10d2c77b Mon Sep 17 00:00:00 2001 From: tierno Date: Mon, 18 Jul 2016 12:36:49 +0200 Subject: [PATCH] v0.4.43 fixes #27 #29 names at vnfs, scenarios, instances can be repeated. Only visible by the owner tenant or public Change-Id: Ie8a1c4edc8eee15bfc46d08ab8d1ad522bb13ecd Signed-off-by: tierno --- database_utils/migrate_mano_db.sh | 16 ++++++++++++++++ nfvo.py | 30 ++++++++++++++++++++---------- openmanod.py | 4 ++-- 3 files changed, 38 insertions(+), 12 deletions(-) diff --git a/database_utils/migrate_mano_db.sh b/database_utils/migrate_mano_db.sh index 86a3b77b..c6983cae 100755 --- a/database_utils/migrate_mano_db.sh +++ b/database_utils/migrate_mano_db.sh @@ -164,6 +164,7 @@ DATABASE_TARGET_VER_NUM=0 [ $OPENMANO_VER_NUM -ge 4032 ] && DATABASE_TARGET_VER_NUM=8 #0.4.32=> 8 [ $OPENMANO_VER_NUM -ge 4033 ] && DATABASE_TARGET_VER_NUM=9 #0.4.33=> 9 [ $OPENMANO_VER_NUM -ge 4036 ] && DATABASE_TARGET_VER_NUM=10 #0.4.36=> 10 +[ $OPENMANO_VER_NUM -ge 4043 ] && DATABASE_TARGET_VER_NUM=11 #0.4.43=> 11 #TODO ... put next versions here @@ -542,6 +543,21 @@ function downgrade_from_10(){ echo "DELETE FROM schema_version WHERE version_int='10';" | $DBCMD || ! echo "ERROR. Aborted!" || exit -1 } +function upgrade_to_11(){ + echo " upgrade database from version 0.10 to version 0.11" + echo " remove unique name at 'scenarios', 'instance_scenarios'" + echo "ALTER TABLE scenarios DROP INDEX name;" | $DBCMD || ! echo "ERROR. Aborted!" || exit -1 + echo "ALTER TABLE instance_scenarios DROP INDEX name;" | $DBCMD || ! echo "ERROR. Aborted!" || exit -1 + echo "INSERT INTO schema_version (version_int, version, openmano_ver, comments, date) VALUES (11, '0.11', '0.4.43', 'remove unique name at scenarios,instance_scenarios', '2016-07-18');" | $DBCMD || ! echo "ERROR. Aborted!" || exit -1 +} +function downgrade_from_11(){ + echo " downgrade database from version 0.11 to version 0.10" + echo " add unique name at 'scenarios', 'instance_scenarios'" + echo "ALTER TABLE scenarios ADD UNIQUE INDEX name (name);" | $DBCMD || ! echo "ERROR. Aborted!" || exit -1 + echo "ALTER TABLE instance_scenarios ADD UNIQUE INDEX name (name);" | $DBCMD || ! echo "ERROR. Aborted!" || exit -1 + echo "DELETE FROM schema_version WHERE version_int='11';" | $DBCMD || ! echo "ERROR. Aborted!" || exit -1 +} + function upgrade_to_X(){ echo " change 'datacenter_nets'" echo "ALTER TABLE datacenter_nets ADD COLUMN vim_tenant_id VARCHAR(36) NOT NULL AFTER datacenter_id, DROP INDEX name_datacenter_id, ADD UNIQUE INDEX name_datacenter_id (name, datacenter_id, vim_tenant_id);" | $DBCMD || ! echo "ERROR. Aborted!" || exit -1 diff --git a/nfvo.py b/nfvo.py index 13d5c9e2..9c6dace5 100644 --- a/nfvo.py +++ b/nfvo.py @@ -768,19 +768,24 @@ def new_scenario(mydb, tenant_id, topo): #1.2: Check that VNF are present at database table vnfs. Insert uuid, description and external interfaces for name,vnf in vnfs.items(): - WHERE_={} + where={} + where_or={"tenant_id": tenant_id, 'public': "true"} error_text = "" error_pos = "'topology':'nodes':'" + name + "'" if 'vnf_id' in vnf: error_text += " 'vnf_id' " + vnf['vnf_id'] - WHERE_['uuid'] = vnf['vnf_id'] + where['uuid'] = vnf['vnf_id'] if 'VNF model' in vnf: error_text += " 'VNF model' " + vnf['VNF model'] - WHERE_['name'] = vnf['VNF model'] - if len(WHERE_) == 0: + where['name'] = vnf['VNF model'] + if len(where) == 0: raise NfvoException("Descriptor need a 'vnf_id' or 'VNF model' field at " + error_pos, HTTP_Bad_Request) - vnf_db = mydb.get_rows(SELECT=('uuid','name','description'), FROM='vnfs', WHERE=WHERE_) + vnf_db = mydb.get_rows(SELECT=('uuid','name','description'), + FROM='vnfs', + WHERE=where, + WHERE_OR=where_or, + WHERE_AND_OR="AND") if len(vnf_db)==0: raise NfvoException("unknown" + error_text + " at " + error_pos, HTTP_Not_Found) elif len(vnf_db)>1: @@ -1024,18 +1029,23 @@ def new_scenario_v02(mydb, tenant_id, scenario_dict): #1: Check that VNF are present at database table vnfs and update content into scenario dict for name,vnf in scenario["vnfs"].iteritems(): - WHERE_={} + where={} + where_or={"tenant_id": tenant_id, 'public': "true"} error_text = "" error_pos = "'topology':'nodes':'" + name + "'" if 'vnf_id' in vnf: error_text += " 'vnf_id' " + vnf['vnf_id'] - WHERE_['uuid'] = vnf['vnf_id'] + where['uuid'] = vnf['vnf_id'] if 'vnf_name' in vnf: error_text += " 'vnf_name' " + vnf['vnf_name'] - WHERE_['name'] = vnf['vnf_name'] - if len(WHERE_) == 0: + where['name'] = vnf['vnf_name'] + if len(where) == 0: raise NfvoException("Needed a 'vnf_id' or 'VNF model' at " + error_pos, HTTP_Bad_Request) - vnf_db = mydb.get_rows(SELECT=('uuid','name','description'), FROM='vnfs', WHERE=WHERE_) + vnf_db = mydb.get_rows(SELECT=('uuid','name','description'), + FROM='vnfs', + WHERE=where, + WHERE_OR=where_or, + WHERE_AND_OR="AND") if len(vnf_db)==0: raise NfvoException("Unknown" + error_text + " at " + error_pos, HTTP_Not_Found) elif len(vnf_db)>1: diff --git a/openmanod.py b/openmanod.py index dbfd5054..f2cfb7e5 100755 --- a/openmanod.py +++ b/openmanod.py @@ -33,9 +33,9 @@ It loads the configuration file and launches the http_server thread that will li ''' __author__="Alfonso Tierno, Gerardo Garcia, Pablo Montes" __date__ ="$26-aug-2014 11:09:29$" -__version__="0.4.42-r479" +__version__="0.4.43-r480" version_date="Jul 2016" -database_version="0.10" #expected database schema version +database_version="0.11" #expected database schema version import httpserver import time -- 2.25.1