Esempio n. 1
0
    def test_flush(self):
        '''
        Test to flush current ipset set.
        '''
        name = 'salt'

        ret = {'name': name,
               'result': False,
               'comment': '',
               'changes': {}}

        mock = MagicMock(side_effect=[False, True, True, True])
        mock_f = MagicMock(side_effect=[True, False])
        with patch.dict(ipset.__salt__, {'ipset.check_set': mock,
                                         'ipset.flush': mock_f}):
            comt = ('ipset set {0} does not exist for ipv4'.format(name))
            ret.update({'comment': comt})
            self.assertDictEqual(ipset.flush(name), ret)

            with patch.dict(ipset.__opts__, {'test': True}):
                comt = ('ipset entries in set {0} family ipv4 needs to '
                        'be flushed'.format(name))
                ret.update({'comment': comt, 'result': None})
                self.assertDictEqual(ipset.flush(name), ret)

            with patch.dict(ipset.__opts__, {'test': False}):
                comt = ('Flush ipset entries in set {0} family ipv4'
                        .format(name))
                ret.update({'comment': comt, 'result': True,
                            'changes': {'locale': 'salt'}})
                self.assertDictEqual(ipset.flush(name), ret)

                comt = ('Failed to flush ipset entries')
                ret.update({'comment': comt, 'result': False, 'changes': {}})
                self.assertDictEqual(ipset.flush(name), ret)
Esempio n. 2
0
 def _runner(self, expected_ret, test=False, check_set=True, flush=True,
             flush_assertion=True):
     mock_check_set = MagicMock(return_value=check_set)
     mock_flush = MagicMock(return_value=flush)
     with patch.dict(ipset.__opts__, {'test': test}):
         with patch.dict(ipset.__salt__, {'ipset.check_set': mock_check_set,
                                          'ipset.flush': mock_flush}):
             actual_ret = ipset.flush(self.fake_name)
     mock_check_set.assert_called_once_with(self.fake_name)
     if flush_assertion:
         mock_flush.assert_called_once_with(self.fake_name, 'ipv4')
     else:
         self.assertTrue(mock_flush.call_count == 0)
     self.assertDictEqual(actual_ret, expected_ret)
Esempio n. 3
0
 def _runner(self, expected_ret, test=False, check_set=True, flush=True,
             flush_assertion=True):
     mock_check_set = MagicMock(return_value=check_set)
     mock_flush = MagicMock(return_value=flush)
     with patch.dict(ipset.__opts__, {'test': test}):
         with patch.dict(ipset.__salt__, {'ipset.check_set': mock_check_set,
                                          'ipset.flush': mock_flush}):
             actual_ret = ipset.flush(self.fake_name)
     mock_check_set.assert_called_once_with(self.fake_name)
     if flush_assertion:
         mock_flush.assert_called_once_with(self.fake_name, 'ipv4')
     else:
         mock_flush.assert_not_called()
     self.assertDictEqual(actual_ret, expected_ret)