Logging multiple WMI job errors
WMI jobs may return multiple errors, but only one of them would be logged. This change ensures that we're fetching all of them, calling the Msvm_ConcreteJob.GetErrorEx method. Change-Id: I7311e63e4f95c4e1d17357d28fdd1c7425362270 Closes-Bug: 1748208
This commit is contained in:
parent
21a2fe8758
commit
e1c83c86bc
21
os_win/tests/unit/utils/test_jobutils.py
Normal file → Executable file
21
os_win/tests/unit/utils/test_jobutils.py
Normal file → Executable file
@ -82,15 +82,32 @@ class JobUtilsTestCase(test_base.OsWinBaseTestCase):
|
||||
{"extended": True,
|
||||
"expected_fields": ["InstanceID", "DetailedStatus"]})
|
||||
@ddt.unpack
|
||||
def test_get_job_details(self, expected_fields, extended):
|
||||
@mock.patch.object(jobutils.JobUtils, '_get_job_error_details')
|
||||
def test_get_job_details(self, mock_get_job_err, expected_fields,
|
||||
extended):
|
||||
mock_job = mock.Mock()
|
||||
|
||||
details = self.jobutils._get_job_details(mock_job, extended=extended)
|
||||
|
||||
if extended:
|
||||
mock_get_job_err.assert_called_once_with(mock_job)
|
||||
self.assertEqual(details['RawErrors'],
|
||||
mock_get_job_err.return_value)
|
||||
|
||||
for field in expected_fields:
|
||||
self.assertEqual(getattr(mock_job, field),
|
||||
details[field])
|
||||
|
||||
def test_get_job_error_details(self):
|
||||
mock_job = mock.Mock()
|
||||
error_details = self.jobutils._get_job_error_details(mock_job)
|
||||
mock_job.GetErrorEx.assert_called_once_with()
|
||||
self.assertEqual(mock_job.GetErrorEx.return_value, error_details)
|
||||
|
||||
def test_get_job_error_details_exception(self):
|
||||
mock_job = mock.Mock()
|
||||
mock_job.GetErrorEx.side_effect = Exception
|
||||
self.assertIsNone(self.jobutils._get_job_error_details(mock_job))
|
||||
|
||||
def test_get_pending_jobs(self):
|
||||
mock_killed_job = mock.Mock(JobState=constants.JOB_STATE_KILLED)
|
||||
mock_running_job = mock.Mock(JobState=constants.WMI_JOB_STATE_RUNNING)
|
||||
|
@ -126,8 +126,13 @@ class JobUtils(baseutils.BaseUtilsVirt):
|
||||
|
||||
return job
|
||||
|
||||
@staticmethod
|
||||
def _get_job_details(job, extended=False):
|
||||
def _get_job_error_details(self, job):
|
||||
try:
|
||||
return job.GetErrorEx()
|
||||
except Exception:
|
||||
LOG.error("Could not get job '%s' error details.", job.InstanceID)
|
||||
|
||||
def _get_job_details(self, job, extended=False):
|
||||
basic_details = [
|
||||
"InstanceID", "Description", "ElementName", "JobStatus",
|
||||
"ElapsedTime", "Cancellable", "JobType", "Owner",
|
||||
@ -139,10 +144,13 @@ class JobUtils(baseutils.BaseUtilsVirt):
|
||||
"ErrorCode", "ErrorDescription", "ErrorSummaryDescription"]
|
||||
|
||||
fields = list(basic_details)
|
||||
details = {}
|
||||
|
||||
if extended:
|
||||
fields += extended_details
|
||||
err_details = self._get_job_error_details(job)
|
||||
details['RawErrors'] = err_details
|
||||
|
||||
details = {}
|
||||
for field in fields:
|
||||
try:
|
||||
details[field] = getattr(job, field)
|
||||
|
Loading…
x
Reference in New Issue
Block a user