changeset 1697:51c68907546d

Use createUser/addUser as appropriate in thermostat-setup. PR 2416 Reviewed-by: omajid Review-thread: http://icedtea.classpath.org/pipermail/thermostat/2015-May/013794.html Review-thread: http://icedtea.classpath.org/pipermail/thermostat/2015-June/014021.html
author Severin Gehwolf <sgehwolf@redhat.com>
date Wed, 27 May 2015 12:17:35 +0200
parents 1f8093247f9b
children 810b066f39e3
files distribution/scripts/thermostat-setup integration-tests/itest-run/src/test/java/com/redhat/thermostat/itest/WebAppTest.java
diffstat 2 files changed, 17 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/distribution/scripts/thermostat-setup	Tue May 26 16:05:46 2015 +0200
+++ b/distribution/scripts/thermostat-setup	Wed May 27 12:17:35 2015 +0200
@@ -279,7 +279,14 @@
   sleep 3
   mongo 127.0.0.1:27518 << EOF
 use thermostat
-db.addUser({ user: "$USERNAME", pwd: "$PASSWORD", roles: [ "readWrite" ] })
+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" ] })
+} else {
+  db.createUser({ user: "$USERNAME", pwd: "$PASSWORD", roles: [ "readWrite" ] })
+}
 quit()
 EOF
   MONGO_SETUP_RETVAL="$?"
--- a/integration-tests/itest-run/src/test/java/com/redhat/thermostat/itest/WebAppTest.java	Tue May 26 16:05:46 2015 +0200
+++ b/integration-tests/itest-run/src/test/java/com/redhat/thermostat/itest/WebAppTest.java	Wed May 27 12:17:35 2015 +0200
@@ -378,8 +378,16 @@
                 ExpectJ mongo = new ExpectJ(TIMEOUT_IN_SECONDS);
                 Spawn mongoSpawn = mongo.spawn("mongo " + HOST + ":" + PORT);
                 mongoSpawn.send("use thermostat\n");
-                mongoSpawn.send(String.format("db.addUser({ user: \"%s\", pwd: \"%s\", roles: [ \"readWrite\" ] })\n",
+                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 <= 4 ) {");
+                mongoSpawn.send(String.format("db.addUser({ user: \"%s\", pwd: \"%s\", roles: [ \"readWrite\" ] })",
                         mongodbUsername, mongodbPassword));
+                mongoSpawn.send("} else {");
+                mongoSpawn.send(String.format("db.createUser({ user: \"%s\", pwd: \"%s\", roles: [ \"readWrite\" ] })",
+                        mongodbUsername, mongodbPassword));
+                mongoSpawn.send("}\n");
                 mongoSpawn.send("quit()\n");
                 mongoSpawn.expectClose();