Server IP : 85.214.239.14 / Your IP : 18.227.0.21 Web Server : Apache/2.4.62 (Debian) System : Linux h2886529.stratoserver.net 4.9.0 #1 SMP Tue Jan 9 19:45:01 MSK 2024 x86_64 User : www-data ( 33) PHP Version : 7.4.18 Disable Function : pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare, MySQL : OFF | cURL : OFF | WGET : ON | Perl : ON | Python : ON | Sudo : ON | Pkexec : OFF Directory : /proc/2/root/proc/2/task/2/root/usr/lib/python3/dist-packages/ansible_test/_internal/ |
Upload File : |
"""Bootstrapping for test hosts.""" from __future__ import annotations import dataclasses import os import typing as t from .io import ( read_text_file, ) from .util import ( ANSIBLE_TEST_TARGET_ROOT, ) from .util_common import ( ShellScriptTemplate, set_shebang, ) from .core_ci import ( SshKey, ) @dataclasses.dataclass class Bootstrap: """Base class for bootstrapping systems.""" controller: bool python_versions: list[str] ssh_key: SshKey @property def bootstrap_type(self) -> str: """The bootstrap type to pass to the bootstrapping script.""" return self.__class__.__name__.replace('Bootstrap', '').lower() def get_variables(self) -> dict[str, t.Union[str, list[str]]]: """The variables to template in the bootstrapping script.""" return dict( bootstrap_type=self.bootstrap_type, controller='yes' if self.controller else '', python_versions=self.python_versions, ssh_key_type=self.ssh_key.KEY_TYPE, ssh_private_key=self.ssh_key.key_contents, ssh_public_key=self.ssh_key.pub_contents, ) def get_script(self) -> str: """Return a shell script to bootstrap the specified host.""" path = os.path.join(ANSIBLE_TEST_TARGET_ROOT, 'setup', 'bootstrap.sh') content = read_text_file(path) content = set_shebang(content, '/bin/sh') template = ShellScriptTemplate(content) variables = self.get_variables() script = template.substitute(**variables) return script @dataclasses.dataclass class BootstrapDocker(Bootstrap): """Bootstrap docker instances.""" def get_variables(self) -> dict[str, t.Union[str, list[str]]]: """The variables to template in the bootstrapping script.""" variables = super().get_variables() variables.update( platform='', platform_version='', ) return variables @dataclasses.dataclass class BootstrapRemote(Bootstrap): """Bootstrap remote instances.""" platform: str platform_version: str def get_variables(self) -> dict[str, t.Union[str, list[str]]]: """The variables to template in the bootstrapping script.""" variables = super().get_variables() variables.update( platform=self.platform, platform_version=self.platform_version, ) return variables