def test_arp_protection_removal(self):
     self._add_arp_protection(self.source, ['1.1.1.1'])
     self._add_arp_protection(self.destination, ['2.2.2.2'])
     no_arping(self.observer.namespace, self.destination.ip)
     no_arping(self.observer.namespace, self.source.ip)
     name = net_helpers.VethFixture.get_peer_name(self.source.port.name)
     arp_protect.delete_arp_spoofing_protection([name])
     # spoofing should have been removed from source, but not dest
     arping(self.observer.namespace, self.source.ip)
     no_arping(self.observer.namespace, self.destination.ip)
 def treat_devices_removed(self, devices):
     resync = False
     self.sg_agent.remove_devices_filter(devices)
     for device in devices:
         LOG.info(_LI("Attachment %s removed"), device)
         details = None
         try:
             details = self.plugin_rpc.update_device_down(self.context, device, self.agent_id, cfg.CONF.host)
         except Exception:
             LOG.exception(_LE("Error occurred while removing port %s"), device)
             resync = True
         if details and details["exists"]:
             LOG.info(_LI("Port %s updated."), device)
         else:
             LOG.debug("Device %s not defined on plugin", device)
     if self.prevent_arp_spoofing:
         arp_protect.delete_arp_spoofing_protection(devices)
     return resync
Example #3
0
    def test_port_delete_arp_spoofing(self, ce, vjp):
        spoof_chain = arp_protect.SPOOF_CHAIN_PREFIX + VIF
        mac_chain = arp_protect.MAC_CHAIN_PREFIX + VIF
        expected = [
            mock.call(['ebtables', '-t', 'nat', '--concurrent', '-L'],
                      check_exit_code=True, extra_ok_codes=None,
                      log_fail_as_error=True, run_as_root=True),
            mock.ANY,
            mock.call(['ebtables', '-t', 'nat', '--concurrent', '-D',
                       'PREROUTING', '-i', VIF, '-j', spoof_chain,
                       '-p', 'ARP'],
                      check_exit_code=True, extra_ok_codes=None,
                      log_fail_as_error=True, run_as_root=True),
            mock.call(['ebtables', '-t', 'nat', '--concurrent', '-X',
                       spoof_chain],
                      check_exit_code=True, extra_ok_codes=None,
                      log_fail_as_error=True, run_as_root=True),
            mock.ANY,
            mock.call(['ebtables', '-t', 'nat', '--concurrent', '-X',
                       mac_chain],
                      check_exit_code=True, extra_ok_codes=None,
                      log_fail_as_error=True, run_as_root=True),
            mock.call(['ebtables', '-t', 'filter', '--concurrent', '-L'],
                      check_exit_code=True, extra_ok_codes=None,
                      log_fail_as_error=True, run_as_root=True),
            mock.ANY,
            mock.call(['ebtables', '-t', 'filter', '--concurrent', '-D',
                       'FORWARD', '-i', VIF, '-j', spoof_chain,
                       '-p', 'ARP'],
                      check_exit_code=True, extra_ok_codes=None,
                      log_fail_as_error=True, run_as_root=True),
            mock.call(['ebtables', '-t', 'filter', '--concurrent', '-X',
                       spoof_chain],
                      check_exit_code=True, extra_ok_codes=None,
                      log_fail_as_error=True, run_as_root=True),
            mock.ANY,
            mock.call(['ebtables', '-t', 'filter', '--concurrent', '-X',
                       mac_chain],
                      check_exit_code=True, extra_ok_codes=None,
                      log_fail_as_error=True, run_as_root=True),
        ]

        arp_protect.delete_arp_spoofing_protection([VIF])
        self.execute.assert_has_calls(expected)
Example #4
0
 def treat_devices_removed(self, devices):
     resync = False
     self.sg_agent.remove_devices_filter(devices)
     for device in devices:
         LOG.info(_LI("Attachment %s removed"), device)
         details = None
         try:
             details = self.plugin_rpc.update_device_down(
                 self.context, device, self.agent_id, cfg.CONF.host)
         except Exception:
             LOG.exception(_LE("Error occurred while removing port %s"),
                           device)
             resync = True
         if details and details['exists']:
             LOG.info(_LI("Port %s updated."), device)
         else:
             LOG.debug("Device %s not defined on plugin", device)
     if self.prevent_arp_spoofing:
         arp_protect.delete_arp_spoofing_protection(devices)
     return resync
Example #5
0
    def test_port_delete_arp_spoofing(self, ce, vjp):
        spoof_chain = arp_protect.SPOOF_CHAIN_PREFIX + VIF
        mac_chain = arp_protect.MAC_CHAIN_PREFIX + VIF
        expected = [
            mock.call(['ebtables', '-t', 'nat', '--concurrent', '-L'],
                      check_exit_code=True, extra_ok_codes=None,
                      log_fail_as_error=True, run_as_root=True,
                      privsep_exec=True),
            mock.ANY,
            mock.call(['ebtables', '-t', 'nat', '--concurrent', '-D',
                       'PREROUTING', '-i', VIF, '-j', spoof_chain,
                       '-p', 'ARP'],
                      check_exit_code=True, extra_ok_codes=None,
                      log_fail_as_error=True, run_as_root=True,
                      privsep_exec=True),
            mock.call(['ebtables', '-t', 'nat', '--concurrent', '-F',
                       spoof_chain],
                      check_exit_code=True, extra_ok_codes=None,
                      log_fail_as_error=True, run_as_root=True,
                      privsep_exec=True),
            mock.call(['ebtables', '-t', 'nat', '--concurrent', '-X',
                       spoof_chain],
                      check_exit_code=True, extra_ok_codes=None,
                      log_fail_as_error=True, run_as_root=True,
                      privsep_exec=True),
            mock.ANY,
            mock.call(['ebtables', '-t', 'nat', '--concurrent', '-F',
                       mac_chain],
                      check_exit_code=True, extra_ok_codes=None,
                      log_fail_as_error=True, run_as_root=True,
                      privsep_exec=True),
            mock.call(['ebtables', '-t', 'nat', '--concurrent', '-X',
                       mac_chain],
                      check_exit_code=True, extra_ok_codes=None,
                      log_fail_as_error=True, run_as_root=True,
                      privsep_exec=True),
        ]

        arp_protect.delete_arp_spoofing_protection([VIF])
        self.execute.assert_has_calls(expected)
 def treat_devices_removed(self, devices):
     resync = False
     self.sg_agent.remove_devices_filter(devices)
     for device in devices:
         LOG.info(_LI("Attachment %s removed"), device)
         details = None
         try:
             details = self.plugin_rpc.update_device_down(self.context,
                                                          device,
                                                          self.agent_id,
                                                          cfg.CONF.host)
         except Exception as e:
             LOG.debug("port_removed failed for %(device)s: %(e)s",
                       {'device': device, 'e': e})
             resync = True
         if details and details['exists']:
             LOG.info(_LI("Port %s updated."), device)
         else:
             LOG.debug("Device %s not defined on plugin", device)
     if self.prevent_arp_spoofing:
         arp_protect.delete_arp_spoofing_protection(devices)
     return resync
 def delete_arp_spoofing_protection(self, devices):
     arp_protect.delete_arp_spoofing_protection(devices)
 def delete_arp_spoofing_protection(self, devices):
     arp_protect.delete_arp_spoofing_protection(devices)