Skip to content

Added Monitoring Script Unit tests #10

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 24 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
2f69dc0
Added Monitoring Script Unit tests
asm582 Oct 20, 2014
4106d6f
Added Check_ip_address.r2py
asm582 Oct 21, 2014
b91e2ee
make changes to the file as suggested
asm582 Oct 22, 2014
be4319b
Removed additional checks and modified IP checks
asm582 Oct 22, 2014
c785bdf
Added tests directory and made changes to file names
asm582 Oct 22, 2014
57010c2
Delete ut_monitor_monitor_processes.py
asm582 Oct 22, 2014
4360a2e
Delete ut_monitor_monitor_processes_clearing_house_backend_daemon.py
asm582 Oct 22, 2014
b417a61
Delete ut_monitor_monitor_processes_clearing_house_check_active_db_no…
asm582 Oct 22, 2014
1333493
Delete ut_monitor_monitor_processes_clearing_house_lockserver_daemon.py
asm582 Oct 22, 2014
fdbdcef
Delete ut_monitor_monitor_processes_clearing_house_transition_canonic…
asm582 Oct 22, 2014
5af4686
Delete ut_monitor_monitor_processes_clearing_house_transition_donatio…
asm582 Oct 22, 2014
06d5c39
Delete ut_monitor_monitor_processes_clearing_house_transition_oneperc…
asm582 Oct 22, 2014
7531aeb
Delete ut_monitor_monitor_processes_clearing_house_transition_twoperc…
asm582 Oct 22, 2014
70381b5
Delete ut_monitor_send_gmail.py
asm582 Oct 22, 2014
5c37d35
Changed to avoid unit test hang
asm582 Oct 26, 2014
021200e
Changes made to avoid unit test hang
asm582 Oct 26, 2014
9c97f47
Changes made to avoid unit test hang
asm582 Oct 26, 2014
48f279f
Changes made to avoid unit test hang
asm582 Oct 26, 2014
f41b4f9
Changes made to avoid unit test hang
asm582 Oct 26, 2014
5b78ec5
Changes made to avoid unit test hang
asm582 Oct 26, 2014
3c0a584
Changes made to avoid unit test hang
asm582 Oct 26, 2014
8574522
Changes made to avoid unit test hang
asm582 Oct 26, 2014
4a17640
Added Unit test to test check_ip_address.r2py
asm582 Oct 27, 2014
e044037
Changes made to be used as library file
asm582 Oct 27, 2014
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 64 additions & 0 deletions check_ip_address.r2py
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
def is_valid_ip_address(ipaddr):
"""
<Purpose>
Determines if ipaddr is a valid IP address.
0.X and 224-255.X addresses are not allowed.
Additionally, 192.168.0.0 is not allowed.

<Arguments>
ipaddr: String to check for validity. (It will check that this is a string).

<Returns>
True if a valid IP, False otherwise.
"""
# Argument must be of the string type
if not type(ipaddr) == str:
log("IP address is not string type")
return False

if ipaddr == '192.168.0.0':
log("IP address 192.168.0.0 is not allowed!!")
return False

# A valid IP should have 4 segments, explode on the period
octets = ipaddr.split(".")

# Check that we have 4 parts
if len(octets) != 4:
return False

# Check that each segment is a number between 0 and 255 inclusively.
for octet in octets:
# Attempt to convert to an integer
try:
ipnumber = int(octet)
except ValueError:
# There was an error converting to an integer, not an IP
log("IP address should have integer value!")
return False

# IP addresses octets must be between 0 and 255
if not (ipnumber >= 0 and ipnumber <= 255):
log("IP address should be in range of 0-255")
return False

# should not have a ValueError (I already checked)
firstipnumber = int(octets[0])

# IP addresses with the first octet 0 refer to all local IPs. These are
# not allowed
if firstipnumber == 0:
log("First Octet of IP address cannot be zero!")
return False

# IP addresses with the first octet >=224 are either Multicast or reserved.
# These are not allowed
if firstipnumber >= 224:
log("Multicast address are not allowed to be used!")
return False

# At this point, assume the IP is valid
log("The IP address mentioned is valid!")
return True


25 changes: 25 additions & 0 deletions tests/ut_monitor_check_advertiseserver.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import sys
import os
import subprocess
import monitor_processes

#pragma out All critical processes on -seattle are up and running

#Creating dummy advertiseserver process
advertiseserver_file=open("advertiseserver.py","w")
advertiseserver_file.write('raw_input("enter something")')
advertiseserver_file.close()


proc = subprocess.Popen([sys.executable, 'advertiseserver.py'])


monitor_process_list = ['python advertiseserver.py']
command_list =["ps auwx | grep python | grep -v grep"]
machine_name ='-seattle'
monitor_output = monitor_processes.monitor_processes(monitor_process_list, command_list, machine_name)
#killing to avoid script hang
proc.kill()
expected_out = "All critical processes on seattle are up and running"


21 changes: 21 additions & 0 deletions tests/ut_monitor_check_backenddaemon.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import sys
import subprocess
import monitor_processes

#pragma out All critical processes on -seattleclearinghouse are up and running

"""
Trying to build dummy backend_daemon.py process
in the local machine for unit test
"""
file=open("backend_daemon.py","w")
file.write('raw_input("enter something")')
file.close()
proc = subprocess.Popen([sys.executable, 'backend_daemon.py'])

monitor_process_list=['python backend_daemon.py']
command_list = ["ps auwx | grep python| grep -v grep"]
machine_name = "-seattleclearinghouse"
monitor_processes.monitor_processes(monitor_process_list, command_list, machine_name)
proc.kill()
expected_out = "All critical processes on seattleclearinghouse are up and running"
22 changes: 22 additions & 0 deletions tests/ut_monitor_check_checkactivedbnodes.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import sys
import subprocess
import monitor_processes

#pragma out All critical processes on -seattleclearinghouse are up and running

"""
Trying to build dummy check_active_db_nodes.py process
in the local machine for unit test
"""
file=open("check_active_db_nodes.py","w")
file.write('raw_input("enter something")')
file.close()
proc = subprocess.Popen([sys.executable, 'check_active_db_nodes.py'])

monitor_process_list=['python check_active_db_nodes.py']
command_list = ["ps auwx | grep python| grep -v grep"]
machine_name = "-seattleclearinghouse"
monitor_processes.monitor_processes(monitor_process_list, command_list, machine_name)
#killing to avoid script hang
proc.kill()
expected_out = "All critical processes on -seattleclearinghouse are up and running"
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import sys
import subprocess
import monitor_processes
#pragma out All critical processes on -seattleclearinghouse are up and running

"""
Trying to build dummy transition_onepercentmanyevents_to_canonical.py process
in the local machine for unit test
"""
file=open("transition_onepercentmanyevents_to_canonical.py","w")
file.write('raw_input("enter something")')
file.close()
proc = subprocess.Popen([sys.executable, 'transition_onepercentmanyevents_to_canonical.py'])

monitor_process_list=['python transition_onepercentmanyevents_to_canonical.py']
command_list = ["ps auwx | grep python| grep -v grep"]
machine_name = "-seattleclearinghouse"
monitor_processes.monitor_processes(monitor_process_list, command_list, machine_name)
#killing to avoid script hang
proc.kill()

expected_out = "All critical processes on -seattleclearinghouse are up and running"
21 changes: 21 additions & 0 deletions tests/ut_monitor_check_lockserverdaemon.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import sys
import subprocess
import monitor_processes

#pragma out All critical processes on -seattleclearinghouse are up and running

"""
Trying to build dummy lockserver_daemon.py process
in the local machine for unit test
"""
file=open("lockserver_daemon.py","w")
file.write('raw_input("enter something")')
file.close()
proc = subprocess.Popen([sys.executable, 'lockserver_daemon.py'])

monitor_process_list=['python lockserver_daemon.py']
command_list = ["ps auwx | grep python| grep -v grep"]
machine_name = "-seattleclearinghouse"
monitor_processes.monitor_processes(monitor_process_list, command_list, machine_name)
proc.kill()
expected_out = "All critical processes on seattleclearinghouse are up and running"
23 changes: 23 additions & 0 deletions tests/ut_monitor_check_transitioncanonicaltotwopercent.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import sys
import subprocess
import monitor_processes

#pragma out All critical processes on -seattleclearinghouse are up and running

"""
Trying to build dummy transition_canonical_to_twopercent.py process
in the local machine for unit test
"""
file=open("transition_canonical_to_twopercent.py","w")
file.write('raw_input("enter something")')
file.close()
proc = subprocess.Popen([sys.executable, 'transition_canonical_to_twopercent.py'])

monitor_process_list=['python transition_canonical_to_twopercent.py']
command_list = ["ps auwx | grep python| grep -v grep"]
machine_name = "-seattleclearinghouse"
monitor_processes.monitor_processes(monitor_process_list, command_list, machine_name)
#killing to avoid script hang
proc.kill()

expected_out = "All critical processes on -seattleclearinghouse are up and running"
19 changes: 19 additions & 0 deletions tests/ut_monitor_check_transitiondonationtocanonical.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import sys
import subprocess
import monitor_processes

#pragma out All critical processes on -seattleclearinghouse are up and running

"""
Trying to build dummy transition_donation_to_canonical.py process
in the local machine for unit test
"""

monitor_process_list=['transition_donation_to_canonical.py']
command_list = ["ps auwx | grep python| grep -v grep"]
machine_name = "-seattleclearinghouse"
monitor_processes.monitor_processes(monitor_process_list, command_list, machine_name)
#killing to avoid script hang
proc.kill()

expected_out = "All critical processes on -seattleclearinghouse are up and running"
22 changes: 22 additions & 0 deletions tests/ut_monitor_check_transitiontwopercenttotwopercent.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import sys
import subprocess
import monitor_processes

#pragma out All critical processes on -seattleclearinghouse are up and running

"""
Trying to build dummy transition_twopercent_to_twopercent.py process
in the local machine for unit test
"""
file=open("transition_twopercent_to_twopercent.py","w")
file.write('raw_input("enter something")')
file.close()
proc = subprocess.Popen([sys.executable, 'transition_twopercent_to_twopercent.py'])

monitor_process_list=['python transition_twopercent_to_twopercent.py']
command_list = ["ps auwx | grep python| grep -v grep"]
machine_name = "-seattleclearinghouse"
monitor_processes.monitor_processes(monitor_process_list, command_list, machine_name)
#killing to avoid script hang
proc.kill()
expected_out = "All critical processes on seattleclearinghouse are up and running"
14 changes: 14 additions & 0 deletions tests/ut_monitor_sendgmail.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import sys
import subprocess
import send_gmail

#pragma out loaded gmail info


def main():
gmail_file_name = "/home/abhishek/monitor_script/seattle_gmail_info"
result = send_gmail.init_gmail('[email protected]','testmail')


if __name__ == "__main__":
main()
11 changes: 11 additions & 0 deletions tests/ut_seattlelib_check_ip_address.r2py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#pragma out The IP address mentioned is valid!

"""
Testing whether check_ip_address.r2py works correctly, when passed
well formatted Ip returns true with a log message
"""
from repyportability import *
add_dy_support(locals())
checkipaddr = dy_import_module('check_ip_address.r2py')
#added dummy IP value
checkipaddr.is_valid_ip_address('192.168.1.1')