Skip to content

Commit

Permalink
Added feature test for pgconsul_util reset-all command
Browse files Browse the repository at this point in the history
  • Loading branch information
EinKrebs committed Dec 13, 2023
1 parent a90edad commit fe8b6c3
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ def reset_all(opts, conf):
"""
conf.set('global', 'iteration_timeout', 5)
zk = zookeeper.Zookeeper(config=conf, plugins=None)
logging.debug("resetting all ZK nodes")
for node in [x for x in zk.get_children("") if x != zk.MEMBERS_PATH]:
logging.debug(f'resetting path "{node}"')
if not zk.delete(node, recursive=True):
Expand Down
46 changes: 46 additions & 0 deletions tests/features/pgconsul_util.feature
Original file line number Diff line number Diff line change
Expand Up @@ -882,3 +882,49 @@ Feature: Check pgconsul-util features
Examples: <lock_type>, <lock_host>
| lock_type | lock_host |
| zookeeper | zookeeper1 |


@pgconsul_util_reset_all
Scenario Outline: Check pgconsul-util failover reset works as expected
Given a "pgconsul" container common config
"""
pgconsul.conf:
global:
priority: 0
use_replication_slots: 'yes'
quorum_commit: 'yes'
primary:
change_replication_type: 'yes'
primary_switch_checks: 1
replica:
allow_potential_data_loss: 'no'
primary_unavailability_timeout: 1
primary_switch_checks: 1
min_failover_timeout: 1
primary_unavailability_timeout: 2
commands:
generate_recovery_conf: /usr/local/bin/gen_rec_conf_with_slot.sh %m %p
"""
Given a following cluster with "<lock_type>" with replication slots
"""
postgresql1:
role: primary
postgresql2:
role: replica
"""
Then <lock_type> "<lock_host>" has key "/pgconsul/postgresql/all_hosts/pgconsul_postgresql1_1.pgconsul_pgconsul_net"
When we set value "some_value" for key "/pgconsul/postgresql/some_key" in <lock_type> "<lock_host>"
And we run following command on host "postgresql1"
"""
pgconsul-util reset-all
"""
Then command exit with return code "0"
And command result contains following output
"""
resetting all ZK nodes
"""
Then <lock_type> "<lock_host>" has key "/pgconsul/postgresql/all_hosts/pgconsul_postgresql1_1.pgconsul_pgconsul_net"
And <lock_type> "<lock_host>" doesn't have key "/pgconsul/postgresql/some_key"
Examples: <lock_type>, <lock_host>
| lock_type | lock_host |
| zookeeper | zookeeper1 |
15 changes: 15 additions & 0 deletions tests/steps/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,21 @@ def get_zk_value(context, zk_name, key):
return None


def zk_has_key(context, zk_name, key):
with contextlib.suppress(Exception):
zk = get_zk(context, zk_name)
zk.start()
try:
_ = zk.get(key)
return True
except NoNodeError:
return False
finally:
zk.stop()
zk.close()
return False


def exec(container, cmd):
"""
Execute command inside of given container
Expand Down
16 changes: 16 additions & 0 deletions tests/steps/zk.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,22 @@ def step_zk_value(context, name, value, key):
)


@then('zookeeper "{name}" has key "{key}"')
@helpers.retry_on_assert
def step_zk_key(context, name, key):
assert helpers.zk_has_key(context, name, key), '{time}: key "{key}" is missing'.format(
time=datetime.now().strftime("%H:%M:%S"), key=key
)


@then('zookeeper "{name}" doesn\'t have key "{key}"')
@helpers.retry_on_assert
def step_zk_key(context, name, key):
assert not helpers.zk_has_key(context, name, key), '{time}: key "{key}" is present'.format(
time=datetime.now().strftime("%H:%M:%S"), key=key
)


@then('zookeeper "{name}" has "{n}" values for key "{key}"')
@helpers.retry_on_assert
def step_zk_key_has_n_values(context, name, n, key):
Expand Down

0 comments on commit fe8b6c3

Please sign in to comment.