Fix deploy host status update when install fails

Currently the deploy host status is being moved to failed only
when it is rejected, thus having a reject reason. However, there
are scenarios where deploy host can fail and not necessarily with
a reject reason, so these scenarios are not being covered.

This commit fixes this issue, along with some minor tox issues.

Test Plan
PASS: force deploy host failure, verify the deploy host status
      is updated accordingly
Regression
PASS: deploy host is rejected, verify the behavior remains the
      same as before (deploy host status failed)
PASS: deploy host with success, verify the behavior remains the
      same as before (deploy host status done)

Story: 2010676
Task: 49936

Signed-off-by: Heitor Matsui <heitorvieira.matsui@windriver.com>
Change-Id: Ibcc2246ee3bf4598ae3e21bdec59247d4e754855
This commit is contained in:
Heitor Matsui 2024-04-23 17:55:02 -03:00
parent c5a7d1d336
commit 41be7fa02c
4 changed files with 11 additions and 11 deletions

View File

@ -585,12 +585,8 @@ class PatchMessageAgentInstallResp(messages.PatchMessage):
# where there could be 4 combinations
if self.status:
deploy_host_state.deployed()
return
elif self.reject_reason:
else:
deploy_host_state.deploy_failed()
return
LOG.error("Bug: shouldn't reach here")
def send(self, sock): # pylint: disable=unused-argument
LOG.error("Should not get here")
@ -1346,7 +1342,7 @@ class PatchController(PatchService):
# Get the release_id from the patch's metadata
# and check to see if it's already uploaded
release_id = get_release_from_patch(patch_file,'id')
release_id = get_release_from_patch(patch_file, 'id')
release = self.release_collection.get_release_by_id(release_id)

View File

@ -1352,6 +1352,7 @@ def validate_host_state_to_deploy_host(hostname):
f"{states.DEPLOY_HOST_STATES.PENDING.value}")
raise SoftwareServiceError(msg)
def deploy_host_validations(hostname):
"""
Check the conditions below:

View File

@ -19,7 +19,7 @@ from software.software_controller import PatchMessageQueryDetailedResp
from software.software_controller import PatchMessageAgentInstallReq
from software.software_controller import PatchMessageAgentInstallResp
from software.software_controller import PatchMessageDropHostReq
from software.states import DEPLOY_HOST_STATES
FAKE_AGENT_ADDRESS = "127.0.0.1"
FAKE_AGENT_MCAST_GROUP = "239.1.1.4"
@ -35,7 +35,7 @@ class FakeSoftwareController(object):
self.allow_insvc_softwareing = True
self.controller_address = FAKE_CONTROLLER_ADDRESS
self.controller_neighbours = {}
self.hosts = {}
self.hosts = {FAKE_HOST_IP: {"hostname": "controller-0"}}
self.interim_state = {}
self.latest_feed_commit = FAKE_OSTREE_FEED_COMMIT
self.patch_op_counter = 0
@ -143,12 +143,16 @@ class SoftwareControllerMessagesTestCase(testtools.TestCase):
mock_sock.sendall.assert_called()
@mock.patch('software.software_controller.sc', FakeSoftwareController())
def test_message_class_handle(self):
@mock.patch('software.db.api.SoftwareAPI.get_deploy_host_by_hostname',
return_value={"state": DEPLOY_HOST_STATES.DEPLOYING})
@mock.patch('software.software_entities.DeployHostHandler.update', return_value=True)
def test_message_class_handle(self, mock_get_deploy_host_by_hostname, mock_update): # pylint: disable=unused-argument
"""'handle' method tests"""
addr = [FAKE_CONTROLLER_ADDRESS, ] # addr is a list
mock_sock = mock.Mock()
special_setup = {
PatchMessageDropHostReq: ('ip', FAKE_HOST_IP),
PatchMessageAgentInstallResp: ('status', True),
}
for message_class in SoftwareControllerMessagesTestCase.message_classes:

View File

@ -192,7 +192,6 @@ class TestSoftwareFunction(unittest.TestCase):
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
@ -200,7 +199,7 @@ class TestSoftwareFunction(unittest.TestCase):
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
# Actions
validate_host_state_to_deploy_host(hostname="abc")
# Assertions
error_msg = "Host state is deployed and should be pending"