Skip to content

Commit

Permalink
removing last vestiges of *audit*
Browse files Browse the repository at this point in the history
audit command was removed early in sr3 development, but
ability to ignore audit configurations was left in place even though
they never appear once the tree was moved away from the old v2 one.

Time has come to remove it entirely.

Also a quick typo from the previous commit, a comma in v2 conversion
stuff.
  • Loading branch information
petersilva committed May 21, 2024
1 parent e1b2e22 commit d2c3422
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 62 deletions.
5 changes: 2 additions & 3 deletions sarracenia/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -277,9 +277,8 @@ def __repr__(self) -> str:
'on_stop': { 'manual_conversion_required' : [ 'continue' ] },
'on_start': { 'manual_conversion_required' : [ 'continue' ] },
'on_watch': { 'manual_conversion_required' : [ 'continue' ] },

'on_post': {
'post_log': ['logEvents', '+after_work']
'post_log': ['logEvents', '+after_work'],
'post_total': ['continue'],
'wmo2msc': [ 'callback', 'filter.wmo2msc.Wmo2Msc'],
'post_hour_tree': [ 'callback', 'accept.posthourtree.PostHourTree'],
Expand Down Expand Up @@ -617,7 +616,7 @@ class Config:
'on_start', 'on_stop', 'on_watch', 'plugin'
]
components = [
'audit', 'cpost', 'cpump', 'flow', 'poll', 'post', 'sarra', 'sender', 'shovel',
'cpost', 'cpump', 'flow', 'poll', 'post', 'sarra', 'sender', 'shovel',
'subscribe', 'watch', 'winnow'
]

Expand Down
64 changes: 5 additions & 59 deletions sarracenia/sr.py
Original file line number Diff line number Diff line change
Expand Up @@ -252,19 +252,14 @@ def _filter_sr_proc(self, p):
del p['memory_full_info']
del p['cpu_times']
self.procs[p['pid']] = p
if p['name'][3:8] == 'audit':
self.procs[p['pid']]['claimed'] = True
self.auditors += 1
else:
self.procs[p['pid']]['claimed'] = (p['name'][-4:] == 'post') or \
self.procs[p['pid']]['claimed'] = (p['name'][-4:] == 'post') or \
any( item in [ 'declare', 'edit', 'foreground', 'sanity', 'setup', 'status' ] for item in p['cmdline'] )

def read_proc_file(self, File="procs.json"):
"""
read process table from a save file, for reproducible testing.
"""
self.procs = {}
self.auditors = 0
print('getting procs from %s: ' % File, end='', flush=True)
pcount = 0
with open(File, 'r') as f:
Expand All @@ -282,7 +277,6 @@ def _read_procs(self):
self.me = getpass.getuser()
if sys.platform == 'win32':
self.me = os.environ['userdomain'] + '\\' + self.me
self.auditors = 0
if not features['process']['present']:
return
for proc in psutil.process_iter():
Expand Down Expand Up @@ -654,6 +648,7 @@ def _clean_missing_proc_state_dir(self, dir):
os.chdir('..')

def _clean_missing_proc_state(self):

self._clean_missing_proc_state_dir(self.user_cache_dir)
self._clean_missing_proc_state_dir(self.user_cache_dir + os.sep +
self.hostdir)
Expand Down Expand Up @@ -1046,7 +1041,7 @@ def _match_patterns(self, patterns=None):
self.v2_config = patterns
return

candidates = ['audit']
candidates=[]
for c in self.components:
if (c not in self.configs):
continue
Expand Down Expand Up @@ -1106,7 +1101,6 @@ def _match_patterns(self, patterns=None):
patterns = patterns[1:]
if self.leftovers[0] == 'examples':
for c in self.components:
if c == 'audit': continue
d = self.package_lib_dir + os.sep + 'examples' + os.sep + c
if not os.path.exists(d): continue
l = os.listdir(d)
Expand Down Expand Up @@ -1376,7 +1370,6 @@ def declare(self):
for f in self.filtered_configurations:
if self.please_stop:
break
if f == 'audit': continue
(c, cfg) = f.split(os.sep)

if not 'options' in self.configs[c][cfg]:
Expand All @@ -1398,7 +1391,6 @@ def declare(self):

# then declare and bind queues....
for f in self.filtered_configurations:
if f == 'audit': continue
if self.please_stop:
break

Expand All @@ -1419,7 +1411,6 @@ def declare(self):

# run on_declare plugins.
for f in self.filtered_configurations:
if f == 'audit': continue
if self.please_stop:
break

Expand All @@ -1446,7 +1437,6 @@ def disable(self):
for f in self.filtered_configurations:
if self.please_stop:
break
if f == 'audit': continue
(c, cfg) = f.split(os.sep)

if not 'options' in self.configs[c][cfg]:
Expand All @@ -1472,7 +1462,6 @@ def edit(self):
for f in self.filtered_configurations:
if self.please_stop:
break
if f == 'audit': continue
(c, cfg) = f.split(os.sep)

if not 'options' in self.configs[c][cfg]:
Expand Down Expand Up @@ -1514,7 +1503,6 @@ def enable(self):
for f in self.filtered_configurations:
if self.please_stop:
break
if f == 'audit': continue
(c, cfg) = f.split(os.sep)

state_file_cfg = self.user_cache_dir + os.sep + c + os.sep + cfg
Expand All @@ -1531,7 +1519,6 @@ def features(self):

# run on_declare plugins.
for f in self.filtered_configurations:
if f == 'audit': continue
if self.please_stop:
break

Expand Down Expand Up @@ -1580,7 +1567,6 @@ def foreground(self):
for f in self.filtered_configurations:
if self.please_stop:
break
if f == 'audit': continue
(c, cfg) = f.split(os.sep)

component_path = self._find_component_path(c)
Expand Down Expand Up @@ -1644,7 +1630,6 @@ def cleanup(self):
for f in self.filtered_configurations:
if self.please_stop:
break
if f == 'audit': continue
(c, cfg) = f.split(os.sep)

o = self.configs[c][cfg]['options']
Expand Down Expand Up @@ -1700,7 +1685,6 @@ def cleanup(self):

# run on_cleanup plugins.
for f in self.filtered_configurations:
if f == 'audit': continue
if self.please_stop:
break

Expand Down Expand Up @@ -1867,7 +1851,6 @@ def config_show(self):
display the resulting settings for selected configurations.
"""
for f in self.filtered_configurations:
if f == 'audit': continue
(c, cfg) = f.split(os.sep)

if not 'options' in self.configs[c][cfg]:
Expand Down Expand Up @@ -1904,7 +1887,6 @@ def remove(self):
if self.please_stop:
break

if f == 'audit': continue
(c, cfg) = f.split(os.sep)

if not 'options' in self.configs[c][cfg]:
Expand Down Expand Up @@ -2003,8 +1985,7 @@ def sanity(self):

if pcount != 0:
self._find_missing_instances()
if not self.options.dry_run:
self._clean_missing_proc_state()
self._clean_missing_proc_state()
self._read_states()
self._resolve()
filtered_missing = []
Expand Down Expand Up @@ -2033,7 +2014,6 @@ def sanity(self):

# run on_sanity plugins.
for f in self.filtered_configurations:
if f == 'audit': continue
if self.please_stop:
break

Expand Down Expand Up @@ -2061,12 +2041,6 @@ def start(self):
pcount = 0
for f in self.filtered_configurations:

if f == 'audit':
if self.auditors == 0:
component_path = self._find_component_path(f)
self._launch_instance(component_path, f, None, 1)
continue

(c, cfg) = f.split(os.sep)

# skip posts that cannot run as daemons
Expand Down Expand Up @@ -2109,6 +2083,7 @@ def stop(self):
stop all of this users sr_ processes.
return 0 on success, non-zero on failure.
"""

self._clean_missing_proc_state()

if len(self.procs) == 0:
Expand All @@ -2118,21 +2093,9 @@ def stop(self):
print('sending SIGTERM ', end='', flush=True)
pcount = 0
fg_instances = set()
# kill sr_audit first, so it does not restart while others shutting down.
# https://github.com/MetPX/sarracenia/issues/210
pids_signalled=set([])

if ('audit' in self.filtered_configurations) and self.auditors > 0:
for p in self.procs:
if 'audit' in self.procs[p]['name']:
signal_pid(p, signal.SIGTERM)
pids_signalled |= set([p])
print('.', end='', flush=True)
pcount += 1

for f in self.filtered_configurations:
if f == 'audit': continue

(c, cfg) = f.split(os.sep)

# exclude foreground instances unless --dangerWillRobinson specified
Expand Down Expand Up @@ -2186,7 +2149,6 @@ def stop(self):

running_pids = 0
for f in self.filtered_configurations:
if f == 'audit': continue
(c, cfg) = f.split(os.sep)
# exclude foreground instances unless --dangerWillRobinson specified
if (not self.options.dangerWillRobinson) and self._cfg_running_foreground(c, cfg):
Expand All @@ -2204,14 +2166,7 @@ def stop(self):

print('doing SIGKILL this time')

if ('audit' in self.filtered_configurations) and self.auditors > 0:
for p in self.procs:
if 'audit' in p['name']:
signal_pid(p, signal.SIGKILL)
pids_signalled |= set([p])

for f in self.filtered_configurations:
if f == 'audit': continue
(c, cfg) = f.split(os.sep)
# exclude foreground instances unless --dangerWillRobinson specified
if (not self.options.dangerWillRobinson) and self._cfg_running_foreground(c, cfg):
Expand Down Expand Up @@ -2244,7 +2199,6 @@ def stop(self):
self._resolve()

for f in self.filtered_configurations:
if f == 'audit': continue
(c, cfg) = f.split(os.sep)
# exclude foreground instances unless --dangerWillRobinson specified
if (not self.options.dangerWillRobinson) and self._cfg_running_foreground(c, cfg):
Expand Down Expand Up @@ -2782,15 +2736,7 @@ def overview(self):
print('%-10s %-10s %-6s %3s %s' %
('---------', '-----', '-----', '---',
'------------------------------'))
if self.auditors == 1:
audst = "OK"
elif self.auditors > 1:
audst = "excess"
else:
audst = "absent"

print("%-10s %-10s %-6s %3d" %
('audit', 'running', audst, self.auditors))
configs_running = 0
for c in self.configs:

Expand Down

0 comments on commit d2c3422

Please sign in to comment.