TestServerMonitor.py 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. from __future__ import division
  2. import unittest
  3. from monitor import Env, DetailProcess, ProcessCounter, Sandbox
  4. import monitor
  5. import os
  6. class TestMonitorServer(unittest.TestCase):
  7. def test_Environment(self):
  8. """
  9. This test case is designed to test the existance of a resource set as an environment variable. This applies to files, folders (not values)
  10. """
  11. p = Env()
  12. p.init(['PATH','HOME','SHELL'])
  13. r = p.composite()
  14. value = r['value']
  15. self.assertTrue(value > 0 and value == 2/3)
  16. self.assertTrue(p.evaluate('PATH') == 0)
  17. def test_RunningProcess(self):
  18. p = DetailProcess()
  19. p.init(['rabbitmq-server','python','apache2'])
  20. r = p.composite()
  21. self.assertTrue(r)
  22. def test_ProcessCount(self):
  23. p= ProcessCounter()
  24. p.init(['foo','apache2','VBoxClient','rabbitmq-server','python'])
  25. r = p.composite()
  26. self.assertTrue( sum(r.values()) > 0 )
  27. self.assertTrue( r['foo'] == 0)
  28. def test_VirtualEnv(self):
  29. requirements_path = os.sep.join([os.environ['PYTHONPATH'],"..","requirements.txt"])
  30. sandbox_path = os.sep.join([os.environ['PYTHONPATH'],"..",'sandbox'])
  31. p = Sandbox()
  32. p.init({"sandbox":sandbox_path,"requirements":requirements_path})
  33. p.composite()
  34. def test_map(self):
  35. p = DetailProcess()
  36. p.init(['rabbitmq-server','python','apache2'])
  37. r ={"test": p.composite()}
  38. logs = [r,{"x-test":p.composite()}]
  39. key = "test"
  40. id = "memory_usage"
  41. def mapper(row,emit):
  42. [emit(item['label'],item) for item in row ]
  43. def reducer(values):
  44. end = len(values)-1
  45. beg = 0 if end < 100 else end - 100
  46. return values[beg:]
  47. #def reducer(values):
  48. mrh = monitor.mapreducer()
  49. logs = mrh.filter('test',logs)
  50. print mrh.run(logs,mapper,None)
  51. if __name__ == '__main__' :
  52. unittest.main()