Allow to run custom ansible modules on NodeCollection

Added run_task method to NodeCollection
Added add_module_paths

Change-Id: I9956787945525b95523d96f3975f580fa6ff2803
This commit is contained in:
Anton Studenov
2016-10-14 13:00:01 +03:00
parent 3b40beabd8
commit 9f5966194a
8 changed files with 80 additions and 3 deletions

View File

@@ -43,6 +43,11 @@ class DevStackNodeTestCase(test.TestCase):
def test_pick(self):
self.assertIs(self.node_collection, self.node_collection.pick())
def test_run_task(self):
self.node_collection.run_task({'foo': 'bar'})
self.mock_cloud_management.execute.assert_called_once_with(
'10.0.0.2', {'foo': 'bar'})
def test_reboot(self):
self.node_collection.reboot()
self.mock_cloud_management.execute.assert_called_once_with(

View File

@@ -63,6 +63,12 @@ class FuelNodeCollectionTestCase(test.TestCase):
self.assertEqual(1, len(one))
self.assertIn(one.hosts[0], self.hosts)
def test_run_task(self):
self.node_collection.run_task({'foo': 'bar'}, raise_on_error=False)
self.mock_cloud_management.execute_on_cloud.assert_called_once_with(
['10.0.0.2', '10.0.0.3', '10.0.0.4', '10.0.0.5'], {'foo': 'bar'},
raise_on_error=False)
def test_pick_count(self):
two = self.node_collection.pick(count=2)
self.assertEqual(2, len(two))

View File

@@ -17,6 +17,7 @@ import mock
import yaml
import os_faults
from os_faults.ansible import executor
from os_faults.api import error
from os_faults.drivers import devstack
from os_faults.drivers import fuel
@@ -132,3 +133,16 @@ class OSFaultsTestCase(test.TestCase):
@mock.patch('os.path.exists', return_value=False)
def test_connect_no_config_files(self, mock_os_path_exists):
self.assertRaises(error.OSFError, os_faults.connect)
@mock.patch('os.path.exists', side_effect=lambda x: 'bad' not in x)
@mock.patch('os.walk', side_effect=lambda x: ([x, [], []],
[x + 'subdir', [], []]))
@mock.patch.object(executor, 'MODULE_PATHS', set())
def test_register_ansible_modules(self, mock_os_walk, mock_os_path_exists):
os_faults.register_ansible_modules(['/my/path/', '/other/path/'])
self.assertEqual(executor.get_module_paths(),
{'/my/path/', '/my/path/subdir',
'/other/path/', '/other/path/subdir'})
self.assertRaises(error.OSFError, os_faults.register_ansible_modules,
['/my/bad/path/'])