def test_parse_return_ifcs_raises(self, *args):
        set_module_args(
            dict(name='somevlan',
                 untagged_interface=['1.2'],
                 server='localhost',
                 password='******',
                 user='******',
                 partition='Common'))

        client = AnsibleF5Client(
            argument_spec=self.spec.argument_spec,
            supports_check_mode=self.spec.supports_check_mode,
            f5_product_name=self.spec.f5_product_name)
        msg = 'No interfaces were found'
        # Override methods to force specific logic in the module to happen
        with patch.object(Parameters, '_get_interfaces_from_device') as obj:
            obj.return_value = []

            mm = ModuleManager(client)
            mm.create_on_device = Mock(return_value=True)
            mm.exists = Mock(return_value=False)

            with pytest.raises(F5ModuleError) as err:
                mm.exec_module()

        assert str(err.value) == msg
Beispiel #2
0
    def test_create_vlan_tagged_interfaces(self, *args):
        set_module_args(
            dict(name='somevlan',
                 tagged_interface=['2.1', '1.1'],
                 tag=213,
                 server='localhost',
                 password='******',
                 user='******',
                 partition='Common'))

        client = AnsibleF5Client(
            argument_spec=self.spec.argument_spec,
            supports_check_mode=self.spec.supports_check_mode,
            f5_product_name=self.spec.f5_product_name)

        # Override methods to force specific logic in the module to happen
        mm = ModuleManager(client)
        mm.create_on_device = Mock(return_value=True)
        mm.exists = Mock(return_value=False)

        results = mm.exec_module()

        assert results['changed'] is True
        assert results['tagged_interfaces'] == ['1.1', '2.1']
        assert results['tag'] == 213
    def test_create_vlan_untagged_interfaces(self, *args):
        set_module_args(
            dict(
                name='somevlan',
                untagged_interface=['2.1', '1.1'],
                server='localhost',
                password='******',
                user='******',
                partition='Common',
            ))

        client = AnsibleF5Client(
            argument_spec=self.spec.argument_spec,
            supports_check_mode=self.spec.supports_check_mode,
            f5_product_name=self.spec.f5_product_name)

        # Override methods to force specific logic in the module to happen
        with patch.object(Parameters, '_get_interfaces_from_device') as obj:
            obj.return_value = self.loaded_ifcs

            mm = ModuleManager(client)
            mm.create_on_device = Mock(return_value=True)
            mm.exists = Mock(return_value=False)

            results = mm.exec_module()

        assert results['changed'] is True
        assert results['interfaces'] == [{
            'untagged': True,
            'name': '2.1'
        }, {
            'untagged': True,
            'name': '1.1'
        }]
        assert results['name'] == 'somevlan'
Beispiel #4
0
    def test_create_vlan(self, *args):
        set_module_args(
            dict(name='somevlan',
                 description='fakevlan',
                 server='localhost',
                 password='******',
                 user='******',
                 partition='Common'))

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

        # Override methods to force specific logic in the module to happen
        mm = ModuleManager(module=module)
        mm.create_on_device = Mock(return_value=True)
        mm.exists = Mock(return_value=False)

        results = mm.exec_module()

        assert results['changed'] is True
        assert results['description'] == 'fakevlan'