Integration tests for Infoblox 2.5 modules (#40344)
* Update nios.py * Update nios.py * Update nios.py * nios lookup errors out when there are no results #37970 Open Indentation failure issue resolved * Returning empty list instead of None In case of no results, res will be returned as an empty list instead of None (implementing ganeshrn comment) * infoblox ipv6 support changes * infoblox ipv6 support changes * for fixing pep8 errors * moving ipaddr check to utils * adding ipv6addr check * increasing space to resolve pep8 error * modified the playbook examples to valid ones * Update nios_network.py * integration tests for nios 2.5 modules * modification done in existing integration nios testcases * dns_view nios module tc * host_record nios module tc * network nios module tc * network_view nios module tc * zone nios module tc * changes to fix shippabe errors for PR 40344 * PR40344 shippable fix * PR40344 shippable fix * PR40344 shippable fix * PR40344 shippable fix * PR40344 shippable fix * PR40344 shippable fix * PR40344 shippable fix * PR40344 shippable fix * PR40344 shippable error fix * 40344 shippable fix * 40344 shippable fix * 40344 shippable fix * 40344 shippable fix * 40344 shippable fix * 40344 shippable fix * PR40344 shippable error fix for block comment should start with '# '
This commit is contained in:
parent
89732a1e5f
commit
fc8663edc0
40 changed files with 905 additions and 4 deletions
|
@ -25,8 +25,9 @@
|
|||
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
|
||||
# USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
#
|
||||
import os
|
||||
|
||||
|
||||
import os
|
||||
from functools import partial
|
||||
|
||||
from ansible.module_utils.six import iteritems
|
||||
|
@ -39,7 +40,6 @@ try:
|
|||
except ImportError:
|
||||
HAS_INFOBLOX_CLIENT = False
|
||||
|
||||
|
||||
nios_provider_spec = {
|
||||
'host': dict(),
|
||||
'username': dict(),
|
||||
|
@ -167,7 +167,6 @@ class WapiModule(WapiBase):
|
|||
def __init__(self, module):
|
||||
self.module = module
|
||||
provider = module.params['provider']
|
||||
|
||||
try:
|
||||
super(WapiModule, self).__init__(provider)
|
||||
except Exception as exc:
|
||||
|
@ -197,6 +196,7 @@ class WapiModule(WapiBase):
|
|||
|
||||
:returns: a results dict
|
||||
'''
|
||||
|
||||
state = self.module.params['state']
|
||||
if state not in ('present', 'absent'):
|
||||
self.module.fail_json(msg='state must be one of `present`, `absent`, got `%s`' % state)
|
||||
|
@ -300,7 +300,6 @@ class WapiModule(WapiBase):
|
|||
return True
|
||||
|
||||
def compare_objects(self, current_object, proposed_object):
|
||||
|
||||
for key, proposed_item in iteritems(proposed_object):
|
||||
current_item = current_object.get(key)
|
||||
|
||||
|
|
1
test/integration/targets/nios_dns_view/aliases
Normal file
1
test/integration/targets/nios_dns_view/aliases
Normal file
|
@ -0,0 +1 @@
|
|||
unsupported
|
|
@ -0,0 +1,3 @@
|
|||
---
|
||||
testcase: "*"
|
||||
test_items: []
|
2
test/integration/targets/nios_dns_view/meta/main.yaml
Normal file
2
test/integration/targets/nios_dns_view/meta/main.yaml
Normal file
|
@ -0,0 +1,2 @@
|
|||
dependencies:
|
||||
- prepare_nios_tests
|
0
test/integration/targets/nios_dns_view/tasks/cli.yaml
Normal file
0
test/integration/targets/nios_dns_view/tasks/cli.yaml
Normal file
2
test/integration/targets/nios_dns_view/tasks/main.yaml
Normal file
2
test/integration/targets/nios_dns_view/tasks/main.yaml
Normal file
|
@ -0,0 +1,2 @@
|
|||
---
|
||||
- { include: cli.yaml, tags: ['cli'] }
|
0
test/integration/targets/nios_dns_view/tasks/niapi.yaml
Normal file
0
test/integration/targets/nios_dns_view/tasks/niapi.yaml
Normal file
1
test/integration/targets/nios_host_record/aliases
Normal file
1
test/integration/targets/nios_host_record/aliases
Normal file
|
@ -0,0 +1 @@
|
|||
unsupported
|
|
@ -0,0 +1,3 @@
|
|||
---
|
||||
testcase: "*"
|
||||
test_items: []
|
2
test/integration/targets/nios_host_record/meta/main.yaml
Normal file
2
test/integration/targets/nios_host_record/meta/main.yaml
Normal file
|
@ -0,0 +1,2 @@
|
|||
dependencies:
|
||||
- prepare_nios_tests
|
22
test/integration/targets/nios_host_record/tasks/cli.yaml
Normal file
22
test/integration/targets/nios_host_record/tasks/cli.yaml
Normal file
|
@ -0,0 +1,22 @@
|
|||
---
|
||||
- name: collect all cli test cases
|
||||
find:
|
||||
paths: "{{ role_path }}/tests/cli"
|
||||
patterns: "{{ testcase }}.yaml"
|
||||
register: test_cases
|
||||
delegate_to: localhost
|
||||
|
||||
- name: set test_items
|
||||
set_fact: test_items="{{ test_cases.files | map(attribute='path') | list }}"
|
||||
|
||||
- name: run test cases (connection=network_cli)
|
||||
include: "{{ test_case_to_run }} "
|
||||
with_items: "{{ test_items }}"
|
||||
loop_control:
|
||||
loop_var: test_case_to_run
|
||||
|
||||
- name: run test case (connection=local)
|
||||
include: "{{ test_case_to_run }} ansible_connection=local"
|
||||
with_first_found: "{{ test_items }}"
|
||||
loop_control:
|
||||
loop_var: test_case_to_run
|
|
@ -0,0 +1,2 @@
|
|||
---
|
||||
- { include: cli.yaml, tags: ['cli'] }
|
1
test/integration/targets/nios_network/aliases
Normal file
1
test/integration/targets/nios_network/aliases
Normal file
|
@ -0,0 +1 @@
|
|||
unsupported
|
0
test/integration/targets/nios_network/defaults/main.yaml
Normal file
0
test/integration/targets/nios_network/defaults/main.yaml
Normal file
2
test/integration/targets/nios_network/meta/main.yaml
Normal file
2
test/integration/targets/nios_network/meta/main.yaml
Normal file
|
@ -0,0 +1,2 @@
|
|||
dependencies:
|
||||
- prepare_nios_tests
|
0
test/integration/targets/nios_network/tasks/cli.yaml
Normal file
0
test/integration/targets/nios_network/tasks/cli.yaml
Normal file
2
test/integration/targets/nios_network/tasks/main.yaml
Normal file
2
test/integration/targets/nios_network/tasks/main.yaml
Normal file
|
@ -0,0 +1,2 @@
|
|||
---
|
||||
- { include: cli.yaml, tags: ['cli'] }
|
0
test/integration/targets/nios_network/tasks/niapi.yaml
Normal file
0
test/integration/targets/nios_network/tasks/niapi.yaml
Normal file
1
test/integration/targets/nios_network_view/aliases
Normal file
1
test/integration/targets/nios_network_view/aliases
Normal file
|
@ -0,0 +1 @@
|
|||
unsupported
|
|
@ -0,0 +1,3 @@
|
|||
---
|
||||
testcase: "*"
|
||||
test_items: []
|
|
@ -0,0 +1,2 @@
|
|||
dependencies:
|
||||
- prepare_nios_tests
|
|
@ -0,0 +1,2 @@
|
|||
---
|
||||
- { include: cli.yaml, tags: ['cli'] }
|
1
test/integration/targets/nios_zone/aliases
Normal file
1
test/integration/targets/nios_zone/aliases
Normal file
|
@ -0,0 +1 @@
|
|||
unsupported
|
3
test/integration/targets/nios_zone/defaults/main.yaml
Normal file
3
test/integration/targets/nios_zone/defaults/main.yaml
Normal file
|
@ -0,0 +1,3 @@
|
|||
---
|
||||
testcase: "*"
|
||||
test_items: []
|
2
test/integration/targets/nios_zone/meta/main.yaml
Normal file
2
test/integration/targets/nios_zone/meta/main.yaml
Normal file
|
@ -0,0 +1,2 @@
|
|||
dependencies:
|
||||
- prepare_nios_tests
|
0
test/integration/targets/nios_zone/tasks/cli.yaml
Normal file
0
test/integration/targets/nios_zone/tasks/cli.yaml
Normal file
2
test/integration/targets/nios_zone/tasks/main.yaml
Normal file
2
test/integration/targets/nios_zone/tasks/main.yaml
Normal file
|
@ -0,0 +1,2 @@
|
|||
---
|
||||
- { include: cli.yaml, tags: ['cli'] }
|
0
test/integration/targets/nios_zone/tasks/niapi.yaml
Normal file
0
test/integration/targets/nios_zone/tasks/niapi.yaml
Normal file
0
test/units/modules/net_tools/nios/__init__.py
Normal file
0
test/units/modules/net_tools/nios/__init__.py
Normal file
127
test/units/modules/net_tools/nios/test_nios_dns_view.py
Normal file
127
test/units/modules/net_tools/nios/test_nios_dns_view.py
Normal file
|
@ -0,0 +1,127 @@
|
|||
# This file is part of Ansible
|
||||
#
|
||||
# Ansible is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# Ansible is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
# Make coding more python3-ish
|
||||
|
||||
|
||||
from __future__ import (absolute_import, division, print_function)
|
||||
__metaclass__ = type
|
||||
|
||||
|
||||
from ansible.modules.net_tools.nios import nios_dns_view
|
||||
from ansible.module_utils.net_tools.nios import api
|
||||
from ansible.compat.tests.mock import patch, MagicMock, Mock
|
||||
from .test_nios_module import TestNiosModule, load_fixture
|
||||
|
||||
|
||||
class TestNiosDnsViewModule(TestNiosModule):
|
||||
|
||||
module = nios_dns_view
|
||||
|
||||
def setUp(self):
|
||||
super(TestNiosDnsViewModule, self).setUp()
|
||||
self.module = MagicMock(name='ansible.modules.net_tools.nios.nios_dns_view.WapiModule')
|
||||
self.module.check_mode = False
|
||||
self.module.params = {'provider': None}
|
||||
self.mock_wapi = patch('ansible.modules.net_tools.nios.nios_dns_view.WapiModule')
|
||||
self.exec_command = self.mock_wapi.start()
|
||||
self.mock_wapi_run = patch('ansible.modules.net_tools.nios.nios_dns_view.WapiModule.run')
|
||||
self.mock_wapi_run.start()
|
||||
self.load_config = self.mock_wapi_run.start()
|
||||
|
||||
def tearDown(self):
|
||||
super(TestNiosDnsViewModule, self).tearDown()
|
||||
self.mock_wapi.stop()
|
||||
self.mock_wapi_run.stop()
|
||||
|
||||
def _get_wapi(self, test_object):
|
||||
wapi = api.WapiModule(self.module)
|
||||
wapi.get_object = Mock(name='get_object', return_value=test_object)
|
||||
wapi.create_object = Mock(name='create_object')
|
||||
wapi.update_object = Mock(name='update_object')
|
||||
wapi.delete_object = Mock(name='delete_object')
|
||||
return wapi
|
||||
|
||||
def load_fixtures(self, commands=None):
|
||||
self.exec_command.return_value = (0, load_fixture('nios_result.txt').strip(), None)
|
||||
self.load_config.return_value = dict(diff=None, session='session')
|
||||
|
||||
def test_nios_dns_view_create(self):
|
||||
self.module.params = {'provider': None, 'state': 'present', 'name': 'ansible-dns',
|
||||
'comment': None, 'extattrs': None}
|
||||
|
||||
test_object = None
|
||||
|
||||
test_spec = {
|
||||
"name": {"ib_req": True},
|
||||
"comment": {},
|
||||
"extattrs": {}
|
||||
}
|
||||
|
||||
wapi = self._get_wapi(test_object)
|
||||
print("WAPI: ", wapi)
|
||||
res = wapi.run('testobject', test_spec)
|
||||
|
||||
self.assertTrue(res['changed'])
|
||||
wapi.create_object.assert_called_once_with('testobject', {'name': 'ansible-dns'})
|
||||
|
||||
def test_nios_dns_view_update_comment(self):
|
||||
self.module.params = {'provider': None, 'state': 'present', 'name': 'ansible-dns',
|
||||
'comment': 'updated comment', 'extattrs': None}
|
||||
|
||||
test_object = [
|
||||
{
|
||||
"comment": "test comment",
|
||||
"_ref": "dnsview/ZG5zLm5ldHdvcmtfdmlldyQw:default/true",
|
||||
"name": "ansible-dns",
|
||||
"extattrs": {}
|
||||
}
|
||||
]
|
||||
|
||||
test_spec = {
|
||||
"name": {"ib_req": True},
|
||||
"comment": {},
|
||||
"extattrs": {}
|
||||
}
|
||||
|
||||
wapi = self._get_wapi(test_object)
|
||||
res = wapi.run('testobject', test_spec)
|
||||
|
||||
self.assertTrue(res['changed'])
|
||||
|
||||
def test_nios_dns_view_remove(self):
|
||||
self.module.params = {'provider': None, 'state': 'absent', 'name': 'ansible-dns',
|
||||
'comment': None, 'extattrs': None}
|
||||
|
||||
ref = "dnsview/ZG5zLm5ldHdvcmtfdmlldyQw:ansible/false"
|
||||
|
||||
test_object = [{
|
||||
"comment": "test comment",
|
||||
"_ref": ref,
|
||||
"name": "ansible-dns",
|
||||
"extattrs": {'Site': {'value': 'test'}}
|
||||
}]
|
||||
|
||||
test_spec = {
|
||||
"name": {"ib_req": True},
|
||||
"comment": {},
|
||||
"extattrs": {}
|
||||
}
|
||||
|
||||
wapi = self._get_wapi(test_object)
|
||||
res = wapi.run('testobject', test_spec)
|
||||
|
||||
self.assertTrue(res['changed'])
|
||||
wapi.delete_object.assert_called_once_with(ref)
|
154
test/units/modules/net_tools/nios/test_nios_host_record.py
Normal file
154
test/units/modules/net_tools/nios/test_nios_host_record.py
Normal file
|
@ -0,0 +1,154 @@
|
|||
# This file is part of Ansible
|
||||
#
|
||||
# Ansible is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# Ansible is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
# Make coding more python3-ish
|
||||
from __future__ import (absolute_import, division, print_function)
|
||||
__metaclass__ = type
|
||||
|
||||
|
||||
from ansible.modules.net_tools.nios import nios_host_record
|
||||
from ansible.module_utils.net_tools.nios import api
|
||||
from units.modules.utils import set_module_args
|
||||
from ansible.compat.tests.mock import patch, MagicMock, Mock
|
||||
from .test_nios_module import TestNiosModule, load_fixture
|
||||
|
||||
|
||||
class TestNiosHostRecordModule(TestNiosModule):
|
||||
|
||||
module = nios_host_record
|
||||
|
||||
def setUp(self):
|
||||
|
||||
super(TestNiosHostRecordModule, self).setUp()
|
||||
self.module = MagicMock(name='ansible.modules.net_tools.nios.nios_host_record.WapiModule')
|
||||
self.module.check_mode = False
|
||||
self.module.params = {'provider': None}
|
||||
|
||||
self.mock_wapi = patch('ansible.modules.net_tools.nios.nios_host_record.WapiModule')
|
||||
self.exec_command = self.mock_wapi.start()
|
||||
self.mock_wapi_run = patch('ansible.modules.net_tools.nios.nios_host_record.WapiModule.run')
|
||||
self.mock_wapi_run.start()
|
||||
|
||||
self.load_config = self.mock_wapi_run.start()
|
||||
|
||||
def tearDown(self):
|
||||
super(TestNiosHostRecordModule, self).tearDown()
|
||||
self.mock_wapi.stop()
|
||||
|
||||
def _get_wapi(self, test_object):
|
||||
wapi = api.WapiModule(self.module)
|
||||
wapi.get_object = Mock(name='get_object', return_value=test_object)
|
||||
wapi.create_object = Mock(name='create_object')
|
||||
wapi.update_object = Mock(name='update_object')
|
||||
wapi.delete_object = Mock(name='delete_object')
|
||||
return wapi
|
||||
|
||||
def load_fixtures(self, commands=None):
|
||||
self.exec_command.return_value = (0, load_fixture('nios_result.txt').strip(), None)
|
||||
self.load_config.return_value = dict(diff=None, session='session')
|
||||
|
||||
def test_nios_host_record_create(self):
|
||||
self.module.params = {'provider': None, 'state': 'present', 'name': 'ansible',
|
||||
'comment': None, 'extattrs': None}
|
||||
|
||||
test_object = None
|
||||
|
||||
test_spec = {
|
||||
"name": {"ib_req": True},
|
||||
"comment": {},
|
||||
"extattrs": {}
|
||||
}
|
||||
|
||||
wapi = self._get_wapi(test_object)
|
||||
print("WAPI: ", wapi)
|
||||
res = wapi.run('testobject', test_spec)
|
||||
|
||||
self.assertTrue(res['changed'])
|
||||
wapi.create_object.assert_called_once_with('testobject', {'name': 'ansible'})
|
||||
|
||||
def test_nios_host_record_remove(self):
|
||||
self.module.params = {'provider': None, 'state': 'absent', 'name': 'ansible',
|
||||
'comment': None, 'extattrs': None}
|
||||
|
||||
ref = "record:host/ZG5zLm5ldHdvcmtfdmlldyQw:ansible/false"
|
||||
|
||||
test_object = [{
|
||||
"comment": "test comment",
|
||||
"_ref": ref,
|
||||
"name": "ansible",
|
||||
"extattrs": {'Site': {'value': 'test'}}
|
||||
}]
|
||||
|
||||
test_spec = {
|
||||
"name": {"ib_req": True},
|
||||
"comment": {},
|
||||
"extattrs": {}
|
||||
}
|
||||
|
||||
wapi = self._get_wapi(test_object)
|
||||
res = wapi.run('testobject', test_spec)
|
||||
self.assertTrue(res['changed'])
|
||||
wapi.delete_object.assert_called_once_with(ref)
|
||||
|
||||
def test_nios_host_record_update_comment(self):
|
||||
self.module.params = {'provider': None, 'state': 'present', 'name': 'default',
|
||||
'comment': 'updated comment', 'extattrs': None}
|
||||
|
||||
test_object = [
|
||||
{
|
||||
"comment": "test comment",
|
||||
"_ref": "record:host/ZG5zLm5ldHdvcmtfdmlldyQw:default/true",
|
||||
"name": "default",
|
||||
"extattrs": {}
|
||||
}
|
||||
]
|
||||
|
||||
test_spec = {
|
||||
"name": {"ib_req": True},
|
||||
"comment": {},
|
||||
"extattrs": {}
|
||||
}
|
||||
|
||||
wapi = self._get_wapi(test_object)
|
||||
res = wapi.run('testobject', test_spec)
|
||||
|
||||
self.assertTrue(res['changed'])
|
||||
wapi.update_object.called_once_with(test_object)
|
||||
|
||||
def test_nios_host_record_update_record_name(self):
|
||||
self.module.params = {'provider': None, 'state': 'present', 'name': 'default', 'old_name': 'old_default',
|
||||
'comment': 'comment', 'extattrs': None}
|
||||
|
||||
test_object = [
|
||||
{
|
||||
"comment": "test comment",
|
||||
"_ref": "record:host/ZG5zLm5ldHdvcmtfdmlldyQw:default/true",
|
||||
"name": "default",
|
||||
"old_name": "old_default",
|
||||
"extattrs": {}
|
||||
}
|
||||
]
|
||||
|
||||
test_spec = {
|
||||
"name": {"ib_req": True},
|
||||
"comment": {},
|
||||
"extattrs": {}
|
||||
}
|
||||
|
||||
wapi = self._get_wapi(test_object)
|
||||
res = wapi.run('testobject', test_spec)
|
||||
|
||||
self.assertTrue(res['changed'])
|
||||
wapi.update_object.called_once_with(test_object)
|
88
test/units/modules/net_tools/nios/test_nios_module.py
Normal file
88
test/units/modules/net_tools/nios/test_nios_module.py
Normal file
|
@ -0,0 +1,88 @@
|
|||
# (c) 2018 Red Hat Inc.
|
||||
#
|
||||
# This file is part of Ansible
|
||||
#
|
||||
# Ansible is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# Ansible is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
# Make coding more python3-ish
|
||||
from __future__ import (absolute_import, division, print_function)
|
||||
__metaclass__ = type
|
||||
|
||||
import os
|
||||
import json
|
||||
|
||||
from units.modules.utils import AnsibleExitJson, AnsibleFailJson, ModuleTestCase
|
||||
|
||||
|
||||
fixture_path = os.path.join(os.path.dirname(__file__), 'fixtures')
|
||||
fixture_data = {}
|
||||
|
||||
|
||||
def load_fixture(name):
|
||||
path = os.path.join(fixture_path, name)
|
||||
|
||||
if path in fixture_data:
|
||||
return fixture_data[path]
|
||||
|
||||
with open(path) as f:
|
||||
data = f.read()
|
||||
|
||||
try:
|
||||
data = json.loads(data)
|
||||
except:
|
||||
pass
|
||||
|
||||
fixture_data[path] = data
|
||||
return data
|
||||
|
||||
|
||||
class TestNiosModule(ModuleTestCase):
|
||||
|
||||
def execute_module(self, failed=False, changed=False, commands=None, sort=True, defaults=False):
|
||||
|
||||
self.load_fixtures(commands)
|
||||
|
||||
if failed:
|
||||
result = self.failed()
|
||||
self.assertTrue(result['failed'], result)
|
||||
else:
|
||||
result = self.changed(changed)
|
||||
self.assertEqual(result['changed'], changed, result)
|
||||
|
||||
if commands is not None:
|
||||
if sort:
|
||||
self.assertEqual(sorted(commands), sorted(result['commands']), result['commands'])
|
||||
else:
|
||||
self.assertEqual(commands, result['commands'], result['commands'])
|
||||
|
||||
return result
|
||||
|
||||
def failed(self):
|
||||
with self.assertRaises(AnsibleFailJson) as exc:
|
||||
self.module.main()
|
||||
|
||||
result = exc.exception.args[0]
|
||||
self.assertTrue(result['failed'], result)
|
||||
return result
|
||||
|
||||
def changed(self, changed=False):
|
||||
with self.assertRaises(AnsibleExitJson) as exc:
|
||||
self.module.main()
|
||||
|
||||
result = exc.exception.args[0]
|
||||
self.assertEqual(result['changed'], changed, result)
|
||||
return result
|
||||
|
||||
def load_fixtures(self, commands=None):
|
||||
pass
|
192
test/units/modules/net_tools/nios/test_nios_network.py
Normal file
192
test/units/modules/net_tools/nios/test_nios_network.py
Normal file
|
@ -0,0 +1,192 @@
|
|||
# This file is part of Ansible
|
||||
#
|
||||
# Ansible is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# Ansible is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
# Make coding more python3-ish
|
||||
from __future__ import (absolute_import, division, print_function)
|
||||
__metaclass__ = type
|
||||
|
||||
|
||||
from ansible.module_utils.net_tools.nios import api
|
||||
from ansible.modules.net_tools.nios import nios_network
|
||||
from ansible.compat.tests.mock import patch, MagicMock, Mock
|
||||
from units.modules.utils import set_module_args
|
||||
from .test_nios_module import TestNiosModule, load_fixture
|
||||
|
||||
|
||||
class TestNiosNetworkModule(TestNiosModule):
|
||||
|
||||
module = nios_network
|
||||
|
||||
def setUp(self):
|
||||
super(TestNiosNetworkModule, self).setUp()
|
||||
self.module = MagicMock(name='ansible.modules.net_tools.nios.nios_network.WapiModule')
|
||||
self.module.check_mode = False
|
||||
self.module.params = {'provider': None}
|
||||
self.mock_wapi = patch('ansible.modules.net_tools.nios.nios_network.WapiModule')
|
||||
self.exec_command = self.mock_wapi.start()
|
||||
self.mock_wapi_run = patch('ansible.modules.net_tools.nios.nios_network.WapiModule.run')
|
||||
self.mock_wapi_run.start()
|
||||
self.load_config = self.mock_wapi_run.start()
|
||||
|
||||
def tearDown(self):
|
||||
super(TestNiosNetworkModule, self).tearDown()
|
||||
self.mock_wapi.stop()
|
||||
self.mock_wapi_run.stop()
|
||||
|
||||
def load_fixtures(self, commands=None):
|
||||
self.exec_command.return_value = (0, load_fixture('nios_result.txt').strip(), None)
|
||||
self.load_config.return_value = dict(diff=None, session='session')
|
||||
|
||||
def _get_wapi(self, test_object):
|
||||
wapi = api.WapiModule(self.module)
|
||||
wapi.get_object = Mock(name='get_object', return_value=test_object)
|
||||
wapi.create_object = Mock(name='create_object')
|
||||
wapi.update_object = Mock(name='update_object')
|
||||
wapi.delete_object = Mock(name='delete_object')
|
||||
return wapi
|
||||
|
||||
def test_nios_network_ipv4_create(self):
|
||||
self.module.params = {'provider': None, 'state': 'present', 'network': '192.168.10.0/24',
|
||||
'comment': None, 'extattrs': None}
|
||||
|
||||
test_object = None
|
||||
test_spec = {
|
||||
"network": {"ib_req": True},
|
||||
"comment": {},
|
||||
"extattrs": {}
|
||||
}
|
||||
|
||||
wapi = self._get_wapi(test_object)
|
||||
print("WAPI: ", wapi)
|
||||
res = wapi.run('testobject', test_spec)
|
||||
|
||||
self.assertTrue(res['changed'])
|
||||
wapi.create_object.assert_called_once_with('testobject', {'network': '192.168.10.0/24'})
|
||||
|
||||
def test_nios_network_ipv4_dhcp_update(self):
|
||||
self.module.params = {'provider': None, 'state': 'present', 'network': '192.168.10.0/24',
|
||||
'comment': 'updated comment', 'extattrs': None}
|
||||
|
||||
test_object = [
|
||||
{
|
||||
"comment": "test comment",
|
||||
"_ref": "network/ZG5zLm5ldHdvcmtfdmlldyQw:default/true",
|
||||
"network": "192.168.10.0/24",
|
||||
"extattrs": {'options': {'name': 'test', 'value': 'ansible.com'}}
|
||||
}
|
||||
]
|
||||
|
||||
test_spec = {
|
||||
"network": {"ib_req": True},
|
||||
"comment": {},
|
||||
"extattrs": {}
|
||||
}
|
||||
|
||||
wapi = self._get_wapi(test_object)
|
||||
res = wapi.run('testobject', test_spec)
|
||||
|
||||
self.assertTrue(res['changed'])
|
||||
|
||||
def test_nios_network_ipv6_dhcp_update(self):
|
||||
self.module.params = {'provider': None, 'state': 'present', 'network': 'fe80::/64',
|
||||
'comment': 'updated comment', 'extattrs': None}
|
||||
|
||||
test_object = [
|
||||
{
|
||||
"comment": "test comment",
|
||||
"_ref": "ipv6network/ZG5zLm5ldHdvcmtfdmlldyQw:default/true",
|
||||
"network": "fe80::/64",
|
||||
"extattrs": {'options': {'name': 'test', 'value': 'ansible.com'}}
|
||||
}
|
||||
]
|
||||
|
||||
test_spec = {
|
||||
"network": {"ib_req": True},
|
||||
"comment": {},
|
||||
"extattrs": {}
|
||||
}
|
||||
|
||||
wapi = self._get_wapi(test_object)
|
||||
res = wapi.run('testobject', test_spec)
|
||||
self.assertTrue(res['changed'])
|
||||
|
||||
def test_nios_network_ipv4_remove(self):
|
||||
self.module.params = {'provider': None, 'state': 'absent', 'network': '192.168.10.0/24',
|
||||
'comment': None, 'extattrs': None}
|
||||
|
||||
ref = "network/ZG5zLm5ldHdvcmtfdmlldyQw:ansible/false"
|
||||
|
||||
test_object = [{
|
||||
"comment": "test comment",
|
||||
"_ref": ref,
|
||||
"network": "192.168.10.0/24",
|
||||
"extattrs": {'Site': {'value': 'test'}}
|
||||
}]
|
||||
|
||||
test_spec = {
|
||||
"network": {"ib_req": True},
|
||||
"comment": {},
|
||||
"extattrs": {}
|
||||
}
|
||||
|
||||
wapi = self._get_wapi(test_object)
|
||||
res = wapi.run('testobject', test_spec)
|
||||
|
||||
self.assertTrue(res['changed'])
|
||||
wapi.delete_object.assert_called_once_with(ref)
|
||||
|
||||
def test_nios_network_ipv6_create(self):
|
||||
self.module.params = {'provider': None, 'state': 'present', 'network': 'fe80::/64',
|
||||
'comment': None, 'extattrs': None}
|
||||
|
||||
test_object = None
|
||||
|
||||
test_spec = {
|
||||
"network": {"ib_req": True},
|
||||
"comment": {},
|
||||
"extattrs": {}
|
||||
}
|
||||
|
||||
wapi = self._get_wapi(test_object)
|
||||
print("WAPI: ", wapi)
|
||||
res = wapi.run('testobject', test_spec)
|
||||
|
||||
self.assertTrue(res['changed'])
|
||||
wapi.create_object.assert_called_once_with('testobject', {'network': 'fe80::/64'})
|
||||
|
||||
def test_nios_network_ipv6_remove(self):
|
||||
self.module.params = {'provider': None, 'state': 'absent', 'network': 'fe80::/64',
|
||||
'comment': None, 'extattrs': None}
|
||||
|
||||
ref = "ipv6network/ZG5zLm5ldHdvcmtfdmlldyQw:ansible/false"
|
||||
|
||||
test_object = [{
|
||||
"comment": "test comment",
|
||||
"_ref": ref,
|
||||
"network": "fe80::/64",
|
||||
"extattrs": {'Site': {'value': 'test'}}
|
||||
}]
|
||||
|
||||
test_spec = {
|
||||
"network": {"ib_req": True},
|
||||
"comment": {},
|
||||
"extattrs": {}
|
||||
}
|
||||
|
||||
wapi = self._get_wapi(test_object)
|
||||
res = wapi.run('testobject', test_spec)
|
||||
|
||||
self.assertTrue(res['changed'])
|
||||
wapi.delete_object.assert_called_once_with(ref)
|
156
test/units/modules/net_tools/nios/test_nios_network_view.py
Normal file
156
test/units/modules/net_tools/nios/test_nios_network_view.py
Normal file
|
@ -0,0 +1,156 @@
|
|||
# This file is part of Ansible
|
||||
#
|
||||
# Ansible is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# Ansible is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
# Make coding more python3-ish
|
||||
|
||||
|
||||
from __future__ import (absolute_import, division, print_function)
|
||||
__metaclass__ = type
|
||||
|
||||
|
||||
from ansible.modules.net_tools.nios import nios_network_view
|
||||
from ansible.module_utils.net_tools.nios import api
|
||||
from ansible.compat.tests.mock import patch, MagicMock, Mock
|
||||
from .test_nios_module import TestNiosModule, load_fixture
|
||||
|
||||
|
||||
class TestNiosNetworkViewModule(TestNiosModule):
|
||||
|
||||
module = nios_network_view
|
||||
|
||||
def setUp(self):
|
||||
super(TestNiosNetworkViewModule, self).setUp()
|
||||
self.module = MagicMock(name='ansible.modules.net_tools.nios.nios_network_view.WapiModule')
|
||||
self.module.check_mode = False
|
||||
self.module.params = {'provider': None}
|
||||
self.mock_wapi = patch('ansible.modules.net_tools.nios.nios_network_view.WapiModule')
|
||||
self.exec_command = self.mock_wapi.start()
|
||||
self.mock_wapi_run = patch('ansible.modules.net_tools.nios.nios_network_view.WapiModule.run')
|
||||
self.mock_wapi_run.start()
|
||||
self.load_config = self.mock_wapi_run.start()
|
||||
|
||||
def tearDown(self):
|
||||
super(TestNiosNetworkViewModule, self).tearDown()
|
||||
self.mock_wapi.stop()
|
||||
self.mock_wapi_run.stop()
|
||||
|
||||
def _get_wapi(self, test_object):
|
||||
wapi = api.WapiModule(self.module)
|
||||
wapi.get_object = Mock(name='get_object', return_value=test_object)
|
||||
wapi.create_object = Mock(name='create_object')
|
||||
wapi.update_object = Mock(name='update_object')
|
||||
wapi.delete_object = Mock(name='delete_object')
|
||||
return wapi
|
||||
|
||||
def load_fixtures(self, commands=None):
|
||||
self.exec_command.return_value = (0, load_fixture('nios_result.txt').strip(), None)
|
||||
self.load_config.return_value = dict(diff=None, session='session')
|
||||
|
||||
def test_nios_network_view_create(self):
|
||||
self.module.params = {'provider': None, 'state': 'present', 'name': 'ansible',
|
||||
'comment': None, 'extattrs': None}
|
||||
|
||||
test_object = None
|
||||
test_spec = {
|
||||
"name": {"ib_req": True},
|
||||
"comment": {},
|
||||
"extattrs": {},
|
||||
|
||||
}
|
||||
|
||||
wapi = self._get_wapi(test_object)
|
||||
print("WAPI: ", wapi)
|
||||
res = wapi.run('testobject', test_spec)
|
||||
|
||||
self.assertTrue(res['changed'])
|
||||
wapi.create_object.assert_called_once_with('testobject', {'name': 'ansible'})
|
||||
|
||||
def test_nios_network_view_update_comment(self):
|
||||
self.module.params = {'provider': None, 'state': 'present', 'name': 'default',
|
||||
'comment': 'updated comment', 'extattrs': None, 'network_view': 'default'}
|
||||
|
||||
test_object = [
|
||||
{
|
||||
"comment": "test comment",
|
||||
"_ref": "networkview/ZG5zLm5ldHdvcmtfdmlldyQw:default/true",
|
||||
"name": "default",
|
||||
"extattrs": {},
|
||||
"network_view": "default"
|
||||
}
|
||||
]
|
||||
|
||||
test_spec = {
|
||||
"name": {"ib_req": True},
|
||||
"comment": {},
|
||||
"extattrs": {}
|
||||
}
|
||||
|
||||
wapi = self._get_wapi(test_object)
|
||||
res = wapi.run('testobject', test_spec)
|
||||
|
||||
self.assertTrue(res['changed'])
|
||||
wapi.update_object.called_once_with(test_object)
|
||||
|
||||
def test_nios_network_view_update_name(self):
|
||||
self.module.params = {'provider': None, 'state': 'present', 'name': 'default', 'old_name': 'old_default',
|
||||
'comment': 'updated comment', 'extattrs': None, 'network_view': 'default'}
|
||||
|
||||
test_object = [
|
||||
{
|
||||
"comment": "test comment",
|
||||
"_ref": "networkview/ZG5zLm5ldHdvcmtfdmlldyQw:default/true",
|
||||
"name": "default",
|
||||
"old_name": "old_default",
|
||||
"extattrs": {},
|
||||
"network_view": "default"
|
||||
}
|
||||
]
|
||||
|
||||
test_spec = {
|
||||
"name": {"ib_req": True},
|
||||
"comment": {},
|
||||
"extattrs": {}
|
||||
}
|
||||
|
||||
wapi = self._get_wapi(test_object)
|
||||
res = wapi.run('testobject', test_spec)
|
||||
|
||||
self.assertTrue(res['changed'])
|
||||
wapi.update_object.called_once_with(test_object)
|
||||
|
||||
def test_nios_network_view_remove(self):
|
||||
self.module.params = {'provider': None, 'state': 'absent', 'name': 'ansible',
|
||||
'comment': None, 'extattrs': None}
|
||||
|
||||
ref = "networkview/ZG5zLm5ldHdvcmtfdmlldyQw:ansible/false"
|
||||
|
||||
test_object = [{
|
||||
"comment": "test comment",
|
||||
"_ref": ref,
|
||||
"name": "ansible",
|
||||
"extattrs": {'Site': {'value': 'test'}}
|
||||
}]
|
||||
|
||||
test_spec = {
|
||||
"name": {"ib_req": True},
|
||||
"comment": {},
|
||||
"extattrs": {}
|
||||
}
|
||||
|
||||
wapi = self._get_wapi(test_object)
|
||||
res = wapi.run('testobject', test_spec)
|
||||
|
||||
self.assertTrue(res['changed'])
|
||||
wapi.delete_object.assert_called_once_with(ref)
|
126
test/units/modules/net_tools/nios/test_nios_zone.py
Normal file
126
test/units/modules/net_tools/nios/test_nios_zone.py
Normal file
|
@ -0,0 +1,126 @@
|
|||
# This file is part of Ansible
|
||||
#
|
||||
# Ansible is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# Ansible is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
# Make coding more python3-ish
|
||||
|
||||
|
||||
from __future__ import (absolute_import, division, print_function)
|
||||
__metaclass__ = type
|
||||
|
||||
|
||||
from ansible.modules.net_tools.nios import nios_zone
|
||||
from ansible.module_utils.net_tools.nios import api
|
||||
from ansible.compat.tests.mock import patch, MagicMock, Mock
|
||||
from .test_nios_module import TestNiosModule, load_fixture
|
||||
|
||||
|
||||
class TestNiosZoneModule(TestNiosModule):
|
||||
|
||||
module = nios_zone
|
||||
|
||||
def setUp(self):
|
||||
super(TestNiosZoneModule, self).setUp()
|
||||
self.module = MagicMock(name='ansible.modules.net_tools.nios.nios_zone.WapiModule')
|
||||
self.module.check_mode = False
|
||||
self.module.params = {'provider': None}
|
||||
self.mock_wapi = patch('ansible.modules.net_tools.nios.nios_zone.WapiModule')
|
||||
self.exec_command = self.mock_wapi.start()
|
||||
self.mock_wapi_run = patch('ansible.modules.net_tools.nios.nios_zone.WapiModule.run')
|
||||
self.mock_wapi_run.start()
|
||||
self.load_config = self.mock_wapi_run.start()
|
||||
|
||||
def tearDown(self):
|
||||
super(TestNiosZoneModule, self).tearDown()
|
||||
self.mock_wapi.stop()
|
||||
self.mock_wapi_run.stop()
|
||||
|
||||
def _get_wapi(self, test_object):
|
||||
wapi = api.WapiModule(self.module)
|
||||
wapi.get_object = Mock(name='get_object', return_value=test_object)
|
||||
wapi.create_object = Mock(name='create_object')
|
||||
wapi.update_object = Mock(name='update_object')
|
||||
wapi.delete_object = Mock(name='delete_object')
|
||||
return wapi
|
||||
|
||||
def load_fixtures(self, commands=None):
|
||||
self.exec_command.return_value = (0, load_fixture('nios_result.txt').strip(), None)
|
||||
self.load_config.return_value = dict(diff=None, session='session')
|
||||
|
||||
def test_nios_zone_create(self):
|
||||
self.module.params = {'provider': None, 'state': 'present', 'name': 'ansible.com',
|
||||
'comment': None, 'extattrs': None}
|
||||
|
||||
test_object = None
|
||||
|
||||
test_spec = {
|
||||
"name": {"ib_req": True},
|
||||
"comment": {},
|
||||
"extattrs": {}
|
||||
}
|
||||
|
||||
wapi = self._get_wapi(test_object)
|
||||
print("WAPI: ", wapi)
|
||||
res = wapi.run('testobject', test_spec)
|
||||
|
||||
self.assertTrue(res['changed'])
|
||||
wapi.create_object.assert_called_once_with('testobject', {'name': 'ansible.com'})
|
||||
|
||||
def test_nios_zone_remove(self):
|
||||
self.module.params = {'provider': None, 'state': 'absent', 'name': 'ansible.com',
|
||||
'comment': None, 'extattrs': None}
|
||||
|
||||
ref = "zone/ZG5zLm5ldHdvcmtfdmlldyQw:ansible/false"
|
||||
|
||||
test_object = [{
|
||||
"comment": "test comment",
|
||||
"_ref": ref,
|
||||
"name": "ansible.com",
|
||||
"extattrs": {'Site': {'value': 'test'}}
|
||||
}]
|
||||
|
||||
test_spec = {
|
||||
"name": {"ib_req": True},
|
||||
"comment": {},
|
||||
"extattrs": {}
|
||||
}
|
||||
wapi = self._get_wapi(test_object)
|
||||
res = wapi.run('testobject', test_spec)
|
||||
|
||||
self.assertTrue(res['changed'])
|
||||
wapi.delete_object.assert_called_once_with(ref)
|
||||
|
||||
def test_nios_zone_update_comment(self):
|
||||
self.module.params = {'provider': None, 'state': 'present', 'name': 'ansible.com',
|
||||
'comment': 'updated comment', 'extattrs': None}
|
||||
|
||||
test_object = [
|
||||
{
|
||||
"comment": "test comment",
|
||||
"_ref": "zone/ZG5zLm5ldHdvcmtfdmlldyQw:default/true",
|
||||
"name": "ansible.com",
|
||||
"extattrs": {'Site': {'value': 'test'}}
|
||||
}
|
||||
]
|
||||
|
||||
test_spec = {
|
||||
"name": {"ib_req": True},
|
||||
"comment": {},
|
||||
"extattrs": {}
|
||||
}
|
||||
|
||||
wapi = self._get_wapi(test_object)
|
||||
res = wapi.run('testobject', test_spec)
|
||||
|
||||
self.assertTrue(res['changed'])
|
Loading…
Reference in a new issue