Fix behavior for Show command to stick to tripleoclient
The behavior of the Show command wasn't exactly as tripleoclient This review aims to fix it Change-Id: I4e1af84675bfe722e232217f15c29fbc3d006333
This commit is contained in:
parent
c98ea9195a
commit
1daa430f9a
@ -30,11 +30,12 @@ class TestUtils(TestCase):
|
||||
@mock.patch('validations_libs.validation.Validation._get_content',
|
||||
return_value=fakes.FAKE_PLAYBOOK)
|
||||
@mock.patch('six.moves.builtins.open')
|
||||
def test_get_validations_data(self, mock_open, mock_data):
|
||||
@mock.patch('os.path.exists', return_value=True)
|
||||
def test_get_validations_data(self, mock_exists, mock_open, mock_data):
|
||||
output = {'Name': 'Advanced Format 512e Support',
|
||||
'Description': 'foo', 'Groups': ['prep', 'pre-deployment'],
|
||||
'ID': '512e'}
|
||||
res = utils.get_validations_data('/foo/512e.yaml')
|
||||
res = utils.get_validations_data('512e')
|
||||
self.assertEqual(res, output)
|
||||
|
||||
def test_get_validations_stats(self):
|
||||
|
@ -33,8 +33,9 @@ class TestValidatorShow(TestCase):
|
||||
'get_all_logfiles_content',
|
||||
return_value=fakes.VALIDATIONS_LOGS_CONTENTS_LIST)
|
||||
@mock.patch('six.moves.builtins.open')
|
||||
def test_validation_show(self, mock_open, mock_parse_validation, mock_data,
|
||||
mock_log):
|
||||
@mock.patch('os.path.exists', return_value=True)
|
||||
def test_validation_show(self, mock_exists, mock_open,
|
||||
mock_parse_validation, mock_data, mock_log):
|
||||
data = {'Name': 'Advanced Format 512e Support',
|
||||
'Description': 'foo', 'Groups': ['prep', 'pre-deployment'],
|
||||
'ID': '512e'}
|
||||
|
@ -111,12 +111,14 @@ def get_validations_details(validation):
|
||||
return {}
|
||||
|
||||
|
||||
def get_validations_data(validation):
|
||||
def get_validations_data(validation, path=constants.ANSIBLE_VALIDATION_DIR):
|
||||
"""
|
||||
Return validations data with format:
|
||||
ID, Name, Description, Groups, Other param
|
||||
"""
|
||||
return Validation(validation).get_formated_data
|
||||
val_path = "{}/{}.yaml".format(path, validation)
|
||||
if os.path.exists(val_path):
|
||||
return Validation(val_path).get_formated_data
|
||||
|
||||
|
||||
def get_validations_parameters(validations_data, validation_name=[],
|
||||
|
@ -52,7 +52,7 @@ class ValidationActions(object):
|
||||
self.log = logging.getLogger(__name__ + ".show_validations")
|
||||
# Get validation data:
|
||||
vlog = ValidationLogs(log_path)
|
||||
data = v_utils.get_validations_data(validation)
|
||||
data = v_utils.get_validations_data(validation, self.validation_path)
|
||||
logfiles = vlog.get_all_logfiles_content()
|
||||
format = vlog.get_validations_stats(logfiles)
|
||||
data.update(format)
|
||||
|
@ -12,11 +12,11 @@
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
#
|
||||
import json
|
||||
import glob
|
||||
import logging
|
||||
import os
|
||||
import time
|
||||
import yaml
|
||||
from os import listdir
|
||||
from os.path import isfile, join
|
||||
|
||||
@ -48,7 +48,7 @@ class ValidationLog(object):
|
||||
|
||||
def _get_content(self, file):
|
||||
with open(file, 'r') as log_file:
|
||||
return yaml.safe_load(log_file)
|
||||
return json.load(log_file)
|
||||
|
||||
def get_log_path(self):
|
||||
"""Return full path of a validation log"""
|
||||
@ -140,7 +140,7 @@ class ValidationLogs(object):
|
||||
|
||||
def _get_content(self, file):
|
||||
with open(file, 'r') as log_file:
|
||||
return yaml.safe_load(log_file)[0]
|
||||
return json.load(log_file)
|
||||
|
||||
def get_logfile_by_validation(self, validation_id):
|
||||
"""Return logfiles by validation_id"""
|
||||
@ -179,8 +179,9 @@ class ValidationLogs(object):
|
||||
|
||||
def get_all_logfiles_content(self):
|
||||
"""Return logfiles content filter by uuid and content"""
|
||||
return [self._get_content(f) for f in listdir(self.logs_path) if
|
||||
isfile(join(self.logs_path, f))]
|
||||
return [self._get_content(join(self.logs_path, f))
|
||||
for f in listdir(self.logs_path)
|
||||
if isfile(join(self.logs_path, f))]
|
||||
|
||||
def get_validations_stats(self, logs):
|
||||
"""
|
||||
|
Loading…
Reference in New Issue
Block a user