From 70fc598dae90f359720a3a7d745d793fe2cb7a06 Mon Sep 17 00:00:00 2001 From: Heitor Matsui Date: Wed, 24 Apr 2024 14:09:13 -0300 Subject: [PATCH] Remove incorrect host validation from deploy host Now with the state machine introduced by commit [1], the host state validation once done by [2] is not needed anymore, and in fact was incorrectly blocking the "deploy host" command from being reentrant. This commit fixes this issue. [1] https://review.opendev.org/c/starlingx/update/+/914929 [2] https://review.opendev.org/c/starlingx/update/+/914825 Test Plan PASS: force "deploy host" to fail, then once the host is in "failed" state, run deploy "host again" and verify the system does not block it from proceeding Story: 2010676 Task: 49938 Change-Id: I0d2a8a4ab9ea98f83fbd7253cf4f174a257ee070 Signed-off-by: Heitor Matsui --- software/software/software_functions.py | 17 ----------------- .../software/tests/test_software_function.py | 19 ------------------- 2 files changed, 36 deletions(-) diff --git a/software/software/software_functions.py b/software/software/software_functions.py index b3629496..8fea59e5 100644 --- a/software/software/software_functions.py +++ b/software/software/software_functions.py @@ -1337,25 +1337,9 @@ def set_host_target_load(hostname, major_release): raise -def validate_host_state_to_deploy_host(hostname): - """ - Check if the deployment host state for the hostname is pending. - - If the validation fails raise SoftwareServiceError exception. - - :param hostname: Hostname of the host to be deployed - """ - - host_state = get_instance().get_deploy_host_by_hostname(hostname).get("state") - if host_state != states.DEPLOY_HOST_STATES.PENDING.value: - msg = (f"Host state is {host_state} and should be " - f"{states.DEPLOY_HOST_STATES.PENDING.value}") - raise SoftwareServiceError(msg) - def deploy_host_validations(hostname): """ Check the conditions below: - Host state is pending. If system mode is duplex, check if provided hostname satisfy the right deployment order. Host is locked and online. @@ -1364,7 +1348,6 @@ def deploy_host_validations(hostname): :param hostname: Hostname of the host to be deployed """ - validate_host_state_to_deploy_host(hostname) _, system_mode = get_system_info() simplex = (system_mode == constants.SYSTEM_MODE_SIMPLEX) if simplex: diff --git a/software/software/tests/test_software_function.py b/software/software/tests/test_software_function.py index c976a9d2..78489dae 100644 --- a/software/software/tests/test_software_function.py +++ b/software/software/tests/test_software_function.py @@ -4,14 +4,9 @@ # Copyright (c) 2024 Wind River Systems, Inc. # import unittest -from unittest.mock import MagicMock -from unittest.mock import patch -from software import states -from software.exceptions import SoftwareServiceError from software.release_data import SWReleaseCollection from software.software_functions import ReleaseData -from software.software_functions import validate_host_state_to_deploy_host metadata = """ @@ -191,17 +186,3 @@ class TestSoftwareFunction(unittest.TestCase): self.assertEqual(val["restart_script"], r.restart_script) self.assertEqual(val["commit_id"], r.commit_id) self.assertEqual(val["checksum"], r.commit_checksum) - - - @patch('software.db.api.SoftwareAPI') - def test_validate_host_state_to_deploy_host_raises_exception_if_deploy_host_state_is_wrong(self, software_api_mock): - # Arrange - deploy_host_state = states.DEPLOY_HOST_STATES.DEPLOYED.value - deploy_by_hostname = MagicMock(return_value={"state": deploy_host_state}) - software_api_mock.return_value = MagicMock(get_deploy_host_by_hostname=deploy_by_hostname) - with self.assertRaises(SoftwareServiceError) as error: - # Actions - validate_host_state_to_deploy_host(hostname="abc") - # Assertions - error_msg = "Host state is deployed and should be pending" - self.assertEqual(str(error.exception), error_msg)