Base for improvement of validator test coverage
Moves test_tripleo_validator.py into v1 dir. Constants used for tests moved to the fakes module. Mock import guard added, in order to preferrentially import new mock package instead of legacy. Signed-off-by: Jiri Podivin <jpodivin@redhat.com> Change-Id: I799885c169acef9c6a772950e0fcaf09c5a97077
This commit is contained in:
parent
46013bb567
commit
94b5840374
|
@ -25,6 +25,130 @@ AUTH_URL = "http://0.0.0.0"
|
|||
WS_URL = "ws://0.0.0.0"
|
||||
WSS_URL = "wss://0.0.0.0"
|
||||
|
||||
VALIDATIONS_LIST = [{
|
||||
'description': 'My Validation One Description',
|
||||
'groups': ['prep', 'pre-deployment'],
|
||||
'id': 'my_val1',
|
||||
'name': 'My Validition One Name',
|
||||
'parameters': {}
|
||||
}, {
|
||||
'description': 'My Validation Two Description',
|
||||
'groups': ['prep', 'pre-introspection'],
|
||||
'id': 'my_val2',
|
||||
'name': 'My Validition Two Name',
|
||||
'parameters': {'min_value': 8}
|
||||
}]
|
||||
|
||||
GROUPS_LIST = [
|
||||
('group1', 'Group1 description'),
|
||||
('group2', 'Group2 description'),
|
||||
('group3', 'Group3 description'),
|
||||
]
|
||||
|
||||
VALIDATIONS_LOGS_CONTENTS_LIST = [{
|
||||
'plays': [{
|
||||
'play': {
|
||||
'duration': {
|
||||
'end': '2019-11-25T13:40:17.538611Z',
|
||||
'start': '2019-11-25T13:40:14.404623Z',
|
||||
'time_elapsed': '0:00:03.753'
|
||||
},
|
||||
'host': 'undercloud',
|
||||
'id': '008886df-d297-1eaa-2a74-000000000008',
|
||||
'validation_id': '512e',
|
||||
'validation_path':
|
||||
'/usr/share/ansible/validation-playbooks'
|
||||
},
|
||||
'tasks': [
|
||||
{
|
||||
'hosts': {
|
||||
'undercloud': {
|
||||
'_ansible_no_log': False,
|
||||
'action': 'command',
|
||||
'changed': False,
|
||||
'cmd': [u'ls', '/sys/class/block/'],
|
||||
'delta': '0:00:00.018913',
|
||||
'end': '2019-11-25 13:40:17.120368',
|
||||
'invocation': {
|
||||
'module_args': {
|
||||
'_raw_params': 'ls /sys/class/block/',
|
||||
'_uses_shell': False,
|
||||
'argv': None,
|
||||
'chdir': None,
|
||||
'creates': None,
|
||||
'executable': None,
|
||||
'removes': None,
|
||||
'stdin': None,
|
||||
'stdin_add_newline': True,
|
||||
'strip_empty_ends': True,
|
||||
'warn': True
|
||||
}
|
||||
},
|
||||
'rc': 0,
|
||||
'start': '2019-11-25 13:40:17.101455',
|
||||
'stderr': '',
|
||||
'stderr_lines': [],
|
||||
'stdout': 'vda',
|
||||
'stdout_lines': [u'vda']
|
||||
}
|
||||
},
|
||||
'task': {
|
||||
'duration': {
|
||||
'end': '2019-11-25T13:40:17.336687Z',
|
||||
'start': '2019-11-25T13:40:14.529880Z'
|
||||
},
|
||||
'id':
|
||||
'008886df-d297-1eaa-2a74-00000000000d',
|
||||
'name':
|
||||
'advanced-format-512e-support : List the available drives'
|
||||
}
|
||||
},
|
||||
{
|
||||
'hosts': {
|
||||
'undercloud': {
|
||||
'action':
|
||||
'advanced_format',
|
||||
'changed': False,
|
||||
'msg':
|
||||
'All items completed',
|
||||
'results': [{
|
||||
'_ansible_item_label': 'vda',
|
||||
'_ansible_no_log': False,
|
||||
'ansible_loop_var': 'item',
|
||||
'changed': False,
|
||||
'item': 'vda',
|
||||
'skip_reason': 'Conditional result was False',
|
||||
'skipped': True
|
||||
}],
|
||||
'skipped': True
|
||||
}
|
||||
},
|
||||
'task': {
|
||||
'duration': {
|
||||
'end': '2019-11-25T13:40:17.538611Z',
|
||||
'start': '2019-11-25T13:40:17.341704Z'
|
||||
},
|
||||
'id': '008886df-d297-1eaa-2a74-00000000000e',
|
||||
'name':
|
||||
'advanced-format-512e-support: Detect the drive'
|
||||
}
|
||||
}
|
||||
]
|
||||
}],
|
||||
'stats': {
|
||||
'undercloud': {
|
||||
'changed': 0,
|
||||
'failures': 0,
|
||||
'ignored': 0,
|
||||
'ok': 1,
|
||||
'rescued': 0,
|
||||
'skipped': 1,
|
||||
'unreachable': 0
|
||||
}
|
||||
},
|
||||
'validation_output': []
|
||||
}]
|
||||
|
||||
|
||||
class FakeOptions(object):
|
||||
def __init__(self):
|
||||
|
|
|
@ -13,134 +13,15 @@
|
|||
# under the License.
|
||||
#
|
||||
|
||||
import mock
|
||||
|
||||
try:
|
||||
from unittest import mock
|
||||
except ImportError:
|
||||
import mock
|
||||
|
||||
from osc_lib.tests import utils
|
||||
from tripleoclient.v1 import tripleo_validator
|
||||
|
||||
VALIDATIONS_LIST = [{
|
||||
'description': 'My Validation One Description',
|
||||
'groups': ['prep', 'pre-deployment'],
|
||||
'id': 'my_val1',
|
||||
'name': 'My Validition One Name',
|
||||
'parameters': {}
|
||||
}, {
|
||||
'description': 'My Validation Two Description',
|
||||
'groups': ['prep', 'pre-introspection'],
|
||||
'id': 'my_val2',
|
||||
'name': 'My Validition Two Name',
|
||||
'parameters': {'min_value': 8}
|
||||
}]
|
||||
|
||||
GROUPS_LIST = [
|
||||
('group1', 'Group1 description'),
|
||||
('group2', 'Group2 description'),
|
||||
('group3', 'Group3 description'),
|
||||
]
|
||||
|
||||
VALIDATIONS_LOGS_CONTENTS_LIST = [{
|
||||
'plays': [{
|
||||
'play': {
|
||||
'duration': {
|
||||
'end': '2019-11-25T13:40:17.538611Z',
|
||||
'start': '2019-11-25T13:40:14.404623Z',
|
||||
'time_elapsed': '0:00:03.753'
|
||||
},
|
||||
'host': 'undercloud',
|
||||
'id': '008886df-d297-1eaa-2a74-000000000008',
|
||||
'validation_id': '512e',
|
||||
'validation_path':
|
||||
'/usr/share/ansible/validation-playbooks'
|
||||
},
|
||||
'tasks': [
|
||||
{
|
||||
'hosts': {
|
||||
'undercloud': {
|
||||
'_ansible_no_log': False,
|
||||
'action': 'command',
|
||||
'changed': False,
|
||||
'cmd': [u'ls', '/sys/class/block/'],
|
||||
'delta': '0:00:00.018913',
|
||||
'end': '2019-11-25 13:40:17.120368',
|
||||
'invocation': {
|
||||
'module_args': {
|
||||
'_raw_params': 'ls /sys/class/block/',
|
||||
'_uses_shell': False,
|
||||
'argv': None,
|
||||
'chdir': None,
|
||||
'creates': None,
|
||||
'executable': None,
|
||||
'removes': None,
|
||||
'stdin': None,
|
||||
'stdin_add_newline': True,
|
||||
'strip_empty_ends': True,
|
||||
'warn': True
|
||||
}
|
||||
},
|
||||
'rc': 0,
|
||||
'start': '2019-11-25 13:40:17.101455',
|
||||
'stderr': '',
|
||||
'stderr_lines': [],
|
||||
'stdout': 'vda',
|
||||
'stdout_lines': [u'vda']
|
||||
}
|
||||
},
|
||||
'task': {
|
||||
'duration': {
|
||||
'end': '2019-11-25T13:40:17.336687Z',
|
||||
'start': '2019-11-25T13:40:14.529880Z'
|
||||
},
|
||||
'id':
|
||||
'008886df-d297-1eaa-2a74-00000000000d',
|
||||
'name':
|
||||
'advanced-format-512e-support : List the available drives'
|
||||
}
|
||||
},
|
||||
{
|
||||
'hosts': {
|
||||
'undercloud': {
|
||||
'action':
|
||||
'advanced_format',
|
||||
'changed': False,
|
||||
'msg':
|
||||
'All items completed',
|
||||
'results': [{
|
||||
'_ansible_item_label': 'vda',
|
||||
'_ansible_no_log': False,
|
||||
'ansible_loop_var': 'item',
|
||||
'changed': False,
|
||||
'item': 'vda',
|
||||
'skip_reason': 'Conditional result was False',
|
||||
'skipped': True
|
||||
}],
|
||||
'skipped': True
|
||||
}
|
||||
},
|
||||
'task': {
|
||||
'duration': {
|
||||
'end': '2019-11-25T13:40:17.538611Z',
|
||||
'start': '2019-11-25T13:40:17.341704Z'
|
||||
},
|
||||
'id': '008886df-d297-1eaa-2a74-00000000000e',
|
||||
'name':
|
||||
'advanced-format-512e-support: Detect the drive'
|
||||
}
|
||||
}
|
||||
]
|
||||
}],
|
||||
'stats': {
|
||||
'undercloud': {
|
||||
'changed': 0,
|
||||
'failures': 0,
|
||||
'ignored': 0,
|
||||
'ok': 1,
|
||||
'rescued': 0,
|
||||
'skipped': 1,
|
||||
'unreachable': 0
|
||||
}
|
||||
},
|
||||
'validation_output': []
|
||||
}]
|
||||
from tripleoclient.tests import fakes
|
||||
|
||||
|
||||
class TestValidatorGroupInfo(utils.TestCommand):
|
||||
|
@ -152,7 +33,7 @@ class TestValidatorGroupInfo(utils.TestCommand):
|
|||
self.cmd = tripleo_validator.TripleOValidatorGroupInfo(self.app, None)
|
||||
|
||||
@mock.patch('validations_libs.validation_actions.ValidationActions.'
|
||||
'group_information', return_value=GROUPS_LIST)
|
||||
'group_information', return_value=fakes.GROUPS_LIST)
|
||||
def test_show_group_info(self, mock_validations):
|
||||
arglist = []
|
||||
verifylist = []
|
||||
|
@ -172,7 +53,7 @@ class TestValidatorList(utils.TestCommand):
|
|||
|
||||
@mock.patch('validations_libs.validation_actions.ValidationActions.'
|
||||
'list_validations',
|
||||
return_value=VALIDATIONS_LIST)
|
||||
return_value=fakes.VALIDATIONS_LIST)
|
||||
def test_validation_list_noargs(self, mock_validations):
|
||||
arglist = []
|
||||
verifylist = []
|
||||
|
@ -192,7 +73,7 @@ class TestValidatorShow(utils.TestCommand):
|
|||
|
||||
@mock.patch('validations_libs.validation_actions.ValidationActions.'
|
||||
'show_validations',
|
||||
return_value=VALIDATIONS_LIST[0])
|
||||
return_value=fakes.VALIDATIONS_LIST[0])
|
||||
def test_validation_show(self, mock_validations):
|
||||
arglist = ['my_val1']
|
||||
verifylist = [('validation_id', 'my_val1')]
|
||||
|
@ -213,7 +94,7 @@ class TestValidatorShowParameter(utils.TestCommand):
|
|||
|
||||
@mock.patch('validations_libs.validation_actions.ValidationActions.'
|
||||
'show_validations_parameters',
|
||||
return_value=VALIDATIONS_LIST[1])
|
||||
return_value=fakes.VALIDATIONS_LIST[1])
|
||||
def test_validation_show_parameter(self, mock_validations):
|
||||
arglist = ['--validation', 'my_val2']
|
||||
verifylist = [('validation_name', ['my_val2'])]
|
||||
|
@ -234,7 +115,7 @@ class TestValidatorShowRun(utils.TestCommand):
|
|||
|
||||
@mock.patch('validations_libs.validation_actions.ValidationLogs.'
|
||||
'get_logfile_content_by_uuid',
|
||||
return_value=VALIDATIONS_LOGS_CONTENTS_LIST)
|
||||
return_value=fakes.VALIDATIONS_LOGS_CONTENTS_LIST)
|
||||
def test_validation_show_run(self, mock_validations):
|
||||
arglist = ['008886df-d297-1eaa-2a74-000000000008']
|
||||
verifylist = [('uuid', '008886df-d297-1eaa-2a74-000000000008')]
|
||||
|
@ -255,7 +136,7 @@ class TestValidatorShowHistory(utils.TestCommand):
|
|||
|
||||
@mock.patch('validations_libs.validation_actions.ValidationActions.'
|
||||
'show_history',
|
||||
return_value=VALIDATIONS_LOGS_CONTENTS_LIST)
|
||||
return_value=fakes.VALIDATIONS_LOGS_CONTENTS_LIST)
|
||||
def test_validation_show_history(self, mock_validations):
|
||||
arglist = []
|
||||
verifylist = []
|
||||
|
@ -266,7 +147,7 @@ class TestValidatorShowHistory(utils.TestCommand):
|
|||
|
||||
@mock.patch('validations_libs.validation_actions.ValidationActions.'
|
||||
'show_history',
|
||||
return_value=VALIDATIONS_LOGS_CONTENTS_LIST)
|
||||
return_value=fakes.VALIDATIONS_LOGS_CONTENTS_LIST)
|
||||
def test_validation_show_history_for_a_validation(self, mock_validations):
|
||||
arglist = [
|
||||
'--validation',
|
Loading…
Reference in New Issue