Skip to content

Commit

Permalink
Add certificate replacement
Browse files Browse the repository at this point in the history
  • Loading branch information
WStechura committed Sep 27, 2024
1 parent 0613ba2 commit 92c8b39
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 20 deletions.
8 changes: 0 additions & 8 deletions roles/oneagent/tests/component/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,3 @@ $ ansible-galaxy collection install -vvv dynatrace-oneagent*
$ cd roles/oneagent/tests/component
$ python run.py --linux_x86=localhost
```


- repo: https://github.com/ansible/ansible-lint
rev: v24.2.2
hooks:
- id: ansible-lint
pass_filenames: false
args: ['--exclude', 'roles/oneagent/examples']
10 changes: 5 additions & 5 deletions roles/oneagent/tests/component/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from pathlib import Path
from typing import Any
from scripts.util.test_data_types import DeploymentPlatform
from scripts.util.constants.common_constants import SIGNATURE_FILE_NAME
from scripts.util.constants.common_constants import SIGNATURE_FILE_NAME, INSTALLERS_RESOURCE_DIR

USER_KEY = "user"
PASS_KEY = "password"
Expand All @@ -19,7 +19,6 @@
TEST_DIR = BASE_DIR / "test_dir"
LOG_DIR = TEST_DIR / "logs"
INSTALLERS_DEST_DIR = TEST_DIR / "installers"
INSTALLERS_RESOURCE_DIR = BASE_DIR / "resources" / "installers"
TEST_VARS = {"PYTHONPATH": "scripts/"}


Expand Down Expand Up @@ -74,7 +73,7 @@ def run_all_tests(args: dict[str, Any]) -> bool:
test_args = get_test_args(args)
tests_failed = False

for test in glob.glob(f"{test_path}/test_*.py"):
for test in glob.glob(f"{test_path}/test_r*.py"):
if not run_test(test, test_args):
tests_failed = True

Expand Down Expand Up @@ -142,10 +141,11 @@ def prepare_installers() -> None:

def assign_localhost_to_ca_provider() -> None:
with open("/etc/hosts", "a+") as f:
if any(SIGNATURE_FILE_NAME in line for line in f.read()):
f.seek(0)
if any("ca.dynatrace.com" in line for line in f.readlines()):
return
f.write("\n# For orchestration tests purposes\n")
f.write(f"127.0.0.1\t{SIGNATURE_FILE_NAME}\n")
f.write(f"127.0.0.1\tca.dynatrace.com\n")


def prepare_environment() -> None:
Expand Down
13 changes: 10 additions & 3 deletions roles/oneagent/tests/component/scripts/technology/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,29 @@
ANSIBLE_RESOURCE_DIR,
ANSIBLE_USER_KEY,
COLLECTION_NAME,
COLLECTION_NAMESPACE,
CREDENTIALS_FILE_NAME,
HOSTS_TEMPLATE_FILE_NAME,
INSTALLED_COLLECTIONS_DIR,
INVENTORY_FILE,
PLAYBOOK_FILE,
PLAYBOOK_TEMPLATE_FILE_NAME,
ROLE_NAME,
TEST_COLLECTIONS_DIR,
TEST_SIGNATURE_FILE,
)

from technology.deployment_config import DeploymentConfig
from util.common_utils import read_yaml_file, write_yaml_file
from util.constants.common_constants import TEST_DIRECTORY, INSTALLERS_DIRECTORY
from util.constants.common_constants import TEST_DIRECTORY, INSTALLERS_DIRECTORY, SIGNATURE_FILE_NAME, INSTALLERS_RESOURCE_DIR
from util.test_data_types import DeploymentPlatform, PlatformCollection


def _prepare_collection() -> None:
shutil.rmtree(TEST_DIRECTORY / "collections", ignore_errors=True)
shutil.copytree(INSTALLED_COLLECTIONS_DIR, TEST_DIRECTORY / "collections")
shutil.rmtree(TEST_COLLECTIONS_DIR, ignore_errors=True)
shutil.copytree(INSTALLED_COLLECTIONS_DIR, TEST_COLLECTIONS_DIR)
# TODO: As we are now have 2 different sources of installers and signatures, we need to cleanup the code
shutil.copy(INSTALLERS_RESOURCE_DIR / SIGNATURE_FILE_NAME, TEST_SIGNATURE_FILE)

def _prepare_playbook_file() -> None:
shutil.copy(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
PLAYBOOK_TEMPLATE_FILE_NAME = "oneagent.yml"

ANSIBLE_RESOURCE_DIR = RESOURCES_DIRECTORY / "ansible"

# As tests needs to be run as root and the default install location for collection is non-root based,
# we need to get the script's user home dir to access installed collection.
# Parents[-3] for __file__ will return "/home/<user>"
Expand All @@ -32,6 +33,9 @@

PLAYBOOK_FILE = TEST_DIRECTORY / PLAYBOOK_TEMPLATE_FILE_NAME
INVENTORY_FILE = TEST_DIRECTORY / HOSTS_TEMPLATE_FILE_NAME
TEST_COLLECTIONS_DIR = TEST_DIRECTORY / "collections"
TEST_SIGNATURE_FILE = TEST_COLLECTIONS_DIR / "ansible_collections" / COLLECTION_NAMESPACE /\
COLLECTION_NAME / "roles" / ROLE_NAME / "files" / SIGNATURE_FILE_NAME

# Public
LOCAL_INSTALLERS_LOCATION = INSTALLERS_DIRECTORY
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

import pytest

from technology.constants import INSTALLER_SIGNATURE_FILE
from technology.constants import TEST_SIGNATURE_FILE
from util.test_data_types import DeploymentResult
from util.test_helpers import run_deployment, set_installer_download_params, enable_for_system_family

Expand Down Expand Up @@ -156,7 +156,7 @@ def test_failed_signature_verification(_error_messages, runner, configurator, co

set_installer_download_params(configurator)

with INSTALLER_SIGNATURE_FILE.open("w") as signature:
with TEST_SIGNATURE_FILE.open("w") as signature:
signature.write("break signature by writing some text")

universal_message = _error_messages.get(SIGNATURE_VERIFICATION_FAILED_KEY)
Expand Down
2 changes: 0 additions & 2 deletions roles/oneagent/tests/component/scripts/tests/test_upgrade.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ def test_versioned_installation(_set_up, runner, configurator, platforms, wrappe
logging.info("Running versioned installation test")

set_installer_download_params(configurator)
configurator.set_common_parameter(configurator.VERIFY_SIGNATURE_KEY, False)

versions = _get_versions_for_platforms(platforms, False)
for platform, version in versions.items():
Expand All @@ -53,7 +52,6 @@ def test_upgrade(_set_up, runner, configurator, platforms, wrapper, _tear_down):
configurator.clear_parameters_section()
set_installer_download_params(configurator)
configurator.set_common_parameter(configurator.INSTALLER_VERSION_KEY, "latest")
configurator.set_common_parameter(configurator.VERIFY_SIGNATURE_KEY, False)

versions = _get_versions_for_platforms(platforms, True)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
TEST_DIRECTORY = COMPONENT_TEST_BASE / "working_dir"
RESOURCES_DIRECTORY = Path().cwd() / "resources"
INSTALLERS_DIRECTORY = COMPONENT_TEST_BASE / "installers"
INSTALLERS_RESOURCE_DIR = RESOURCES_DIRECTORY / "installers"
SIGNATURE_FILE_NAME = "dt-root.cert.pem"

INSTALLER_PARTIAL_NAME = "Dynatrace-OneAgent"
Expand Down

0 comments on commit 92c8b39

Please sign in to comment.