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
This commit is contained in:
parent
87a80f6af5
commit
ff78b92048
.zuul.yaml
os_faults
setup.cfgtest-requirements.txttox.ini@ -2,7 +2,7 @@
|
||||
templates:
|
||||
- docs-on-readthedocs
|
||||
- openstack-python-jobs
|
||||
- openstack-python35-jobs
|
||||
- openstack-python36-jobs
|
||||
vars:
|
||||
rtd_webhook_id: '47124'
|
||||
check:
|
||||
|
@ -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()
|
@ -60,23 +60,23 @@ NODE_ACTIONS = list_actions(node_collection_pkg.NodeCollection)
|
||||
NODE_ACTIONS_PATTERN = '|'.join(NODE_ACTIONS)
|
||||
|
||||
PATTERNS = [
|
||||
re.compile('(?P<action>%s)'
|
||||
'\s+(?P<service>\S+)\s+service'
|
||||
'(\s+on(\s+(?P<node>\S+))?\s+nodes?)?'
|
||||
'(\s+for\s+(?P<duration>\d+)\s+seconds)?' %
|
||||
re.compile(r'(?P<action>%s)'
|
||||
r'\s+(?P<service>\S+)\s+service'
|
||||
r'(\s+on(\s+(?P<node>\S+))?\s+nodes?)?'
|
||||
r'(\s+for\s+(?P<duration>\d+)\s+seconds)?' %
|
||||
SERVICE_ACTIONS_PATTERN),
|
||||
re.compile('(?P<action>%s)'
|
||||
'\s+(?P<container>\S+)\s+container'
|
||||
'(\s+on(\s+(?P<node>\S+))?\s+nodes?)?'
|
||||
'(\s+for\s+(?P<duration>\d+)\s+seconds)?' %
|
||||
re.compile(r'(?P<action>%s)'
|
||||
r'\s+(?P<container>\S+)\s+container'
|
||||
r'(\s+on(\s+(?P<node>\S+))?\s+nodes?)?'
|
||||
r'(\s+for\s+(?P<duration>\d+)\s+seconds)?' %
|
||||
CONTAINER_ACTIONS_PATTERN),
|
||||
re.compile('(?P<action>%s)'
|
||||
'(\s+(?P<network>\w+)\s+network\s+on)?'
|
||||
'(\s+(?P<target>\w+)'
|
||||
'(\s+for\s+(?P<duration>\d+)\s+seconds)(\s+on)?)?'
|
||||
'(\s+(?P<node>%s|\S+))?'
|
||||
'\s+nodes?'
|
||||
'(\s+with\s+(?P<service>\S+)\s+service)?' %
|
||||
re.compile(r'(?P<action>%s)'
|
||||
r'(\s+(?P<network>\w+)\s+network\s+on)?'
|
||||
r'(\s+(?P<target>\w+)'
|
||||
r'(\s+for\s+(?P<duration>\d+)\s+seconds)(\s+on)?)?'
|
||||
r'(\s+(?P<node>%s|\S+))?'
|
||||
r'\s+nodes?'
|
||||
r'(\s+with\s+(?P<service>\S+)\s+service)?' %
|
||||
(NODE_ACTIONS_PATTERN, NODE_ALIASES_PATTERN)),
|
||||
]
|
||||
|
||||
|
@ -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',
|
||||
}
|
||||
},
|
@ -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
|
||||
|
@ -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',
|
||||
)
|
@ -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',
|
||||
)
|
@ -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',
|
||||
)
|
@ -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',
|
||||
)
|
@ -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 + '... <cut>',
|
||||
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(
|
||||
|
@ -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()
|
||||
|
||||
|
@ -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()
|
@ -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)
|
||||
|
||||
|
@ -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))
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
5
tox.ini
5
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}
|
||||
|
Loading…
x
Reference in New Issue
Block a user