summaryrefslogtreecommitdiff
diff options
authorFelipe Reyes <felipe.reyes@canonical.com>2018-05-18 21:50:08 +0000
committerFelipe Reyes <felipe.reyes@canonical.com>2018-05-18 21:50:08 +0000
commitf52c8db6cb88f3693a326f1d6c4e4285635e6257 (patch)
tree8cb2fec6c5c4025de960aedf07e389fcf8c0b52c
parent2ef8834546e06c16ed37a71c9abe36dac5d7622a (diff)
Add functional test to check workload status
Verify that a mongodb cluster (with replica set) has one primary and the rest of the units are secondary cleary identified by the workload message.
-rw-r--r--tests/deploy_replicaset.py32
1 files changed, 32 insertions, 0 deletions
diff --git a/tests/deploy_replicaset.py b/tests/deploy_replicaset.py
index 9506407..6fa0290 100644
--- a/tests/deploy_replicaset.py
+++ b/tests/deploy_replicaset.py
@@ -1,6 +1,8 @@
#!/usr/bin/env python3
import amulet
+import logging
+import re
import sys
import time
import traceback
@@ -12,6 +14,7 @@ from base_deploy import BasicMongo
# max amount of time to wait before testing for replicaset status
wait_for_replicaset = 600
+logger = logging.getLogger(__name__)
class Replicaset(BasicMongo):
@@ -109,6 +112,34 @@ class Replicaset(BasicMongo):
def validate_running_services(self):
super(Replicaset, self).validate_running_services()
+ def validate_workload_status(self):
+ primaries = 0
+ secondaries = 0
+ regex = re.compile('^Unit is ready as (PRIMARY|SECONDARY)$')
+ self.d.sentry.wait_for_messages({'mongodb': regex})
+
+ # count how many primaries and secondaries were reported in the
+ # workload status
+ for unit_name, unit in self.d.sentry.get_status()['mongodb'].items():
+ workload_msg = unit['workload-status']['message']
+ matched = re.match(regex, workload_msg)
+
+ if not matched:
+ msg = "'{}' does not match '{}'".format(workload_msg, regex)
+ amulet.raise_status(amulet.FAIL, msg=msg)
+ elif matched.group(1) == 'PRIMARY':
+ primaries += 1
+ elif matched.group(1) == 'SECONDARY':
+ secondaries += 1
+ else:
+ amulet.raise_status(amulet.FAIL,
+ msg='Unknown state: %s' % matched.group(1))
+
+ logger.debug('Secondary units found: %d' % secondaries)
+ if primaries > 1:
+ msg = "Found %d primaries, expected 1" % primaries
+ amulet.raise_status(amulet.FAIL, msg=msg)
+
def run(self):
self.deploy()
self.validate_status_interface()
@@ -116,3 +147,4 @@ class Replicaset(BasicMongo):
self.validate_replicaset_setup()
self.validate_replicaset_relation_joined()
self.validate_world_connectivity()
+ self.validate_workload_status()