Skip to content

Commit

Permalink
Move certificate download URL to pytest.ini file
Browse files Browse the repository at this point in the history
  • Loading branch information
WStechura committed Nov 22, 2024
1 parent 13731c4 commit 8be0ece
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
10 changes: 9 additions & 1 deletion roles/oneagent/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,16 @@
SERVER_DIRECTORY, LOG_DIRECTORY)


# Command line options
USER_KEY = "user"
PASS_KEY = "password"
TENANT_KEY = "tenant"
TENANT_TOKEN_KEY = "tenant_token"
PRESERVE_INSTALLERS_KEY = "preserve_installers"

# Ini file configuration
CA_CERT_URL_KEY = "dynatrace_ca_cert_url"

RUNNER_KEY = "runner"
WRAPPER_KEY = "wrapper"
CONSTANTS_KEY = "constants"
Expand Down Expand Up @@ -73,6 +77,8 @@ def prepare_installers(request) -> None:
preserve_installers = request.config.getoption(PRESERVE_INSTALLERS_KEY)
platforms = parse_platforms_from_options(vars(request.config.option))

cert_url = request.config.getini(CA_CERT_URL_KEY)

if preserve_installers:
logging.info("Skipping installers preparation...")
return
Expand All @@ -83,7 +89,7 @@ def prepare_installers(request) -> None:
pytest.exit("Generating installers failed")
elif tenant and tenant_token:
logging.info("Downloading installers and signature...")
if not download_signature() or not download_installers(tenant, tenant_token, platforms):
if not download_signature(cert_url) or not download_installers(tenant, tenant_token, platforms):
pytest.exit("Downloading installers and signature failed")
else:
pytest.exit("No tenant or tenant token provided, cannot download installers")
Expand Down Expand Up @@ -137,6 +143,8 @@ def handle_test_environment(runner, configurator, platforms, wrapper) -> None:


def pytest_addoption(parser) -> None:
parser.addini(CA_CERT_URL_KEY, "Url to CA certificate for downloading installers")

parser.addoption(f"--{USER_KEY}", type=str, help="Name of the user", required=False)
parser.addoption(f"--{PASS_KEY}", type=str, help="Password of the user", required=False)
parser.addoption(f"--{TENANT_KEY}", type=str, help="Tenant URL for downloading installer", required=False)
Expand Down
1 change: 1 addition & 0 deletions roles/oneagent/tests/pytest.ini
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
[pytest]
pythonpath = .
dynatrace_ca_cert_url = "https://ca.dynatrace.com/dt-root.cert.pem"
3 changes: 1 addition & 2 deletions roles/oneagent/tests/util/installer_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,7 @@ def download_and_save(path: Path, url: str, headers: dict[str, str]) -> bool:
return True


def download_signature() -> bool:
url = "https://ca.dynatrace.com/dt-root.cert.pem"
def download_signature(url: str) -> bool:
path = INSTALLERS_DIRECTORY / INSTALLER_CERTIFICATE_FILE_NAME
return download_and_save(path, url, {})

Expand Down

0 comments on commit 8be0ece

Please sign in to comment.