Add the --upload-only option to dcmanager upgrade_strategy CLI

This commit adds a new option --upload-only to dcmanager
upgrade-strategy create. If this option is used, the releases
are uploaded to the subclouds and the strategy state is set to complete.

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

Test Plan:
1. PASS - Run dcmanager help upgrade-strategy create and verify
that the --upload-only argument is present.
2. PASS - Create and apply a patch strategy using the --upload-only
option and verify that the strategy completes after uploading
the patches to the subclouds.
3. PASS - Create and apply a patch strategy without using the
--upload-only option and verify that the strategy continues
after uploading the patches to the subclouds.
4. PASS - Verify that the CLI output of dcmanager upgrade-strategy
create/delete/show/abort/apply contains the 'upload only' field.

Story: 2010676
Task: 48746

Change-Id: I3ab70ff7287ae54fa4c407ef0f3c15784bfc19a6
Signed-off-by: Christopher Souza <Christopher.DeOliveiraSouza@windriver.com>
This commit is contained in:
Christopher Souza 2023-09-07 07:58:22 -03:00
parent 671db8b561
commit f7487d291f
4 changed files with 78 additions and 5 deletions

View File

@ -1,5 +1,5 @@
# Copyright (c) 2017 Ericsson AB.
# Copyright (c) 2020-2021 Wind River Systems, Inc.
# Copyright (c) 2020-2023 Wind River Systems, Inc.
# All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
@ -24,4 +24,5 @@ class sw_upgrade_manager(sw_update_manager):
def __init__(self, http_client):
super(sw_upgrade_manager, self).__init__(
http_client,
update_type=SW_UPDATE_TYPE_UPGRADE)
update_type=SW_UPDATE_TYPE_UPGRADE,
extra_args=['upload-only'])

View File

@ -1,5 +1,5 @@
# Copyright (c) 2017 Ericsson AB.
# Copyright (c) 2020-2021 Wind River Systems, Inc.
# Copyright (c) 2020-2023 Wind River Systems, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
@ -24,6 +24,8 @@ from dcmanagerclient import exceptions
# also handles 'steps' and 'strategies'
# A new field may change where the upload only column
# will be added by the upgrade manager.
def detail_format(sw_update_strategy=None):
columns = (
'strategy type',

View File

@ -1,5 +1,5 @@
# Copyright (c) 2017 Ericsson AB.
# Copyright (c) 2020-2021 Wind River Systems, Inc.
# Copyright (c) 2020-2023 Wind River Systems, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
@ -23,6 +23,23 @@ class SwUpgradeManagerMixin(object):
dcmanager_client = self.app.client_manager.sw_upgrade_manager
return dcmanager_client.sw_upgrade_manager
def custom_format_function(self, sw_update_strategy=None):
original_fmt_func = super()._get_format_function()
columns, data = original_fmt_func(sw_update_strategy)
if sw_update_strategy and sw_update_strategy.extra_args:
upload_only = sw_update_strategy.extra_args.get("upload-only",
False)
else:
upload_only = False
# Insert the 'upload only' field before the 'state',
# 'created_at' and 'updated_at' fields
columns = columns[:-3] + ("upload only",) + columns[-3:]
data = data[:-3] + (upload_only,) + data[-3:]
return columns, data
def _get_format_function(self):
return self.custom_format_function
class CreateSwUpgradeStrategy(SwUpgradeManagerMixin,
sw_update_manager.CreateSwUpdateStrategy):
@ -40,8 +57,22 @@ class CreateSwUpgradeStrategy(SwUpgradeManagerMixin,
parser = super(CreateSwUpgradeStrategy,
self).get_parser(prog_name)
parser.add_argument(
'--upload-only',
required=False,
action='store_true',
help='Stops strategy after uploading releases to subclouds'
)
return parser
def process_custom_params(self, parsed_args, kwargs_dict):
"""Updates kwargs dictionary from parsed_args for patching"""
if parsed_args.upload_only:
kwargs_dict['upload-only'] = 'true'
else:
kwargs_dict['upload-only'] = 'false'
# override validate_force_params defined in CreateSwUpdateStrategy
def validate_force_params(self, parsed_args):
pass

View File

@ -1,5 +1,5 @@
#
# Copyright (c) 2020-2021 Wind River Systems, Inc.
# Copyright (c) 2020-2023 Wind River Systems, Inc.
#
# SPDX-License-Identifier: Apache-2.0
#
@ -7,12 +7,17 @@
from dcmanagerclient.commands.v1 import sw_upgrade_manager as cli_cmd
from dcmanagerclient.tests import base
from dcmanagerclient.tests.v1.mixins import UpdateStrategyMixin
from dcmanagerclient.tests.v1 import utils
class TestSwUpgradeStrategy(UpdateStrategyMixin, base.BaseCommandTest):
def setUp(self):
super(TestSwUpgradeStrategy, self).setUp()
# Increase results_length due to the 'upload only' field
self.results_length += 1
self.sw_update_manager = \
self.app.client_manager.sw_upgrade_manager.sw_upgrade_manager
self.create_command = cli_cmd.CreateSwUpgradeStrategy
@ -20,3 +25,37 @@ class TestSwUpgradeStrategy(UpdateStrategyMixin, base.BaseCommandTest):
self.delete_command = cli_cmd.DeleteSwUpgradeStrategy
self.apply_command = cli_cmd.ApplySwUpgradeStrategy
self.abort_command = cli_cmd.AbortSwUpgradeStrategy
def test_create_strategy_upload_only(self):
"""Test that a strategy can be created with the --upload-only option"""
# prepare mixin attributes
manager_to_test = self.sw_update_manager
expected_strategy_type = manager_to_test.update_type
# mock the result of the API call
strategy = utils.make_strategy(strategy_type=expected_strategy_type,
extra_args={"upload-only": True})
# mock that there is no pre-existing strategy
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], expected_strategy_type)
self.assertEqual(fields[-4], 'upload only')
self.assertEqual(results[-4], True)