Handle unreachable case in the log statistics
The unreachable status is a fail state that should be treat. Change-Id: Ia610448421196572909567deb144d9a490be27a0
This commit is contained in:
parent
be5a95d4e0
commit
0641b17a5a
@ -50,9 +50,36 @@ BAD_VALIDATIONS_LOGS_CONTENTS_LIST = [{
|
||||
'changed': 0,
|
||||
'failures': 0,
|
||||
'ignored': 0,
|
||||
'ok': 1,
|
||||
'ok': 0,
|
||||
'rescued': 0,
|
||||
'skipped': 1
|
||||
'skipped': 0,
|
||||
'unreachable': 1
|
||||
}
|
||||
},
|
||||
'validation_output': []
|
||||
}]
|
||||
|
||||
FAILED_VALIDATIONS_LOGS_CONTENTS_LIST = [{
|
||||
'plays': [{
|
||||
'play': {
|
||||
'duration': {
|
||||
'end': '2019-11-25T13:40:17.538611Z',
|
||||
},
|
||||
'host': 'undercloud',
|
||||
'id': '008886df-d297-1eaa-2a74-000000000008',
|
||||
'validation_id': '512e',
|
||||
'validation_path':
|
||||
'/usr/share/openstack-tripleo-validations/playbooks'
|
||||
}}],
|
||||
'stats': {
|
||||
'undercloud': {
|
||||
'changed': 0,
|
||||
'failures': 1,
|
||||
'ignored': 0,
|
||||
'ok': 0,
|
||||
'rescued': 0,
|
||||
'skipped': 0,
|
||||
'unreachable': 0
|
||||
}
|
||||
},
|
||||
'validation_output': []
|
||||
|
@ -144,6 +144,24 @@ class TestValidationLog(TestCase):
|
||||
status = val.get_status
|
||||
self.assertEquals(status, 'PASSED')
|
||||
|
||||
@mock.patch('json.load',
|
||||
return_value=fakes.FAILED_VALIDATIONS_LOGS_CONTENTS_LIST[0])
|
||||
@mock.patch('six.moves.builtins.open')
|
||||
def test_get_status_failed(self, mock_open, mock_json):
|
||||
val = ValidationLog(
|
||||
logfile='/tmp/123_foo_2020-03-30T13:17:22.447857Z.json')
|
||||
status = val.get_status
|
||||
self.assertEquals(status, 'FAILED')
|
||||
|
||||
@mock.patch('json.load',
|
||||
return_value=fakes.BAD_VALIDATIONS_LOGS_CONTENTS_LIST[0])
|
||||
@mock.patch('six.moves.builtins.open')
|
||||
def test_get_status_unreachable(self, mock_open, mock_json):
|
||||
val = ValidationLog(
|
||||
logfile='/tmp/123_foo_2020-03-30T13:17:22.447857Z.json')
|
||||
status = val.get_status
|
||||
self.assertEquals(status, 'FAILED')
|
||||
|
||||
@mock.patch('json.load',
|
||||
return_value=fakes.VALIDATIONS_LOGS_CONTENTS_LIST[0])
|
||||
@mock.patch('six.moves.builtins.open')
|
||||
@ -162,6 +180,24 @@ class TestValidationLog(TestCase):
|
||||
host_group = val.get_hosts_status
|
||||
self.assertEquals(host_group, 'undercloud,PASSED')
|
||||
|
||||
@mock.patch('json.load',
|
||||
return_value=fakes.FAILED_VALIDATIONS_LOGS_CONTENTS_LIST[0])
|
||||
@mock.patch('six.moves.builtins.open')
|
||||
def test_get_hosts_status_failed(self, mock_open, mock_json):
|
||||
val = ValidationLog(
|
||||
logfile='/tmp/123_foo_2020-03-30T13:17:22.447857Z.json')
|
||||
host_group = val.get_hosts_status
|
||||
self.assertEquals(host_group, 'undercloud,FAILED')
|
||||
|
||||
@mock.patch('json.load',
|
||||
return_value=fakes.BAD_VALIDATIONS_LOGS_CONTENTS_LIST[0])
|
||||
@mock.patch('six.moves.builtins.open')
|
||||
def test_get_hosts_status_unreachable(self, mock_open, mock_json):
|
||||
val = ValidationLog(
|
||||
logfile='/tmp/123_foo_2020-03-30T13:17:22.447857Z.json')
|
||||
host_group = val.get_hosts_status
|
||||
self.assertEquals(host_group, 'undercloud,UNREACHABLE')
|
||||
|
||||
@mock.patch('json.load',
|
||||
return_value=fakes.VALIDATIONS_LOGS_CONTENTS_LIST[0])
|
||||
@mock.patch('six.moves.builtins.open')
|
||||
@ -178,7 +214,7 @@ class TestValidationLog(TestCase):
|
||||
val = ValidationLog(
|
||||
logfile='/tmp/123_foo_2020-03-30T13:17:22.447857Z.json')
|
||||
unreachable = val.get_unreachable_hosts
|
||||
self.assertEquals(unreachable, '')
|
||||
self.assertEquals(unreachable, 'undercloud')
|
||||
|
||||
@mock.patch('json.load',
|
||||
return_value=fakes.VALIDATIONS_LOGS_CONTENTS_LIST[0])
|
||||
|
@ -190,6 +190,8 @@ class ValidationLog(object):
|
||||
for h in self.content['stats'].keys():
|
||||
if self.content['stats'][h].get('failures'):
|
||||
failed += 1
|
||||
if self.content['stats'][h].get('unreachable'):
|
||||
failed += 1
|
||||
return ('FAILED' if failed else 'PASSED')
|
||||
|
||||
@property
|
||||
@ -220,6 +222,8 @@ class ValidationLog(object):
|
||||
for h in self.content['stats'].keys():
|
||||
if self.content['stats'][h].get('failures'):
|
||||
hosts.append('{},{}'.format(h, 'FAILED'))
|
||||
elif self.content['stats'][h].get('unreachable'):
|
||||
hosts.append('{},{}'.format(h, 'UNREACHABLE'))
|
||||
else:
|
||||
hosts.append('{},{}'.format(h, 'PASSED'))
|
||||
return ', '.join(hosts)
|
||||
|
Loading…
x
Reference in New Issue
Block a user