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,
and convert the db api lock logs to debug, since they were
generating log lines that were bloating software.log.

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 70fc598dae
commit 4040061ebe
3 changed files with 11 additions and 13 deletions

View File

@ -110,11 +110,11 @@ class SoftwareAPI:
def begin_update(self):
tid = threading.get_native_id()
msg = f"{tid} is to acquire lock."
LOG.info(msg)
LOG.debug(msg)
SoftwareAPI._lock.acquire()
def end_update(self):
SoftwareAPI._lock.release()
tid = threading.get_native_id()
msg = f"{tid} released lock."
LOG.info(msg)
LOG.debug(msg)

View File

@ -581,16 +581,10 @@ class PatchMessageAgentInstallResp(messages.PatchMessage):
sc.hosts_lock.release()
deploy_host_state = DeployHostState(hostname)
# NOTE(bqian) apparently it uses 2 boolean to indicate 2 situations
# 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 +1340,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

@ -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: