-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Move zookeeper.py in chadmin * Review fixes * Changes * Update chadmin_zookeeper.feature
- Loading branch information
1 parent
3024d65
commit 8c07351
Showing
5 changed files
with
296 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
Feature: chadmin zookeeper commands. | ||
|
||
Background: | ||
Given default configuration | ||
And a working s3 | ||
And a working zookeeper | ||
And a working clickhouse on clickhouse01 | ||
|
||
|
||
Scenario: Cleanup all hosts | ||
When we execute chadmin create zk nodes on zookeeper01 | ||
""" | ||
/test/write_sli_part/shard1/replicas/host1.net | ||
/test/write_sli_part/shard1/replicas/host2.net | ||
/test/read_sli_part/shard1/replicas/host1.net | ||
/test/read_sli_part/shard1/replicas/host2.net | ||
/test/write_sli_part/shard1/log | ||
""" | ||
And we do hosts cleanup on zookeeper01 with fqdn host1.net,host2.net and zk root /test | ||
|
||
Then the list of children on zookeeper01 for zk node /test/write_sli_part are empty | ||
And the list of children on zookeeper01 for zk node /test/read_sli_part are empty | ||
|
||
Scenario: Cleanup single host | ||
When we execute chadmin create zk nodes on zookeeper01 | ||
""" | ||
/test/write_sli_part/shard1/replicas/host1.net | ||
/test/write_sli_part/shard1/replicas/host2.net | ||
/test/read_sli_part/shard1/replicas/host1.net | ||
/test/read_sli_part/shard1/replicas/host2.net | ||
/test/write_sli_part/shard1/log | ||
""" | ||
And we do hosts cleanup on zookeeper01 with fqdn host1.net and zk root /test | ||
|
||
|
||
Then the list of children on zookeeper01 for zk node /test/write_sli_part/shard1/replicas/ are equal to | ||
""" | ||
/test/write_sli_part/shard1/replicas/host2.net | ||
""" | ||
And the list of children on zookeeper01 for zk node /test/read_sli_part/shard1/replicas/ are equal to | ||
""" | ||
/test/read_sli_part/shard1/replicas/host2.net | ||
""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import logging | ||
|
||
|
||
class Chadmin: | ||
def __init__(self, container): | ||
self._container = container | ||
|
||
def exec_cmd(self, cmd): | ||
ch_admin_cmd = f"chadmin {cmd}" | ||
logging.debug("chadmin command:", ch_admin_cmd) | ||
result = self._container.exec_run(["bash", "-c", ch_admin_cmd], user="root") | ||
return result | ||
|
||
def create_zk_node(self, zk_node, no_ch_config=True, recursive=True): | ||
cmd = "zookeeper {use_config} create {make_parents} {node}".format( | ||
use_config="--no-ch-config" if no_ch_config else "", | ||
make_parents="--make-parents" if recursive else "", | ||
node=zk_node, | ||
) | ||
return self.exec_cmd(cmd) | ||
|
||
def zk_list(self, zk_node, no_ch_config=True): | ||
cmd = "zookeeper {use_config} list {node}".format( | ||
use_config="--no-ch-config" if no_ch_config else "", | ||
node=zk_node, | ||
) | ||
return self.exec_cmd(cmd) | ||
|
||
def zk_cleanup(self, fqdn, zk_root, no_ch_config=True): | ||
cmd = "zookeeper {use_config} --chroot {root} cleanup-removed-hosts-metadata {hosts}".format( | ||
use_config="--no-ch-config" if no_ch_config else "", | ||
root=zk_root, | ||
hosts=fqdn, | ||
) | ||
return self.exec_cmd(cmd) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
""" | ||
Steps for interacting with chadmin. | ||
""" | ||
|
||
from behave import then, when | ||
from hamcrest import assert_that, equal_to | ||
from modules.chadmin import Chadmin | ||
from modules.docker import get_container | ||
|
||
|
||
@when("we execute chadmin create zk nodes on {node:w}") | ||
def step_create_(context, node): | ||
container = get_container(context, node) | ||
nodes = context.text.strip().split("\n") | ||
chadmin = Chadmin(container) | ||
|
||
for node in nodes: | ||
result = chadmin.create_zk_node(node) | ||
assert result.exit_code == 0, f" output:\n {result.output.decode().strip()}" | ||
|
||
|
||
@when("we do hosts cleanup on {node} with fqdn {fqdn} and zk root {zk_root}") | ||
def step_host_cleanup(context, node, fqdn, zk_root): | ||
container = get_container(context, node) | ||
result = Chadmin(container).zk_cleanup(fqdn, zk_root) | ||
assert result.exit_code == 0, f" output:\n {result.output.decode().strip()}" | ||
|
||
|
||
@then("the list of children on {node:w} for zk node {zk_node} are equal to") | ||
def step_childen_list(context, node, zk_node): | ||
container = get_container(context, node) | ||
result = Chadmin(container).zk_list(zk_node) | ||
assert_that(result.output.decode(), equal_to(context.text + "\n")) | ||
|
||
|
||
@then("the list of children on {node:w} for zk node {zk_node} are empty") | ||
def step_childen_list_empty(context, node, zk_node): | ||
container = get_container(context, node) | ||
result = Chadmin(container).zk_list(zk_node) | ||
assert_that(result.output.decode(), equal_to("\n")) |