def _get_journalctl_l3_agent(self): if not constants.USE_ALL_LOGS: date = cli_helpers.get_date(format="--iso-8601").rstrip() else: date = None out = cli_helpers.get_journalctl(unit="neutron-l3-agent", date=date) self.f_journalctl = mktemp_dump(''.join(out))
def test_get_date_w_invalid_tz(self): with tempfile.TemporaryDirectory() as dtmp: with mock.patch.object(cli_helpers, 'DATA_ROOT', dtmp): os.makedirs(os.path.join(dtmp, "sos_commands/date")) with open(os.path.join(dtmp, "sos_commands/date/date"), 'w') as fd: fd.write("Thu Mar 25 10:55:05 123UTC 2021") self.assertEquals(cli_helpers.get_date(), "")
def get_date_secs(self, datestring=None): if datestring: cmd = ["date", "--utc", "--date={}".format(datestring), "+%s"] date_in_secs = subprocess.check_output(cmd) else: date_in_secs = cli_helpers.get_date() or 0 if date_in_secs: date_in_secs = date_in_secs.strip() return int(date_in_secs)
def get_vrrp_transitions(self): if "keepalived" not in L3HA_CHECKS: return transitions = {} with tempfile.NamedTemporaryFile(mode='w', delete=False) as ftmp: if not constants.USE_ALL_LOGS: date = cli_helpers.get_date(format="--iso-8601").rstrip() else: date = None out = cli_helpers.get_journalctl(unit="neutron-l3-agent", date=date) ftmp.write(''.join(out)) ftmp.close() for router in L3HA_CHECKS["keepalived"]: vr_id = ROUTER_VR_IDS[router] expr = (r"^(\S+) [0-9]+ [0-9:]+ \S+ Keepalived_vrrp" r"\[([0-9]+)\]: VRRP_Instance\(VR_{}\) .+ (\S+) " "STATE.*".format(vr_id)) d = SearchDef(expr, tag=router) self.searcher.add_search_term(d, ftmp.name) results = self.searcher.search() for router in L3HA_CHECKS["keepalived"]: transitions[router] = len(results.find_by_tag(router)) os.unlink(ftmp.name) if transitions: L3HA_CHECKS["keepalived"] = {"transitions": {}} for k, v in sorted(transitions.items(), key=lambda x: x[1], reverse=True): L3HA_CHECKS["keepalived"]["transitions"][k] = v
def test_get_date(self): self.assertEquals(cli_helpers.get_date(), '1616669705\n')
def test_get_date_local(self): self.assertEquals(type(cli_helpers.get_date()), str)