-
Notifications
You must be signed in to change notification settings - Fork 0
/
pulpito.py
executable file
·135 lines (111 loc) · 5.32 KB
/
pulpito.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
#!/usr/bin/python3
from bs4 import BeautifulSoup
import re
import requests
import argparse
import subprocess
import sys
import os
import pathlib
from subprocess import Popen
pulp_base='https://pulpito.ceph.com'
node_base='.front.sepia.ceph.com'
dbg=0
# create a dictionary of run times
def find_times(soup, is_v):
all_times={}
running_jobs = soup.find_all(attrs={ 'class' :re.compile(".*job_running.*")})
for jb in running_jobs:
if dbg > 3:
print (jb)
#jbid = re.search('[0-9]+', jb.find(attrs={'data-title':'Job ID'}).text)[0]
jbid = jb.find(attrs={'data-title':'Job ID'}).text.strip()
trun = jb.find(attrs={'data-title':'Runtime'}).text.strip()
if is_v:
print(f" {jbid} == {trun}")
all_times[jbid] = trun
return all_times
#counting the number of files in a remote node directory
def remote_crash_files_count(node_ad, pth):
remote_cmd = f'sudo ls --color=never -1 {pth}'
if dbg > 1:
print (f' cmd: {remote_cmd}')
core1 = subprocess.Popen(["ssh", "-q", node_ad, remote_cmd], stdout=subprocess.PIPE)
core1_st = subprocess.Popen([ 'wc', '-l' ], stdin=core1.stdout, stdout=subprocess.PIPE)
ot, er = core1_st.communicate()
if dbg > 0:
print (f' ot was {ot}. Er - {er}. Ret: {int(ot)}')
return int(ot)
def remote_crash_files_Ccount(node_ad, pth):
remote_cmd = f'sudo ls {pth}'
if dbg > 1:
print (f' cmd: {remote_cmd}')
core1 = subprocess.Popen(["ssh", "-q", node_ad, remote_cmd], stdout=subprocess.PIPE)
core1_st = subprocess.Popen([ 'wc', '-c' ], stdin=core1.stdout, stdout=subprocess.PIPE)
ot, er = core1_st.communicate()
if dbg > 0:
print (f' ot was {ot}. Er - {er}. Ret: {int(ot)}')
return int(ot)
def look_for_core(node_name, is_v):
node_ad = f"{node_name}{node_base}"
kgn = subprocess.Popen(["ssh-keygen", "-q", "-R", node_ad], stderr=subprocess.DEVNULL, stdout=subprocess.PIPE)
kgn_out, kgn_er = kgn.communicate()
crash_dir_nf = remote_crash_files_count(node_ad, '/var/lib/ceph/crash')
postd_dir_nf = remote_crash_files_count(node_ad, '/var/lib/ceph/crash/posted')
ubunt_dir_nf = remote_crash_files_Ccount(node_ad, '/home/ubuntu/cephtest/archive/coredump')
if is_v:
print (f' -{node_name}-- files in crash:{crash_dir_nf}, crash/posted:{postd_dir_nf}, ~ubuntu:{ubunt_dir_nf}')
#ubu_ls = subprocess.Popen(["ssh", "-q", node_ad, "sudo ls /home/ubuntu/cephtest"], stdout=subprocess.PIPE)
#otu, eru = ubu_ls.communicate()
#print (f" - ubuntu: {otu}")
if (crash_dir_nf > 1):
crs_nf = subprocess.Popen(["ssh", "-q", node_ad, "sudo ls /var/lib/ceph/crash"], stdout=subprocess.PIPE)
ot, er = crs_nf.communicate()
print (f" $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ \n{ot}")
if (postd_dir_nf > 0):
pst_nf = subprocess.Popen(["ssh", "-q", node_ad, "sudo ls /var/lib/ceph/crash/posted"], stderr=subprocess.stdout, stdout=subprocess.PIPE)
ot2, er = pst_nf.communicate()
print (f" $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ \n{ot2}")
if (ubunt_dir_nf > 3):
ubu_ls = subprocess.Popen(["ssh", "-q", node_ad, "sudo ls /home/ubuntu/cephtest/archive/coredump"], stderr=subprocess.DEVNULL, stdout=subprocess.PIPE)
ot3, er = ubu_ls.communicate()
print (f" $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ \n{ot3}")
def jobs_category(cat_name, cat, is_v, times, is_times):
for jb in cat:
jbid_tree = jb.find(attrs={'data-title':'ID:'})
jbid = jbid_tree.a.next_sibling.next_sibling.text
jbst = jb.find(attrs={'data-title':'Status:'}).a.string
if is_v or True:
if is_times:
print (f" ({cat_name}) {jbid} -> {jbst} {times[jbid]}")
else:
print (f" ({cat_name}) {jbid} -> {jbst}")
nds = jb.find(attrs={'data-title':'Targets:'}).find_all('a')
for nd in nds:
#print (' - ', nd.text)
look_for_core(nd.text, args.verbose)
parser = argparse.ArgumentParser(description='the nodes of running jobs')
parser.add_argument('-v', '--verbose', action='store_true')
parser.add_argument('-d', '--deads', action='store_true', help='visit dead jobs')
parser.add_argument('-t', '--times', action='store_true', help='fetch run-time data')
parser.add_argument('run_name', help='rfriedma/...')
args = parser.parse_args()
#r=requests.get("https://pulpito.ceph.com/khiremat-2021-08-05_17:51:48-fs:workload-wip-khiremat-test-kernel-exclude-failures-distro-basic-smithi/detail")
run_full_path = f"{pulp_base}/{args.run_name}/detail"
if dbg > 0 or args.verbose:
print (run_full_path)
r = requests.get(run_full_path)
s = BeautifulSoup(r.text,"html.parser")
if args.times:
# fetch run time for 'running' jobs
short_path = f"{pulp_base}/{args.run_name}"
r_short = requests.get(short_path)
s_short = BeautifulSoup(r_short.text,"html.parser")
allt = find_times(s_short, args.verbose)
else:
allt = {}
running_jobs = s.find_all('div', attrs={ 'class' :re.compile(".*job_running.*")})
jobs_category('running', running_jobs, args.verbose, allt, args.times)
if args.deads:
dead_jobs = s.find_all('div', attrs={ 'class' :re.compile(".*dead.*")})
jobs_category('dead', dead_jobs, args.verbose, allt, False)