Beispiel #1
0
    def rpc_loop(self, polling_manager=None):
        if not polling_manager:
            polling_manager = polling.AlwaysPoll()

        start = time.time()
        ovs_restarted = self.check_ovs_restart()
        if ovs_restarted and self.sync:
            self._setup_external_bridges()

        if self.run_daemon_loop:
            if self._agent_has_updates(polling_manager) or ovs_restarted:
                try:
                    LOG.info('ovs rpc loop running')
                    updated_ports_copy = self.updated_ports
                    self.updated_ports = set()
                    reg_ports = (set() if ovs_restarted else self.ports)
                    port_info = self.scan_ports(reg_ports, updated_ports_copy)
                    if (self._port_info_has_changes(port_info)
                            or ovs_restarted):
                        LOG.debug(_("Starting to process devices in:%s"),
                                  port_info)
                        self.process_network_ports(port_info, ovs_restarted)
                        self.ports = port_info['current']
                        polling_manager.polling_completed()
                    self.sync = False
                except Exception:
                    LOG.exception(_("Error while processing VIF ports"))
                    # Put the ports back in self.updated_port
                    self.updated_ports |= updated_ports_copy
                    self.sync = True
    def rpc_loop(self, polling_manager=None):
        if not polling_manager:
            polling_manager = polling.AlwaysPoll()

        sync = True
        ports = set()
        updated_ports_copy = set()
        ovs_restarted = False

        while self.run_daemon_loop:
            if self.use_call == True:
                time.sleep(Agent_Start_Report_Retry_Interval)
                continue
            try:
                start = time.time()
                if sync:
                    LOG.info(
                        _("Agent out of sync with plugin! Should br synchronized!"
                          ))
                    ports.clear()
                    sync = False
                    polling_manager.force_polling()

                try:

                    if not self.bridge_mappings:
                        LOG.debug(_("Bridge mapping is not configured!"))
                        elapsed = (time.time() - start)
                        if (elapsed < self.polling_interval):
                            time.sleep(self.polling_interval - elapsed)
                        continue

                    #check if ovs-vswitchd restart
                    ovs_restarted = self.check_ovs_restart()

                    if self._agent_has_updates(
                            polling_manager) or ovs_restarted:

                        updated_ports_copy = self.updated_ports
                        self.updated_ports = set()

                        reg_ports = (set() if ovs_restarted else ports)
                        if ovs_restarted:
                            self.integ_ebr.add_flow(table=RESTART_TABLE,
                                                    priority=0,
                                                    actions="drop")

                        port_info = self.scan_ports(reg_ports,
                                                    updated_ports_copy)

                        if self._port_info_has_changes(port_info):
                            LOG.debug(_("Starting to process devices in:%s"),
                                      port_info)
                            # If treat devices fails - must resync with plugin
                            sync = self.process_network_ports(
                                port_info, ovs_restarted)
                        ports = port_info['current']
                        polling_manager.polling_completed()
                except Exception:
                    LOG.exception(_("Error while processing VIF ports"))
                    # Put the ports back in self.updated_port
                    self.updated_ports |= updated_ports_copy
                    sync = True
            except Exception:
                LOG.exception(_("Error in agent event loop"))
                sync = True
            # sleep till end of polling interval
            elapsed = (time.time() - start)
            if (elapsed < self.polling_interval):
                time.sleep(self.polling_interval - elapsed)
            else:
                LOG.debug(
                    _("Loop iteration exceeded interval "
                      "(%(polling_interval)s vs. %(elapsed)s)!"), {
                          'polling_interval': self.polling_interval,
                          'elapsed': elapsed
                      })
            self.iter_num = self.iter_num + 1
Beispiel #3
0
 def test_is_polling_required_always_returns_true(self):
     pm = polling.AlwaysPoll()
     self.assertTrue(pm.is_polling_required)