Bugfix: apex_lake: sort json keys for git 77/27477/3
authorRoss Brattain <ross.b.brattain@intel.com>
Wed, 25 Jan 2017 00:46:05 +0000 (16:46 -0800)
committerRoss Brattain <ross.b.brattain@intel.com>
Wed, 8 Feb 2017 06:51:13 +0000 (06:51 +0000)
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 <ross.b.brattain@intel.com>
yardstick/vTC/apexlake/experimental_framework/heat_template_generation.py
yardstick/vTC/apexlake/tests/data/generated_templates/experiment_1.yaml.json
yardstick/vTC/apexlake/tests/data/generated_templates/experiment_2.yaml.json

index 1904af2..bbf5585 100644 (file)
@@ -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 \
index 3af9a1c..44a8aeb 100644 (file)
@@ -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
index 9f24689..0a66448 100644 (file)
@@ -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