diff --git a/features/environment.py b/features/environment.py index 15abe1fa..e3f9355d 100644 --- a/features/environment.py +++ b/features/environment.py @@ -117,12 +117,24 @@ class PatroniController(AbstractController): except IOError: return None - def add_tag_to_config(self, tag, value): + @staticmethod + def recursive_update(dst, src): + for k, v in src.items(): + if k in dst and isinstance(dst[k], dict): + PatroniController.recursive_update(dst[k], v) + else: + dst[k] = v + + def update_config(self, custom_config): with open(self._config) as r: config = yaml.safe_load(r) - config['tags']['tag'] = value + self.recursive_update(config, custom_config) with open(self._config, 'w') as w: yaml.safe_dump(config, w, default_flow_style=False) + self._scope = config.get('scope', 'batman') + + def add_tag_to_config(self, tag, value): + self.update_config({'tags': {tag: value}}) def _start(self): if self.watchdog: @@ -174,13 +186,7 @@ class PatroniController(AbstractController): config['bootstrap']['initdb'].extend([{'auth': 'md5'}, {'auth-host': 'md5'}]) if custom_config is not None: - def recursive_update(dst, src): - for k, v in src.items(): - if k in dst and isinstance(dst[k], dict): - recursive_update(dst[k], v) - else: - dst[k] = v - recursive_update(config, custom_config) + self.recursive_update(config, custom_config) if config['postgresql'].get('callbacks', {}).get('on_role_change'): config['postgresql']['callbacks']['on_role_change'] += ' ' + str(self.__PORT) diff --git a/features/patroni_api.feature b/features/patroni_api.feature index 107a7199..64b55098 100644 --- a/features/patroni_api.feature +++ b/features/patroni_api.feature @@ -43,7 +43,7 @@ Scenario: check dynamic configuration change via DCS And I receive a response loop_wait 2 When I issue a GET request to http://127.0.0.1:8008/patroni Then I receive a response code 200 - And I receive a response tags {'tag': 'new_value'} + And I receive a response tags {'new_tag': 'new_value'} Scenario: check API requests for the primary-replica pair in the pause mode Given I run patronictl.py pause batman diff --git a/features/standby_cluster.feature b/features/standby_cluster.feature index e04c24a9..bc6b3b7e 100644 --- a/features/standby_cluster.feature +++ b/features/standby_cluster.feature @@ -3,13 +3,15 @@ Feature: standby cluster Given I start postgres1 Then postgres1 is a leader after 10 seconds And I sleep for 2 seconds - When I issue a PATCH request to http://127.0.0.1:8009/config with {"slots": {"pm_1": {"type": "physical"}}, "postgresql": {"parameters": {"wal_level": "logical"}}} + When I issue a PATCH request to http://127.0.0.1:8009/config with {"loop_wait": 2, "slots": {"pm_1": {"type": "physical"}}, "postgresql": {"parameters": {"wal_level": "logical"}}} Then I receive a response code 200 And Response on GET http://127.0.0.1:8009/config contains slots after 10 seconds + And I sleep for 2 seconds When I issue a PATCH request to http://127.0.0.1:8009/config with {"slots": {"test_logical": {"type": "logical", "database": "postgres", "plugin": "test_decoding"}}} Then I receive a response code 200 When I start postgres0 with callback configured Then "members/postgres0" key in DCS has state=running after 10 seconds + And replication works from postgres1 to postgres0 after 15 seconds When I shut down postgres1 Then postgres0 is a leader after 10 seconds And I sleep for 2 seconds @@ -20,8 +22,7 @@ Feature: standby cluster Scenario: check replication of a single table in a standby cluster Given I start postgres1 in a standby cluster batman1 as a clone of postgres0 Then postgres1 is a leader of batman1 after 10 seconds - When I issue a PATCH request to http://127.0.0.1:8009/config with {"ttl": 20, "loop_wait": 2} - And I add the table foo to postgres0 + When I add the table foo to postgres0 Then table foo is present on postgres1 after 20 seconds When I start postgres2 in a cluster batman1 Then postgres2 role is the replica after 24 seconds diff --git a/features/steps/standby_cluster.py b/features/steps/standby_cluster.py index b5e87d62..cdadcc62 100644 --- a/features/steps/standby_cluster.py +++ b/features/steps/standby_cluster.py @@ -30,12 +30,10 @@ def start_patroni(context, name, cluster_name): @step('I start {name:w} in a standby cluster {cluster_name:w} as a clone of {name2:w}') def start_patroni_stanby_cluster(context, name, cluster_name, name2): - ctl = context.pctl._processes.pop(name, None) # we need to remove patroni.dynamic.json in order to "bootstrap" standby cluster with existing PGDATA - if ctl: - os.unlink(os.path.join(ctl._data_dir, 'patroni.dynamic.json')) + os.unlink(os.path.join(context.pctl._processes[name]._data_dir, 'patroni.dynamic.json')) port = context.pctl._processes[name2]._connkwargs.get('port') - return context.pctl.start(name, custom_config={ + context.pctl._processes[name].update_config({ "scope": cluster_name, "bootstrap": { "dcs": { @@ -47,6 +45,7 @@ def start_patroni_stanby_cluster(context, name, cluster_name, name2): } } }) + return context.pctl.start(name) @step('{pg_name1:w} is replicating from {pg_name2:w} after {timeout:d} seconds')