Coverage for osm_policy_module/cmd/policy_module_healthcheck.py: 0%

30 statements  

« prev     ^ index     » next       coverage.py v6.4.1, created at 2024-06-30 08:29 +0000

1# Copyright 2018 Whitestack, LLC 

2# ************************************************************* 

3 

4# This file is part of OSM Monitoring module 

5# All Rights Reserved to Whitestack, LLC 

6 

7# Licensed under the Apache License, Version 2.0 (the "License"); you may 

8# not use this file except in compliance with the License. You may obtain 

9# a copy of the License at 

10 

11# http://www.apache.org/licenses/LICENSE-2.0 

12 

13# Unless required by applicable law or agreed to in writing, software 

14# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 

15# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 

16# License for the specific language governing permissions and limitations 

17# under the License. 

18 

19# For those usages not covered by the Apache License, Version 2.0 please 

20# contact: bdiaz@whitestack.com or glavado@whitestack.com 

21## 

22import argparse 

23import logging 

24import subprocess 

25import sys 

26import os 

27 

28log = logging.getLogger(__name__) 

29 

30 

31def main(): 

32 parser = argparse.ArgumentParser(prog="osm-policy-healthcheck") 

33 parser.add_argument("--config-file", nargs="?", help="POL configuration file") 

34 # args = parser.parse_args() 

35 # cfg = Config(args.config_file) 

36 

37 if not _processes_running(): 

38 sys.exit(1) 

39 sys.exit(0) 

40 

41 

42def _processes_running(): 

43 def _contains_process(processes, process_name): 

44 for row in processes: 

45 if process_name in row: 

46 return True 

47 return False 

48 

49 processes_to_check = ["osm-policy-agent"] 

50 ps = subprocess.Popen(["ps", "aux"], stdout=subprocess.PIPE).communicate()[0] 

51 processes_running = ps.decode().split("\n") 

52 for p in processes_to_check: 

53 if not _contains_process(processes_running, p): 

54 log.error("Process %s not running!" % p) 

55 return False 

56 

57 # Check if process is running properly (listening to kafka bus) 

58 if os.path.exists("/tmp/osm_pol_agent_health_flag"): 

59 return True 

60 else: 

61 return False 

62 

63 

64if __name__ == "__main__": 

65 main()