From 15a583dbf4fa869448c3fa833a6d9cd74811721b Mon Sep 17 00:00:00 2001 From: Anthony Dodd Date: Tue, 23 Aug 2022 13:11:33 -0500 Subject: [PATCH] More review items (will squash) --- features/environment.py | 2 +- features/static_primary.feature | 7 +++--- features/steps/static_primary.py | 38 +++++++++++++++++++++++++++----- 3 files changed, 38 insertions(+), 9 deletions(-) diff --git a/features/environment.py b/features/environment.py index 855990cf8..03bd91fea 100644 --- a/features/environment.py +++ b/features/environment.py @@ -671,7 +671,7 @@ def start_with_expected_failure(self, name, max_wait_limit=40, custom_config=Non try: self.start(name, max_wait_limit, custom_config) assert False, 'expected startup to fail' - except: + except Exception: pass def __getattr__(self, func): diff --git a/features/static_primary.feature b/features/static_primary.feature index 9dc02971b..ad586cb03 100644 --- a/features/static_primary.feature +++ b/features/static_primary.feature @@ -5,13 +5,14 @@ Feature: static primary Given I start postgres0 as static primary Then postgres0 is a leader after 10 seconds And there is a non empty initialize key in DCS after 15 seconds - When I issue a PATCH request to http://127.0.0.1:8008/config with {"ttl": 20, "loop_wait": 2, "synchronous_mode": true} + When I issue a PATCH request to http://127.0.0.1:8008/config with {"ttl": 20, "loop_wait": 2} Then I receive a response code 200 When I start postgres1 with a configured static primary will not boot after 20 seconds And I start postgres2 with a configured static primary will not boot after 20 seconds And "sync" key not in DCS after waiting 20 seconds - And "members/postgres1" key not in DCS after waiting 10 seconds - And "members/postgres2" key not in DCS after waiting 10 seconds + And "members/postgres1" is stopped and uninitialized after waiting 10 seconds + # NOTE: no need to wait an additional 10 seconds here. + And "members/postgres2" is stopped and uninitialized after waiting 1 seconds Scenario: check removing static primary config from dcs allows replica startup Given I issue a PATCH request to http://127.0.0.1:8008/config with {"static_primary": null} diff --git a/features/steps/static_primary.py b/features/steps/static_primary.py index b2aab9e65..b84fce4c9 100644 --- a/features/steps/static_primary.py +++ b/features/steps/static_primary.py @@ -1,8 +1,7 @@ import json -import patroni.psycopg as pg -from behave import step, then -from time import sleep, time +from behave import step +from time import sleep @step('I start {name:w} as static primary') @@ -18,8 +17,37 @@ def start_patroni_as_replica_with_static_primary(context, name, time_limit): @step('"{name}" key not in DCS after waiting {time_limit:d} seconds') def check_member_not_present(context, name, time_limit): sleep(time_limit) + found_value = False try: - json.loads(context.dcs_ctl.query(name)) + res = json.loads(context.dcs_ctl.query(name)) + if res is not None: + found_value = True + except Exception: + pass + + if found_value: + print("found value under DCS key {}: {}".format(name, res)) assert False, "found value under DCS key {} after {} seconds".format(name, time_limit) + return True + + +@step('"{name}" is stopped and uninitialized after waiting {time_limit:d} seconds') +def member_is_stopped_and_uninitialized(context, name, time_limit): + sleep(time_limit) + value = None + try: + value = json.loads(context.dcs_ctl.query(name)) + print("response from dcs_ctl.query({}): {}".format(name, value)) except Exception: - return + pass + + if value is None: + assert False, "context.dcs_ctl.query({}) unexpectedly returned None".format(name) + + state = value.get("state") + role = value.get("role") + if state != "stopped": + assert False, "{} has state {}, expected 'stopped', after {} seconds".format(name, state, time_limit) + if role != "uninitialized": + assert False, "{} has role {}, expected 'uninitialized', after {} seconds".format(name, role, time_limit) + return True