Skip to content

Commit

Permalink
Add missing types
Browse files Browse the repository at this point in the history
  • Loading branch information
WStechura committed Sep 11, 2024
1 parent 78e4dcb commit 71808c4
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 13 deletions.
12 changes: 6 additions & 6 deletions roles/oneagent/tests/component/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,14 @@ def __exit__(self, exc_type, exc_val, exc_tb):
save_log(self.proc.stdout, LOG_DIR / "server.log")


def get_env_vars():
def get_env_vars() -> dict[str, str]:
# This is required to pass current venv vars down to the subprocess for tests and server
env_vars = os.environ.copy()
env_vars.update(TEST_VARS)
return env_vars


def save_log(out, log_path: Path):
def save_log(out, log_path: Path) -> None:
with log_path.open("w") as log:
for line in out:
log.write(line)
Expand Down Expand Up @@ -78,14 +78,14 @@ def run_all_tests(args: dict[str, Any]) -> bool:
return tests_failed


def run_server():
def run_server() -> None:
logging.info("Running server...")
server_path = Path("scripts") / "server" / "server.py"
return subprocess.Popen(["python", server_path], env=get_env_vars(),
stdout=subprocess.PIPE, stderr=subprocess.STDOUT, encoding="utf-8")


def get_file_content(path: Path):
def get_file_content(path: Path) -> list[str]:
with path.open("r") as f:
return f.readlines()

Expand All @@ -94,7 +94,7 @@ def replace_tag(source: list[str], old: str, new: str) -> list[str]:
return [line.replace(old, new) for line in source]


def prepare_installers():
def prepare_installers() -> None:
logging.info("Preparing installers...")

oneagentctl_bin_name = "oneagentctl.sh"
Expand Down Expand Up @@ -126,7 +126,7 @@ def prepare_installers():
f.writelines(installer_code)


def prepare_environment():
def prepare_environment() -> None
logging.basicConfig(
format="%(asctime)s [server] %(levelname)s: %(message)s", datefmt="%H:%M:%S", level=logging.INFO
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,13 @@
TECH_VERSION_KEY = "tech_version"
TECH_SCRIPT_VERSION_KEY = "script_version"

# Tags and properties for regular installation
INSTALLER_TAG = "install_tag"
INSTALLER_PROPERTY = "install_prop1=install_1"
PLATFORM_TAG = "platform_install_tag"
PLATFORM_PROPERTY = "platform_install_property"

# Tags and properties for intended configuration with oneagentctl
CONFIG_INSTALL_TAG = "config_install_tag"
CONFIG_INSTALL_PROPERTY = "install_prop2=config_install_prop"
CONFIG_INTENDED_TAG = "config_intended_tag"
Expand Down Expand Up @@ -87,7 +90,7 @@ def _check_output_for_secrets(result: DeploymentResult) -> None:
def test_basic_installation(_set_up, runner, configurator, constants, platforms, wrapper):
logging.info("Running basic installation test")

set_installer_download_params(configurator)
set_installer_download_params(configurator)
configurator.set_common_parameter(configurator.PRESERVE_INSTALLER_KEY, True)
configurator.set_common_parameter(configurator.INSTALLER_ARGS_KEY, INSTALLER_ARGS)
configurator.set_common_parameter(configurator.VERIFY_SIGNATURE_KEY, False)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

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

MISSING_REQUIRED_PARAMETERS_KEY = "missing_mandatory_params"
UNKNOWN_ARCHITECTURE_KEY = "unknown_arch"
Expand Down Expand Up @@ -86,7 +86,7 @@ def test_missing_local_installer(_error_messages, runner, configurator, constant
)


@enable_for_family(family="unix")
@enable_for_system_family(family="unix")
def test_directories_contain_spaces(_error_messages, runner, configurator, constants):
logging.info("Running directories contain spaces test")

Expand Down Expand Up @@ -150,7 +150,7 @@ def test_failed_download(_error_messages, runner, configurator, constants):


# noinspection PyUnusedLocal
@enable_for_family(family="unix")
@enable_for_system_family(family="unix")
def test_failed_signature_verification(_error_messages, runner, configurator, constants):
logging.info("Running failed signature verification test")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,14 @@ def system(self) -> str:
return str(self.value).split("_")[0]

@staticmethod
def from_str(param: str):
def from_str(param: str) -> "DeploymentPlatform":
try:
return DeploymentPlatform[param.upper()]
except KeyError:
raise ValueError(f"Invalid option passed: {param}") from KeyError

@staticmethod
def from_system_and_arch(system: str, arch: str):
def from_system_and_arch(system: str, arch: str) -> "DeploymentPlatform":
return DeploymentPlatform.from_str(f"{system}_{arch}")


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def platforms_wrapper(*args, **kwargs):
return func_wrapper


def enable_for_family(family: str):
def enable_for_system_family(family: str):
def func_wrapper(func):
@functools.wraps(func)
def params_wrapper(*args, **kwargs):
Expand Down

0 comments on commit 71808c4

Please sign in to comment.