-
Notifications
You must be signed in to change notification settings - Fork 277
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add rpm support for integTest framework #1992
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,12 +12,14 @@ | |
|
||
|
||
class Process: | ||
def __init__(self) -> None: | ||
def __init__(self, filename: str, distribution: str) -> None: | ||
self.process: subprocess.Popen[bytes] = None | ||
self.stdout: Any = None | ||
self.stderr: Any = None | ||
self.__stdout_data__: str = None | ||
self.__stderr_data__: str = None | ||
self.filename = filename | ||
self.distribution = distribution | ||
|
||
def start(self, command: str, cwd: str) -> None: | ||
if self.started: | ||
|
@@ -38,7 +40,7 @@ def terminate(self) -> int: | |
if not self.started: | ||
raise ProcessNotStartedError() | ||
|
||
parent = psutil.Process(self.process.pid) | ||
parent = psutil.Process(self.pid) | ||
logging.debug("Checking for child processes") | ||
child_processes = parent.children(recursive=True) | ||
for child in child_processes: | ||
|
@@ -65,6 +67,10 @@ def terminate(self) -> int: | |
self.return_code = self.process.returncode | ||
self.process = None | ||
|
||
if self.distribution == "rpm": | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should not live in |
||
logging.info("Clean up process related files for packages") | ||
subprocess.check_call(f"yum remove -y '{self.filename}*'", shell=True) | ||
|
||
return self.return_code | ||
|
||
@property | ||
|
@@ -73,6 +79,8 @@ def started(self) -> bool: | |
|
||
@property | ||
def pid(self) -> int: | ||
if self.distribution == "rpm": | ||
return int(subprocess.check_output(f"sleep 1 && systemctl show --property MainPID {self.filename}", encoding='UTF-8', shell=True).split("=")[1]) if self.started else None | ||
return self.process.pid if self.started else None | ||
|
||
@property | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,7 @@ | |
|
||
import abc | ||
import logging | ||
import os | ||
import time | ||
|
||
import requests | ||
|
@@ -19,14 +20,30 @@ class Service(abc.ABC): | |
Abstract base class for all types of test clusters. | ||
""" | ||
|
||
def __init__(self, work_dir, version, security_enabled, additional_config, dependency_installer): | ||
def __init__(self, work_dir, filename, version, distribution, security_enabled, additional_config, dependency_installer): | ||
self.filename = filename | ||
self.work_dir = work_dir | ||
self.version = version | ||
self.distribution = distribution | ||
self.security_enabled = security_enabled | ||
self.additional_config = additional_config | ||
self.dependency_installer = dependency_installer | ||
|
||
self.process_handler = Process() | ||
self.process_handler = Process(self.filename, self.distribution) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This class is a generic |
||
self.install_dir_map = { | ||
"tar": os.path.join(self.work_dir, f"{self.filename}-{self.version}"), | ||
"rpm": os.path.join(os.sep, "usr", "share", self.filename) | ||
} | ||
self.config_file_map = { | ||
"tar": os.path.join(self.install_dir_map[self.distribution], "config", f"{self.filename.replace('-', '_')}.yml"), | ||
"rpm": os.path.join(os.sep, "etc", self.filename, f"{self.filename.replace('-', '_')}.yml") | ||
} | ||
self.start_cmd_map = { | ||
"tar-opensearch": "./opensearch-tar-install.sh", | ||
"tar-opensearch-dashboards": "./opensearch-dashboards", | ||
"rpm-opensearch": "systemctl start opensearch", | ||
"rpm-opensearch-dashboards": "systemctl start opensearch-dashboards" | ||
} | ||
self.install_dir = "" | ||
|
||
@abc.abstractmethod | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,7 @@ | |
|
||
import logging | ||
import os | ||
import subprocess | ||
import tarfile | ||
|
||
import requests | ||
|
@@ -17,22 +18,27 @@ | |
class ServiceOpenSearch(Service): | ||
def __init__( | ||
self, | ||
filename, | ||
version, | ||
distribution, | ||
additional_config, | ||
security_enabled, | ||
dependency_installer, | ||
work_dir | ||
): | ||
super().__init__(work_dir, version, security_enabled, additional_config, dependency_installer) | ||
super().__init__(work_dir, filename, version, distribution, security_enabled, additional_config, dependency_installer) | ||
|
||
self.dependency_installer = dependency_installer | ||
self.filename = filename | ||
self.distribution = distribution | ||
|
||
self.install_dir = os.path.join(self.work_dir, f"opensearch-{self.version}") | ||
logging.info(f'{self.filename} distribution: {self.distribution}') | ||
self.install_dir = self.install_dir_map[self.distribution] | ||
|
||
def start(self): | ||
self.__download() | ||
|
||
self.opensearch_yml_dir = os.path.join(self.install_dir, "config", "opensearch.yml") | ||
self.opensearch_yml_dir = self.config_file_map[self.distribution] | ||
self.security_plugin_dir = os.path.join(self.install_dir, "plugins", "opensearch-security") | ||
|
||
if not self.security_enabled and os.path.isdir(self.security_plugin_dir): | ||
|
@@ -41,7 +47,7 @@ def start(self): | |
if self.additional_config: | ||
self.__add_plugin_specific_config(self.additional_config) | ||
|
||
self.process_handler.start("./opensearch-tar-install.sh", self.install_dir) | ||
self.process_handler.start(self.start_cmd_map[f"{self.distribution}-{self.filename}"], self.install_dir) | ||
logging.info(f"Started OpenSearch with parent PID {self.process_handler.pid}") | ||
|
||
def __download(self): | ||
|
@@ -50,11 +56,31 @@ def __download(self): | |
bundle_name = self.dependency_installer.download_dist(self.work_dir) | ||
logging.info(f"Downloaded bundle to {os.path.realpath(bundle_name)}") | ||
|
||
logging.info(f"Unpacking {bundle_name}") | ||
with tarfile.open(bundle_name, 'r') as bundle_tar: | ||
bundle_tar.extractall(self.work_dir) | ||
|
||
logging.info(f"Unpacked {bundle_name}") | ||
logging.info(f"Installing {bundle_name} in {self.install_dir}") | ||
|
||
if self.distribution == "tar": | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Subclass |
||
with tarfile.open(bundle_name, 'r') as bundle_tar: | ||
bundle_tar.extractall(self.work_dir) | ||
elif self.distribution == "rpm": | ||
logging.info("rpm installation requires sudo, script will exit if current user does not have sudo access") | ||
rpm_install_cmd = " ".join( | ||
[ | ||
'yum', | ||
'remove', | ||
'-y', | ||
self.filename, | ||
'&&', | ||
'yum', | ||
'install', | ||
'-y', | ||
bundle_name | ||
] | ||
) | ||
subprocess.check_call(rpm_install_cmd, cwd=self.work_dir, shell=True) | ||
else: | ||
raise(f'{self.distribution} is not supported in integ-test yet') | ||
|
||
logging.info(f"Installed {bundle_name}") | ||
|
||
def url(self, path=""): | ||
return f'{"https" if self.security_enabled else "http"}://{self.endpoint()}:{self.port()}{path}' | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Process is a generic class in
system
, it should have nothing to do with distribution, this doesn't belong here.