From 678b3b39b3fbcb0b0dced90a9c9912c40559a1a0 Mon Sep 17 00:00:00 2001 From: Ross Brattain Date: Tue, 24 Jan 2017 16:46:05 -0800 Subject: Bugfix: apex_lake: sort json keys for git experiment_1.yaml.json are in git and everytime the unnitests are run the json file is re-generated with a slightly different key order so it make the git directory dirty. use sort_keys=True to try to maintain a consistent json file so git doesn't detect a difference Change-Id: I7859664e00561e8db032849a6664fb933a36702b Signed-off-by: Ross Brattain --- .../experimental_framework/heat_template_generation.py | 11 +++++++---- .../tests/data/generated_templates/experiment_1.yaml.json | 2 +- .../tests/data/generated_templates/experiment_2.yaml.json | 2 +- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/yardstick/vTC/apexlake/experimental_framework/heat_template_generation.py b/yardstick/vTC/apexlake/experimental_framework/heat_template_generation.py index 1904af20b..bbf55853d 100644 --- a/yardstick/vTC/apexlake/experimental_framework/heat_template_generation.py +++ b/yardstick/vTC/apexlake/experimental_framework/heat_template_generation.py @@ -18,9 +18,11 @@ Generation of the heat templates from the base template """ from __future__ import absolute_import -import json import os import shutil + +from oslo_serialization import jsonutils + from experimental_framework import common from experimental_framework.constants import framework_parameters as fp @@ -193,7 +195,7 @@ def generates_templates(base_heat_template, deployment_configuration): new_template += "_" + str(counter) + template_file_extension shutil.copy(base_template, new_template) - metadata = dict() + metadata = {} for var in heat_template_vars: if var.get_variable_name(): common.replace_in_file(new_template, "#" + @@ -203,7 +205,8 @@ def generates_templates(base_heat_template, deployment_configuration): # Save the metadata on a JSON file with open(new_template + ".json", 'w') as outfile: - json.dump(metadata, outfile) + # sort keys to maintain persistent order for git + jsonutils.dump(metadata, outfile, sort_keys=True) common.LOG.debug("Heat Templates and Metadata file " + str(counter) + " created") @@ -222,7 +225,7 @@ def get_all_heat_templates(template_dir, template_file_extension): (type: str) :return: type: list """ - template_files = list() + template_files = [] for dirname, dirnames, filenames in os.walk(template_dir): for filename in filenames: if template_file_extension in filename and \ diff --git a/yardstick/vTC/apexlake/tests/data/generated_templates/experiment_1.yaml.json b/yardstick/vTC/apexlake/tests/data/generated_templates/experiment_1.yaml.json index 3af9a1cc7..44a8aeb2e 100644 --- a/yardstick/vTC/apexlake/tests/data/generated_templates/experiment_1.yaml.json +++ b/yardstick/vTC/apexlake/tests/data/generated_templates/experiment_1.yaml.json @@ -1 +1 @@ -{"vnic_type": "normal", "ram": "1024", "vcpus": "2"} \ No newline at end of file +{"ram": "1024", "vcpus": "2", "vnic_type": "normal"} \ No newline at end of file diff --git a/yardstick/vTC/apexlake/tests/data/generated_templates/experiment_2.yaml.json b/yardstick/vTC/apexlake/tests/data/generated_templates/experiment_2.yaml.json index 9f246891d..0a66448b7 100644 --- a/yardstick/vTC/apexlake/tests/data/generated_templates/experiment_2.yaml.json +++ b/yardstick/vTC/apexlake/tests/data/generated_templates/experiment_2.yaml.json @@ -1 +1 @@ -{"vnic_type": "direct", "ram": "1024", "vcpus": "2"} \ No newline at end of file +{"ram": "1024", "vcpus": "2", "vnic_type": "direct"} \ No newline at end of file -- cgit 1.2.3-korg