예제 #1
0
    def test_delete_chain(self):
        '''
        Test if it delete the chain from the specified table.
        '''
        self.assertEqual(nftables.delete_chain(),
                         'Error: Chain needs to be specified')

        ret = 'Error: table filter in family ipv4 does not exist'
        mock = MagicMock(return_value='')
        with patch.dict(nftables.__salt__, {'cmd.run': mock}):
            self.assertEqual(nftables.delete_chain(chain='input'), ret)

        ret = 'Error: chain input in table filter in family ipv4 does not exist'
        mock = MagicMock(return_value='table ip filter')
        with patch.dict(nftables.__salt__, {'cmd.run': mock}):
            self.assertEqual(nftables.delete_chain(chain='input'), ret)
예제 #2
0
 def test_delete_chain_variables(self):
     '''
     Test if it delete the chain from the specified table.
     '''
     mock = MagicMock(return_value='')
     with patch.dict(nftables.__salt__, {'cmd.run': mock}):
         self.assertTrue(nftables.delete_chain(chain='input'))
예제 #3
0
 def test_delete_chain_variables(self):
     '''
     Test if it delete the chain from the specified table.
     '''
     mock = MagicMock(return_value='')
     with patch.dict(nftables.__salt__, {'cmd.run': mock}):
         self.assertTrue(nftables.delete_chain(chain='input'))
예제 #4
0
    def test_delete_chain(self):
        '''
        Test if it delete the chain from the specified table.
        '''
        self.assertEqual(nftables.delete_chain(),
                         'Error: Chain needs to be specified')

        ret = 'Error: table filter in family ipv4 does not exist'
        mock = MagicMock(return_value='')
        with patch.dict(nftables.__salt__, {'cmd.run': mock}):
            self.assertEqual(nftables.delete_chain(chain='input'), ret)

        ret = 'Error: chain input in table filter in family ipv4 does not exist'
        mock = MagicMock(return_value='table ip filter')
        with patch.dict(nftables.__salt__, {'cmd.run': mock}):
            self.assertEqual(nftables.delete_chain(chain='input'), ret)
예제 #5
0
    def test_delete_chain(self):
        '''
        Test if it delete the chain from the specified table.
        '''
        self.assertEqual(nftables.delete_chain(), {
            'result': False,
            'comment': 'Chain needs to be specified'
        })

        ret = {
            'result': False,
            'comment': 'Table filter in family ipv4 does not exist'
        }
        mock = MagicMock(return_value='')
        with patch.dict(nftables.__salt__, {'cmd.run': mock}):
            self.assertEqual(nftables.delete_chain(chain='input'), ret)

        ret = {
            'result':
            False,
            'comment':
            'Chain input in table filter in family ipv4 could not be deleted'
        }
        mock = MagicMock(return_value='table ip filter')
        with patch.dict(nftables.__salt__, {'cmd.run': mock}), \
                patch('salt.modules.nftables.check_table',
                      MagicMock(return_value={'result': True,
                                              'comment': ''})), \
                patch('salt.modules.nftables.check_chain',
                      MagicMock(return_value={'result': True,
                                              'comment': ''})):
            self.assertEqual(nftables.delete_chain(chain='input'), ret)

        ret = {
            'result': True,
            'comment': 'Chain input in table filter in family ipv4 deleted'
        }
        mock = MagicMock(return_value='')
        with patch.dict(nftables.__salt__, {'cmd.run': mock}), \
                patch('salt.modules.nftables.check_table',
                      MagicMock(return_value={'result': True,
                                              'comment': ''})), \
                patch('salt.modules.nftables.check_chain',
                      MagicMock(return_value={'result': True,
                                              'comment': ''})):
            self.assertEqual(nftables.delete_chain(chain='input'), ret)
예제 #6
0
    def test_delete_chain(self):
        """
        Test if it delete the chain from the specified table.
        """
        self.assertEqual(
            nftables.delete_chain(),
            {"result": False, "comment": "Chain needs to be specified"},
        )

        ret = {"result": False, "comment": "Table filter in family ipv4 does not exist"}
        mock = MagicMock(return_value="")
        with patch.dict(nftables.__salt__, {"cmd.run": mock}):
            self.assertEqual(nftables.delete_chain(chain="input"), ret)

        ret = {
            "result": False,
            "comment": (
                "Chain input in table filter in family ipv4 could not be deleted"
            ),
        }
        mock = MagicMock(return_value="table ip filter")
        with patch.dict(nftables.__salt__, {"cmd.run": mock}), patch(
            "salt.modules.nftables.check_table",
            MagicMock(return_value={"result": True, "comment": ""}),
        ), patch(
            "salt.modules.nftables.check_chain",
            MagicMock(return_value={"result": True, "comment": ""}),
        ):
            self.assertEqual(nftables.delete_chain(chain="input"), ret)

        ret = {
            "result": True,
            "comment": "Chain input in table filter in family ipv4 deleted",
        }
        mock = MagicMock(return_value="")
        with patch.dict(nftables.__salt__, {"cmd.run": mock}), patch(
            "salt.modules.nftables.check_table",
            MagicMock(return_value={"result": True, "comment": ""}),
        ), patch(
            "salt.modules.nftables.check_chain",
            MagicMock(return_value={"result": True, "comment": ""}),
        ):
            self.assertEqual(nftables.delete_chain(chain="input"), ret)
예제 #7
0
 def test_delete_chain_variables(self):
     '''
     Test if it delete the chain from the specified table.
     '''
     mock = MagicMock(return_value='')
     with patch.dict(nftables.__salt__, {'cmd.run': mock}), \
             patch('salt.modules.nftables.check_chain',
                   MagicMock(return_value={'result': True,
                                           'comment': ''})), \
             patch('salt.modules.nftables.check_table',
                   MagicMock(return_value={'result': True,
                                           'comment': ''})):
         _expected = {'comment': 'Chain input in table filter in family ipv4 deleted',
                      'result': True}
         self.assertEqual(nftables.delete_chain(chain='input'), _expected)
예제 #8
0
 def test_delete_chain_variables(self):
     """
     Test if it delete the chain from the specified table.
     """
     mock = MagicMock(return_value="")
     with patch.dict(nftables.__salt__, {"cmd.run": mock}), patch(
         "salt.modules.nftables.check_chain",
         MagicMock(return_value={"result": True, "comment": ""}),
     ), patch(
         "salt.modules.nftables.check_table",
         MagicMock(return_value={"result": True, "comment": ""}),
     ):
         _expected = {
             "comment": "Chain input in table filter in family ipv4 deleted",
             "result": True,
         }
         self.assertEqual(nftables.delete_chain(chain="input"), _expected)