-
Notifications
You must be signed in to change notification settings - Fork 80
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactors for using BinaryKey enum, factory pattern, and creating Art…
…ifactVariablesProvider helper class (#183) * Refactors for using BinaryKey enum, factory pattern, and creating ArtifactVariablesProvider helper class Signed-off-by: Chase Engelbrecht <[email protected]> * Add unit tests for ArtifactVariablesProvider Signed-off-by: Chase Engelbrecht <[email protected]> * Refactor ArchitectureTypes to an enum Signed-off-by: Chase Engelbrecht <[email protected]>
- Loading branch information
Showing
16 changed files
with
142 additions
and
77 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
6 changes: 2 additions & 4 deletions
6
osbenchmark/builder/downloaders/plugin_distribution_downloader.py
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
6 changes: 2 additions & 4 deletions
6
osbenchmark/builder/downloaders/repositories/opensearch_distribution_repository_provider.py
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
7 changes: 2 additions & 5 deletions
7
osbenchmark/builder/downloaders/repositories/plugin_distribution_repository_provider.py
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
from enum import Enum | ||
|
||
|
||
class ArchitectureTypes(Enum): | ||
""" | ||
Represents a machine's architecture type | ||
:param hardware_name: The value returned by the machine when querying the architecture. Obtained via `uname -m` for unix machines | ||
;param opensearch_name: The value used by opensearch artifacts to represent the architecture | ||
""" | ||
|
||
def __init__(self, hardware_name, opensearch_name): | ||
self.hardware_name = hardware_name | ||
self.opensearch_name = opensearch_name | ||
|
||
ARM = "aarch64", "arm64" | ||
x86 = "x86_64", "x64" | ||
|
||
@staticmethod | ||
def get_from_hardware_name(hardware_name): | ||
for arch_type in ArchitectureTypes: | ||
if arch_type.hardware_name == hardware_name: | ||
return arch_type | ||
|
||
raise ValueError |
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,21 @@ | ||
from osbenchmark.builder.models.architecture_types import ArchitectureTypes | ||
|
||
|
||
class ArtifactVariablesProvider: | ||
def __init__(self, executor): | ||
self.executor = executor | ||
|
||
def get_artifact_variables(self, host, opensearch_version=None): | ||
return { | ||
"VERSION": opensearch_version, | ||
"OSNAME": self._get_os_name(host), | ||
"ARCH": self._get_arch(host) | ||
} | ||
|
||
def _get_os_name(self, host): | ||
os_name = self.executor.execute(host, "uname", output=True)[0] | ||
return os_name.lower() | ||
|
||
def _get_arch(self, host): | ||
arch = self.executor.execute(host, "uname -m", output=True)[0] | ||
return ArchitectureTypes.get_from_hardware_name(arch.lower()).opensearch_name |
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,5 @@ | ||
from enum import Enum | ||
|
||
|
||
class BinaryKeys(str, Enum): | ||
OPENSEARCH = "opensearch" |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
from unittest import TestCase | ||
from unittest.mock import Mock | ||
|
||
from osbenchmark.builder.utils.artifact_variables_provider import ArtifactVariablesProvider | ||
|
||
|
||
class ArtifactVariablesProviderTest(TestCase): | ||
def setUp(self): | ||
self.host = None | ||
|
||
self.executor = Mock() | ||
self.artifact_variables_provider = ArtifactVariablesProvider(self.executor) | ||
|
||
def test_x86(self): | ||
self.executor.execute.side_effect = [["Linux"], ["x86_64"]] | ||
variables = self.artifact_variables_provider.get_artifact_variables(self.host) | ||
|
||
self.assertEqual(variables, { | ||
"VERSION": None, | ||
"OSNAME": "linux", | ||
"ARCH": "x64" | ||
}) | ||
|
||
def test_arm(self): | ||
self.executor.execute.side_effect = [["Linux"], ["aarch64"]] | ||
variables = self.artifact_variables_provider.get_artifact_variables(self.host) | ||
|
||
self.assertEqual(variables, { | ||
"VERSION": None, | ||
"OSNAME": "linux", | ||
"ARCH": "arm64" | ||
}) | ||
|
||
def test_version_supplied(self): | ||
self.executor.execute.side_effect = [["Linux"], ["aarch64"]] | ||
variables = self.artifact_variables_provider.get_artifact_variables(self.host, "1.23") | ||
|
||
self.assertEqual(variables, { | ||
"VERSION": "1.23", | ||
"OSNAME": "linux", | ||
"ARCH": "arm64" | ||
}) |