summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorrumale <rumale@ebaysf.com>2014-09-11 16:19:47 -0700
committerrumale <rumale@ebaysf.com>2014-09-25 12:18:50 -0700
commit31cede58f36d9abb29fd102e6ebbe84a410d32d8 (patch)
tree754ee8276ad22fe69ff4019e4f8799bbd142a1a5
parent2acb6ecd0d8d5ad95f71f230693d9d252588dc64 (diff)
downloadtrove-31cede58f36d9abb29fd102e6ebbe84a410d32d8.tar.gz
Discover config file for mongodb
mongodb 2.6 uses diff config file as opposed to lower versions. Given diff file candidates code selects config file that is available Change-Id: I8fe9eea39a47aa890834a0c55e98c062f9b9fd15 Closes-Bug: #1368468
-rw-r--r--trove/guestagent/common/operating_system.py6
-rw-r--r--trove/guestagent/datastore/mongodb/service.py20
-rw-r--r--trove/guestagent/datastore/mongodb/system.py7
3 files changed, 21 insertions, 12 deletions
diff --git a/trove/guestagent/common/operating_system.py b/trove/guestagent/common/operating_system.py
index 9223bd2b..1f90f591 100644
--- a/trove/guestagent/common/operating_system.py
+++ b/trove/guestagent/common/operating_system.py
@@ -29,6 +29,12 @@ def get_os():
return DEBIAN
+def file_discovery(file_candidates):
+ for file in file_candidates:
+ if os.path.isfile(file):
+ return file
+
+
def service_discovery(service_candidates):
"""
This function discovering how to start, stop, enable, disable service
diff --git a/trove/guestagent/datastore/mongodb/service.py b/trove/guestagent/datastore/mongodb/service.py
index 31016e3a..2f3832bd 100644
--- a/trove/guestagent/datastore/mongodb/service.py
+++ b/trove/guestagent/datastore/mongodb/service.py
@@ -30,6 +30,8 @@ from trove.openstack.common.gettextutils import _
LOG = logging.getLogger(__name__)
CONF = cfg.CONF
+CONFIG_FILE = (operating_system.
+ file_discovery(system.CONFIG_CANDIDATES))
class MongoDBApp(object):
@@ -174,11 +176,10 @@ class MongoDBApp(object):
t.write(config_contents)
LOG.info(_("Moving %(a)s to %(b)s")
- % {'a': system.TMP_CONFIG,
- 'b': system.CONFIG})
+ % {'a': system.TMP_CONFIG, 'b': CONFIG_FILE})
utils.execute_with_timeout("mv",
system.TMP_CONFIG,
- system.CONFIG,
+ CONFIG_FILE,
run_as_root=True,
root_helper="sudo")
except Exception:
@@ -189,10 +190,10 @@ class MongoDBApp(object):
def _read_config(self):
try:
- with open(system.CONFIG, 'r') as f:
+ with open(CONFIG_FILE, 'r') as f:
return f.read()
except IOError:
- LOG.info(_("Config file %s not found") % system.CONFIG)
+ LOG.info(_("Config file %s not found") % CONFIG_FILE)
return ''
def _delete_config_parameters(self, config_contents, parameters):
@@ -235,10 +236,11 @@ class MongoDBApp(object):
self.start_db_with_conf_changes(contents)
def write_mongos_upstart(self):
-
+ upstart_contents = (system.MONGOS_UPSTART_CONTENTS.
+ format(config_file_placeholder=CONFIG_FILE))
LOG.info(_("Writing %s") % system.TMP_MONGOS_UPSTART)
with open(system.TMP_MONGOS_UPSTART, 'w') as t:
- t.write(system.MONGOS_UPSTART_CONTENTS)
+ t.write(upstart_contents)
LOG.info(_("Moving %(a)s to %(b)s")
% {'a': system.TMP_MONGOS_UPSTART,
@@ -335,7 +337,7 @@ class MongoDbAppStatus(service.BaseDbStatus):
if self.is_config_server is None:
try:
cmd = ("grep '^configsvr[ \t]*=[ \t]*true$' %s"
- % system.CONFIG)
+ % CONFIG_FILE)
utils.execute_with_timeout(cmd, shell=True)
self.is_config_server = True
except exception.ProcessExecutionError:
@@ -346,7 +348,7 @@ class MongoDbAppStatus(service.BaseDbStatus):
if self.is_query_router is None:
try:
cmd = ("grep '^configdb[ \t]*=.*$' %s"
- % system.CONFIG)
+ % CONFIG_FILE)
utils.execute_with_timeout(cmd, shell=True)
self.is_query_router = True
except exception.ProcessExecutionError:
diff --git a/trove/guestagent/datastore/mongodb/system.py b/trove/guestagent/datastore/mongodb/system.py
index efe5d750..30324730 100644
--- a/trove/guestagent/datastore/mongodb/system.py
+++ b/trove/guestagent/datastore/mongodb/system.py
@@ -21,7 +21,7 @@ MONGODB_MOUNT_POINT = "/var/lib/mongodb"
CMD_STATUS = "mongostat --host %s -n 1 | grep connected"
TMP_CONFIG = "/tmp/mongodb.conf.tmp"
-CONFIG = "/etc/mongodb.conf"
+CONFIG_CANDIDATES = ["/etc/mongodb.conf", "/etc/mongod.conf"]
MONGOS_UPSTART = "/etc/init/mongos.conf"
TMP_MONGOS_UPSTART = "/tmp/mongos.conf.tmp"
MONGOS_SERVICE_CANDIDATES = ["mongos"]
@@ -31,7 +31,8 @@ FIND_PID = "ps xau | grep 'mongo[ds]'"
TIME_OUT = 1000
INIT_EXEC_MONGOS = ("start-stop-daemon --start --quiet --chuid mongodb "
- "--exec /usr/bin/mongos -- --config %s" % CONFIG)
+ "--exec /usr/bin/mongos -- "
+ "--config {config_file_placeholder}")
MONGOS_UPSTART_CONTENTS = """pre-start script
mkdir -p /var/log/mongodb/
@@ -44,6 +45,6 @@ script
ENABLE_MONGOS="yes"
if [ -f /etc/default/mongos ]; then . /etc/default/mongos; fi
if [ "x$ENABLE_MONGOS" = "xyes" ]; then exec %s; fi
-end script""" % INIT_EXEC_MONGOS
+end script """ % INIT_EXEC_MONGOS
PACKAGER = pkg.Package()