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 #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_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
    def test_update_vlan_description(self, *args):
        set_module_args(
            dict(
                name='somevlan',
                description='changed_that',
                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)
        ifcs = self.loaded_vlan_ifc_tag
        # 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)

            current = (Parameters(
                load_fixture('update_vlan_description.json')), ifcs)

            mm.update_on_device = Mock(return_value=True)
            mm.exists = Mock(return_value=True)
            mm.read_current_from_device = Mock(return_value=current)

            results = mm.exec_module()

        assert results['changed'] is True
        assert results['description'] == 'changed_that'
Beispiel #5
0
    def test_update_vlan_tag_interface(self, *args):
        set_module_args(
            dict(
                name='somevlan',
                tagged_interface=['2.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
        mm = ModuleManager(client)

        current = ApiParameters(load_fixture('load_vlan.json'))

        mm.update_on_device = Mock(return_value=True)
        mm.exists = Mock(return_value=True)
        mm.read_current_from_device = Mock(return_value=current)

        results = mm.exec_module()

        assert results['changed'] is True
        assert results['tagged_interfaces'] == ['2.1']
Beispiel #6
0
    def test_update_vlan_description(self, *args):
        set_module_args(
            dict(
                name='somevlan',
                description='changed_that',
                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)

        current = ApiParameters(
            params=load_fixture('update_vlan_description.json'))

        mm.update_on_device = Mock(return_value=True)
        mm.exists = Mock(return_value=True)
        mm.read_current_from_device = Mock(return_value=current)

        results = mm.exec_module()

        assert results['changed'] is True
        assert results['description'] == 'changed_that'
Beispiel #7
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'