Skip to content

Commit

Permalink
test: add tests for tcs cluster publish/show
Browse files Browse the repository at this point in the history
There were integration tests for `tt cluster publish/show` only for
`etcd` and weren't for Tarantool Config Storage.

Due to the same interface tests have been parametrised to do the same
business logic for different storages.

Closes #716
  • Loading branch information
themilchenko authored and oleg-jukovec committed Jul 18, 2024
1 parent 8b5a6f3 commit abb860d
Show file tree
Hide file tree
Showing 10 changed files with 770 additions and 192 deletions.
34 changes: 27 additions & 7 deletions test/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
import signal
import subprocess

import etcd_helper
import psutil
import pytest
from cartridge_helper import CartridgeApp
from etcd_helper import EtcdInstance

from utils import create_tt_config, kill_procs
import utils


# ######## #
Expand Down Expand Up @@ -52,7 +52,7 @@ def tt_cmd(tmp_path_factory):

@pytest.fixture()
def tmpdir_with_cfg(tmp_path):
create_tt_config(tmp_path, "")
utils.create_tt_config(tmp_path, "")
return tmp_path.as_posix()


Expand Down Expand Up @@ -89,16 +89,16 @@ def etcd_session(request, tmp_path_factory):
tmpdir = tmp_path_factory.mktemp("etcd")
host = "localhost"
port = 12388
etcd_instance = EtcdInstance(host, port, tmpdir)
etcd_instance = etcd_helper.EtcdInstance(host, port, tmpdir)

def stop_etcd_children():
etcd_instance.stop()

# Additionally, we stop all etcd children;
# Finalizer may execute while ectd is starting.
me = psutil.Process()
kill_procs(list(filter(lambda p: p.name() == "etcd",
me.children())))
utils.kill_procs(list(filter(lambda p: p.name() == "etcd",
me.children())))

request.addfinalizer(stop_etcd_children)
etcd_instance.start()
Expand All @@ -115,7 +115,7 @@ def etcd(etcd_session):
@pytest.fixture(scope="session")
def cartridge_app_session(request, tt_cmd, tmp_path_factory):
tmpdir = tmp_path_factory.mktemp("cartridge_app")
create_tt_config(tmpdir, "")
utils.create_tt_config(tmpdir, "")
cartridge_app = CartridgeApp(tmpdir, tt_cmd)
request.addfinalizer(lambda: cartridge_app.stop())
cartridge_app.start()
Expand All @@ -132,3 +132,23 @@ def cartridge_app(request, cartridge_app_session):
bootstrap_vshard = params["bootstrap_vshard"]
cartridge_app_session.truncate(bootstrap_vshard=bootstrap_vshard)
return cartridge_app_session


@pytest.fixture
def fixture_params():
return {}


@pytest.fixture(scope="function")
def tcs(request, tmp_path, fixture_params):
test_app_path = os.path.join(fixture_params.get("path_to_cfg_dir"), "config.yaml")
inst = utils.TarantoolTestInstance(test_app_path, fixture_params.get("path_to_cfg_dir"),
"", tmp_path)
inst.start(connection_test=fixture_params.get("connection_test"),
connection_test_user=fixture_params.get("connection_test_user"),
connection_test_password=fixture_params.get("connection_test_password"),
instance_name=fixture_params.get("instance_name"),
instance_host=fixture_params.get("instance_host"),
instance_port=fixture_params.get("instance_port"))
request.addfinalizer(lambda: inst.stop())
return inst
18 changes: 11 additions & 7 deletions test/etcd_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,21 @@

import etcd3

etcd_username = "root"
etcd_password = "password"
DEFAULT_ETCD_USERNAME = "root"
DEFAULT_ETCD_PASSWORD = "password"


class EtcdInstance():
def __init__(self, host, port, workdir):
def __init__(self, host, port, workdir,
username=DEFAULT_ETCD_USERNAME,
password=DEFAULT_ETCD_PASSWORD):
self.host = host
self.port = port
self.workdir = workdir
self.endpoint = f"http://{self.host}:{self.port}"
self.popen = None
self.connection_username = username
self.connection_password = password

def start(self):
popen = subprocess.Popen(
Expand Down Expand Up @@ -57,17 +61,17 @@ def enable_auth(self):
# authentication enabled in latest python versions. So we need a separate steps
# to upload/fetch data to/from etcd via the client.
try:
subprocess.run(["etcdctl", "user", "add", etcd_username,
f"--new-user-password={etcd_password}",
subprocess.run(["etcdctl", "user", "add", self.connection_username,
f"--new-user-password={self.connection_password}",
f"--endpoints={self.endpoint}"])
subprocess.run(["etcdctl", "auth", "enable",
f"--user={etcd_username}:{etcd_password}",
f"--user={self.connection_username}:{self.connection_password}",
f"--endpoints={self.endpoint}"])
except Exception as ex:
self.stop()
raise ex

def disable_auth(self):
subprocess.run(["etcdctl", "auth", "disable",
f"--user={etcd_username}:{etcd_password}",
f"--user={self.connection_username}:{self.connection_password}",
f"--endpoints={self.endpoint}"])
15 changes: 9 additions & 6 deletions test/integration/cluster/test_cluster_demote.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import pytest
from etcd_helper import etcd_password, etcd_username
from etcd_helper import DEFAULT_ETCD_PASSWORD, DEFAULT_ETCD_USERNAME

from utils import run_command_and_get_output

Expand Down Expand Up @@ -133,18 +133,21 @@ def test_cluster_demote_auth(tt_cmd, tmpdir_with_cfg, etcd, auth):

if auth == "url":
env = None
url = f"http://{etcd_username}:{etcd_password}@{etcd.host}:{etcd.port}/prefix?timeout=5"
url = (
f"http://{DEFAULT_ETCD_USERNAME}:{DEFAULT_ETCD_PASSWORD}@"
f"{etcd.host}:{etcd.port}/prefix?timeout=5"
)
demote_cmd = [tt_cmd, "cluster", "rs", "demote", "-f", url, "instance-001"]
elif auth == "flag":
env = None
url = f"{etcd.endpoint}/prefix?timeout=5"
demote_cmd = [tt_cmd, "cluster", "rs", "demote", "-f",
"-u", etcd_username,
"-p", etcd_password,
"-u", DEFAULT_ETCD_USERNAME,
"-p", DEFAULT_ETCD_PASSWORD,
url, "instance-001"]
elif auth == "env":
env = {"TT_CLI_ETCD_USERNAME": etcd_username,
"TT_CLI_ETCD_PASSWORD": etcd_password}
env = {"TT_CLI_ETCD_USERNAME": DEFAULT_ETCD_USERNAME,
"TT_CLI_ETCD_PASSWORD": DEFAULT_ETCD_PASSWORD}
url = f"{etcd.endpoint}/prefix?timeout=5"
demote_cmd = [tt_cmd, "cluster", "rs", "demote", "-f", url, "instance-001"]

Expand Down
15 changes: 9 additions & 6 deletions test/integration/cluster/test_cluster_promote.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import os

import pytest
from etcd_helper import etcd_password, etcd_username
from etcd_helper import DEFAULT_ETCD_PASSWORD, DEFAULT_ETCD_USERNAME

from utils import read_kv, run_command_and_get_output

Expand Down Expand Up @@ -257,18 +257,21 @@ def test_cluster_promote_auth(tt_cmd, etcd, tmpdir_with_cfg, auth):

if auth == "url":
env = None
url = f"http://{etcd_username}:{etcd_password}@{etcd.host}:{etcd.port}/prefix?timeout=5"
url = (
f"http://{DEFAULT_ETCD_USERNAME}:{DEFAULT_ETCD_PASSWORD}@"
f"{etcd.host}:{etcd.port}/prefix?timeout=5"
)
promote_cmd = [tt_cmd, "cluster", "rs", "promote", "-f", url, "instance-002"]
elif auth == "flag":
env = None
url = f"{etcd.endpoint}/prefix?timeout=5"
promote_cmd = [tt_cmd, "cluster", "rs", "promote", "-f",
"-u", etcd_username,
"-p", etcd_password,
"-u", DEFAULT_ETCD_USERNAME,
"-p", DEFAULT_ETCD_PASSWORD,
url, "instance-002"]
elif auth == "env":
env = {"TT_CLI_ETCD_USERNAME": etcd_username,
"TT_CLI_ETCD_PASSWORD": etcd_password}
env = {"TT_CLI_ETCD_USERNAME": DEFAULT_ETCD_USERNAME,
"TT_CLI_ETCD_PASSWORD": DEFAULT_ETCD_PASSWORD}
url = f"{etcd.endpoint}/prefix?timeout=5"
promote_cmd = [tt_cmd, "cluster", "rs", "promote", "-f", url, "instance-002"]

Expand Down
Loading

0 comments on commit abb860d

Please sign in to comment.