Move "read_yaml_file" to common.yaml_loader 13/59313/3
authorRodolfo Alonso Hernandez <rodolfo.alonso.hernandez@intel.com>
Thu, 28 Jun 2018 16:17:08 +0000 (17:17 +0100)
committerRodolfo Alonso Hernandez <rodolfo.alonso.hernandez@intel.com>
Fri, 29 Jun 2018 10:44:00 +0000 (10:44 +0000)
JIRA: YARDSTICK-1265

Change-Id: Ic2813dca7fc9a3230632f6e8bd75aeacc7e951b0
Signed-off-by: Rodolfo Alonso Hernandez <rodolfo.alonso.hernandez@intel.com>
yardstick/benchmark/contexts/base.py
yardstick/benchmark/contexts/standalone/model.py
yardstick/common/utils.py
yardstick/common/yaml_loader.py
yardstick/tests/unit/benchmark/contexts/test_base.py
yardstick/tests/unit/benchmark/contexts/test_heat.py
yardstick/tests/unit/benchmark/contexts/test_node.py

index 022e365..796a14b 100644 (file)
@@ -14,6 +14,7 @@ import os
 
 from yardstick.common import constants
 from yardstick.common import utils
+from yardstick.common import yaml_loader
 from yardstick.common.constants import YARDSTICK_ROOT_PATH
 
 
@@ -73,13 +74,13 @@ class Context(object):
     def read_pod_file(self, attrs):
         self.file_path = file_path = attrs.get("file", "pod.yaml")
         try:
-            cfg = utils.read_yaml_file(self.file_path)
+            cfg = yaml_loader.read_yaml_file(self.file_path)
         except IOError as io_error:
             if io_error.errno != errno.ENOENT:
                 raise
 
             self.file_path = os.path.join(YARDSTICK_ROOT_PATH, file_path)
-            cfg = utils.read_yaml_file(self.file_path)
+            cfg = yaml_loader.read_yaml_file(self.file_path)
 
         self.nodes.extend(cfg["nodes"])
         self.controllers.extend([node for node in cfg["nodes"]
index 764cde3..ecddcbb 100644 (file)
@@ -26,7 +26,7 @@ import xml.etree.ElementTree as ET
 from yardstick import ssh
 from yardstick.common import constants
 from yardstick.common import exceptions
-from yardstick.common.utils import read_yaml_file
+from yardstick.common import yaml_loader
 from yardstick.network_services.utils import PciAddress
 from yardstick.network_services.helpers.cpu import CpuSysCores
 
@@ -399,13 +399,13 @@ class StandaloneContextHelper(object):
         nodes = []
         nfvi_host = []
         try:
-            cfg = read_yaml_file(self.file_path)
+            cfg = yaml_loader.read_yaml_file(self.file_path)
         except IOError as io_error:
             if io_error.errno != errno.ENOENT:
                 raise
             self.file_path = os.path.join(constants.YARDSTICK_ROOT_PATH,
                                           file_path)
-            cfg = read_yaml_file(self.file_path)
+            cfg = yaml_loader.read_yaml_file(self.file_path)
 
         nodes.extend([node for node in cfg["nodes"] if str(node["role"]) != nfvi_role])
         nfvi_host.extend([node for node in cfg["nodes"] if str(node["role"]) == nfvi_role])
index 251e5cc..f9fe0e3 100644 (file)
@@ -37,7 +37,6 @@ from oslo_utils import encodeutils
 
 import yardstick
 from yardstick.common import exceptions
-from yardstick.common.yaml_loader import yaml_load
 
 
 logger = logging.getLogger(__name__)
@@ -528,11 +527,3 @@ def wait_until_true(predicate, timeout=60, sleep=1, exception=None):
         if exception and issubclass(exception, Exception):
             raise exception  # pylint: disable=raising-bad-type
         raise exceptions.WaitTimeout
-
-
-def read_yaml_file(path):
-    """Read yaml file"""
-
-    with open(path) as stream:
-        data = yaml_load(stream)
-    return data
index 0572bd5..18673be 100644 (file)
 #    License for the specific language governing permissions and limitations
 #    under the License.
 
-# yardstick: this file is copied from python-heatclient and slightly modified
-
-from __future__ import absolute_import
-
 import yaml
 
 
@@ -23,6 +19,7 @@ if hasattr(yaml, 'CSafeLoader'):
 else:
     yaml_loader = type('CustomLoader', (yaml.SafeLoader,), {})
 
+
 if hasattr(yaml, 'CSafeDumper'):
     yaml_dumper = yaml.CSafeDumper
 else:
@@ -31,3 +28,10 @@ else:
 
 def yaml_load(tmpl_str):
     return yaml.load(tmpl_str, Loader=yaml_loader)
+
+
+def read_yaml_file(path):
+    """Read yaml file"""
+    with open(path) as stream:
+        data = yaml_load(stream)
+        return data
index 8f1cbcc..64499cf 100644 (file)
@@ -19,6 +19,7 @@ import mock
 
 from yardstick.benchmark.contexts import base
 from yardstick.benchmark.contexts.base import Context
+from yardstick.common import yaml_loader
 from yardstick.tests.unit import base as ut_base
 from yardstick.common.constants import YARDSTICK_ROOT_PATH
 
@@ -129,7 +130,7 @@ class ContextTestCase(ut_base.BaseUnitTestCase):
         mock_get_ctx.assert_called_once()
         self.assertIsNone(result)
 
-    @mock.patch('yardstick.common.utils.read_yaml_file')
+    @mock.patch.object(yaml_loader, 'read_yaml_file')
     def test_read_pod_file(self, mock_read_yaml_file):
         attrs = {'name': 'foo',
                  'task_id': '12345678',
index 7605ef2..7782d96 100644 (file)
@@ -20,6 +20,7 @@ from yardstick.benchmark.contexts import model
 from yardstick.common import constants as consts
 from yardstick.common import exceptions as y_exc
 from yardstick.common import openstack_utils
+from yardstick.common import yaml_loader
 from yardstick import ssh
 
 
@@ -80,12 +81,13 @@ class HeatContextTestCase(unittest.TestCase):
         self.assertIsNone(self.test_context.heat_parameters)
         self.assertIsNone(self.test_context.key_filename)
 
-    @mock.patch('yardstick.common.utils.read_yaml_file')
+    @mock.patch.object(yaml_loader, 'read_yaml_file')
     @mock.patch('yardstick.benchmark.contexts.heat.PlacementGroup')
     @mock.patch('yardstick.benchmark.contexts.heat.ServerGroup')
     @mock.patch('yardstick.benchmark.contexts.heat.Network')
     @mock.patch('yardstick.benchmark.contexts.heat.Server')
-    def test_init(self, mock_server, mock_network, mock_sg, mock_pg, mock_read_yaml):
+    def test_init(self, mock_server, mock_network, mock_sg, mock_pg,
+                  mock_read_yaml):
 
         mock_read_yaml.return_value = self.HEAT_POD_SAMPLE
         pgs = {'pgrp1': {'policy': 'availability'}}
@@ -764,7 +766,7 @@ class HeatContextTestCase(unittest.TestCase):
         nodes = self.test_context._get_physical_nodes()
         self.assertEquals(nodes, {})
 
-    @mock.patch('yardstick.common.utils.read_yaml_file')
+    @mock.patch.object(yaml_loader, 'read_yaml_file')
     def test__get_physical_node_for_server(self, mock_read_yaml):
         attrs = {'name': 'foo',
                  'task_id': '12345678',
index 5d7b24c..4c8d3d1 100644 (file)
@@ -8,14 +8,16 @@
 ##############################################################################
 
 import os
-import unittest
 import errno
+
 import mock
+import unittest
 
-from yardstick.common import constants as consts
 from yardstick.benchmark.contexts import base
 from yardstick.benchmark.contexts import node
+from yardstick.common import constants as consts
 from yardstick.common import exceptions
+from yardstick.common import yaml_loader
 
 
 class NodeContextTestCase(unittest.TestCase):
@@ -56,7 +58,7 @@ class NodeContextTestCase(unittest.TestCase):
         self.assertEqual(self.test_context.env, {})
         self.assertEqual(self.test_context.attrs, {})
 
-    @mock.patch('yardstick.common.utils.read_yaml_file')
+    @mock.patch.object(yaml_loader, 'read_yaml_file')
     @mock.patch('{}.os.path.join'.format(PREFIX))
     def test_init_negative(self, mock_path_join, read_mock):
         special_path = '/foo/bar/error_file'