diff options
Diffstat (limited to 'tests')
| -rwxr-xr-x | tests/03_deploy_replicaset.py | 96 |
1 files changed, 59 insertions, 37 deletions
diff --git a/tests/03_deploy_replicaset.py b/tests/03_deploy_replicaset.py index cae5930..d7120a3 100755 --- a/tests/03_deploy_replicaset.py +++ b/tests/03_deploy_replicaset.py @@ -46,39 +46,12 @@ sentry_dict = { ############################################################# -# Check presence of MongoDB GUI HEALTH Status +# Test Utilities ############################################################# -def validate_status_interface(): - pubaddy = d.sentry['mongodb'][0].info['public-address'] - fmt = "http://{}:28017" - if ":" in pubaddy: - fmt = "http://[{}]:28017" - r = requests.get(fmt.format(pubaddy), verify=False) - r.raise_for_status - - -############################################################# -# Validate that each unit has an active mongo service -############################################################# -def validate_running_services(): - for service in sentry_dict: - output = sentry_dict[service].run('service mongodb status') - service_active = str(output).find('active (running)') - if service_active == -1: - message = "Failed to find running MongoDB on host {}".format( - service) - amulet.raise_status(amulet.SKIP, msg=message) - - -############################################################# -# Validate proper replicaset setup -############################################################# -def validate_replicaset_setup(): - - d.sentry.wait(seconds) - +def _expect_replicaset_counts(primaries_count, + secondaries_count, + time_between=10): unit_status = [] - time_between = 10 tries = wait_for_replicaset / time_between for service in sentry_dict: @@ -107,19 +80,67 @@ def validate_replicaset_setup(): client.close() primaries = Counter(unit_status)[1] - if primaries != 1: - message = "Only one PRIMARY unit allowed! Found: %s %s" % (primaries, - unit_status) + if primaries != primaries_count: + message = "Expected %d PRIMARY unit(s)! Found: %s %s" % ( + primaries_count, + primaries, + unit_status) amulet.raise_status(amulet.FAIL, message) secondrs = Counter(unit_status)[2] - if secondrs != 2: - message = ("Only two SECONDARY units allowed! (Found %s) %s" % - (secondrs, unit_status)) + if secondrs != secondaries_count: + message = ("Expected %d secondary units! (Found %s) %s" % + (secondaries_count, secondrs, unit_status)) amulet.raise_status(amulet.FAIL, message) ############################################################# +# Check presence of MongoDB GUI HEALTH Status +############################################################# +def validate_status_interface(): + pubaddy = d.sentry['mongodb'][0].info['public-address'] + fmt = "http://{}:28017" + if ":" in pubaddy: + fmt = "http://[{}]:28017" + r = requests.get(fmt.format(pubaddy), verify=False) + r.raise_for_status + + +############################################################# +# Validate that each unit has an active mongo service +############################################################# +def validate_running_services(): + for service in sentry_dict: + output = sentry_dict[service].run('service mongodb status') + service_active = str(output).find('mongodb start/running') + if series='xenial': + service_active = str(output).find('active (running)') + if service_active == -1: + message = "Failed to find running MongoDB on host {}".format( + service) + amulet.raise_status(amulet.SKIP, msg=message) + + +############################################################# +# Validate proper replicaset setup +############################################################# +def validate_replicaset_setup(): + d.sentry.wait(seconds) + _expect_replicaset_counts(1, 2) + + +############################################################# +# Validate replicaset joined +############################################################# +def validate_replicaset_relation_joined(): + d.add_unit('mongodb', units=2) + d.sentry.wait(wait_for_replicaset) + sentry_dict.update({'mongodb3-sentry': d.sentry['mongodb'][3], + 'mongodb4-sentry': d.sentry['mongodb'][4]}) + _expect_replicaset_counts(1, 4) + + +############################################################# # Validate connectivity from $WORLD ############################################################# def validate_world_connectivity(): @@ -165,4 +186,5 @@ def validate_world_connectivity(): validate_status_interface() validate_running_services() validate_replicaset_setup() +validate_replicaset_relation_joined() validate_world_connectivity() |
