Exemplo n.º 1
0
    def test_add_nflog_rules_accepted(self):
        ipt_mgr = mock.Mock()
        f_accept_prefix = log.LogPrefix(FAKE_PORT_ID, log_const.ACCEPT_EVENT,
                                        FAKE_PROJECT_ID)

        f_port_log = self._fake_port_log('fake_log_id', log_const.ACCEPT_EVENT,
                                         FAKE_PORT_ID)

        self.log_driver._add_rules_to_chain_v4v6 = mock.Mock()
        self.log_driver._get_ipt_mgr_by_port = mock.Mock(return_value=ipt_mgr)
        self.log_driver._get_intf_name = mock.Mock(return_value='fake_device')

        with mock.patch.object(self.log_driver,
                               '_get_prefix',
                               side_effect=[f_accept_prefix, None]):

            # Test with prefix already added into prefixes_table
            self.log_driver._add_nflog_rules_accepted(ipt_mgr, f_port_log)
            self.log_driver._add_rules_to_chain_v4v6.assert_not_called()
            self.assertEqual(set(['fake_log_id']),
                             f_accept_prefix.log_object_refs)

            # Test with prefixes_tables does not include the prefix
            prefix = log.LogPrefix(FAKE_PORT_ID, log_const.ACCEPT_EVENT,
                                   FAKE_PROJECT_ID)
            with mock.patch.object(log, 'LogPrefix', return_value=prefix):
                self.log_driver._add_nflog_rules_accepted(ipt_mgr, f_port_log)
                v4_rules, v6_rules = self._fake_nflog_rule_v4v6(
                    'fake_device', prefix.id)

                self.log_driver._add_rules_to_chain_v4v6.\
                    assert_called_once_with(ipt_mgr, 'accepted',
                                            v4_rules, v6_rules,
                                            wrap=True, top=True, tag=prefix.id)
                self.assertEqual(set(['fake_log_id']), prefix.log_object_refs)
Exemplo n.º 2
0
 def setUp(self):
     super(TestLogPrefix, self).setUp()
     self.log_prefix = log.LogPrefix(FAKE_PORT_ID, 'fake_event',
                                     FAKE_PROJECT_ID)
     self.log_prefix.log_object_refs = set([FAKE_LOG_ID])