Enabling the classes to function as visitors

master
Steve L. Nyemba 8 years ago
parent ebca0eab60
commit 96d6a0e7d9

@ -1,7 +1,9 @@
""" """
This program is designed to inspect an application environment This program is designed to inspect an application environment
This program should only be run on unix friendly systems This program should only be run on unix friendly systems
We enable the engines to be able to run a several configurations
Similarly to what a visitor design-pattern would do
""" """
from __future__ import division from __future__ import division
import os import os
@ -20,8 +22,9 @@ class Analysis:
The class returns a quantifiable assessment of the environment variables (expected 100%) The class returns a quantifiable assessment of the environment variables (expected 100%)
""" """
class Env(Analysis): class Env(Analysis):
def __init__(self,values): def __init__(self):
Analysis.__init__(self) Analysis.__init__(self)
def init(self,values):
self.values = values self.values = values
""" """
This function evaluate the validity of an environment variable by returning a 1 or 0 (computable) This function evaluate the validity of an environment variable by returning a 1 or 0 (computable)
@ -55,8 +58,9 @@ class Env(Analysis):
return {"value":value,"missing":missing} return {"value":value,"missing":missing}
class Sandbox(Analysis): class Sandbox(Analysis):
def __init__(self,conf): def __init__(self):
Analysis.__init__(self) Analysis.__init__(self)
def init(self,conf):
self.sandbox_path = conf['sandbox'] self.sandbox_path = conf['sandbox']
self.requirements_path = conf['requirements'] self.requirements_path = conf['requirements']
def get_requirements (self): def get_requirements (self):
@ -91,8 +95,9 @@ class Sandbox(Analysis):
The class provides a quantifiable measure of how many processes it found over all The class provides a quantifiable measure of how many processes it found over all
""" """
class ProcessCounter(Analysis): class ProcessCounter(Analysis):
def __init__(self,names): def __init__(self):
Analysis.__init__(self) Analysis.__init__(self)
def init(self,names):
self.names = names self.names = names
def evaluate(self,name): def evaluate(self,name):
cmd = "".join(['ps -eo comm |grep ',name,' |wc -l']) cmd = "".join(['ps -eo comm |grep ',name,' |wc -l'])
@ -112,7 +117,9 @@ class ProcessCounter(Analysis):
This class returns an application's both memory and cpu usage This class returns an application's both memory and cpu usage
""" """
class DetailProcess(Analysis): class DetailProcess(Analysis):
def __init__(self,names): def __init__(self):
Analysis.__init__(self)
def init (self,names):
self.names = names; self.names = names;
def evaluate(self,name) : def evaluate(self,name) :
cmd = "ps -eo pmem,pcpu,vsize,comm|grep :app$" cmd = "ps -eo pmem,pcpu,vsize,comm|grep :app$"
@ -122,8 +129,11 @@ class DetailProcess(Analysis):
r = [] r = []
for row in ostream : for row in ostream :
#
row = [float(value) for value in row if value.strip() not in ['',name]] +[name] # Though the comm should only return the name as specified,
# On OSX it has been observed that the fully qualified path is sometimes returned (go figure)
#
row = [float(value) for value in row if value.strip() != '' and name not in value ] +[name]
r.append(row) r.append(row)
return r return r
def format(self,row): def format(self,row):
@ -141,41 +151,3 @@ class DetailProcess(Analysis):
#return [{"memory_usage":row[0],"cpu_usage":row[1],"memory_available":row[2]/1000,"label":row[3]} for row in ma] #return [{"memory_usage":row[0],"cpu_usage":row[1],"memory_available":row[2]/1000,"label":row[3]} for row in ma]
return ma return ma
"""
This class will require
"""
class QueueServer(Analysis):
def __init__(self,conf):
Analysis.__init__(self)
pass
def is_running(self):
p = Process(['rabbitmq-server'])
return p.composite()
def has_virtualhost(self,name):
return 0
def has_user(self,uid):
return 0
def composite(self):
if self.is_running() :
pass
else:
return [0,0,0]
"""
Normalization will be required for the data produced by this class
"""
class DatabaseServer(Analysis):
def __init__(self,conf):
Analysis.__init__(self)
pass
def has_table(self,name):
pass
def has_fields(self,table,fields):
pass
def has_data(self,table):
pass
"""
This function will return the number of test-cases of the last build.
The use of the returned number will have to be normalized if used in a dataset.
"""
#class TestCaseCount(Analysis):
#pass

@ -8,20 +8,23 @@ class TestMonitorServer(unittest.TestCase):
""" """
This test case is designed to test the existance of a resource set as an environment variable. This applies to files, folders (not values) This test case is designed to test the existance of a resource set as an environment variable. This applies to files, folders (not values)
""" """
p = Env(['PATH','HOME','SHELL']) p = Env()
p.init(['PATH','HOME','SHELL'])
r = p.composite() r = p.composite()
value = r['value'] value = r['value']
self.assertTrue(value > 0 and value == 2/3) self.assertTrue(value > 0 and value == 2/3)
self.assertTrue(p.evaluate('PATH') == 0) self.assertTrue(p.evaluate('PATH') == 0)
def test_RunningProcess(self): def test_RunningProcess(self):
p = DetailProcess(['rabbitmq-server','python','apache2']) p = DetailProcess()
p.init(['rabbitmq-server','python','apache2'])
r = p.composite() r = p.composite()
print r print r
self.assertTrue(r) self.assertTrue(r)
def test_ProcessCount(self): def test_ProcessCount(self):
p= ProcessCounter(['apache2','VBoxClient','rabbitmq-server','foo']) p= ProcessCounter()
p.init(['foo','apache2','VBoxClient','rabbitmq-server','python'])
r = p.composite() r = p.composite()
self.assertTrue( sum(r.values()) > 0 ) self.assertTrue( sum(r.values()) > 0 )
@ -29,7 +32,8 @@ class TestMonitorServer(unittest.TestCase):
def test_VirtualEnv(self): def test_VirtualEnv(self):
requirements_path = os.sep.join([os.environ['PYTHONPATH'],"..","requirements.txt"]) requirements_path = os.sep.join([os.environ['PYTHONPATH'],"..","requirements.txt"])
sandbox_path = os.sep.join([os.environ['PYTHONPATH'],"..",'sandbox']) sandbox_path = os.sep.join([os.environ['PYTHONPATH'],"..",'sandbox'])
p = Sandbox({"sandbox":sandbox_path,"requirements":requirements_path}) p = Sandbox()
p.init({"sandbox":sandbox_path,"requirements":requirements_path})
print p.composite() print p.composite()
if __name__ == '__main__' : if __name__ == '__main__' :
unittest.main() unittest.main()
Loading…
Cancel
Save