allow pdu without image 75/7075/2
authortierno <alfonso.tiernosepulveda@telefonica.com>
Wed, 19 Dec 2018 16:00:25 +0000 (16:00 +0000)
committertierno <alfonso.tiernosepulveda@telefonica.com>
Fri, 21 Dec 2018 13:08:17 +0000 (13:08 +0000)
Change-Id: Icb02d22d2c1497c1af5cfeff2702d2757bcdcda1
Signed-off-by: tierno <alfonso.tiernosepulveda@telefonica.com>
database_utils/migrate_mano_db.sh
openmanod
osm_ro/nfvo.py
osm_ro/nfvo_db.py

index 4819db4..3970a7c 100755 (executable)
@@ -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}
index f16a54c..ba60e25 100755 (executable)
--- 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
index 1290690..00738e9 100644 (file)
@@ -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"):
index 99562e0..bad7cec 100644 (file)
@@ -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," \