TestServerMonitor.py 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. from __future__ import division
  2. import unittest
  3. from monitor import Env, DetailProcess, ProcessCounter, Sandbox, FileWatch
  4. import monitor
  5. import os
  6. import json
  7. # from utils.workers import Top, Learner
  8. #from multiprocessing import Lock
  9. from threading import Lock
  10. path = os.environ['MONITOR_CONFIG_PATH']
  11. f = open(path)
  12. CONFIG = json.loads( f.read())
  13. f.close()
  14. class TestMonitorServer(unittest.TestCase):
  15. def test_Environment(self):
  16. """
  17. This test case is designed to test the existance of a resource set as an environment variable. This applies to files, folders (not values)
  18. """
  19. p = Env()
  20. p.init(['PATH','HOME','SHELL'])
  21. r = p.composite()
  22. value = r['value']
  23. self.assertTrue(value > 0 and value >= (100*2/3),value)
  24. self.assertTrue(p.evaluate('PATH') == 0)
  25. def test_RunningProcess(self):
  26. p = DetailProcess()
  27. p.init(['kate','rabbitmq-server','python','apache2','firefox'])
  28. r = p.composite()
  29. #for row in r:
  30. # print row['label'],row['status'], sum([1 for item in r if item['label']==row['label']])
  31. self.assertTrue(r)
  32. def test_ProcessCount(self):
  33. p= ProcessCounter()
  34. p.init(['foo','apache2','VBoxClient','rabbitmq-server','python'])
  35. r = p.composite()
  36. self.assertTrue( sum(r.values()) > 0 )
  37. self.assertTrue( r['foo'] == 0)
  38. def test_VirtualEnv(self):
  39. requirements_path = os.sep.join([os.environ['PYTHONPATH'],"..","requirements.txt"])
  40. sandbox_path = os.sep.join([os.environ['PYTHONPATH'],"..",'sandbox'])
  41. p = Sandbox()
  42. p.init({"sandbox":sandbox_path,"requirements":requirements_path})
  43. p.composite()
  44. def test_StartLearner(self):
  45. pass
  46. def test_FileWatch(self):
  47. fw = FileWatch()
  48. fw.init(CONFIG['folders'])
  49. #r = fw.evaluate('/Users/steve/git/resume')
  50. fw.composite()
  51. if __name__ == '__main__' :
  52. unittest.main()