Change --patch to patch_id in Patch Update Strategy

This commit changes the --patch argument, previously used
for patch file path, to a required positional parameter patch_id.

Note: This also updates the .git-blame-ignore-revs file with
tox configuration and pylint fixes.

Test Plan:
PASS - Create a patch-strategy
- `dcmanager patch-strategy create stx-10.1`
or
- `dcmanager patch-strategy create stx-10.1 --upload-only`

Failure Path:
PASS - Command `dcmanager patch-strategy create` fail
- error: the following arguments are required: patch_id

Depends-on: https://review.opendev.org/c/starlingx/distcloud/+/924879

Story: 2010676
Task: 50014

Change-Id: If6726f0b5e05f4e842ddc6801b225e5a6c129686
Signed-off-by: Hugo Brito <hugo.brito@windriver.com>
This commit is contained in:
Hugo Brito 2024-07-24 15:12:43 -03:00
parent 4ac85ea810
commit 41c100f15e
4 changed files with 36 additions and 28 deletions

View File

@ -18,5 +18,12 @@
# - Because you must use a hash, you need to append to this list in a follow-up
# commit to the actual reformatting commit that you are trying to ignore.
# Tox configuration and pylint fixes
b87508a41011b06637a9c67e51082c55befc0929
a507c6449d9bbe3ae02506b27e45272b96635216
1614a6ae75825afd49d996d5a44144ba36da47bd
d847780a4d179485bc76f57e56951ce380eae26a
8405f3b47c97927326b6eaae65b9bbe43f7d5952
# Format all Python files with Black formatter
b5cbd9480cef12fee05ae6cf68aaae5aaa931969

View File

@ -22,4 +22,4 @@ SW_UPDATE_TYPE_PATCH = "patch"
class SwPatchManager(SwUpdateManager):
def __init__(self, http_client):
super().__init__(http_client, update_type=SW_UPDATE_TYPE_PATCH)
self.extra_args = ["upload-only", "patch"]
self.extra_args = ["upload-only", "patch_id"]

View File

@ -14,8 +14,6 @@
# limitations under the License.
#
import os
from dcmanagerclient.commands.v1 import sw_update_manager
@ -62,9 +60,8 @@ class CreatePatchUpdateStrategy(
)
parser.add_argument(
"--patch",
required=False,
help="Path to a patch to upload.",
"patch_id",
help="The patch ID to upload/apply on the subcloud.",
)
return parser
@ -75,8 +72,8 @@ class CreatePatchUpdateStrategy(
kwargs_dict["upload-only"] = "true"
else:
kwargs_dict["upload-only"] = "false"
if parsed_args.patch:
kwargs_dict["patch"] = os.path.abspath(parsed_args.patch)
kwargs_dict["patch_id"] = parsed_args.patch_id
class ShowPatchUpdateStrategy(

View File

@ -29,12 +29,34 @@ class TestPatchUpdateStrategy(UpdateStrategyMixin, base.BaseCommandTest):
self.manager_to_test = self.sw_update_manager
self.expected_strategy_type = self.manager_to_test.update_type
def test_create_strategy(self):
"""Test that a strategy needs a patch_id option"""
# mock the result of the API call
strategy = utils.make_strategy(
strategy_type=self.expected_strategy_type,
extra_args={"patch_id": "stx-10.1"},
)
self.manager_to_test.create_sw_update_strategy.return_value = strategy
# invoke the backend method for the CLI.
# Assert raises Exception for API call without required parameter
self.assertRaises(SystemExit, self.call, self.create_command, [])
# Assert call will not raise Exception for API call with required parameter
try:
self.call(self.create_command, ["stx-10.1"])
except Exception:
self.fail("Unexpected Exception raised")
def test_create_strategy_upload_only(self):
"""Test that a strategy can be created with the --upload-only option"""
# mock the result of the API call
strategy = utils.make_strategy(
strategy_type=self.expected_strategy_type, extra_args={"upload-only": True}
strategy_type=self.expected_strategy_type,
extra_args={"upload-only": True, "patch_id": "stx-10.1"},
)
# mock that there is no pre-existing strategy
@ -42,7 +64,7 @@ class TestPatchUpdateStrategy(UpdateStrategyMixin, base.BaseCommandTest):
# invoke the backend method for the CLI.
# Returns a tuple of field descriptions, and a second tuple of values
fields, results = self.call(self.create_command, ["--upload-only"])
fields, results = self.call(self.create_command, ["stx-10.1", "--upload-only"])
# results is a tuple of expected length
self.assertEqual(len(results), self.results_length)
@ -59,21 +81,3 @@ class TestPatchUpdateStrategy(UpdateStrategyMixin, base.BaseCommandTest):
self.assertEqual(results[0], self.expected_strategy_type)
self.assertEqual(fields[-4], "upload only")
self.assertEqual(results[-4], True)
def test_create_strategy_patch_file(self):
"""Test that a strategy can be created with the --patch option"""
# mock the result of the API call
strategy = utils.make_strategy(strategy_type=self.expected_strategy_type)
# mock that there is no pre-existing strategy
self.manager_to_test.create_sw_update_strategy.return_value = strategy
# invoke the backend method for the CLI.
# Returns a tuple of field descriptions, and a second tuple of values
# with self.assertRaises(argparse.ArgumentError):
_, results = self.call(self.create_command, ["--patch usm.patch"])
# results is a tuple of expected length
self.assertEqual(len(results), self.results_length)
self.assertEqual(results[0], self.expected_strategy_type)