From be7402b88c0bf774ca6297501451ffc2f60bd92e Mon Sep 17 00:00:00 2001 From: micafer Date: Thu, 26 Apr 2018 13:09:26 +0200 Subject: [PATCH 1/7] Exit if not database available. --- IM/InfrastructureList.py | 3 ++- im_service.py | 4 +++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/IM/InfrastructureList.py b/IM/InfrastructureList.py index c40f54088..a3612a19d 100644 --- a/IM/InfrastructureList.py +++ b/IM/InfrastructureList.py @@ -148,10 +148,11 @@ def init_table(): db = DataBase(Config.DATA_DB) if db.connect(): if not db.table_exists("inf_list"): + InfrastructureList.logger.debug("Creating the IM database!.") db.execute("CREATE TABLE inf_list(id VARCHAR(255) PRIMARY KEY, deleted INTEGER," " date TIMESTAMP, data LONGBLOB)") db.close() - return True + return True else: InfrastructureList.logger.error("ERROR connecting with the database!.") diff --git a/im_service.py b/im_service.py index 0ca33e8e3..c0ed75964 100755 --- a/im_service.py +++ b/im_service.py @@ -200,7 +200,9 @@ def launch_daemon(): """ Launch the IM daemon """ - InfrastructureList.init_table() + if not InfrastructureList.init_table(): + print("Error connecting with the DB!!.") + sys.exit(2) if Config.XMLRCP_SSL: # if specified launch the secure version From fee9e6eb5ccb783470462b9287d7c9619b1bc1bc Mon Sep 17 00:00:00 2001 From: micafer Date: Thu, 26 Apr 2018 13:19:51 +0200 Subject: [PATCH 2/7] Update dockerfile with mysql lib --- docker/Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docker/Dockerfile b/docker/Dockerfile index e269f0c6a..2da36dd14 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -15,7 +15,7 @@ RUN pip install pyOpenSSL --upgrade -I RUN pip install msrest msrestazure azure-common azure-mgmt-storage azure-mgmt-compute azure-mgmt-network azure-mgmt-resource azure-mgmt-dns cheroot xmltodict # Install IM -RUN apt-get update && apt-get install --no-install-recommends -y gcc libmysqld-dev libssl-dev libffi-dev libsqlite3-dev && \ +RUN apt-get update && apt-get install --no-install-recommends -y gcc libmysqld-dev libssl-dev libffi-dev libsqlite3-dev libmysqlclient20 && \ pip install pycrypto && \ pip install MySQL-python && \ pip install IM==1.7.0 && \ From 7cda1fb675c4c52aabd4bf34e44ab0cf65243fa7 Mon Sep 17 00:00:00 2001 From: micafer Date: Fri, 27 Apr 2018 10:07:16 +0200 Subject: [PATCH 3/7] Fix error with mysql DB --- IM/InfrastructureList.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/IM/InfrastructureList.py b/IM/InfrastructureList.py index a3612a19d..6a87dfb44 100644 --- a/IM/InfrastructureList.py +++ b/IM/InfrastructureList.py @@ -149,8 +149,12 @@ def init_table(): if db.connect(): if not db.table_exists("inf_list"): InfrastructureList.logger.debug("Creating the IM database!.") - db.execute("CREATE TABLE inf_list(id VARCHAR(255) PRIMARY KEY, deleted INTEGER," - " date TIMESTAMP, data LONGBLOB)") + if db.db_type == DataBase.MYSQL: + db.execute("CREATE TABLE test(rowid INTEGER NOT NULL AUTO_INCREMENT PRIMARY KEY," + " id VARCHAR(255) UNIQUE, deleted INTEGER, date TIMESTAMP, data LONGBLOB)") + else: + db.execute("CREATE TABLE inf_list(id VARCHAR(255) PRIMARY KEY, deleted INTEGER," + " date TIMESTAMP, data LONGBLOB)") db.close() return True else: From 85a77da7b909a32a3fabf919f13f2907c5d553ee Mon Sep 17 00:00:00 2001 From: micafer Date: Fri, 27 Apr 2018 10:16:02 +0200 Subject: [PATCH 4/7] Fix error with mysql DB --- IM/InfrastructureList.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/IM/InfrastructureList.py b/IM/InfrastructureList.py index 6a87dfb44..789ef89de 100644 --- a/IM/InfrastructureList.py +++ b/IM/InfrastructureList.py @@ -150,7 +150,7 @@ def init_table(): if not db.table_exists("inf_list"): InfrastructureList.logger.debug("Creating the IM database!.") if db.db_type == DataBase.MYSQL: - db.execute("CREATE TABLE test(rowid INTEGER NOT NULL AUTO_INCREMENT PRIMARY KEY," + db.execute("CREATE TABLE inf_list(rowid INTEGER NOT NULL AUTO_INCREMENT PRIMARY KEY," " id VARCHAR(255) UNIQUE, deleted INTEGER, date TIMESTAMP, data LONGBLOB)") else: db.execute("CREATE TABLE inf_list(id VARCHAR(255) PRIMARY KEY, deleted INTEGER," From 3c7138c054827a4417399d89cd6b33a808b34ce4 Mon Sep 17 00:00:00 2001 From: micafer Date: Fri, 27 Apr 2018 10:43:58 +0200 Subject: [PATCH 5/7] Patch to avoid pip 10 errors --- contextualization/conf-ansible.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/contextualization/conf-ansible.yml b/contextualization/conf-ansible.yml index f09293423..21d65f0c4 100644 --- a/contextualization/conf-ansible.yml +++ b/contextualization/conf-ansible.yml @@ -95,8 +95,9 @@ # - name: Install Pip (alternative) # shell: wget https://bootstrap.pypa.io/get-pip.py && python get-pip.py + # do not upgrade to 10 as it is failing - name: Upgrade pip - pip: name=pip extra_args="-I" state=latest + pip: name=pip extra_args="-I" version=9.0.3 - name: Upgrade setuptools with Pip pip: name=setuptools state=latest From 67a5d723dd380413ff8343a32cfb7eab5249ab90 Mon Sep 17 00:00:00 2001 From: micafer Date: Fri, 27 Apr 2018 12:09:39 +0200 Subject: [PATCH 6/7] Fix error with mysql DB --- IM/InfrastructureList.py | 9 +++---- scripts/db_1_5_0_to_1_7_0.py | 46 ++++++++++++++++++++++++++++++++++++ 2 files changed, 51 insertions(+), 4 deletions(-) create mode 100644 scripts/db_1_5_0_to_1_7_0.py diff --git a/IM/InfrastructureList.py b/IM/InfrastructureList.py index 789ef89de..0d7d3173c 100644 --- a/IM/InfrastructureList.py +++ b/IM/InfrastructureList.py @@ -150,8 +150,8 @@ def init_table(): if not db.table_exists("inf_list"): InfrastructureList.logger.debug("Creating the IM database!.") if db.db_type == DataBase.MYSQL: - db.execute("CREATE TABLE inf_list(rowid INTEGER NOT NULL AUTO_INCREMENT PRIMARY KEY," - " id VARCHAR(255) UNIQUE, deleted INTEGER, date TIMESTAMP, data LONGBLOB)") + db.execute("CREATE TABLE inf_list(rowid INTEGER NOT NULL AUTO_INCREMENT UNIQUE," + " id VARCHAR(255) PRIMARY KEY, deleted INTEGER, date TIMESTAMP, data LONGBLOB)") else: db.execute("CREATE TABLE inf_list(id VARCHAR(255) PRIMARY KEY, deleted INTEGER," " date TIMESTAMP, data LONGBLOB)") @@ -170,8 +170,6 @@ def _get_data_from_db(db_url, inf_id=None, auth=None): If auth is specified only auth data will be loaded. """ if InfrastructureList.init_table(): - return {} - else: db = DataBase(db_url) if db.connect(): inf_list = {} @@ -201,6 +199,9 @@ def _get_data_from_db(db_url, inf_id=None, auth=None): else: InfrastructureList.logger.error("ERROR connecting with the database!.") return {} + else: + InfrastructureList.logger.error("ERROR connecting with the database!.") + return {} @staticmethod def _save_data_to_db(db_url, inf_list, inf_id=None): diff --git a/scripts/db_1_5_0_to_1_7_0.py b/scripts/db_1_5_0_to_1_7_0.py new file mode 100644 index 000000000..b6176fa5c --- /dev/null +++ b/scripts/db_1_5_0_to_1_7_0.py @@ -0,0 +1,46 @@ +# IM - Infrastructure Manager +# Copyright (C) 2011 - GRyCAP - Universitat Politecnica de Valencia +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +import sys + +sys.path.append("..") +sys.path.append(".") + +from IM.config import Config +from IM.db import DataBase + + +if __name__ == "__main__": + if not Config.DATA_DB: + sys.stderr.write("No DATA_DB defined in the im.cfg file!!") + sys.exit(-1) + + db = DataBase(Config.DATA_DB) + if db.connect(): + if db.table_exists("inf_list"): + if db.db_type == DataBase.MYSQL: + sys.stdout.write("Updating DB: %s.\n" % Config.DATA_DB) + db.execute("ALTER TABLE `inf_list` ADD COLUMN `rowid` INT AUTO_INCREMENT UNIQUE FIRST;") + else: + sys.stdout.write("SQLite DB does not need to be updated.") + db.close() + else: + sys.stdout.write("There are no inf_list table. Do not need to update.") + else: + sys.stderr.write("Error connecting with DB: %s\n" % Config.DATA_DB) + sys.exit(-1) + + sys.exit(0) \ No newline at end of file From 21fb0a33f1987725e29043430d11df6fef1e0d17 Mon Sep 17 00:00:00 2001 From: micafer Date: Fri, 27 Apr 2018 12:10:02 +0200 Subject: [PATCH 7/7] Use image base ubuntu 18 --- docker/Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docker/Dockerfile b/docker/Dockerfile index 2da36dd14..492d8f9f9 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -1,5 +1,5 @@ # Dockerfile to create a container with the IM service -FROM ubuntu:16.04 +FROM ubuntu:18.04 LABEL maintainer="Miguel Caballer " LABEL version="1.7.0" LABEL description="Container image to run the IM service. (http://www.grycap.upv.es/im)"