def test_chain_absent(self):
        """
        Test to verify the chain is absent.
        """
        ret = {"name": "salt", "changes": {}, "result": True, "comment": ""}

        mock = MagicMock(side_effect=[False, True, True, True])
        with patch.dict(iptables.__salt__, {"iptables.check_chain": mock}):
            ret.update(
                {
                    "comment": (
                        "iptables salt chain is already absent in filter table for ipv4"
                    )
                }
            )
            self.assertDictEqual(iptables.chain_absent("salt"), ret)

            with patch.dict(iptables.__opts__, {"test": True}):
                ret.update(
                    {
                        "comment": (
                            "iptables salt chain in filter"
                            " table needs to be removed ipv4"
                        ),
                        "result": None,
                    }
                )
                self.assertDictEqual(iptables.chain_absent("salt"), ret)

            with patch.dict(iptables.__opts__, {"test": False}):
                mock = MagicMock(side_effect=[False, "a"])
                with patch.dict(iptables.__salt__, {"iptables.flush": mock}):
                    mock = MagicMock(return_value=True)
                    with patch.dict(iptables.__salt__, {"iptables.delete_chain": mock}):
                        ret.update(
                            {
                                "changes": {"locale": "salt"},
                                "comment": (
                                    "iptables salt chain in filter"
                                    " table delete success for ipv4"
                                ),
                                "result": True,
                            }
                        )
                        self.assertDictEqual(iptables.chain_absent("salt"), ret)

                    ret.update(
                        {
                            "changes": {},
                            "result": False,
                            "comment": (
                                "Failed to flush salt chain in filter table: a for ipv4"
                            ),
                        }
                    )
                    self.assertDictEqual(iptables.chain_absent("salt"), ret)
示例#2
0
    def test_chain_absent(self):
        '''
            Test to verify the chain is absent.
        '''
        ret = {'name': 'salt', 'changes': {}, 'result': True, 'comment': ''}

        mock = MagicMock(side_effect=[False, True, True, True])
        with patch.dict(iptables.__salt__, {'iptables.check_chain': mock}):
            ret.update({
                'comment':
                'iptables salt chain is already'
                ' absent in filter table for ipv4'
            })
            self.assertDictEqual(iptables.chain_absent("salt"), ret)

            with patch.dict(iptables.__opts__, {'test': True}):
                ret.update({
                    'comment': 'iptables salt chain in filter'
                    ' table needs to be removed ipv4',
                    'result': None
                })
                self.assertDictEqual(iptables.chain_absent("salt"), ret)

            with patch.dict(iptables.__opts__, {'test': False}):
                mock = MagicMock(side_effect=[False, 'a'])
                with patch.dict(iptables.__salt__, {'iptables.flush': mock}):
                    mock = MagicMock(return_value=True)
                    with patch.dict(iptables.__salt__,
                                    {'iptables.delete_chain': mock}):
                        ret.update({
                            'changes': {
                                'locale': 'salt'
                            },
                            'comment': 'iptables salt chain in filter'
                            ' table delete success for ipv4',
                            'result': True
                        })
                        self.assertDictEqual(iptables.chain_absent("salt"),
                                             ret)

                    ret.update({
                        'changes': {},
                        'result':
                        False,
                        'comment':
                        'Failed to flush salt chain'
                        ' in filter table: a for ipv4'
                    })
                    self.assertDictEqual(iptables.chain_absent("salt"), ret)
示例#3
0
    def test_chain_absent(self):
        '''
            Test to verify the chain is absent.
        '''
        ret = {'name': 'salt',
               'changes': {},
               'result': True,
               'comment': ''
               }

        mock = MagicMock(side_effect=[False, True, True, True])
        with patch.dict(iptables.__salt__, {'iptables.check_chain': mock}):
            ret.update({'comment': 'iptables salt chain is already'
                        ' absent in filter table for ipv4'})
            self.assertDictEqual(iptables.chain_absent("salt"), ret)

            with patch.dict(iptables.__opts__, {'test': True}):
                ret.update({'comment': 'iptables salt chain in filter'
                            ' table needs to be removed ipv4',
                            'result': None})
                self.assertDictEqual(iptables.chain_absent("salt"), ret)

            with patch.dict(iptables.__opts__, {'test': False}):
                mock = MagicMock(side_effect=[False, 'a'])
                with patch.dict(iptables.__salt__, {'iptables.flush': mock}):
                    mock = MagicMock(return_value=True)
                    with patch.dict(iptables.__salt__,
                                    {'iptables.delete_chain': mock}):
                        ret.update({'changes': {'locale': 'salt'},
                                    'comment': 'iptables salt chain in filter'
                                    ' table delete success for ipv4',
                                    'result': True})
                        self.assertDictEqual(iptables.chain_absent("salt"),
                                             ret)

                    ret.update({'changes': {}, 'result': False,
                                'comment': 'Failed to flush salt chain'
                                ' in filter table: a for ipv4'})
                    self.assertDictEqual(iptables.chain_absent("salt"), ret)