Exemplo n.º 1
0
    def test_flush(self):
        '''
            Test to flush current iptables state
        '''
        ret = {'name': 'salt',
               'changes': {},
               'result': None,
               'comment': ''}

        mock = MagicMock(return_value=[])
        with patch.object(iptables, '_STATE_INTERNAL_KEYWORDS', mock):
            with patch.dict(iptables.__opts__, {'test': True}):
                ret.update({'comment': 'iptables rules in salt table filter'
                            ' chain ipv4 family needs to be flushed'})
                self.assertDictEqual(iptables.flush('salt'), ret)

            with patch.dict(iptables.__opts__, {'test': False}):
                mock = MagicMock(side_effect=[False, True])
                with patch.dict(iptables.__salt__,
                                {'iptables.flush': mock}):
                    ret.update({'changes': {'locale': 'salt'},
                                'comment': 'Flush iptables rules in  '
                                'table  chain ipv4 family',
                                'result': True})
                    self.assertDictEqual(iptables.flush('salt',
                                                        table='', chain=''),
                                         ret)

                    ret.update({'changes': {},
                                'comment': 'Failed to flush iptables rules',
                                'result': False})
                    self.assertDictEqual(iptables.flush('salt',
                                                        table='', chain=''),
                                         ret)
Exemplo n.º 2
0
    def test_flush(self):
        '''
            Test to flush current iptables state
        '''
        ret = {'name': 'salt',
               'changes': {},
               'result': None,
               'comment': ''}

        mock = MagicMock(return_value=[])
        with patch.object(iptables, '_STATE_INTERNAL_KEYWORDS', mock):
            with patch.dict(iptables.__opts__, {'test': True}):
                ret.update({'comment': 'iptables rules in salt table filter'
                            ' chain ipv4 family needs to be flushed'})
                self.assertDictEqual(iptables.flush('salt'), ret)

            with patch.dict(iptables.__opts__, {'test': False}):
                mock = MagicMock(side_effect=[False, True])
                with patch.dict(iptables.__salt__,
                                {'iptables.flush': mock}):
                    ret.update({'changes': {'locale': 'salt'},
                                'comment': 'Flush iptables rules in'
                                '  table  chain ipv4 family',
                                'result': True})
                    self.assertDictEqual(iptables.flush('salt',
                                                        table='', chain=''),
                                         ret)

                    ret.update({'changes': {},
                                'comment': 'Failed to flush iptables rules',
                                'result': False})
                    self.assertDictEqual(iptables.flush('salt',
                                                        table='', chain=''),
                                         ret)
Exemplo n.º 3
0
def test_flush():
    """
    Test to flush current iptables state
    """
    ret = {"name": "salt", "changes": {}, "result": None, "comment": ""}

    mock = MagicMock(return_value=[])
    with patch.object(iptables, "_STATE_INTERNAL_KEYWORDS", mock):
        with patch.dict(iptables.__opts__, {"test": True}):
            ret.update({
                "comment": ("iptables rules in salt table filter"
                            " chain ipv4 family needs to be flushed")
            })
            assert iptables.flush("salt") == ret

        with patch.dict(iptables.__opts__, {"test": False}):
            mock = MagicMock(side_effect=[False, True])
            with patch.dict(iptables.__salt__, {"iptables.flush": mock}):
                ret.update({
                    "changes": {
                        "locale": "salt"
                    },
                    "comment":
                    ("Flush iptables rules in  table  chain ipv4 family"),
                    "result":
                    True,
                })
                assert iptables.flush("salt", table="", chain="") == ret

                ret.update({
                    "changes": {},
                    "comment": "Failed to flush iptables rules",
                    "result": False,
                })
                assert iptables.flush("salt", table="", chain="") == ret