From 7c5bafbf8438a27f63d27304494ee8ef12e62e49 Mon Sep 17 00:00:00 2001 From: spaceman1984 Date: Tue, 6 Jul 2021 15:05:53 +0200 Subject: [PATCH 1/6] Added ability to create schemas only when using cloudstack-setup-databases --- setup/bindir/cloud-setup-databases.in | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/setup/bindir/cloud-setup-databases.in b/setup/bindir/cloud-setup-databases.in index 61f2f948aef9..9d6066f68c0c 100755 --- a/setup/bindir/cloud-setup-databases.in +++ b/setup/bindir/cloud-setup-databases.in @@ -188,7 +188,7 @@ for full help sys.exit(1) def setupDBSchema(self): - if not self.rootuser: + if not self.options.createschema and not self.rootuser: self.info("No mysql root user specified, will not create Cloud DB schema\n", None) return @@ -219,13 +219,17 @@ for full help ""), ) - for f in ["create-database","create-schema", "create-database-premium","create-schema-premium"]: + scriptsToRun = ["create-database","create-schema", "create-database-premium","create-schema-premium"] + if self.options.createschema: + scriptsToRun = ["create-schema", "create-schema-premium"] + + for f in scriptsToRun: p = os.path.join(self.dbFilesPath,"%s.sql"%f) if not os.path.exists(p): continue text = open(p).read() for t, r in replacements: text = text.replace(t,r) self.info("Applying %s"%p) - self.runMysql(text, p, True) + self.runMysql(text, p, self.rootuser != None) self.info(None, True) if self.serversetup: @@ -248,21 +252,21 @@ for full help p = os.path.join(self.dbFilesPath, 'server-setup.sql') text = open(p).read() self.info("Applying %s"%p) - self.runMysql(text, p, True) + self.runMysql(text, p, self.rootuser != None) self.info(None, True) for f in ["templates"]: p = os.path.join(self.dbFilesPath,"%s.sql"%f) text = open(p).read() self.info("Applying %s"%p) - self.runMysql(text, p, True) + self.runMysql(text, p, self.rootuser != None) self.info(None, True) p = os.path.join(self.dbFilesPath,"schema-level.sql") if os.path.isfile(p): text = open(p).read() self.info("Applying %s"%p) - self.runMysql(text, p, True) + self.runMysql(text, p, self.rootuser != None) self.info(None, True) def prepareDBFiles(self): @@ -576,7 +580,11 @@ for example: self.parser.add_option("-j", "--encryption-jar-path", action="store", dest="encryptionJarPath", help="The path to the jasypt library to be used to encrypt the values in db.properties") self.parser.add_option("-n", "--encryption-key-file", action="store", dest="encryptionKeyFile", help="The name of the file in which encryption key to be generated") self.parser.add_option("-b", "--mysql-bin-path", action="store", dest="mysqlbinpath", help="The mysql installed bin path") - + self.parser.add_option("-s", "--create-schema-only", action="store_true", dest="createschema", default=False, + help="Creates the db schema without having to pass root credentials - "\ + "Please note: The databases and user has to be configured manually prior to running this script when using this flag. "\ + "If a management server has already upgraded the database and you intend to reinitialise the database, "\ + "the cloud and cloud_usage databases will need to be recreated manually prior to running this script.") (self.options, self.args) = self.parser.parse_args() parseCasualCredit() parseOtherOptions() From ceaf2263dd429b61295b2a86fe3549ba27de9de4 Mon Sep 17 00:00:00 2001 From: spaceman1984 Date: Thu, 8 Jul 2021 09:29:30 +0200 Subject: [PATCH 2/6] Renamed var name --- setup/bindir/cloud-setup-databases.in | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/setup/bindir/cloud-setup-databases.in b/setup/bindir/cloud-setup-databases.in index 9d6066f68c0c..9f29de109723 100755 --- a/setup/bindir/cloud-setup-databases.in +++ b/setup/bindir/cloud-setup-databases.in @@ -188,7 +188,7 @@ for full help sys.exit(1) def setupDBSchema(self): - if not self.options.createschema and not self.rootuser: + if not self.options.schemaonly and not self.rootuser: self.info("No mysql root user specified, will not create Cloud DB schema\n", None) return @@ -220,7 +220,7 @@ for full help ) scriptsToRun = ["create-database","create-schema", "create-database-premium","create-schema-premium"] - if self.options.createschema: + if self.options.schemaonly: scriptsToRun = ["create-schema", "create-schema-premium"] for f in scriptsToRun: @@ -580,7 +580,7 @@ for example: self.parser.add_option("-j", "--encryption-jar-path", action="store", dest="encryptionJarPath", help="The path to the jasypt library to be used to encrypt the values in db.properties") self.parser.add_option("-n", "--encryption-key-file", action="store", dest="encryptionKeyFile", help="The name of the file in which encryption key to be generated") self.parser.add_option("-b", "--mysql-bin-path", action="store", dest="mysqlbinpath", help="The mysql installed bin path") - self.parser.add_option("-s", "--create-schema-only", action="store_true", dest="createschema", default=False, + self.parser.add_option("-s", "--schema-only", action="store_true", dest="schemaonly", default=False, help="Creates the db schema without having to pass root credentials - "\ "Please note: The databases and user has to be configured manually prior to running this script when using this flag. "\ "If a management server has already upgraded the database and you intend to reinitialise the database, "\ From 5ee88a96b62bcdf9850ffdaadf9851f0648b332c Mon Sep 17 00:00:00 2001 From: spaceman1984 Date: Thu, 8 Jul 2021 15:24:02 +0200 Subject: [PATCH 3/6] Added a check for passing --schema-only and --deploy-as together/. --- setup/bindir/cloud-setup-databases.in | 3 +++ 1 file changed, 3 insertions(+) diff --git a/setup/bindir/cloud-setup-databases.in b/setup/bindir/cloud-setup-databases.in index 9f29de109723..8da68f1e382c 100755 --- a/setup/bindir/cloud-setup-databases.in +++ b/setup/bindir/cloud-setup-databases.in @@ -188,6 +188,9 @@ for full help sys.exit(1) def setupDBSchema(self): + if self.options.schemaonly and self.rootuser != None: + self.info("--schema-only and --deploy-as cannot be passed together\n", None) + return if not self.options.schemaonly and not self.rootuser: self.info("No mysql root user specified, will not create Cloud DB schema\n", None) return From 5ba7206ed8aa1cf4bd262e13d6d97f1de7e704bc Mon Sep 17 00:00:00 2001 From: spaceman1984 Date: Fri, 9 Jul 2021 10:52:59 +0200 Subject: [PATCH 4/6] Moved validation to appropriate method --- setup/bindir/cloud-setup-databases.in | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/setup/bindir/cloud-setup-databases.in b/setup/bindir/cloud-setup-databases.in index 8da68f1e382c..405f19b004cb 100755 --- a/setup/bindir/cloud-setup-databases.in +++ b/setup/bindir/cloud-setup-databases.in @@ -188,9 +188,6 @@ for full help sys.exit(1) def setupDBSchema(self): - if self.options.schemaonly and self.rootuser != None: - self.info("--schema-only and --deploy-as cannot be passed together\n", None) - return if not self.options.schemaonly and not self.rootuser: self.info("No mysql root user specified, will not create Cloud DB schema\n", None) return @@ -521,6 +518,8 @@ for example: self.info("Mysql server port:%s"%self.port, True) def validateParameters(): + if self.options.schemaonly and self.rootuser != None: + self.errorAndExit("--schema-only and --deploy-as cannot be passed together\n") if self.encryptiontype != 'file' and self.encryptiontype != 'web': self.errorAndExit('Wrong encryption type %s, --encrypt-type can only be "file" or "web'%self.encryptiontype) From badee0fd0f7c910bac77220967e0c055b262524e Mon Sep 17 00:00:00 2001 From: spaceman1984 Date: Fri, 9 Jul 2021 14:14:25 +0200 Subject: [PATCH 5/6] Moved description --- setup/bindir/cloud-setup-databases.in | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/setup/bindir/cloud-setup-databases.in b/setup/bindir/cloud-setup-databases.in index 405f19b004cb..945ba6f276ca 100755 --- a/setup/bindir/cloud-setup-databases.in +++ b/setup/bindir/cloud-setup-databases.in @@ -565,6 +565,10 @@ for example: help="If enabled, print the commands it will run as they run") self.parser.add_option("-d", "--deploy-as", action="store", type="string", dest="rootcreds", default="", help="Colon-separated user name and password of a MySQL user with administrative privileges") + self.parser.add_option("-s", "--schema-only", action="store_true", dest="schemaonly", default=False, + help="Creates the db schema without having to pass root credentials - " \ + "Please note: The databases (cloud, cloud_usage) and user (cloud) has to be configured manually" \ + "prior to running this script when using this flag.") self.parser.add_option("-a", "--auto", action="store", type="string", dest="serversetup", default="", help="Path to an XML file describing an automated unattended cloud setup") self.parser.add_option("-e", "--encrypt-type", action="store", type="string", dest="encryptiontype", default="file", @@ -582,11 +586,6 @@ for example: self.parser.add_option("-j", "--encryption-jar-path", action="store", dest="encryptionJarPath", help="The path to the jasypt library to be used to encrypt the values in db.properties") self.parser.add_option("-n", "--encryption-key-file", action="store", dest="encryptionKeyFile", help="The name of the file in which encryption key to be generated") self.parser.add_option("-b", "--mysql-bin-path", action="store", dest="mysqlbinpath", help="The mysql installed bin path") - self.parser.add_option("-s", "--schema-only", action="store_true", dest="schemaonly", default=False, - help="Creates the db schema without having to pass root credentials - "\ - "Please note: The databases and user has to be configured manually prior to running this script when using this flag. "\ - "If a management server has already upgraded the database and you intend to reinitialise the database, "\ - "the cloud and cloud_usage databases will need to be recreated manually prior to running this script.") (self.options, self.args) = self.parser.parse_args() parseCasualCredit() parseOtherOptions() From 9cd8c97c9c96de1f391835a0d870a69e4a4d2bbf Mon Sep 17 00:00:00 2001 From: spaceman1984 Date: Mon, 12 Jul 2021 08:02:23 +0200 Subject: [PATCH 6/6] fixed whitespace --- setup/bindir/cloud-setup-databases.in | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/setup/bindir/cloud-setup-databases.in b/setup/bindir/cloud-setup-databases.in index 945ba6f276ca..37b696f9fce6 100755 --- a/setup/bindir/cloud-setup-databases.in +++ b/setup/bindir/cloud-setup-databases.in @@ -567,8 +567,9 @@ for example: help="Colon-separated user name and password of a MySQL user with administrative privileges") self.parser.add_option("-s", "--schema-only", action="store_true", dest="schemaonly", default=False, help="Creates the db schema without having to pass root credentials - " \ - "Please note: The databases (cloud, cloud_usage) and user (cloud) has to be configured manually" \ - "prior to running this script when using this flag.") + "Please note: The databases (cloud, cloud_usage) and user (cloud) has to be configured " \ + "manually prior to running this script when using this flag.") + self.parser.add_option("-a", "--auto", action="store", type="string", dest="serversetup", default="", help="Path to an XML file describing an automated unattended cloud setup") self.parser.add_option("-e", "--encrypt-type", action="store", type="string", dest="encryptiontype", default="file",