-
Notifications
You must be signed in to change notification settings - Fork 272
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor and simplify assembly workflow. (#827)
* Extracted assemble args into a class, add keep. Signed-off-by: dblock <[email protected]> * Remove TemporaryDirectory inside another TemporaryDirectory. Signed-off-by: dblock <[email protected]>
- Loading branch information
Showing
7 changed files
with
119 additions
and
38 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,39 @@ | ||
# 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 argparse | ||
import logging | ||
|
||
|
||
class AssembleArgs: | ||
manifest: str | ||
keep: bool | ||
|
||
def __init__(self): | ||
parser = argparse.ArgumentParser(description="Assemble an OpenSearch Distribution") | ||
parser.add_argument("manifest", type=argparse.FileType("r"), help="Manifest file.") | ||
parser.add_argument("-b", "--base-url", dest="base_url", help="The base url to download the artifacts.") | ||
parser.add_argument( | ||
"--keep", | ||
dest="keep", | ||
action="store_true", | ||
help="Do not delete the working temporary directory.", | ||
) | ||
parser.add_argument( | ||
"-v", | ||
"--verbose", | ||
help="Show more verbose output.", | ||
action="store_const", | ||
default=logging.INFO, | ||
const=logging.DEBUG, | ||
dest="logging_level", | ||
) | ||
|
||
args = parser.parse_args() | ||
self.logging_level = args.logging_level | ||
self.manifest = args.manifest | ||
self.keep = args.keep | ||
self.base_url = args.base_url |
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,52 @@ | ||
# 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 unittest | ||
from unittest.mock import patch | ||
|
||
from assemble_workflow.assemble_args import AssembleArgs | ||
|
||
|
||
class TestAssembleArgs(unittest.TestCase): | ||
|
||
ASSEMBLE_PY = "./src/run_assembly.py" | ||
|
||
OPENSEARCH_MANIFEST = os.path.realpath( | ||
os.path.join( | ||
os.path.dirname(__file__), | ||
"..", | ||
"..", | ||
"manifests", | ||
"1.1.0", | ||
"opensearch-1.1.0.yml", | ||
) | ||
) | ||
|
||
@patch("argparse._sys.argv", [ASSEMBLE_PY, OPENSEARCH_MANIFEST]) | ||
def test_manifest(self): | ||
self.assertEqual(AssembleArgs().manifest.name, TestAssembleArgs.OPENSEARCH_MANIFEST) | ||
|
||
@patch("argparse._sys.argv", [ASSEMBLE_PY, OPENSEARCH_MANIFEST]) | ||
def test_keep_default(self): | ||
self.assertFalse(AssembleArgs().keep) | ||
|
||
@patch("argparse._sys.argv", [ASSEMBLE_PY, OPENSEARCH_MANIFEST, "--keep"]) | ||
def test_keep_true(self): | ||
self.assertTrue(AssembleArgs().keep) | ||
|
||
@patch("argparse._sys.argv", [ASSEMBLE_PY, OPENSEARCH_MANIFEST]) | ||
def test_verbose_default(self): | ||
self.assertEqual(AssembleArgs().logging_level, logging.INFO) | ||
|
||
@patch("argparse._sys.argv", [ASSEMBLE_PY, OPENSEARCH_MANIFEST, "--verbose"]) | ||
def test_verbose_true(self): | ||
self.assertTrue(AssembleArgs().logging_level, logging.DEBUG) | ||
|
||
@patch("argparse._sys.argv", [ASSEMBLE_PY, OPENSEARCH_MANIFEST, "--base-url", "url"]) | ||
def test_base_url(self): | ||
self.assertEqual(AssembleArgs().base_url, "url") |
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