def test_run(self): row = fakes.FakeOvsdbRow.create_one_ovsdb_row( attrs={'external_ids': { ovn_const.OVN_AGENT_METADATA_SB_CFG_KEY: '1'}}) self.event.run(mock.ANY, row, mock.ANY) self.agent_stats.add_stat.assert_called_once_with( utils.ovn_metadata_name(row.uuid), 1)
def run(self, event, row, old): try: stats.AgentStats.add_stat(utils.ovn_metadata_name(row.uuid), self._metadata_nb_cfg(row)) except (AttributeError, KeyError): LOG.warning( 'No "%(key)s" key found for the metadata agent at ' 'Chassis %(chassis)s', { 'key': ovn_const.OVN_AGENT_METADATA_SB_CFG_KEY, 'chassis': row.uuid }) return
def run(self, event, row, old): if event != self.ROW_DELETE: stats.AgentStats.add_stat(row.uuid, row.nb_cfg) # Update the metadata agent stats metadata_nb_cfg = row.external_ids.get( ovn_const.OVN_AGENT_METADATA_SB_CFG_KEY, None) if event == self.ROW_UPDATE and metadata_nb_cfg: try: old_metadata_nb_cfg = old.external_ids.get( ovn_const.OVN_AGENT_METADATA_SB_CFG_KEY, None) except AttributeError: return if metadata_nb_cfg != old_metadata_nb_cfg: stats.AgentStats.add_stat( utils.ovn_metadata_name(row.uuid), int(metadata_nb_cfg)) else: stats.AgentStats.del_agent(row.uuid) stats.AgentStats.del_agent(utils.ovn_metadata_name(row.uuid))
def agent_alive(self, chassis, type_): nb_cfg = chassis.nb_cfg id_ = chassis.uuid if type_ == ovn_const.OVN_METADATA_AGENT: id_ = utils.ovn_metadata_name(chassis.uuid) nb_cfg = int( chassis.external_ids.get( ovn_const.OVN_AGENT_METADATA_SB_CFG_KEY, 0)) if self._nb_ovn.nb_global.nb_cfg == nb_cfg: return True now = timeutils.utcnow() updated_at = stats.AgentStats.get_stat(id_).updated_at if (now - updated_at).total_seconds() < cfg.CONF.agent_down_time: return True return False
def run(self, event, row, old): stats.AgentStats.del_agent(row.uuid) stats.AgentStats.del_agent(utils.ovn_metadata_name(row.uuid))