diff --git a/tests/integration/tests/conftest.py b/tests/integration/tests/conftest.py index 53a6055b4..e713ecf8a 100644 --- a/tests/integration/tests/conftest.py +++ b/tests/integration/tests/conftest.py @@ -3,7 +3,7 @@ # import logging from pathlib import Path -from typing import Generator, List +from typing import Generator, List, Union import pytest from test_util import config, harness, util @@ -49,9 +49,11 @@ def h() -> harness.Harness: def pytest_configure(config): config.addinivalue_line( "markers", - "node_count: Mark a test to specify how many instance nodes need to be created\n" + "bootstrap_config: Provide a custom bootstrap config to the bootstrapping node.\n" "disable_k8s_bootstrapping: By default, the first k8s node is bootstrapped. This marker disables that.\n" - "etcd_count: Mark a test to specify how many etcd instance nodes need to be created (None by default)\n", + "dualstack: Support dualstack on the instances.\n" + "etcd_count: Mark a test to specify how many etcd instance nodes need to be created (None by default)\n" + "node_count: Mark a test to specify how many instance nodes need to be created\n", ) @@ -65,13 +67,32 @@ def node_count(request) -> int: @pytest.fixture(scope="function") -def disable_k8s_bootstrapping(request) -> int: +def disable_k8s_bootstrapping(request) -> bool: return bool(request.node.get_closest_marker("disable_k8s_bootstrapping")) +@pytest.fixture(scope="function") +def bootstrap_config(request) -> Union[str, None]: + bootstrap_config_marker = request.node.get_closest_marker("bootstrap_config") + if not bootstrap_config_marker: + return None + config, *_ = bootstrap_config_marker.args + return config + + +@pytest.fixture(scope="function") +def dualstack(request) -> bool: + return bool(request.node.get_closest_marker("dualstack")) + + @pytest.fixture(scope="function") def instances( - h: harness.Harness, node_count: int, tmp_path: Path, disable_k8s_bootstrapping: bool + h: harness.Harness, + node_count: int, + tmp_path: Path, + disable_k8s_bootstrapping: bool, + bootstrap_config: Union[str, None], + dualstack: bool, ) -> Generator[List[harness.Instance], None, None]: """Construct instances for a cluster. @@ -90,13 +111,20 @@ def instances( for _ in range(node_count): # Create instances and setup the k8s snap in each. - instance = h.new_instance() + instance = h.new_instance(dualstack=dualstack) instances.append(instance) util.setup_k8s_snap(instance, snap_path) if not disable_k8s_bootstrapping: first_node, *_ = instances - first_node.exec(["k8s", "bootstrap"]) + + if bootstrap_config is not None: + first_node.exec( + ["k8s", "bootstrap", "--file", "-"], + input=str.encode(bootstrap_config), + ) + else: + first_node.exec(["k8s", "bootstrap"]) yield instances diff --git a/tests/integration/tests/test_control_plane_taints.py b/tests/integration/tests/test_control_plane_taints.py index 38d3caf02..51b97e51f 100644 --- a/tests/integration/tests/test_control_plane_taints.py +++ b/tests/integration/tests/test_control_plane_taints.py @@ -6,28 +6,19 @@ from typing import List import pytest -import yaml from test_util import harness, util LOG = logging.getLogger(__name__) @pytest.mark.node_count(1) -@pytest.mark.disable_k8s_bootstrapping() +@pytest.mark.bootstrap_config( + 'control-plane-taints: ["node-role.kubernetes.io/control-plane:NoSchedule"]' +) def test_control_plane_taints(instances: List[harness.Instance]): k8s_instance = instances[0] - - bootstrap_conf = yaml.safe_dump( - {"control-plane-taints": ["node-role.kubernetes.io/control-plane:NoSchedule"]} - ) - - k8s_instance.exec( - ["dd", "of=/root/config.yaml"], - input=str.encode(bootstrap_conf), - ) - - k8s_instance.exec(["k8s", "bootstrap", "--file", "/root/config.yaml"]) retries = 10 + while retries and not (nodes := util.get_nodes(k8s_instance)): LOG.info("Waiting for Nodes") time.sleep(3) diff --git a/tests/integration/tests/test_dualstack.py b/tests/integration/tests/test_dualstack.py index cc6003cf2..53d586504 100644 --- a/tests/integration/tests/test_dualstack.py +++ b/tests/integration/tests/test_dualstack.py @@ -3,7 +3,7 @@ # import logging from ipaddress import IPv4Address, IPv6Address, ip_address -from pathlib import Path +from typing import List import pytest from test_util import config, harness, util @@ -12,19 +12,12 @@ @pytest.mark.node_count(1) -def test_dualstack(h: harness.Harness, tmp_path: Path): - snap_path = (tmp_path / "k8s.snap").as_posix() - main = h.new_instance(dualstack=True) - util.setup_k8s_snap(main, snap_path) - - bootstrap_config = (config.MANIFESTS_DIR / "bootstrap-dualstack.yaml").read_text() - - main.exec( - ["k8s", "bootstrap", "--file", "-"], - input=str.encode(bootstrap_config), - ) - util.wait_until_k8s_ready(main, [main]) - +@pytest.mark.bootstrap_config( + (config.MANIFESTS_DIR / "bootstrap-dualstack.yaml").read_text() +) +@pytest.mark.dualstack() +def test_dualstack(instances: List[harness.Instance]): + main = instances[0] dualstack_config = (config.MANIFESTS_DIR / "nginx-dualstack.yaml").read_text() # Deploy nginx with dualstack service diff --git a/tests/integration/tests/test_smoke.py b/tests/integration/tests/test_smoke.py index e66994048..afafe2001 100644 --- a/tests/integration/tests/test_smoke.py +++ b/tests/integration/tests/test_smoke.py @@ -8,25 +8,18 @@ from typing import List import pytest -from test_util import config, harness, util +from test_util import config, harness LOG = logging.getLogger(__name__) @pytest.mark.node_count(1) -@pytest.mark.disable_k8s_bootstrapping() +@pytest.mark.bootstrap_config( + (config.MANIFESTS_DIR / "bootstrap-smoke.yaml").read_text() +) def test_smoke(instances: List[harness.Instance]): instance = instances[0] - bootstrap_smoke_config_path = "/home/ubuntu/bootstrap-smoke.yaml" - instance.send_file( - (config.MANIFESTS_DIR / "bootstrap-smoke.yaml").as_posix(), - bootstrap_smoke_config_path, - ) - - instance.exec(["k8s", "bootstrap", "--file", bootstrap_smoke_config_path]) - util.wait_until_k8s_ready(instance, [instance]) - # Verify the functionality of the k8s config command during the smoke test. # It would be excessive to deploy a cluster solely for this purpose. result = instance.exec( diff --git a/tests/integration/tests/test_util/util.py b/tests/integration/tests/test_util/util.py index 33f4c5087..0df7d8045 100644 --- a/tests/integration/tests/test_util/util.py +++ b/tests/integration/tests/test_util/util.py @@ -139,7 +139,7 @@ def setup_k8s_snap(instance: harness.Instance, snap_path: Path): def wait_until_k8s_ready( control_node: harness.Instance, instances: List[harness.Instance], - retries: int = 15, + retries: int = 30, delay_s: int = 5, ): """