コード例 #1
0
 def setUp(self):
     super(TestNiosDnsViewModule, self).setUp()
     self.module = MagicMock(name='ansible_collections.ansible.infoblox.plugins.modules.nios_dns_view.WapiModule')
     self.module.check_mode = False
     self.module.params = {'provider': None}
     self.mock_wapi = patch('ansible_collections.ansible.infoblox.plugins.modules.nios_dns_view.WapiModule')
     self.exec_command = self.mock_wapi.start()
     self.mock_wapi_run = patch('ansible_collections.ansible.infoblox.plugins.modules.nios_dns_view.WapiModule.run')
     self.mock_wapi_run.start()
     self.load_config = self.mock_wapi_run.start()
コード例 #2
0
class TestNiosARecordModule(TestNiosModule):

    module = nios_a_record

    def setUp(self):
        super(TestNiosARecordModule, self).setUp()
        self.module = MagicMock(
            name=
            'ansible_collections.ansible.infoblox.plugins.modules.nios_a_record.WapiModule'
        )
        self.module.check_mode = False
        self.module.params = {'provider': None}
        self.mock_wapi = patch(
            'ansible_collections.ansible.infoblox.plugins.modules.nios_a_record.WapiModule'
        )
        self.exec_command = self.mock_wapi.start()
        self.mock_wapi_run = patch(
            'ansible_collections.ansible.infoblox.plugins.modules.nios_a_record.WapiModule.run'
        )
        self.mock_wapi_run.start()
        self.load_config = self.mock_wapi_run.start()

    def tearDown(self):
        super(TestNiosARecordModule, 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_a_record_create(self):
        self.module.params = {
            'provider': None,
            'state': 'present',
            'name': 'a.ansible.com',
            'ipv4': '192.168.10.1',
            'comment': None,
            'extattrs': None
        }

        test_object = None

        test_spec = {
            "name": {
                "ib_req": True
            },
            "ipv4": {
                "ib_req": True
            },
            "comment": {},
            "extattrs": {}
        }

        wapi = self._get_wapi(test_object)
        print("WAPI: ", wapi.__dict__)
        res = wapi.run('testobject', test_spec)

        self.assertTrue(res['changed'])
        wapi.create_object.assert_called_once_with(
            'testobject', {
                'name': self.module._check_type_dict().__getitem__(),
                'ipv4': '192.168.10.1'
            })

    def test_nios_a_record_update_comment(self):
        self.module.params = {
            'provider': None,
            'state': 'present',
            'name': 'a.ansible.com',
            'ipv4': '192.168.10.1',
            'comment': 'updated comment',
            'extattrs': None
        }

        test_object = [{
            "comment": "test comment",
            "_ref": "arecord/ZG5zLm5ldHdvcmtfdmlldyQw:default/true",
            "name": "a.ansible.com",
            "ipv4": "192.168.10.1",
            "extattrs": {}
        }]

        test_spec = {
            "name": {
                "ib_req": True
            },
            "ipv4": {
                "ib_req": True
            },
            "comment": {},
            "extattrs": {}
        }

        wapi = self._get_wapi(test_object)
        res = wapi.run('testobject', test_spec)

        self.assertTrue(res['changed'])

    def test_nios_a_record_remove(self):
        self.module.params = {
            'provider': None,
            'state': 'absent',
            'name': 'a.ansible.com',
            'ipv4': '192.168.10.1',
            'comment': None,
            'extattrs': None
        }

        ref = "arecord/ZG5zLm5ldHdvcmtfdmlldyQw:default/false"

        test_object = [{
            "comment": "test comment",
            "_ref": ref,
            "name": "a.ansible.com",
            "ipv4": "192.168.10.1",
            "extattrs": {
                'Site': {
                    'value': 'test'
                }
            }
        }]

        test_spec = {
            "name": {
                "ib_req": True
            },
            "ipv4": {
                "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_a_record_update_record_name(self):
        self.module.params = {
            'provider': None,
            'state': 'present',
            'name': {
                'new_name': 'a_new.ansible.com',
                'old_name': 'a.ansible.com'
            },
            'comment': 'comment',
            'extattrs': None
        }

        test_object = [{
            "comment": "test comment",
            "_ref": "arecord/ZG5zLm5ldHdvcmtfdmlldyQw:default/true",
            "name": "a_new.ansible.com",
            "old_name": "a.ansible.com",
            "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)
コード例 #3
0
class TestNiosNSGroupModule(TestNiosModule):

    module = nios_nsgroup

    def setUp(self):

        super(TestNiosNSGroupModule, self).setUp()
        self.module = MagicMock(
            name=
            'ansible_collections.ansible.infoblox.plugins.modules.nios_nsgroup.WapiModule'
        )
        self.module.check_mode = False
        self.module.params = {'provider': None}

        self.mock_wapi = patch(
            'ansible_collections.ansible.infoblox.plugins.modules.nios_nsgroup.WapiModule'
        )
        self.exec_command = self.mock_wapi.start()
        self.mock_wapi_run = patch(
            'ansible_collections.ansible.infoblox.plugins.modules.nios_nsgroup.WapiModule.run'
        )
        self.mock_wapi_run.start()

        self.load_config = self.mock_wapi_run.start()

    def tearDown(self):
        super(TestNiosNSGroupModule, 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_nsgroup_create(self):
        self.module.params = {
            'provider': None,
            'state': 'present',
            'name': 'my-simple-group',
            'comment': None,
            'grid_primary': None
        }

        test_object = None
        test_spec = {
            "name": {
                "ib_req": True
            },
            "comment": {},
            "grid_primary": {}
        }

        wapi = self._get_wapi(test_object)
        res = wapi.run('testobject', test_spec)

        self.assertTrue(res['changed'])
        wapi.create_object.assert_called_once_with(
            'testobject',
            {'name': self.module._check_type_dict().__getitem__()})

    def test_nios_nsgroup_remove(self):
        self.module.params = {
            'provider': None,
            'state': 'absent',
            'name': 'my-simple-group',
            'comment': None,
            'grid_primary': None
        }

        ref = "nsgroup/ZG5zLm5ldHdvcmtfdmlldyQw:ansible/false"

        test_object = [{
            "comment": "test comment",
            "_ref": ref,
            "name": "my-simple-group",
            "grid_primary": {
                'name': 'infoblox-test.example.com'
            }
        }]

        test_spec = {
            "name": {
                "ib_req": True
            },
            "comment": {},
            "grid_primary": {}
        }

        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_nsgroup_update_comment(self):
        self.module.params = {
            'provider': None,
            'state': 'present',
            'name': 'default',
            'comment': 'updated comment',
            'grid_primary': None
        }

        test_object = [{
            "comment": "test comment",
            "_ref": "nsgroup/ZG5zLm5ldHdvcmtfdmlldyQw:default/true",
            "name": "default",
            "grid_primary": {}
        }]

        test_spec = {
            "name": {
                "ib_req": True
            },
            "comment": {},
            "grid_primary": {}
        }

        wapi = self._get_wapi(test_object)
        res = wapi.run('testobject', test_spec)

        self.assertTrue(res['changed'])
        wapi.update_object.called_once_with(test_object)
コード例 #4
0
ファイル: path.py プロジェクト: coll-test/ansible.hetzner
from ansible_collections.ansible.hetzner.tests.unit.compat.mock import MagicMock
from ansible.utils.path import unfrackpath

mock_unfrackpath_noop = MagicMock(spec_set=unfrackpath,
                                  side_effect=lambda x, *args, **kwargs: x)
コード例 #5
0
class TestNiosSRVRecordModule(TestNiosModule):

    module = nios_srv_record

    def setUp(self):
        super(TestNiosSRVRecordModule, self).setUp()
        self.module = MagicMock(
            name=
            'ansible_collections.ansible.infoblox.plugins.modules.nios_srv_record.WapiModule'
        )
        self.module.check_mode = False
        self.module.params = {'provider': None}
        self.mock_wapi = patch(
            'ansible_collections.ansible.infoblox.plugins.modules.nios_srv_record.WapiModule'
        )
        self.exec_command = self.mock_wapi.start()
        self.mock_wapi_run = patch(
            'ansible_collections.ansible.infoblox.plugins.modules.nios_srv_record.WapiModule.run'
        )
        self.mock_wapi_run.start()
        self.load_config = self.mock_wapi_run.start()

    def tearDown(self):
        super(TestNiosSRVRecordModule, 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_srv_record_create(self):
        self.module.params = {
            'provider': None,
            'state': 'present',
            'name': '_sip._tcp.service.ansible.com',
            'port': 5080,
            'target': 'service1.ansible.com',
            'priority': 10,
            'weight': 10,
            'comment': None,
            'extattrs': None
        }

        test_object = None

        test_spec = {
            "name": {
                "ib_req": True
            },
            "port": {
                "ib_req": True
            },
            "target": {
                "ib_req": True
            },
            "priority": {
                "ib_req": True
            },
            "weight": {
                "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': self.module._check_type_dict().__getitem__(),
                'port': 5080,
                'target': 'service1.ansible.com',
                'priority': 10,
                'weight': 10
            })

    def test_nios_srv_record_update_comment(self):
        self.module.params = {
            'provider': None,
            'state': 'present',
            'name': '_sip._tcp.service.ansible.com',
            'port': 5080,
            'target': 'service1.ansible.com',
            'priority': 10,
            'weight': 10,
            'comment': None,
            'extattrs': None
        }

        test_object = [{
            "comment": "test comment",
            "_ref": "srvrecord/ZG5zLm5ldHdvcmtfdmlldyQw:default/true",
            "name": "_sip._tcp.service.ansible.com",
            'port': 5080,
            "target": "mailhost.ansible.com",
            "priority": 10,
            'weight': 10,
            "extattrs": {}
        }]

        test_spec = {
            "name": {
                "ib_req": True
            },
            "port": {
                "ib_req": True
            },
            "target": {
                "ib_req": True
            },
            "priority": {
                "ib_req": True
            },
            "weight": {
                "ib_req": True
            },
            "comment": {},
            "extattrs": {}
        }

        wapi = self._get_wapi(test_object)
        res = wapi.run('testobject', test_spec)

        self.assertTrue(res['changed'])

    def test_nios_srv_record_remove(self):
        self.module.params = {
            'provider': None,
            'state': 'absent',
            'name': '_sip._tcp.service.ansible.com',
            'port': 5080,
            'target': 'service1.ansible.com',
            'priority': 10,
            'weight': 10,
            'comment': None,
            'extattrs': None
        }

        ref = "srvrecord/ZG5zLm5ldHdvcmtfdmlldyQw:default/false"

        test_object = [{
            "comment": "test comment",
            "_ref": ref,
            "name": "_sip._tcp.service.ansible.com",
            "port": 5080,
            "target": "mailhost.ansible.com",
            "priority": 10,
            "weight": 10,
            "extattrs": {
                'Site': {
                    'value': 'test'
                }
            }
        }]

        test_spec = {
            "name": {
                "ib_req": True
            },
            "port": {
                "ib_req": True
            },
            "target": {
                "ib_req": True
            },
            "priority": {
                "ib_req": True
            },
            "weight": {
                "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)