aboutsummaryrefslogtreecommitdiffstats
path: root/yardstick/tests/unit/benchmark/contexts/test_node.py
diff options
context:
space:
mode:
Diffstat (limited to 'yardstick/tests/unit/benchmark/contexts/test_node.py')
-rw-r--r--yardstick/tests/unit/benchmark/contexts/test_node.py60
1 files changed, 47 insertions, 13 deletions
diff --git a/yardstick/tests/unit/benchmark/contexts/test_node.py b/yardstick/tests/unit/benchmark/contexts/test_node.py
index 8b232481b..da16074d9 100644
--- a/yardstick/tests/unit/benchmark/contexts/test_node.py
+++ b/yardstick/tests/unit/benchmark/contexts/test_node.py
@@ -8,12 +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):
@@ -33,9 +37,11 @@ class NodeContextTestCase(unittest.TestCase):
'file': self._get_file_abspath(self.NODES_SAMPLE)
}
- def _remove_contexts(self):
- if self.test_context in self.test_context.list:
- self.test_context._delete_context()
+ @staticmethod
+ def _remove_contexts():
+ for context in base.Context.list:
+ context._delete_context()
+ base.Context.list = []
def _get_file_abspath(self, filename):
curr_path = os.path.dirname(os.path.abspath(__file__))
@@ -52,8 +58,9 @@ class NodeContextTestCase(unittest.TestCase):
self.assertEqual(self.test_context.env, {})
self.assertEqual(self.test_context.attrs, {})
+ @mock.patch.object(yaml_loader, 'read_yaml_file')
@mock.patch('{}.os.path.join'.format(PREFIX))
- def test_init_negative(self, mock_path_join):
+ def test_init_negative(self, mock_path_join, read_mock):
special_path = '/foo/bar/error_file'
error_path = self._get_file_abspath("error_file")
@@ -65,7 +72,6 @@ class NodeContextTestCase(unittest.TestCase):
# we can't count mock_path_join calls because
# it can catch join calls for .pyc files.
mock_path_join.side_effect = path_join
- self.test_context.read_config_file = read_mock = mock.Mock()
read_calls = 0
with self.assertRaises(KeyError):
@@ -83,7 +89,7 @@ class NodeContextTestCase(unittest.TestCase):
self.test_context.init(attrs)
read_calls += 1
- self.assertEqual(read_mock.called, read_calls)
+ self.assertEqual(read_mock.call_count, read_calls)
self.assertIn(attrs['file'], self.test_context.file_path)
self.assertEqual(raised.exception.errno, errno.EBUSY)
self.assertEqual(str(raised.exception), str(read_mock.side_effect))
@@ -98,11 +104,6 @@ class NodeContextTestCase(unittest.TestCase):
self.assertEqual(raised.exception.errno, errno.ENOENT)
self.assertEqual(str(raised.exception), str(read_mock.side_effect))
- def test_read_config_file(self):
- self.test_context.init(self.attrs)
-
- self.assertIsNotNone(self.test_context.read_config_file())
-
def test__dispatch_script(self):
self.test_context.init(self.attrs)
@@ -168,6 +169,39 @@ class NodeContextTestCase(unittest.TestCase):
self.assertEqual(result['user'], 'root')
self.assertEqual(result['key_filename'], '/root/.yardstick_key')
+ def test__get_physical_nodes(self):
+ self.test_context.init(self.attrs)
+ nodes = self.test_context._get_physical_nodes()
+ self.assertEqual(nodes, self.test_context.nodes)
+
+ def test__get_physical_node_for_server(self):
+ self.test_context.init(self.attrs)
+
+ # When server is not from this context
+ result = self.test_context._get_physical_node_for_server('node1.another-context')
+ self.assertIsNone(result)
+
+ # When node_name is not from this context
+ result = self.test_context._get_physical_node_for_server('fake.foo-12345678')
+ self.assertIsNone(result)
+
+ result = self.test_context._get_physical_node_for_server('node1.foo-12345678')
+ self.assertEqual(result, 'node1.foo')
+
+ def test_update_collectd_options_for_node(self):
+ self.test_context.init(self.attrs)
+ options = {'collectd': {'interval': 5}}
+
+ with self.assertRaises(exceptions.ContextUpdateCollectdForNodeError):
+ self.test_context.update_collectd_options_for_node(options, 'fake.foo-12345678')
+
+ self.test_context.update_collectd_options_for_node(options, 'node1.foo-12345678')
+
+ node_collectd_options = [node for node in self.test_context.nodes
+ if node['name'] == 'node1'][0]['collectd']
+
+ self.assertEqual(node_collectd_options, options)
+
@mock.patch('{}.NodeContext._dispatch_script'.format(PREFIX))
def test_deploy(self, dispatch_script_mock):
obj = node.NodeContext()