
Create a Zuul job to check Black Formatter in the code. This commit also applies the Black formatter to the entire project. Test Plan Pass - Success on stx-distcloud-client-tox-black Pass - Success on tox command Story: 2011149 Task: 50393 Change-Id: I5d7b537e83931304ffd5f67ce51e8ebb44f7e65b Signed-off-by: Hugo Brito <hugo.brito@windriver.com>
80 lines
3.0 KiB
Python
80 lines
3.0 KiB
Python
#
|
|
# Copyright (c) 2023-2024 Wind River Systems, Inc.
|
|
#
|
|
# SPDX-License-Identifier: Apache-2.0
|
|
#
|
|
|
|
|
|
from dcmanagerclient.commands.v1 import sw_patch_manager as cli_cmd
|
|
from dcmanagerclient.tests import base
|
|
from dcmanagerclient.tests.v1 import utils
|
|
from dcmanagerclient.tests.v1.mixins import UpdateStrategyMixin
|
|
|
|
|
|
class TestPatchUpdateStrategy(UpdateStrategyMixin, base.BaseCommandTest):
|
|
def setUp(self):
|
|
super().setUp()
|
|
|
|
# Increase results_length due to the 'upload only' field
|
|
self.results_length += 1
|
|
|
|
self.sw_update_manager = self.app.client_manager.sw_patch_manager
|
|
self.create_command = cli_cmd.CreatePatchUpdateStrategy
|
|
self.show_command = cli_cmd.ShowPatchUpdateStrategy
|
|
self.delete_command = cli_cmd.DeletePatchUpdateStrategy
|
|
self.apply_command = cli_cmd.ApplyPatchUpdateStrategy
|
|
self.abort_command = cli_cmd.AbortPatchUpdateStrategy
|
|
|
|
# prepare mixin attributes
|
|
self.manager_to_test = self.sw_update_manager
|
|
self.expected_strategy_type = self.manager_to_test.update_type
|
|
|
|
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}
|
|
)
|
|
|
|
# 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
|
|
fields, results = self.call(self.create_command, ["--upload-only"])
|
|
|
|
# results is a tuple of expected length
|
|
self.assertEqual(len(results), self.results_length)
|
|
# result tuple values are
|
|
# - strategy type
|
|
# - subcloud apply type
|
|
# - max parallel subclouds
|
|
# - stop on failure
|
|
# - upload only
|
|
# - state
|
|
# - created_at
|
|
# - updated_at
|
|
|
|
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)
|