-
Notifications
You must be signed in to change notification settings - Fork 277
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add rpm support in integTest framework (2nd PR) (#2000)
* Add rpm support in integTest framework (2nd PR) Signed-off-by: Peter Zhu <[email protected]> * Add syntax checks Signed-off-by: Peter Zhu <[email protected]> * Update tests Signed-off-by: Peter Zhu <[email protected]> * Fix isort Signed-off-by: Peter Zhu <[email protected]> * More typo fixes Signed-off-by: Peter Zhu <[email protected]> * Rename vars Signed-off-by: Peter Zhu <[email protected]> * More map removal Signed-off-by: Peter Zhu <[email protected]> * More tweaks Signed-off-by: Peter Zhu <[email protected]>
- Loading branch information
1 parent
6c8817b
commit 74b532b
Showing
17 changed files
with
369 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
# SPDX-License-Identifier: Apache-2.0 | ||
# | ||
# The OpenSearch Contributors require contributions made to | ||
# this file be licensed under the Apache-2.0 license or a | ||
# compatible open source license. | ||
|
||
from abc import ABC, abstractmethod | ||
|
||
|
||
class Distribution(ABC): | ||
def __enter__(self) -> 'Distribution': | ||
return self | ||
|
||
def __init__(self, filename: str, version: str, work_dir: str) -> None: | ||
self.filename = filename | ||
self.version = version | ||
self.work_dir = work_dir | ||
|
||
@property | ||
@abstractmethod | ||
def install_dir(self) -> str: | ||
""" | ||
Return the install directory for the distribution | ||
""" | ||
pass | ||
|
||
@property | ||
@abstractmethod | ||
def config_dir(self, bundle_name: str) -> str: | ||
""" | ||
Return the config directory for the distribution | ||
""" | ||
pass | ||
|
||
@abstractmethod | ||
def install(self) -> None: | ||
""" | ||
The detailed method to install the distribution before start the service | ||
""" | ||
pass | ||
|
||
@property | ||
@abstractmethod | ||
def start_cmd(self) -> str: | ||
""" | ||
Return the start command for the distribution | ||
""" | ||
pass | ||
|
||
def uninstall(self) -> None: | ||
""" | ||
Allow distribution that is not 'tar' to do proper cleanup | ||
""" | ||
pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
# SPDX-License-Identifier: Apache-2.0 | ||
# | ||
# The OpenSearch Contributors require contributions made to | ||
# this file be licensed under the Apache-2.0 license or a | ||
# compatible open source license. | ||
|
||
import logging | ||
import os | ||
import subprocess | ||
|
||
from test_workflow.integ_test.distribution import Distribution | ||
|
||
|
||
class DistributionRpm(Distribution): | ||
def __init__(self, filename: str, version: str, work_dir: str) -> None: | ||
super().__init__(filename, version, work_dir) | ||
|
||
@property | ||
def install_dir(self) -> str: | ||
return os.path.join(os.sep, "usr", "share", self.filename) | ||
|
||
@property | ||
def config_dir(self) -> str: | ||
return os.path.join(os.sep, "etc", self.filename) | ||
|
||
def install(self, bundle_name: str) -> None: | ||
logging.info(f"Installing {bundle_name} in {self.install_dir}") | ||
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) | ||
|
||
@property | ||
def start_cmd(self) -> str: | ||
return f"systemctl start {self.filename}" | ||
|
||
def uninstall(self) -> None: | ||
logging.info("Uninstall {self.filename} package after the test") | ||
subprocess.check_call(f"yum remove -y {self.filename}", shell=True) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
# SPDX-License-Identifier: Apache-2.0 | ||
# | ||
# The OpenSearch Contributors require contributions made to | ||
# this file be licensed under the Apache-2.0 license or a | ||
# compatible open source license. | ||
|
||
import logging | ||
import os | ||
import tarfile | ||
|
||
from test_workflow.integ_test.distribution import Distribution | ||
|
||
|
||
class DistributionTar(Distribution): | ||
def __init__(self, filename: str, version: str, work_dir: str) -> None: | ||
super().__init__(filename, version, work_dir) | ||
|
||
@property | ||
def install_dir(self) -> str: | ||
return os.path.join(self.work_dir, f"{self.filename}-{self.version}") | ||
|
||
@property | ||
def config_dir(self) -> str: | ||
return os.path.join(self.install_dir, "config") | ||
|
||
def install(self, bundle_name: str) -> None: | ||
logging.info(f"Installing {bundle_name} in {self.install_dir}") | ||
with tarfile.open(bundle_name, 'r:gz') as bundle_tar: | ||
bundle_tar.extractall(self.work_dir) | ||
|
||
@property | ||
def start_cmd(self) -> str: | ||
start_cmd_map = { | ||
"opensearch": "./opensearch-tar-install.sh", | ||
"opensearch-dashboards": "./opensearch-dashboards", | ||
} | ||
return start_cmd_map[self.filename] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
# SPDX-License-Identifier: Apache-2.0 | ||
# | ||
# The OpenSearch Contributors require contributions made to | ||
# this file be licensed under the Apache-2.0 license or a | ||
# compatible open source license. | ||
|
||
import logging | ||
|
||
from test_workflow.integ_test.distribution import Distribution | ||
from test_workflow.integ_test.distribution_rpm import DistributionRpm | ||
from test_workflow.integ_test.distribution_tar import DistributionTar | ||
|
||
|
||
class Distributions: | ||
DISTRIBUTIONS_MAP = { | ||
"tar": DistributionTar, | ||
"rpm": DistributionRpm, | ||
} | ||
|
||
@classmethod | ||
def from_name(cls, name: str) -> Distribution: | ||
klass = cls.DISTRIBUTIONS_MAP.get(name, None) | ||
if not klass: | ||
raise ValueError(f"Unsupported distribution: {name}") | ||
return klass # type: ignore[return-value] | ||
|
||
@classmethod | ||
def get_distribution(cls, filename: str, distribution: str, version: str, work_dir: str) -> Distribution: | ||
klass = cls.from_name(distribution) | ||
logging.info(f"{filename} distribution: {distribution}") | ||
return klass(filename, version, work_dir) # type: ignore[no-any-return, operator] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file added
BIN
+223 Bytes
.../test_integ_workflow/integ_test/data/artifacts/dist/opensearch-min-1.3.0-linux-x64.tar.gz
Binary file not shown.
Oops, something went wrong.