BB: Gather enabled tests and select GCP machines needed for the specific tests

This commit is contained in:
Ilija Lazoroski 2022-08-10 17:32:39 +02:00
parent 126f37a1f2
commit 736e779f4c
2 changed files with 32 additions and 15 deletions

View File

@ -1,5 +1,10 @@
import pytest
from envs.monkey_zoo.blackbox.gcp_test_machine_list import (
GCP_SINGLE_TEST_LIST,
GCP_TEST_MACHINE_LIST,
)
def pytest_addoption(parser):
parser.addoption(
@ -33,8 +38,30 @@ def no_gcp(request):
@pytest.fixture(scope="session")
def machines_to_start(request):
return request.config.getoption("-k")
def list_machines(request):
enabled_tests = [test.name for test in request.node.items]
if len(enabled_tests) == len(GCP_SINGLE_TEST_LIST.keys()):
return GCP_TEST_MACHINE_LIST
try:
list_machines_to_start = [GCP_SINGLE_TEST_LIST[test] for test in enabled_tests]
if len(list_machines_to_start) == 1:
return list_machines_to_start[0]
single_machine_list = {}
for machine_dict in list_machines_to_start:
for zone, machines in machine_dict.items():
for machine in machines:
if machine not in single_machine_list[zone]:
single_machine_list[zone].append(machine)
except KeyError:
return GCP_TEST_MACHINE_LIST
return single_machine_list
def pytest_runtest_setup(item):

View File

@ -6,10 +6,6 @@ import pytest
from envs.monkey_zoo.blackbox.analyzers.communication_analyzer import CommunicationAnalyzer
from envs.monkey_zoo.blackbox.analyzers.zerologon_analyzer import ZerologonAnalyzer
from envs.monkey_zoo.blackbox.gcp_test_machine_list import (
GCP_SINGLE_TEST_LIST,
GCP_TEST_MACHINE_LIST,
)
from envs.monkey_zoo.blackbox.island_client.monkey_island_client import MonkeyIslandClient
from envs.monkey_zoo.blackbox.island_client.test_configuration_parser import get_target_ips
from envs.monkey_zoo.blackbox.log_handlers.test_logs_handler import TestLogsHandler
@ -38,16 +34,10 @@ LOGGER = logging.getLogger(__name__)
@pytest.fixture(autouse=True, scope="session")
def GCPHandler(request, no_gcp, machines_to_start):
def GCPHandler(request, no_gcp, list_machines):
if not no_gcp:
list_machines = GCP_TEST_MACHINE_LIST
if machines_to_start:
try:
list_machines = GCP_SINGLE_TEST_LIST[machines_to_start]
except KeyError as err:
LOGGER.warning(
f"Partial or wrong test name provided. " f"Starting all GCP machines:{err}"
)
LOGGER.info(f"MACHINES TO START: {list_machines}")
try:
initialize_gcp_client()
start_machines(list_machines)