From ff78b920486bb8b370a31d9ff743aaadd7949522 Mon Sep 17 00:00:00 2001 From: Ilya Shakhat Date: Wed, 2 Jan 2019 12:33:07 +0100 Subject: [PATCH] Tests cleanup * Remove dependency on ansible and libvirt libraries * Bump python 3 version to 3.6 * Fix python warnings in the code Change-Id: If7b495e9c3b2f5031d535954c3c3280e247871a6 --- .zuul.yaml | 2 +- .../ansible/modules/fuel_network_mgmt.py | 44 ------------ os_faults/api/human.py | 30 ++++---- .../cloud/{tcpcloud.py => saltcloud.py} | 2 +- os_faults/registry.py | 3 +- .../tests/unit/ansible/modules/__init__.py | 0 .../tests/unit/ansible/modules/test_freeze.py | 47 ------------- .../ansible/modules/test_fule_network_mgmt.py | 51 -------------- .../unit/ansible/modules/test_iptables.py | 68 ------------------- .../tests/unit/ansible/modules/test_kill.py | 45 ------------ os_faults/tests/unit/ansible/test_executor.py | 27 +++++--- .../tests/unit/drivers/cloud/test_devstack.py | 3 +- .../{test_tcpcloud.py => test_saltcloud.py} | 35 +++++----- .../tests/unit/drivers/power/test_libvirt.py | 6 +- os_faults/tests/unit/test_os_faults.py | 12 ++-- setup.cfg | 6 +- test-requirements.txt | 3 - tox.ini | 5 +- 18 files changed, 73 insertions(+), 316 deletions(-) delete mode 100644 os_faults/ansible/modules/fuel_network_mgmt.py rename os_faults/drivers/cloud/{tcpcloud.py => saltcloud.py} (99%) delete mode 100644 os_faults/tests/unit/ansible/modules/__init__.py delete mode 100644 os_faults/tests/unit/ansible/modules/test_freeze.py delete mode 100644 os_faults/tests/unit/ansible/modules/test_fule_network_mgmt.py delete mode 100644 os_faults/tests/unit/ansible/modules/test_iptables.py delete mode 100644 os_faults/tests/unit/ansible/modules/test_kill.py rename os_faults/tests/unit/drivers/cloud/{test_tcpcloud.py => test_saltcloud.py} (93%) diff --git a/.zuul.yaml b/.zuul.yaml index d95a914..4fb0b42 100644 --- a/.zuul.yaml +++ b/.zuul.yaml @@ -2,7 +2,7 @@ templates: - docs-on-readthedocs - openstack-python-jobs - - openstack-python35-jobs + - openstack-python36-jobs vars: rtd_webhook_id: '47124' check: diff --git a/os_faults/ansible/modules/fuel_network_mgmt.py b/os_faults/ansible/modules/fuel_network_mgmt.py deleted file mode 100644 index b42cfe5..0000000 --- a/os_faults/ansible/modules/fuel_network_mgmt.py +++ /dev/null @@ -1,44 +0,0 @@ -#!/usr/bin/python - -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file except in compliance with the License. You may obtain -# a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. - -from ansible.module_utils.basic import * # noqa - -NETWORK_NAME_TO_INTERFACE = { - 'management': 'br-mgmt', - 'public': 'br-ex', - 'private': 'br-prv', - 'storage': 'br-storage', -} - - -def main(): - module = AnsibleModule( - argument_spec=dict( - operation=dict(choices=['up', 'down']), - network_name=dict(default='management', - choices=list(NETWORK_NAME_TO_INTERFACE.keys())), - )) - - operation = module.params['operation'] - network_name = module.params['network_name'] - - interface = NETWORK_NAME_TO_INTERFACE[network_name] - cmd = 'ip link set %s %s' % (interface, operation) - - rc, stdout, stderr = module.run_command(cmd, check_rc=True) - module.exit_json(cmd=cmd, rc=rc, stderr=stderr, stdout=stdout) - - -if __name__ == '__main__': - main() diff --git a/os_faults/api/human.py b/os_faults/api/human.py index 8b60bef..3d1c94f 100644 --- a/os_faults/api/human.py +++ b/os_faults/api/human.py @@ -60,23 +60,23 @@ NODE_ACTIONS = list_actions(node_collection_pkg.NodeCollection) NODE_ACTIONS_PATTERN = '|'.join(NODE_ACTIONS) PATTERNS = [ - re.compile('(?P%s)' - '\s+(?P\S+)\s+service' - '(\s+on(\s+(?P\S+))?\s+nodes?)?' - '(\s+for\s+(?P\d+)\s+seconds)?' % + re.compile(r'(?P%s)' + r'\s+(?P\S+)\s+service' + r'(\s+on(\s+(?P\S+))?\s+nodes?)?' + r'(\s+for\s+(?P\d+)\s+seconds)?' % SERVICE_ACTIONS_PATTERN), - re.compile('(?P%s)' - '\s+(?P\S+)\s+container' - '(\s+on(\s+(?P\S+))?\s+nodes?)?' - '(\s+for\s+(?P\d+)\s+seconds)?' % + re.compile(r'(?P%s)' + r'\s+(?P\S+)\s+container' + r'(\s+on(\s+(?P\S+))?\s+nodes?)?' + r'(\s+for\s+(?P\d+)\s+seconds)?' % CONTAINER_ACTIONS_PATTERN), - re.compile('(?P%s)' - '(\s+(?P\w+)\s+network\s+on)?' - '(\s+(?P\w+)' - '(\s+for\s+(?P\d+)\s+seconds)(\s+on)?)?' - '(\s+(?P%s|\S+))?' - '\s+nodes?' - '(\s+with\s+(?P\S+)\s+service)?' % + re.compile(r'(?P%s)' + r'(\s+(?P\w+)\s+network\s+on)?' + r'(\s+(?P\w+)' + r'(\s+for\s+(?P\d+)\s+seconds)(\s+on)?)?' + r'(\s+(?P%s|\S+))?' + r'\s+nodes?' + r'(\s+with\s+(?P\S+)\s+service)?' % (NODE_ACTIONS_PATTERN, NODE_ALIASES_PATTERN)), ] diff --git a/os_faults/drivers/cloud/tcpcloud.py b/os_faults/drivers/cloud/saltcloud.py similarity index 99% rename from os_faults/drivers/cloud/tcpcloud.py rename to os_faults/drivers/cloud/saltcloud.py index 74d35cf..23701c6 100644 --- a/os_faults/drivers/cloud/tcpcloud.py +++ b/os_faults/drivers/cloud/saltcloud.py @@ -116,7 +116,7 @@ class SaltCloudManagement(cloud_management.CloudManagement, 'rabbitmq': { 'driver': 'salt_service', 'args': { - 'grep': 'beam\.smp .*rabbitmq_server', + 'grep': r'beam\.smp .*rabbitmq_server', 'salt_service': 'rabbitmq-server', } }, diff --git a/os_faults/registry.py b/os_faults/registry.py index 38766c0..5097fac 100644 --- a/os_faults/registry.py +++ b/os_faults/registry.py @@ -27,8 +27,9 @@ DRIVERS = {} def _import_modules_from_package(): folder = os.path.dirname(os_faults.__file__) library_root = os.path.normpath(os.path.join(folder, os.pardir)) + drivers_folder = os.path.join(folder, 'drivers') - for root, dirs, files in os.walk(folder): + for root, dirs, files in os.walk(drivers_folder): for filename in files: if (filename.startswith('__') or filename.startswith('test') or diff --git a/os_faults/tests/unit/ansible/modules/__init__.py b/os_faults/tests/unit/ansible/modules/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/os_faults/tests/unit/ansible/modules/test_freeze.py b/os_faults/tests/unit/ansible/modules/test_freeze.py deleted file mode 100644 index f217e8b..0000000 --- a/os_faults/tests/unit/ansible/modules/test_freeze.py +++ /dev/null @@ -1,47 +0,0 @@ -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or -# implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import mock - -from os_faults.ansible.modules import freeze -from os_faults.tests.unit import test - - -class FreezeTestCase(test.TestCase): - - @mock.patch("os_faults.ansible.modules.freeze.AnsibleModule") - def test_main(self, mock_ansible_module): - ansible_module_inst = mock_ansible_module.return_value - ansible_module_inst.run_command.return_value = [ - 'myrc', 'mystdout', 'mystderr'] - ansible_module_inst.params = { - 'grep': 'foo', - 'sec': 15, - } - freeze.main() - - cmd = ('bash -c "tf=$(mktemp /tmp/script.XXXXXX);' - 'echo -n \'#!\' > $tf; ' - 'echo -en \'/bin/bash\\npids=`ps ax | ' - 'grep -v grep | ' - 'grep foo | awk {{\\047print $1\\047}}`; ' - 'echo $pids | xargs kill -19; sleep 15; ' - 'echo $pids | xargs kill -18; rm \' >> $tf; ' - 'echo -n $tf >> $tf; ' - 'chmod 770 $tf; nohup $tf &"') - ansible_module_inst.exit_json.assert_called_once_with( - cmd=cmd, - rc='myrc', - stdout='mystdout', - stderr='mystderr', - ) diff --git a/os_faults/tests/unit/ansible/modules/test_fule_network_mgmt.py b/os_faults/tests/unit/ansible/modules/test_fule_network_mgmt.py deleted file mode 100644 index ce2dc25..0000000 --- a/os_faults/tests/unit/ansible/modules/test_fule_network_mgmt.py +++ /dev/null @@ -1,51 +0,0 @@ -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or -# implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import ddt -import mock - -from os_faults.ansible.modules import fuel_network_mgmt -from os_faults.tests.unit import test - - -@ddt.ddt -class FuelNetworkManagementTestCase(test.TestCase): - - def setUp(self): - super(FuelNetworkManagementTestCase, self).setUp() - - @ddt.data(['management', 'up', 'ip link set br-mgmt up'], - ['management', 'down', 'ip link set br-mgmt down'], - ['public', 'up', 'ip link set br-ex up'], - ['public', 'down', 'ip link set br-ex down'], - ['private', 'up', 'ip link set br-prv up'], - ['private', 'down', 'ip link set br-prv down'], - ['storage', 'up', 'ip link set br-storage up'], - ['storage', 'down', 'ip link set br-storage down']) - @ddt.unpack - @mock.patch("os_faults.ansible.modules.fuel_network_mgmt.AnsibleModule") - def test_main(self, network_name, operation, cmd, mock_ansible_module): - ansible_module_inst = mock_ansible_module.return_value - ansible_module_inst.run_command.return_value = [ - 'myrc', 'mystdout', 'mystderr'] - ansible_module_inst.params = { - 'network_name': network_name, - 'operation': operation, - } - fuel_network_mgmt.main() - ansible_module_inst.exit_json.assert_called_once_with( - cmd=cmd, - rc='myrc', - stdout='mystdout', - stderr='mystderr', - ) diff --git a/os_faults/tests/unit/ansible/modules/test_iptables.py b/os_faults/tests/unit/ansible/modules/test_iptables.py deleted file mode 100644 index 6481f0b..0000000 --- a/os_faults/tests/unit/ansible/modules/test_iptables.py +++ /dev/null @@ -1,68 +0,0 @@ -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or -# implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import mock - -from os_faults.ansible.modules import iptables -from os_faults.tests.unit import test - - -class IptablesTestCase(test.TestCase): - - @mock.patch("os_faults.ansible.modules.iptables.AnsibleModule") - def test_main_unblock(self, mock_ansible_module): - ansible_module_inst = mock_ansible_module.return_value - ansible_module_inst.run_command.return_value = [ - 'myrc', 'mystdout', 'mystderr'] - ansible_module_inst.params = { - 'service': 'foo', - 'action': 'unblock', - 'port': 5555, - 'protocol': 'tcp', - } - iptables.main() - - cmd = ( - 'bash -c "rule=`iptables -L INPUT -n --line-numbers | ' - 'grep "foo_temporary_DROP" | cut -d \' \' -f1`; for arg in $rule;' - ' do iptables -D INPUT -p tcp --dport 5555 ' - '-j DROP -m comment --comment "foo_temporary_DROP"; done"') - ansible_module_inst.exit_json.assert_called_once_with( - cmd=cmd, - rc='myrc', - stdout='mystdout', - stderr='mystderr', - ) - - @mock.patch("os_faults.ansible.modules.iptables.AnsibleModule") - def test_main_block(self, mock_ansible_module): - ansible_module_inst = mock_ansible_module.return_value - ansible_module_inst.run_command.return_value = [ - 'myrc', 'mystdout', 'mystderr'] - ansible_module_inst.params = { - 'service': 'foo', - 'action': 'block', - 'port': 5555, - 'protocol': 'tcp', - } - iptables.main() - - cmd = ( - 'bash -c "iptables -I INPUT 1 -p tcp --dport 5555 ' - '-j DROP -m comment --comment "foo_temporary_DROP""') - ansible_module_inst.exit_json.assert_called_once_with( - cmd=cmd, - rc='myrc', - stdout='mystdout', - stderr='mystderr', - ) diff --git a/os_faults/tests/unit/ansible/modules/test_kill.py b/os_faults/tests/unit/ansible/modules/test_kill.py deleted file mode 100644 index c93d02f..0000000 --- a/os_faults/tests/unit/ansible/modules/test_kill.py +++ /dev/null @@ -1,45 +0,0 @@ -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or -# implied. -# See the License for the specific language governing permissions and -# limitations under the License. - - -import ddt -import mock - -from os_faults.ansible.modules import kill -from os_faults.tests.unit import test - - -@ddt.ddt -class KillTestCase(test.TestCase): - - @ddt.data(['foo', 9, 'bash -c "ps ax | grep -v grep | grep \'foo\' ' - '| awk {\'print $1\'} | xargs kill -9"'], - ['bar', 3, 'bash -c "ps ax | grep -v grep | grep \'bar\' ' - '| awk {\'print $1\'} | xargs kill -3"']) - @ddt.unpack - @mock.patch("os_faults.ansible.modules.kill.AnsibleModule") - def test_main(self, grep, sig, cmd, mock_ansible_module): - ansible_module_inst = mock_ansible_module.return_value - ansible_module_inst.run_command.return_value = [ - 'myrc', 'mystdout', 'mystderr'] - ansible_module_inst.params = { - 'grep': grep, - 'sig': sig, - } - kill.main() - ansible_module_inst.exit_json.assert_called_once_with( - cmd=cmd, - rc='myrc', - stdout='mystdout', - stderr='mystderr', - ) diff --git a/os_faults/tests/unit/ansible/test_executor.py b/os_faults/tests/unit/ansible/test_executor.py index e116d17..01871ef 100644 --- a/os_faults/tests/unit/ansible/test_executor.py +++ b/os_faults/tests/unit/ansible/test_executor.py @@ -34,6 +34,7 @@ class AnsibleRunnerTestCase(test.TestCase): r = executor.resolve_relative_path('') self.assertIsNotNone(r) + @mock.patch('os_faults.ansible.executor.find_ansible') @mock.patch.object(executor, 'Options') @ddt.data(( {}, @@ -88,15 +89,16 @@ class AnsibleRunnerTestCase(test.TestCase): 'juser@jhost.com"')), )) @ddt.unpack - def test___init__options(self, auth, default_host_vars, mock_options): + def test___init__options(self, auth, default_host_vars, mock_options, _): runner = executor.AnsibleRunner(auth=auth) module_path = executor.make_module_path_option() mock_options.assert_called_once_with( module_path=module_path, connection='smart', forks=100) self.assertEqual(default_host_vars, runner.default_host_vars) + @mock.patch('os_faults.ansible.executor.find_ansible') @mock.patch('os_faults.ansible.executor.AnsibleRunner._run_play') - def test_run_playbook(self, mock_run_play): + def test_run_playbook(self, mock_run_play, _): ex = executor.AnsibleRunner() my_playbook = [{'gather_facts': 'yes'}, {'gather_facts': 'no'}] ex.run_playbook(my_playbook, {}) @@ -105,8 +107,9 @@ class AnsibleRunnerTestCase(test.TestCase): {'gather_facts': 'no'}]) self.assertEqual(mock_run_play.call_count, 2) + @mock.patch('os_faults.ansible.executor.find_ansible') @mock.patch('os_faults.ansible.executor.AnsibleRunner.run_playbook') - def test_execute(self, mock_run_playbook): + def test_execute(self, mock_run_playbook, _): my_hosts = [node_collection.Host('0.0.0.0'), node_collection.Host('255.255.255.255')] my_tasks = 'my_task' @@ -117,8 +120,9 @@ class AnsibleRunnerTestCase(test.TestCase): 'hosts': ['0.0.0.0', '255.255.255.255'], 'serial': 10}], {'0.0.0.0': {}, '255.255.255.255': {}}) + @mock.patch('os_faults.ansible.executor.find_ansible') @mock.patch('os_faults.ansible.executor.AnsibleRunner.run_playbook') - def test_execute_with_host_vars(self, mock_run_playbook): + def test_execute_with_host_vars(self, mock_run_playbook, _): my_hosts = [ node_collection.Host('0.0.0.0', auth={'username': 'foo', 'password': 'bar', @@ -161,8 +165,9 @@ class AnsibleRunnerTestCase(test.TestCase): '-o ConnectTimeout=60 ' 'foo@192.168.1.100"'}}) + @mock.patch('os_faults.ansible.executor.find_ansible') @mock.patch('os_faults.ansible.executor.AnsibleRunner.run_playbook') - def test_execute_with_serial(self, mock_run_playbook): + def test_execute_with_serial(self, mock_run_playbook, _): my_hosts = [node_collection.Host('0.0.0.0'), node_collection.Host('255.255.255.255')] my_tasks = 'my_task' @@ -173,8 +178,9 @@ class AnsibleRunnerTestCase(test.TestCase): 'hosts': ['0.0.0.0', '255.255.255.255'], 'serial': 50}], {'0.0.0.0': {}, '255.255.255.255': {}}) + @mock.patch('os_faults.ansible.executor.find_ansible') @mock.patch('os_faults.ansible.executor.AnsibleRunner.run_playbook') - def test_execute_status_unreachable(self, mock_run_playbook): + def test_execute_status_unreachable(self, mock_run_playbook, _): my_hosts = [node_collection.Host('0.0.0.0'), node_collection.Host('255.255.255.255')] my_tasks = 'my_task' @@ -193,8 +199,9 @@ class AnsibleRunnerTestCase(test.TestCase): ex.execute, my_hosts, my_tasks, my_statuses) self.assertEqual(type(err), executor.AnsibleExecutionUnreachable) + @mock.patch('os_faults.ansible.executor.find_ansible') @mock.patch('os_faults.ansible.executor.AnsibleRunner.run_playbook') - def test_execute_status_failed(self, mock_run_playbook): + def test_execute_status_failed(self, mock_run_playbook, _): my_hosts = [node_collection.Host('0.0.0.0'), node_collection.Host('255.255.255.255')] my_tasks = 'my_task' @@ -213,10 +220,11 @@ class AnsibleRunnerTestCase(test.TestCase): ex.execute, my_hosts, my_tasks, my_statuses) self.assertEqual(type(err), executor.AnsibleExecutionException) + @mock.patch('os_faults.ansible.executor.find_ansible') @mock.patch('copy.deepcopy') @mock.patch('os_faults.ansible.executor.AnsibleRunner.run_playbook') def test_execute_stdout_is_more_than_stdout_limit( - self, mock_run_playbook, mock_deepcopy): + self, mock_run_playbook, mock_deepcopy, _): result = mock.Mock() result.payload = {'stdout': 'a' * (executor.STDOUT_LIMIT + 1), 'stdout_lines': 'a' * (executor.STDOUT_LIMIT + 1)} @@ -234,10 +242,11 @@ class AnsibleRunnerTestCase(test.TestCase): self.assertEqual('a' * executor.STDOUT_LIMIT + '... ', log_result.payload['stdout']) + @mock.patch('os_faults.ansible.executor.find_ansible') @mock.patch('os_faults.ansible.executor.LOG.debug') @mock.patch('os_faults.ansible.executor.AnsibleRunner.run_playbook') def test_execute_payload_without_stdout(self, mock_run_playbook, - mock_debug): + mock_debug, _): task = {'task': 'foo'} host = '0.0.0.0' result = executor.AnsibleExecutionRecord( diff --git a/os_faults/tests/unit/drivers/cloud/test_devstack.py b/os_faults/tests/unit/drivers/cloud/test_devstack.py index 8976650..047ce63 100644 --- a/os_faults/tests/unit/drivers/cloud/test_devstack.py +++ b/os_faults/tests/unit/drivers/cloud/test_devstack.py @@ -130,7 +130,8 @@ class DevStackManagementTestCase(test.TestCase): fqdn='')], nodes.hosts) - def test_validate_services(self): + @mock.patch('os_faults.ansible.executor.AnsibleRunner') + def test_validate_services(self, _): devstack_management = devstack.DevStackCloudManagement(self.conf) devstack_management.validate_services() diff --git a/os_faults/tests/unit/drivers/cloud/test_tcpcloud.py b/os_faults/tests/unit/drivers/cloud/test_saltcloud.py similarity index 93% rename from os_faults/tests/unit/drivers/cloud/test_tcpcloud.py rename to os_faults/tests/unit/drivers/cloud/test_saltcloud.py index 77a34dd..92c93fa 100644 --- a/os_faults/tests/unit/drivers/cloud/test_tcpcloud.py +++ b/os_faults/tests/unit/drivers/cloud/test_saltcloud.py @@ -16,7 +16,7 @@ import mock from os_faults.ansible import executor from os_faults.api import node_collection -from os_faults.drivers.cloud import tcpcloud +from os_faults.drivers.cloud import saltcloud from os_faults.tests.unit import fakes from os_faults.tests.unit import test @@ -98,7 +98,7 @@ class SaltCloudManagementTestCase(test.TestCase): def test_init(self, config, expected_runner_calls, mock_ansible_runner): ansible_runner_inst = mock_ansible_runner.return_value - tcp_managment = tcpcloud.SaltCloudManagement(config) + tcp_managment = saltcloud.SaltCloudManagement(config) mock_ansible_runner.assert_has_calls(expected_runner_calls) self.assertIs(tcp_managment.master_node_executor, ansible_runner_inst) @@ -114,7 +114,7 @@ class SaltCloudManagementTestCase(test.TestCase): fakes.FakeAnsibleResult(payload={'stdout': ''})], ] self.tcp_conf['slave_name_regexp'] = '(ctl*|cmp*)' - tcp_managment = tcpcloud.SaltCloudManagement(self.tcp_conf) + tcp_managment = saltcloud.SaltCloudManagement(self.tcp_conf) tcp_managment.verify() get_nodes_cmd = "salt -E '(ctl*|cmp*)' network.interfaces --out=yaml" @@ -126,8 +126,9 @@ class SaltCloudManagementTestCase(test.TestCase): mock.call(self.hosts, {'command': 'hostname'}), ]) - def test_validate_services(self): - tcp_managment = tcpcloud.SaltCloudManagement(self.tcp_conf) + @mock.patch('os_faults.ansible.executor.AnsibleRunner') + def test_validate_services(self, _): + tcp_managment = saltcloud.SaltCloudManagement(self.tcp_conf) tcp_managment.validate_services() @mock.patch('os_faults.ansible.executor.AnsibleRunner', autospec=True) @@ -137,7 +138,7 @@ class SaltCloudManagementTestCase(test.TestCase): [self.fake_ansible_result], [self.fake_node_ip_result], ] - tcp_managment = tcpcloud.SaltCloudManagement(self.tcp_conf) + tcp_managment = saltcloud.SaltCloudManagement(self.tcp_conf) nodes = tcp_managment.get_nodes() ansible_runner_inst.execute.assert_has_calls([ @@ -158,7 +159,7 @@ class SaltCloudManagementTestCase(test.TestCase): ] node_discover_driver = mock.Mock() node_discover_driver.discover_hosts.return_value = hosts - tcp_managment = tcpcloud.SaltCloudManagement(self.tcp_conf) + tcp_managment = saltcloud.SaltCloudManagement(self.tcp_conf) tcp_managment.set_node_discover(node_discover_driver) nodes = tcp_managment.get_nodes() @@ -174,7 +175,7 @@ class SaltCloudManagementTestCase(test.TestCase): [fakes.FakeAnsibleResult(payload={'stdout': ''}), fakes.FakeAnsibleResult(payload={'stdout': ''})] ] - tcp_managment = tcpcloud.SaltCloudManagement(self.tcp_conf) + tcp_managment = saltcloud.SaltCloudManagement(self.tcp_conf) nodes = tcp_managment.get_nodes() result = tcp_managment.execute_on_cloud( nodes.hosts, {'command': 'mycmd'}, raise_on_error=False) @@ -196,13 +197,13 @@ class SaltCloudManagementTestCase(test.TestCase): [self.fake_ansible_result], [self.fake_node_ip_result], ] - tcp_managment = tcpcloud.SaltCloudManagement(self.tcp_conf) + tcp_managment = saltcloud.SaltCloudManagement(self.tcp_conf) nodes = tcp_managment.get_nodes(fqdns=['cmp02.mk20.local']) self.assertEqual(nodes.hosts, [self.hosts[1]]) @mock.patch('os_faults.ansible.executor.AnsibleRunner', autospec=True) - @ddt.data(*tcpcloud.SaltCloudManagement.SERVICES.keys()) + @ddt.data(*saltcloud.SaltCloudManagement.SERVICES.keys()) def test_get_service_nodes(self, service_name, mock_ansible_runner): ansible_runner_inst = mock_ansible_runner.return_value ansible_runner_inst.execute.side_effect = [ @@ -215,7 +216,7 @@ class SaltCloudManagementTestCase(test.TestCase): host='10.0.0.3')] ] - tcp_managment = tcpcloud.SaltCloudManagement(self.tcp_conf) + tcp_managment = saltcloud.SaltCloudManagement(self.tcp_conf) service = tcp_managment.get_service(service_name) nodes = service.get_nodes() @@ -274,7 +275,7 @@ class SaltCloudServiceTestCase(test.TestCase): ] @mock.patch('os_faults.ansible.executor.AnsibleRunner', autospec=True) - @ddt.data(*tcpcloud.SaltCloudManagement.SERVICES.keys()) + @ddt.data(*saltcloud.SaltCloudManagement.SERVICES.keys()) def test_restart(self, service_name, mock_ansible_runner): ansible_runner_inst = mock_ansible_runner.return_value ansible_runner_inst.execute.side_effect = [ @@ -291,7 +292,7 @@ class SaltCloudServiceTestCase(test.TestCase): host='10.0.0.3')] ] - tcp_managment = tcpcloud.SaltCloudManagement(self.tcp_conf) + tcp_managment = saltcloud.SaltCloudManagement(self.tcp_conf) service = tcp_managment.get_service(service_name) service.restart() @@ -307,7 +308,7 @@ class SaltCloudServiceTestCase(test.TestCase): ]) @mock.patch('os_faults.ansible.executor.AnsibleRunner', autospec=True) - @ddt.data(*tcpcloud.SaltCloudManagement.SERVICES.keys()) + @ddt.data(*saltcloud.SaltCloudManagement.SERVICES.keys()) def test_terminate(self, service_name, mock_ansible_runner): ansible_runner_inst = mock_ansible_runner.return_value ansible_runner_inst.execute.side_effect = [ @@ -324,7 +325,7 @@ class SaltCloudServiceTestCase(test.TestCase): host='10.0.0.3')] ] - tcp_managment = tcpcloud.SaltCloudManagement(self.tcp_conf) + tcp_managment = saltcloud.SaltCloudManagement(self.tcp_conf) service = tcp_managment.get_service(service_name) service.terminate() @@ -340,7 +341,7 @@ class SaltCloudServiceTestCase(test.TestCase): ]) @mock.patch('os_faults.ansible.executor.AnsibleRunner', autospec=True) - @ddt.data(*tcpcloud.SaltCloudManagement.SERVICES.keys()) + @ddt.data(*saltcloud.SaltCloudManagement.SERVICES.keys()) def test_start(self, service_name, mock_ansible_runner): ansible_runner_inst = mock_ansible_runner.return_value ansible_runner_inst.execute.side_effect = [ @@ -357,7 +358,7 @@ class SaltCloudServiceTestCase(test.TestCase): host='10.0.0.3')] ] - tcp_managment = tcpcloud.SaltCloudManagement(self.tcp_conf) + tcp_managment = saltcloud.SaltCloudManagement(self.tcp_conf) service = tcp_managment.get_service(service_name) service.start() diff --git a/os_faults/tests/unit/drivers/power/test_libvirt.py b/os_faults/tests/unit/drivers/power/test_libvirt.py index 425c5fa..09d05ed 100644 --- a/os_faults/tests/unit/drivers/power/test_libvirt.py +++ b/os_faults/tests/unit/drivers/power/test_libvirt.py @@ -34,8 +34,10 @@ class LibvirtDriverTestCase(test.TestCase): self.host = node_collection.Host( ip='10.0.0.2', mac='00:00:00:00:00:00', fqdn='node1.com') - @mock.patch('libvirt.open') - def test__get_connection_no_cached_connection(self, mock_libvirt_open): + @mock.patch('oslo_utils.importutils.try_import') + def test__get_connection_no_cached_connection(self, mock_import): + mock_libvirt = mock_import.return_value = mock.Mock() + mock_libvirt_open = mock_libvirt.open = mock.Mock() self.driver._get_connection() self.assertNotEqual(self.driver._cached_conn, None) diff --git a/os_faults/tests/unit/test_os_faults.py b/os_faults/tests/unit/test_os_faults.py index c5ebcaf..bd4a61a 100644 --- a/os_faults/tests/unit/test_os_faults.py +++ b/os_faults/tests/unit/test_os_faults.py @@ -47,7 +47,8 @@ class OSFaultsTestCase(test.TestCase): }] } - def test_connect_devstack(self): + @mock.patch('os_faults.ansible.executor.AnsibleRunner') + def test_connect_devstack(self, _): cloud_config = { 'cloud_management': { 'driver': 'devstack', @@ -63,7 +64,8 @@ class OSFaultsTestCase(test.TestCase): destructor = os_faults.connect(cloud_config) self.assertIsInstance(destructor, devstack.DevStackCloudManagement) - def test_config_with_services(self): + @mock.patch('os_faults.ansible.executor.AnsibleRunner') + def test_config_with_services(self, _): self.cloud_config['services'] = { 'app': { 'driver': 'process', @@ -74,7 +76,8 @@ class OSFaultsTestCase(test.TestCase): app = destructor.get_service('app') self.assertIsNotNone(app) - def test_config_with_services_and_hosts(self): + @mock.patch('os_faults.ansible.executor.AnsibleRunner') + def test_config_with_services_and_hosts(self, _): self.cloud_config['node_discover'] = { 'driver': 'node_list', 'args': [ @@ -105,7 +108,8 @@ class OSFaultsTestCase(test.TestCase): self.assertEqual(['01:ab:cd:01:ab:cd', '02:ab:cd:02:ab:cd'], nodes.get_macs()) - def test_connect_with_libvirt(self): + @mock.patch('os_faults.ansible.executor.AnsibleRunner') + def test_connect_with_libvirt(self, _): destructor = os_faults.connect(self.cloud_config) self.assertIsInstance(destructor, devstack.DevStackCloudManagement) self.assertEqual(1, len(destructor.power_manager.power_drivers)) diff --git a/setup.cfg b/setup.cfg index 39bacfe..1eedffa 100644 --- a/setup.cfg +++ b/setup.cfg @@ -15,6 +15,8 @@ classifier = Programming Language :: Python Programming Language :: Python :: 2 Programming Language :: Python :: 2.7 + Programming Language :: Python :: 3 + Programming Language :: Python :: 3.6 [files] packages = @@ -25,10 +27,6 @@ console_scripts = os-inject-fault = os_faults.cmd.cmd:main os-faults = os_faults.cmd.main:main -[extras] -libvirt = - libvirt-python>=1.2.5 # LGPLv2+ - [build_sphinx] source-dir = doc/source build-dir = doc/build diff --git a/test-requirements.txt b/test-requirements.txt index 8602d77..f72ee21 100644 --- a/test-requirements.txt +++ b/test-requirements.txt @@ -21,8 +21,5 @@ testrepository>=0.0.18 # Apache-2.0/BSD testscenarios>=0.4 # Apache-2.0/BSD testtools>=1.4.0 # MIT -# used for testing only -ansible # GPL-3.0 - # releasenotes reno>=1.8.0 # Apache-2.0 diff --git a/tox.ini b/tox.ini index 2df0fd3..47718c3 100644 --- a/tox.ini +++ b/tox.ini @@ -1,6 +1,6 @@ [tox] minversion = 2.6 -envlist = pep8-constraints,py27-constraints,py35-constraints,cover +envlist = pep8-constraints,py27-constraints,py36-constraints,cover skipsdist = True [testenv] @@ -16,8 +16,6 @@ whitelist_externals = deps = -r{toxinidir}/test-requirements.txt -extras = - libvirt commands = find . -type f -name "*.pyc" -delete py.test -vvvv --html={envlogdir}/pytest_results.html --self-contained-html --durations=10 "os_faults/tests/unit" {posargs} @@ -67,6 +65,7 @@ setenv = {[testenv]setenv} OS_TEST_PATH=./os_faults/tests/devstack OS_DEBUG=True deps = {[testenv]deps} + ansible extras = commands = py.test -vvvv --html={envlogdir}/pytest_results.html --self-contained-html --durations=10 "os_faults/tests/devstack" {posargs}