From 89aada4f5e6bd52afd284ed8b2a27a5b36e677bb Mon Sep 17 00:00:00 2001 From: tierno Date: Wed, 19 Dec 2018 16:00:25 +0000 Subject: [PATCH] allow pdu without image Change-Id: Icb02d22d2c1497c1af5cfeff2702d2757bcdcda1 Signed-off-by: tierno --- database_utils/migrate_mano_db.sh | 23 ++++++++++++++++++++++- openmanod | 4 ++-- osm_ro/nfvo.py | 7 ++++++- osm_ro/nfvo_db.py | 28 ++++++++++++++++------------ 4 files changed, 46 insertions(+), 16 deletions(-) diff --git a/database_utils/migrate_mano_db.sh b/database_utils/migrate_mano_db.sh index 4819db4f..3970a7ca 100755 --- a/database_utils/migrate_mano_db.sh +++ b/database_utils/migrate_mano_db.sh @@ -34,7 +34,7 @@ DBPORT="3306" DBNAME="mano_db" QUIET_MODE="" #TODO update it with the last database version -LAST_DB_VERSION=35 +LAST_DB_VERSION=36 # Detect paths MYSQL=$(which mysql) @@ -204,6 +204,7 @@ fi #[ $OPENMANO_VER_NUM -ge 5082 ] && DB_VERSION=33 #0.5.82 => 33 #[ $OPENMANO_VER_NUM -ge 6000 ] && DB_VERSION=34 #0.6.00 => 34 #[ $OPENMANO_VER_NUM -ge 6001 ] && DB_VERSION=35 #0.6.01 => 35 +#[ $OPENMANO_VER_NUM -ge 6003 ] && DB_VERSION=35 #0.6.03 => 36 #TODO ... put next versions here function upgrade_to_1(){ @@ -1337,6 +1338,26 @@ function downgrade_from_35(){ script="$(find "${DBUTILS}/migrations/down" -iname "35*.sql" | tail -1)" sql "source ${script}" } +function upgrade_to_36(){ + echo " Allow null for image_id at 'vms'" + sql "ALTER TABLE vms ALTER image_id DROP DEFAULT;" + sql "ALTER TABLE vms CHANGE COLUMN image_id image_id VARCHAR(36) NULL COMMENT 'Link to image table' AFTER " \ + "flavor_id;" + echo " Enlarge config at 'wims' and 'wim_accounts'" + sql "ALTER TABLE wims CHANGE COLUMN config config TEXT NULL DEFAULT NULL AFTER wim_url;" + sql "ALTER TABLE wim_accounts CHANGE COLUMN config config TEXT NULL DEFAULT NULL AFTER password;" + sql "INSERT INTO schema_version (version_int, version, openmano_ver, comments, date) "\ + "VALUES (36, '0.36', '0.6.03', 'Allow vm without image_id for PDUs', '2018-12-19');" +} +function downgrade_from_36(){ + echo " Force back not null for image_id at 'vms'" + sql "ALTER TABLE vms ALTER image_id DROP DEFAULT;" + sql "ALTER TABLE vms CHANGE COLUMN image_id image_id VARCHAR(36) NOT NULL COMMENT 'Link to image table' AFTER " \ + "flavor_id;" + # For downgrade do not restore wims/wim_accounts config to varchar 4000 + sql "DELETE FROM schema_version WHERE version_int='36';" +} + #TODO ... put functions here # echo "db version = "${DATABASE_VER_NUM} diff --git a/openmanod b/openmanod index f16a54cd..ba60e25c 100755 --- a/openmanod +++ b/openmanod @@ -50,9 +50,9 @@ import osm_ro __author__ = "Alfonso Tierno, Gerardo Garcia, Pablo Montes" __date__ = "$26-aug-2014 11:09:29$" -__version__ = "0.6.02" +__version__ = "0.6.03" version_date = "Dec 2018" -database_version = 35 # expected database schema version +database_version = 36 # expected database schema version global global_config global logger diff --git a/osm_ro/nfvo.py b/osm_ro/nfvo.py index 12906900..00738e98 100644 --- a/osm_ro/nfvo.py +++ b/osm_ro/nfvo.py @@ -343,7 +343,7 @@ def get_imagelist(mydb, vnf_id, nfvo_tenant=None): image_list = [] vms = mydb.get_rows(SELECT=('image_id','image_list'), FROM='vms', WHERE={'vnf_id': vnf_id}) for vm in vms: - if vm["image_id"] not in image_list: + if vm["image_id"] and vm["image_id"] not in image_list: image_list.append(vm["image_id"]) if vm["image_list"]: vm_image_list = yaml.load(vm["image_list"]) @@ -1069,6 +1069,11 @@ def new_vnfd_v3(mydb, tenant_id, vnf_descriptor): devices.append(device) + if not db_vm.get("image_id"): + if not db_vm["pdu_type"]: + raise NfvoException("Not defined image for VDU") + # create a fake image + # cloud-init boot_data = {} if vdu.get("cloud-init"): diff --git a/osm_ro/nfvo_db.py b/osm_ro/nfvo_db.py index 99562e0e..bad7cec2 100644 --- a/osm_ro/nfvo_db.py +++ b/osm_ro/nfvo_db.py @@ -629,18 +629,22 @@ class nfvo_db(db_base.db_base): else: del vm["image_list"] if datacenter_vim_id!=None: - cmd = "SELECT vim_id FROM datacenters_images WHERE image_id='{}' AND datacenter_vim_id='{}'".format(vm['image_id'],datacenter_vim_id) - self.logger.debug(cmd) - self.cur.execute(cmd) - if self.cur.rowcount==1: - vim_image_dict = self.cur.fetchone() - vm['vim_image_id']=vim_image_dict['vim_id'] - cmd = "SELECT vim_id FROM datacenters_flavors WHERE flavor_id='{}' AND datacenter_vim_id='{}'".format(vm['flavor_id'],datacenter_vim_id) - self.logger.debug(cmd) - self.cur.execute(cmd) - if self.cur.rowcount==1: - vim_flavor_dict = self.cur.fetchone() - vm['vim_flavor_id']=vim_flavor_dict['vim_id'] + if vm['image_id']: + cmd = "SELECT vim_id FROM datacenters_images WHERE image_id='{}' AND " \ + "datacenter_vim_id='{}'".format(vm['image_id'], datacenter_vim_id) + self.logger.debug(cmd) + self.cur.execute(cmd) + if self.cur.rowcount==1: + vim_image_dict = self.cur.fetchone() + vm['vim_image_id']=vim_image_dict['vim_id'] + if vm['flavor_id']: + cmd = "SELECT vim_id FROM datacenters_flavors WHERE flavor_id='{}' AND " \ + "datacenter_vim_id='{}'".format(vm['flavor_id'], datacenter_vim_id) + self.logger.debug(cmd) + self.cur.execute(cmd) + if self.cur.rowcount==1: + vim_flavor_dict = self.cur.fetchone() + vm['vim_flavor_id']=vim_flavor_dict['vim_id'] #interfaces cmd = "SELECT uuid,internal_name,external_name,net_id,type,vpci,mac,bw,model,ip_address," \ -- 2.25.1