summaryrefslogtreecommitdiff
path: root/hooks
diff options
authorBilly Olsen <billy.olsen@canonical.com>2014-12-17 23:42:08 -0700
committerBilly Olsen <billy.olsen@canonical.com>2014-12-17 23:42:08 -0700
commitcbf28963824fc2867182e6711cc4bae8df01cdd9 (patch)
tree81f030a70e221ff54b160fb0c69e40970811fa24 /hooks
parent94e8c29812dd2086ce4a028945e6a316e3546c4d (diff)
Finish out unit test coverage for changes.
Diffstat (limited to 'hooks')
-rwxr-xr-xhooks/hooks.py36
1 files changed, 19 insertions, 17 deletions
diff --git a/hooks/hooks.py b/hooks/hooks.py
index 84ffa9d..747d0ad 100755
--- a/hooks/hooks.py
+++ b/hooks/hooks.py
@@ -49,15 +49,16 @@ except ImportError:
pass
from charmhelpers.core.hookenv import (
+ close_port,
config,
+ local_unit,
+ open_port,
unit_get,
relation_get,
relation_set,
relations_of_type,
relation_id,
relation_ids,
- open_port,
- close_port,
Hooks,
DEBUG,
)
@@ -190,6 +191,10 @@ def process_check_pidfile(pidfile=None):
return((None, None))
+class MasterNotFoundException(Exception):
+ pass
+
+
class TimeoutException(Exception):
pass
@@ -384,13 +389,8 @@ def mongo_client_smart(host='localhost', command=None):
if command is None:
return(False)
- cmd_line = []
- cmd_line.append('mongo')
- cmd_line.append('--quiet')
- cmd_line.append('--host')
- cmd_line.append(host)
- cmd_line.append('--eval')
- cmd_line.append('printjson(%s)' % command)
+ cmd_line = ['mongo', '--quiet', '--host', host,
+ '--eval', 'printjson(%s)' % command]
juju_log("mongo_client_smart executing: %s" % str(cmd_line), DEBUG)
for i in xrange(0, 10):
@@ -1078,7 +1078,7 @@ def replica_set_relation_joined():
def get_unit_id():
- return os.environ.get('JUJU_UNIT_NAME').split('/')[1]
+ return local_unit().split('/')[1]
def get_replicaset_members():
@@ -1110,6 +1110,7 @@ def get_replicaset_master():
(idx, hostname, port) = member
if "%s:%s" % (hostname, port) == replica:
return member
+ raise MasterNotFoundException("%s was not found." % (replica))
return (current_id,
unit_get('private-address'),
@@ -1145,11 +1146,14 @@ def am_i_primary():
def replica_set_relation_changed():
(idx, master_hostname, master_port) = get_replicaset_master()
+ private_address = unit_get('private-address')
+ remote_hostname = relation_get('hostname')
+
juju_log('replica_set_relation_changed-start')
- juju_log('I am: %s' % unit_get('private-address'))
- juju_log('Joiner: %s' % relation_get('hostname'))
+ juju_log('I am: %s' % (private_address))
+ juju_log('Joiner: %s' % (remote_hostname))
- if relation_get('hostname') is None:
+ if remote_hostname is None:
juju_log('Joiner not ready yet... bailing out')
return
@@ -1168,10 +1172,8 @@ def replica_set_relation_changed():
(master_hostname, master_port), DEBUG)
init_replset("%s:%s" % (master_hostname, master_port))
- unit = "%s:%s" % (unit_get('private-address'),
- config('port'))
- unit_remote = "%s:%s" % (relation_get('hostname'),
- relation_get('port'))
+ unit = "%s:%s" % (private_address, config('port'))
+ unit_remote = "%s:%s" % (remote_hostname, relation_get('port'))
juju_log("DEBUG: %s - %s" % (unit, master_hostname))
# If this is primary, add joined unit to replicaset