示例#1
0
    def test_create_gtm_irule(self, *args):
        set_module_args(dict(
            name='foo',
            module='gtm',
            content='this is my content',
            partition='Common',
            server='localhost',
            password='******',
            user='******'
        ))

        module = AnsibleModule(
            argument_spec=self.spec.argument_spec,
            supports_check_mode=self.spec.supports_check_mode,
            mutually_exclusive=self.spec.mutually_exclusive,
        )

        # Override methods in the specific type of manager
        tm = GtmManager(module=module, params=module.params)
        tm.exists = Mock(side_effect=[False, True])
        tm.create_on_device = Mock(return_value=True)

        # Override methods to force specific logic in the module to happen
        mm = ModuleManager(module=module)
        mm.get_manager = Mock(return_value=tm)

        results = mm.exec_module()

        assert results['changed'] is True
        assert results['content'] == 'this is my content'
示例#2
0
    def test_create_gtm_irule(self, *args):
        set_module_args(dict(
            name='foo',
            module='gtm',
            content='this is my content',
            partition='Common',
            server='localhost',
            password='******',
            user='******'
        ))

        module = AnsibleModule(
            argument_spec=self.spec.argument_spec,
            supports_check_mode=self.spec.supports_check_mode,
            mutually_exclusive=self.spec.mutually_exclusive,
        )

        # Override methods in the specific type of manager
        tm = GtmManager(module=module, params=module.params)
        tm.exists = Mock(side_effect=[False, True])
        tm.create_on_device = Mock(return_value=True)

        # Override methods to force specific logic in the module to happen
        mm = ModuleManager(module=module)
        mm.get_manager = Mock(return_value=tm)

        results = mm.exec_module()

        assert results['changed'] is True
        assert results['content'] == 'this is my content'
    def test_create_gtm_irule_src(self, *args):
        set_module_args(
            dict(name='foo',
                 module='gtm',
                 src='{0}/create_ltm_irule.tcl'.format(fixture_path),
                 partition='Common',
                 provider=dict(server='localhost',
                               password='******',
                               user='******')))

        module = AnsibleModule(
            argument_spec=self.spec.argument_spec,
            supports_check_mode=self.spec.supports_check_mode,
            mutually_exclusive=self.spec.mutually_exclusive,
        )

        if PY3:
            builtins_name = 'builtins'
        else:
            builtins_name = '__builtin__'

        with patch(builtins_name + '.open',
                   mock_open(read_data='this is my content'),
                   create=True):
            # Override methods in the specific type of manager
            tm = GtmManager(module=module, params=module.params)
            tm.exists = Mock(side_effect=[False, True])
            tm.create_on_device = Mock(return_value=True)

            # Override methods to force specific logic in the module to happen
            mm = ModuleManager(module=module)
            mm.get_manager = Mock(return_value=tm)

            results = mm.exec_module()

        assert results['changed'] is True
        assert results['content'] == 'this is my content'
        assert results['module'] == 'gtm'
        assert results['src'] == '{0}/create_ltm_irule.tcl'.format(
            fixture_path)
        assert len(results.keys()) == 4
示例#4
0
    def test_create_gtm_irule_src(self, *args):
        set_module_args(dict(
            name='foo',
            module='gtm',
            src='{0}/create_ltm_irule.tcl'.format(fixture_path),
            partition='Common',
            server='localhost',
            password='******',
            user='******'
        ))

        module = AnsibleModule(
            argument_spec=self.spec.argument_spec,
            supports_check_mode=self.spec.supports_check_mode,
            mutually_exclusive=self.spec.mutually_exclusive,
        )

        if PY3:
            builtins_name = 'builtins'
        else:
            builtins_name = '__builtin__'

        with patch(builtins_name + '.open', mock_open(read_data='this is my content'), create=True):
            # Override methods in the specific type of manager
            tm = GtmManager(module=module, params=module.params)
            tm.exists = Mock(side_effect=[False, True])
            tm.create_on_device = Mock(return_value=True)

            # Override methods to force specific logic in the module to happen
            mm = ModuleManager(module=module)
            mm.get_manager = Mock(return_value=tm)

            results = mm.exec_module()

        assert results['changed'] is True
        assert results['content'] == 'this is my content'
        assert results['module'] == 'gtm'
        assert results['src'] == '{0}/create_ltm_irule.tcl'.format(fixture_path)
        assert len(results.keys()) == 4