changeset 1699:44d60d1362ee

Allow for thermostat-setup to work with mongodb <= 2.2 PR 2416 Reviewed-by: omajid Review-thread: http://icedtea.classpath.org/pipermail/thermostat/2015-May/013854.html Review-thread: http://icedtea.classpath.org/pipermail/thermostat/2015-June/014021.html
author Severin Gehwolf <sgehwolf@redhat.com>
date Thu, 28 May 2015 14:57:42 +0200
parents 810b066f39e3
children c4c7131a6285
files distribution/scripts/thermostat-setup integration-tests/itest-run/src/test/java/com/redhat/thermostat/itest/WebAppTest.java
diffstat 2 files changed, 13 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/distribution/scripts/thermostat-setup	Wed May 27 18:29:13 2015 +0200
+++ b/distribution/scripts/thermostat-setup	Thu May 28 14:57:42 2015 +0200
@@ -282,10 +282,16 @@
 var v = db.version();
 var minorMicro = v.substr(v.indexOf('.') + 1)
 var minorVersion = minorMicro.substr(0, minorMicro.indexOf('.'))
-if ( minorVersion <= 4 ) {
-  db.addUser({ user: "$USERNAME", pwd: "$PASSWORD", roles: [ "readWrite" ] })
+if ( minorVersion <= 2 ) {
+    // mongodb version 2.2 and below don't have the third argument.
+    // this should create the user as read + write.
+    db.addUser("$USERNAME","$PASSWORD")
 } else {
-  db.createUser({ user: "$USERNAME", pwd: "$PASSWORD", roles: [ "readWrite" ] })
+  if ( minorVersion <= 4 ) {
+    db.addUser({ user: "$USERNAME", pwd: "$PASSWORD", roles: [ "readWrite" ] })
+  } else {
+    db.createUser({ user: "$USERNAME", pwd: "$PASSWORD", roles: [ "readWrite" ] })
+  }
 }
 quit()
 EOF
--- a/integration-tests/itest-run/src/test/java/com/redhat/thermostat/itest/WebAppTest.java	Wed May 27 18:29:13 2015 +0200
+++ b/integration-tests/itest-run/src/test/java/com/redhat/thermostat/itest/WebAppTest.java	Thu May 28 14:57:42 2015 +0200
@@ -381,6 +381,9 @@
                 mongoSpawn.send("var v = db.version()\n");
                 mongoSpawn.send("var minorMicro = v.substr(v.indexOf('.') + 1)\n");
                 mongoSpawn.send("var minorVersion = minorMicro.substr(0, minorMicro.indexOf('.'))\n");
+                mongoSpawn.send("if ( minorVersion <= 2 ) {");
+                mongoSpawn.send(String.format("db.addUser(\"%s\", \"%s\")", mongodbUsername, mongodbPassword));
+                mongoSpawn.send("} else {");
                 mongoSpawn.send("if ( minorVersion <= 4 ) {");
                 mongoSpawn.send(String.format("db.addUser({ user: \"%s\", pwd: \"%s\", roles: [ \"readWrite\" ] })",
                         mongodbUsername, mongodbPassword));
@@ -388,6 +391,7 @@
                 mongoSpawn.send(String.format("db.createUser({ user: \"%s\", pwd: \"%s\", roles: [ \"readWrite\" ] })",
                         mongodbUsername, mongodbPassword));
                 mongoSpawn.send("}\n");
+                mongoSpawn.send("}\n");
                 mongoSpawn.send("quit()\n");
                 mongoSpawn.expectClose();