From 0c317ee648f2bec1c4fc2158ff3e4b6fb18e0ac5 Mon Sep 17 00:00:00 2001 From: garciadeblas Date: Mon, 29 Aug 2016 12:33:06 +0200 Subject: [PATCH] Changes in database for allowing IP parameters, changes in DB migration script, new DB version 12, small changes in openmano_schemas and other files to deal with new DB version, basictest run successfully Change-Id: I30e00c5bcd30aab35a39746dbf568dac4164f247 Signed-off-by: garciadeblas --- database_utils/init_mano_db.sh | 21 ++++++++++++++---- database_utils/migrate_mano_db.sh | 37 +++++++++++++++++++++++++++++++ httpserver.py | 4 ++-- nfvo.py | 1 + nfvo_db.py | 2 +- openmano_schemas.py | 31 +++++++++++++------------- openmanod.py | 4 ++-- test/basictest.sh | 2 +- 8 files changed, 77 insertions(+), 25 deletions(-) diff --git a/database_utils/init_mano_db.sh b/database_utils/init_mano_db.sh index cbb76ef4..8afd9c22 100755 --- a/database_utils/init_mano_db.sh +++ b/database_utils/init_mano_db.sh @@ -26,6 +26,7 @@ DBPASS="" DBHOST="localhost" DBPORT="3306" DBNAME="mano_db" +CREATEDB="" # Detect paths MYSQL=$(which mysql) @@ -43,6 +44,7 @@ function usage(){ echo -e " -h HOST database host. '$DBHOST' by default" echo -e " -d NAME database name. '$DBNAME' by default. Prompts if DB access fails" echo -e " --help shows this help" + echo -e " --createdb forces the deletion and creation of the database" } while getopts ":u:p:P:d:h:-:" o; do @@ -63,9 +65,14 @@ while getopts ":u:p:P:d:h:-:" o; do DBHOST="$OPTARG" ;; -) - [ "${OPTARG}" == "help" ] && usage && exit 0 - echo "Invalid option: --$OPTARG" >&2 && usage >&2 - exit 1 + if [ "${OPTARG}" == "help" ]; then + usage && exit 0 + elif [ "${OPTARG}" == "createdb" ]; then + CREATEDB="yes" + else + echo "Invalid option: --$OPTARG" >&2 && usage >&2 + exit 1 + fi ;; \?) echo "Invalid option: -$OPTARG" >&2 && usage >&2 @@ -104,7 +111,13 @@ do echo done -#${DIRNAME}/quick_delete_db.sh $MUSER $MPASS $MDB $HOST $PORT +if [ -n "${CREATEDB}" ]; then + echo " deleting previous database ${DBNAME}" + echo "DROP DATABASE IF EXISTS ${DBNAME}" | mysql $DBHOST_ $DBPORT_ $DBUSER_ $DBPASS_ + echo " creating database ${DBNAME}" + mysqladmin $DBUSER_ $DBPASS_ -s create ${DBNAME} || exit 1 +fi + echo " loading ${DIRNAME}/${DBNAME}_structure.sql" mysql $DBHOST_ $DBPORT_ $DBUSER_ $DBPASS_ $DBNAME < ${DIRNAME}/mano_db_structure.sql diff --git a/database_utils/migrate_mano_db.sh b/database_utils/migrate_mano_db.sh index c6983cae..f7c2b1bb 100755 --- a/database_utils/migrate_mano_db.sh +++ b/database_utils/migrate_mano_db.sh @@ -165,6 +165,7 @@ DATABASE_TARGET_VER_NUM=0 [ $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 +[ $OPENMANO_VER_NUM -ge 4046 ] && DATABASE_TARGET_VER_NUM=12 #0.4.46=> 12 #TODO ... put next versions here @@ -558,6 +559,42 @@ function downgrade_from_11(){ echo "DELETE FROM schema_version WHERE version_int='11';" | $DBCMD || ! echo "ERROR. Aborted!" || exit -1 } +function upgrade_to_12(){ + echo " upgrade database from version 0.11 to version 0.12" + echo " create ip_profiles table, with foreign keys to all nets tables, and add ip_address column to 'interfaces' and 'sce_interfaces'" + echo "CREATE TABLE ip_profiles ( + id INT(11) NOT NULL AUTO_INCREMENT, + net_id VARCHAR(36) NULL DEFAULT NULL, + sce_net_id VARCHAR(36) NULL DEFAULT NULL, + instance_net_id VARCHAR(36) NULL DEFAULT NULL, + ip_version ENUM('IPv4','IPv6') NOT NULL DEFAULT 'IPv4', + subnet_address VARCHAR(64) NULL DEFAULT NULL, + gateway_address VARCHAR(64) NULL DEFAULT NULL, + security_group VARCHAR(255) NULL DEFAULT NULL, + dns_address VARCHAR(64) NULL DEFAULT NULL, + dhcp_enabled ENUM('true','false') NOT NULL DEFAULT 'true', + dhcp_start_address VARCHAR(64) NULL DEFAULT NULL, + dhcp_count INT(11) NULL DEFAULT NULL, + PRIMARY KEY (id), + CONSTRAINT FK_ipprofiles_nets FOREIGN KEY (net_id) REFERENCES nets (uuid) ON DELETE CASCADE, + CONSTRAINT FK_ipprofiles_scenets FOREIGN KEY (sce_net_id) REFERENCES sce_nets (uuid) ON DELETE CASCADE, + CONSTRAINT FK_ipprofiles_instancenets FOREIGN KEY (instance_net_id) REFERENCES instance_nets (uuid) ON DELETE CASCADE ) + COMMENT='Table containing the IP parameters of a network, either a net, a sce_net or and instance_net.' + COLLATE='utf8_general_ci' + ENGINE=InnoDB;" | $DBCMD || ! echo "ERROR. Aborted!" || exit -1 + echo "ALTER TABLE interfaces ADD COLUMN ip_address VARCHAR(64) NULL DEFAULT NULL AFTER mac;" | $DBCMD || ! echo "ERROR. Aborted!" || exit -1 + echo "ALTER TABLE sce_interfaces ADD COLUMN ip_address VARCHAR(64) NULL DEFAULT NULL AFTER interface_id;" | $DBCMD || ! echo "ERROR. Aborted!" || exit -1 + echo "INSERT INTO schema_version (version_int, version, openmano_ver, comments, date) VALUES (12, '0.12', '0.4.46', 'create ip_profiles table, with foreign keys to all nets tables, and add ip_address column to interfaces and sce_interfaces', '2016-07-18');" | $DBCMD || ! echo "ERROR. Aborted!" || exit -1 +} +function downgrade_from_12(){ + echo " downgrade database from version 0.12 to version 0.11" + echo " delete ip_profiles table, and remove ip_address column in 'interfaces' and 'sce_interfaces'" + echo "DROP TABLE ip_profiles;" | $DBCMD || ! echo "ERROR. Aborted!" || exit -1 + echo "ALTER TABLE interfaces DROP COLUMN ip_address;" | $DBCMD || ! echo "ERROR. Aborted!" || exit -1 + echo "ALTER TABLE sce_interfaces DROP COLUMN ip_address;" | $DBCMD || ! echo "ERROR. Aborted!" || exit -1 + echo "DELETE FROM schema_version WHERE version_int='12';" | $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/httpserver.py b/httpserver.py index 680fddf7..771ff1b0 100644 --- a/httpserver.py +++ b/httpserver.py @@ -39,7 +39,7 @@ import logging from jsonschema import validate as js_v, exceptions as js_e from openmano_schemas import vnfd_schema_v01, vnfd_schema_v02, \ nsd_schema_v01, nsd_schema_v02, scenario_edit_schema, \ - scenario_action_schema, instance_scenario_action_schema, instance_scenario_create_schema, \ + scenario_action_schema, instance_scenario_action_schema, instance_scenario_create_schema_v01, \ tenant_schema, tenant_edit_schema,\ datacenter_schema, datacenter_edit_schema, datacenter_action_schema, datacenter_associate_schema,\ object_schema, netmap_new_schema, netmap_edit_schema @@ -973,7 +973,7 @@ def http_post_instances(tenant_id): if tenant_id != "any": nfvo.check_tenant(mydb, tenant_id) #parse input data - http_content,used_schema = format_in( instance_scenario_create_schema) + http_content,used_schema = format_in( instance_scenario_create_schema_v01) r = utils.remove_extra_items(http_content, used_schema) if r is not None: print "http_post_instances: Warning: remove extra items ", r data = nfvo.create_instance(mydb, tenant_id, http_content["instance"]) diff --git a/nfvo.py b/nfvo.py index 25a484bf..c33a44b0 100644 --- a/nfvo.py +++ b/nfvo.py @@ -1318,6 +1318,7 @@ def start_scenario(mydb, tenant_id, scenario_id, instance_scenario_name, instanc def create_instance(mydb, tenant_id, instance_dict): #print "Checking that nfvo_tenant_id exists and getting the VIM URI and the VIM tenant_id" + logger.debug("Creating instance...") scenario = instance_dict["scenario"] datacenter_id = None datacenter_name=None diff --git a/nfvo_db.py b/nfvo_db.py index 3ff11ada..127eb98c 100644 --- a/nfvo_db.py +++ b/nfvo_db.py @@ -614,7 +614,7 @@ class nfvo_db(db_base.db_base): for vm in vnf['vms']: vm_manage_iface_list=[] #instance_interfaces - cmd = "SELECT vim_interface_id, instance_net_id, internal_name,external_name, mac_address, ip_address, vim_info, i.type as type "\ + cmd = "SELECT vim_interface_id, instance_net_id, internal_name,external_name, mac_address, ii.ip_address as ip_address, vim_info, i.type as type "\ " FROM instance_interfaces as ii join interfaces as i on ii.interface_id=i.uuid "\ " WHERE instance_vm_id='{}' ORDER BY created_at".format(vm['uuid']) self.logger.debug(cmd) diff --git a/openmano_schemas.py b/openmano_schemas.py index aad972bb..4f5edfe6 100644 --- a/openmano_schemas.py +++ b/openmano_schemas.py @@ -358,7 +358,7 @@ internal_connection_element_schema_v02 = { "properties":{ "VNFC": name_schema, "local_iface_name": name_schema, - "ip-address": ip_schema + "ip_address": ip_schema } } @@ -655,7 +655,7 @@ nsd_schema_v02 = { "$schema": "http://json-schema.org/draft-04/schema#", "type":"object", "properties":{ - "schema_version": {"type": "string", "enum": ["0.2"]}, + "schema_version": schema_version_2, "scenario":{ "type":"object", "properties":{ @@ -717,7 +717,7 @@ nsd_schema_v03 = { "tenant_id": id_schema, #only valid for admin "public": {"type": "boolean"}, "cloud-config": cloud_config_schema, #common for all vnfs in the scenario - #"site": name_schema, + #"datacenter": name_schema, "vnfs": { "type":"object", "patternProperties":{ @@ -727,8 +727,8 @@ nsd_schema_v03 = { "vnf_id": id_schema, "graph": graph_schema, "vnf_name": name_schema, - "cloud-config": cloud_config_schema, #particular for a vnf - #"site": name_schema, + #"cloud-config": cloud_config_schema, #particular for a vnf + #"datacenter": name_schema, "internal-connections": { "type": "object", "patternProperties": { @@ -743,7 +743,7 @@ nsd_schema_v03 = { "properties":{ "VNFC": name_schema, "local_iface_name": name_schema, - "ip-address": ip_schema + "ip_address": ip_schema }, "required": ["VNFC", "local_iface_name"], } @@ -769,7 +769,7 @@ nsd_schema_v03 = { "items":{ "type":"object", "properties":{ - "ip-address": ip_schema + "ip_address": ip_schema }, "patternProperties":{ ".": {"type": "string"} @@ -899,7 +899,8 @@ instance_scenario_create_schema_v01 = { "properties":{ "name":name_schema, "description":description_schema, - "site": name_schema, + "datacenter": name_schema, + "scenario" : name_schema, #can be an UUID or name "action":{"enum": ["deploy","reserve","verify" ]}, "connect_mgmt_interfaces": {"oneOf": [{"type":"boolean"}, {"type":"object"}]},# can be true or a dict with datacenter: net_name "cloud-config": cloud_config_schema, #common to all vnfs in the instance scenario @@ -910,10 +911,10 @@ instance_scenario_create_schema_v01 = { "type": "object", "properties":{ "name": name_schema, #override vnf name - "site": name_schema, + "datacenter": name_schema, #"metadata": {"type": "object"}, #"user_data": {"type": "string"} - "cloud-config": cloud_config_schema, #particular for a vnf + #"cloud-config": cloud_config_schema, #particular for a vnf "external-connections": { "type": "object", "patternProperties": { @@ -921,7 +922,7 @@ instance_scenario_create_schema_v01 = { "type": "object", "properties": { "vim-network-name": name_schema, - "ip-address": ip_schema + "ip_address": ip_schema } } } @@ -940,7 +941,7 @@ instance_scenario_create_schema_v01 = { "properties":{ "VNFC": name_schema, "local_iface_name": name_schema, - "ip-address": ip_schema + "ip_address": ip_schema }, "required": ["VNFC", "local_iface_name"], } @@ -965,7 +966,7 @@ instance_scenario_create_schema_v01 = { "items":{ "type":"object", "properties":{ - "ip-address": ip_schema + "ip_address": ip_schema }, "patternProperties":{ ".": {"type": "string"} @@ -974,9 +975,9 @@ instance_scenario_create_schema_v01 = { }, "netmap-create": {"oneOf":[name_schema,{"type": "null"}]}, #datacenter network to use. Null if must be created as an internal net "netmap-use": name_schema, - "name": name_schema, #override network name + #"name": name_schema, #override network name "ip-profile": ip_profile_schema, - #"site": name_schema, + #"datacenter": name_schema, "vim-network-name": name_schema } } diff --git a/openmanod.py b/openmanod.py index 3422a7cc..c3de0127 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.45-r484" +__version__="0.4.46-r485" version_date="Aug 2016" -database_version="0.11" #expected database schema version +database_version="0.12" #expected database schema version import httpserver import time diff --git a/test/basictest.sh b/test/basictest.sh index ad243c63..891736c6 100755 --- a/test/basictest.sh +++ b/test/basictest.sh @@ -126,7 +126,7 @@ then echo "Stopping openmano" $DIRscript/service-openmano.sh mano stop echo "Initializing openmano database" - $DIRmano/database_utils/init_mano_db.sh -u mano -p manopw + $DIRmano/database_utils/init_mano_db.sh -u mano -p manopw --createdb echo "Starting openmano" $DIRscript/service-openmano.sh mano start echo -- 2.17.1