Browse Source

Merge "Refactoring of the cli show module"

changes/13/790913/3
Zuul 1 week ago
committed by Gerrit Code Review
parent
commit
eaf304f62e
2 changed files with 30 additions and 14 deletions
  1. +6
    -7
      validations_libs/cli/show.py
  2. +24
    -7
      validations_libs/validation_actions.py

+ 6
- 7
validations_libs/cli/show.py View File

@ -14,9 +14,6 @@
# License for the specific language governing permissions and limitations
# under the License.
import json
import sys
from cliff.show import ShowOne
from validations_libs.validation_actions import ValidationActions
@ -33,7 +30,7 @@ class Show(ShowOne):
parser.add_argument('--validation-dir', dest='validation_dir',
default=constants.ANSIBLE_VALIDATION_DIR,
help=("Path where the validation playbooks "
"is located."))
"are located."))
parser.add_argument('validation_name',
metavar="<validation>",
type=str,
@ -62,7 +59,7 @@ class ShowGroup(ShowOne):
parser.add_argument('--validation-dir', dest='validation_dir',
default=constants.ANSIBLE_VALIDATION_DIR,
help=("Path where the validation playbooks "
"is located."))
"are located."))
parser.add_argument('--group', '-g',
metavar='<group_name>',
dest="group",
@ -88,7 +85,7 @@ class ShowParameter(ShowOne):
parser.add_argument('--validation-dir', dest='validation_dir',
default=constants.ANSIBLE_VALIDATION_DIR,
help=("Path where the validation playbooks "
"is located."))
"are located."))
ex_group = parser.add_mutually_exclusive_group(required=False)
ex_group.add_argument(
@ -145,7 +142,9 @@ class ShowParameter(ShowOne):
parsed_args.group,
parsed_args.format_output,
parsed_args.download)
if parsed_args.download:
print("The file {} has been created successfully".format(
self.app.LOG.info(
"The file {} has been created successfully".format(
parsed_args.download))
return params.keys(), params.values()

+ 24
- 7
validations_libs/validation_actions.py View File

@ -504,19 +504,36 @@ class ValidationActions(object):
group)
if download_file:
params_only = {}
with open(download_file, 'w') as f:
for val_name in params.keys():
params_only.update(params[val_name].get('parameters'))
try:
with open(download_file, 'w') as parameters_file:
for val_name in params.keys():
params_only.update(params[val_name].get('parameters'))
if output_format == 'json':
f.write(json.dumps(params_only,
if output_format == 'json':
parameters_file.write(
json.dumps(params_only,
indent=4,
sort_keys=True))
else:
f.write(yaml.safe_dump(params_only,
else:
parameters_file.write(
yaml.safe_dump(params_only,
allow_unicode=True,
default_flow_style=False,
indent=2))
self.log.debug(
"Validations parameters file {} saved as {} ".format(
download_file,
output_format))
except (PermissionError, OSError) as error:
self.log.exception(
(
"Exception {} encountered while tring to write "
"a validations parameters file {}"
).format(
error,
download_file))
return params
def show_history(self, validation_ids=None, extension='json',


Loading…
Cancel
Save