2019-08-29 20:14:07 +08:00
|
|
|
import pytest
|
|
|
|
|
2022-08-10 23:32:39 +08:00
|
|
|
from envs.monkey_zoo.blackbox.gcp_test_machine_list import (
|
|
|
|
GCP_SINGLE_TEST_LIST,
|
|
|
|
GCP_TEST_MACHINE_LIST,
|
|
|
|
)
|
|
|
|
|
2019-08-29 20:14:07 +08:00
|
|
|
|
2019-08-29 19:57:04 +08:00
|
|
|
def pytest_addoption(parser):
|
2021-04-06 21:19:27 +08:00
|
|
|
parser.addoption(
|
|
|
|
"--island",
|
|
|
|
action="store",
|
|
|
|
default="",
|
|
|
|
help="Specify the Monkey Island address (host+port).",
|
|
|
|
)
|
|
|
|
parser.addoption(
|
|
|
|
"--no-gcp",
|
|
|
|
action="store_true",
|
|
|
|
default=False,
|
|
|
|
help="Use for no interaction with the cloud.",
|
|
|
|
)
|
2021-09-27 19:08:52 +08:00
|
|
|
parser.addoption(
|
2021-09-28 22:42:16 +08:00
|
|
|
"--skip-powershell-reuse",
|
|
|
|
action="store_true",
|
|
|
|
default=False,
|
|
|
|
help="Use to run PowerShell credentials reuse test.",
|
2021-09-27 19:08:52 +08:00
|
|
|
)
|
2021-04-06 21:19:27 +08:00
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture(scope="session")
|
2019-08-29 20:14:07 +08:00
|
|
|
def island(request):
|
2019-09-11 17:39:28 +08:00
|
|
|
return request.config.getoption("--island")
|
2020-05-13 15:44:04 +08:00
|
|
|
|
|
|
|
|
2021-04-06 21:19:27 +08:00
|
|
|
@pytest.fixture(scope="session")
|
2020-05-13 15:44:04 +08:00
|
|
|
def no_gcp(request):
|
|
|
|
return request.config.getoption("--no-gcp")
|
|
|
|
|
|
|
|
|
2022-07-27 21:03:29 +08:00
|
|
|
@pytest.fixture(scope="session")
|
2022-08-10 23:32:39 +08:00
|
|
|
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
|
2022-07-27 21:03:29 +08:00
|
|
|
|
|
|
|
|
2021-04-29 20:45:39 +08:00
|
|
|
def pytest_runtest_setup(item):
|
2021-09-28 22:42:16 +08:00
|
|
|
if "skip_powershell_reuse" in item.keywords and item.config.getoption(
|
|
|
|
"--skip-powershell-reuse"
|
|
|
|
):
|
2021-09-27 23:12:28 +08:00
|
|
|
pytest.skip(
|
2021-09-28 22:42:16 +08:00
|
|
|
"Skipping powershell credentials reuse test because "
|
|
|
|
"--skip-powershell-cached flag isn't specified."
|
2021-09-27 23:12:28 +08:00
|
|
|
)
|