Exemplo n.º 1
0
    def setUp(self):
        self.pm = ProcessMatcher()

        path = os.path.join(ResourceService.BIN_PATH, "cms")
        self.w0_cmdlines = [
            "/usr/bin/python3 %sWorker 0" % path,
            "/usr/bin/python3 %sWorker" % path,
            "python3 %sWorker 0 -c 1" % path,
            "python3 %sWorker -c 1" % path,
            "python3 %sWorker -c 1 0" % path,
            "/usr/bin/env python3 %sWorker 0" % path,
            "/usr/bin/env python3 %sWorker" % path,
            "/usr/bin/env python3 %sWorker 0 -c 1" % path,
            "/usr/bin/env python3 %sWorker -c 1" % path,
            "/usr/bin/env python3 %sWorker -c 1 0" % path,
            sys.executable + " %sWorker" % path,
            sys.executable + " %sWorker 0" % path,
            sys.executable + " %sWorker 0 -c 1" % path,
            sys.executable + " %sWorker -c 1" % path,
            sys.executable + " %sWorker -c 1 0" % path,
        ]
        self.bad_cmdlines = [
            "ps",
            "less %sWorker 0" % path,
            "less /usr/bin/python3 %sWorker 0" % path,
            "/usr/bin/python3 %sWorker 1" % path,
            "/usr/bin/python3 %sAdminWebServer 0" % path,
        ]
        self.w0 = ServiceCoord("Worker", 0)
Exemplo n.º 2
0
 def setUp(self):
     self.pm = ProcessMatcher()
     self.w0_cmdlines = [
         "/usr/bin/python2 cmsWorker 0",
         "/usr/bin/python2 cmsWorker",
         "python2 cmsWorker 0 -c 1",
         "python2 cmsWorker -c 1",
         "python2 cmsWorker -c 1 0",
         "/usr/bin/env python2 cmsWorker 0",
         "/usr/bin/env python2 cmsWorker",
         "/usr/bin/env python2 cmsWorker 0 -c 1",
         "/usr/bin/env python2 cmsWorker -c 1",
         "/usr/bin/env python2 cmsWorker -c 1 0",
         sys.executable + " cmsWorker",
         sys.executable + " cmsWorker 0",
         sys.executable + " cmsWorker 0 -c 1",
         sys.executable + " cmsWorker -c 1",
         sys.executable + " cmsWorker -c 1 0",
     ]
     self.bad_cmdlines = [
         "ps",
         "less cmsWorker 0",
         "less /usr/bin/python2 cmsWorker 0",
         "/usr/bin/python2 cmsWorker 1",
         "/usr/bin/python2 cmsAdminWebServer 0",
     ]
     self.w0 = ServiceCoord("Worker", 0)
Exemplo n.º 3
0
    def setUp(self):
        self.pm = ProcessMatcher()

        path = os.path.join(ResourceService.BIN_PATH, "cms")
        self.w0_cmdlines = [
            "/usr/bin/python3 %sWorker 0" % path,
            "/usr/bin/python3 %sWorker" % path,
            "python3 %sWorker 0 -c 1" % path,
            "python3 %sWorker -c 1" % path,
            "python3 %sWorker -c 1 0" % path,
            "/usr/bin/env python3 %sWorker 0" % path,
            "/usr/bin/env python3 %sWorker" % path,
            "/usr/bin/env python3 %sWorker 0 -c 1" % path,
            "/usr/bin/env python3 %sWorker -c 1" % path,
            "/usr/bin/env python3 %sWorker -c 1 0" % path,
            sys.executable + " %sWorker" % path,
            sys.executable + " %sWorker 0" % path,
            sys.executable + " %sWorker 0 -c 1" % path,
            sys.executable + " %sWorker -c 1" % path,
            sys.executable + " %sWorker -c 1 0" % path,
        ]
        self.bad_cmdlines = [
            "ps",
            "less %sWorker 0" % path,
            "less /usr/bin/python3 %sWorker 0" % path,
            "/usr/bin/python3 %sWorker 1" % path,
            "/usr/bin/python3 %sAdminWebServer 0" % path,
        ]
        self.w0 = ServiceCoord("Worker", 0)
Exemplo n.º 4
0
class TestProcessMatcher(unittest.TestCase):
    def setUp(self):
        self.pm = ProcessMatcher()

        path = os.path.join(ResourceService.BIN_PATH, "cms")
        self.w0_cmdlines = [
            "/usr/bin/python3 %sWorker 0" % path,
            "/usr/bin/python3 %sWorker" % path,
            "python3 %sWorker 0 -c 1" % path,
            "python3 %sWorker -c 1" % path,
            "python3 %sWorker -c 1 0" % path,
            "/usr/bin/env python3 %sWorker 0" % path,
            "/usr/bin/env python3 %sWorker" % path,
            "/usr/bin/env python3 %sWorker 0 -c 1" % path,
            "/usr/bin/env python3 %sWorker -c 1" % path,
            "/usr/bin/env python3 %sWorker -c 1 0" % path,
            sys.executable + " %sWorker" % path,
            sys.executable + " %sWorker 0" % path,
            sys.executable + " %sWorker 0 -c 1" % path,
            sys.executable + " %sWorker -c 1" % path,
            sys.executable + " %sWorker -c 1 0" % path,
        ]
        self.bad_cmdlines = [
            "ps",
            "less %sWorker 0" % path,
            "less /usr/bin/python3 %sWorker 0" % path,
            "/usr/bin/python3 %sWorker 1" % path,
            "/usr/bin/python3 %sAdminWebServer 0" % path,
        ]
        self.w0 = ServiceCoord("Worker", 0)

    @staticmethod
    def _get_all_processes_ret(cmdlines_and_maybe_procs):
        ret = []
        for c in cmdlines_and_maybe_procs:
            if isinstance(c, tuple):
                ret.append((c[0].split(), c[1]))
            else:
                ret.append((c.split(), "base"))
        return ret

    def test_find_works(self):
        for c in self.w0_cmdlines:
            with patch.object(ProcessMatcher, '_get_all_processes') as f:
                f.return_value = (TestProcessMatcher._get_all_processes_ret(
                    self.bad_cmdlines + [(c, "good")] + self.bad_cmdlines))
                self.assertEqual(self.pm.find(self.w0), "good")

    def test_find_fails(self):
        service = ServiceCoord("EvaluationService", 0)
        for c in self.w0_cmdlines:
            with patch.object(ProcessMatcher, '_get_all_processes') as f:
                f.return_value = (TestProcessMatcher._get_all_processes_ret(
                    self.bad_cmdlines + [(c, "good")] + self.bad_cmdlines))
                self.assertIsNone(self.pm.find(service))

    def test_get_all_processes_is_called_once(self):
        with patch.object(ProcessMatcher, '_get_all_processes') as f:
            f.return_value = (
                TestProcessMatcher._get_all_processes_ret(self.w0_cmdlines +
                                                          self.bad_cmdlines))
            self.assertEqual(self.pm.find(self.w0), "base")
            self.assertEqual(self.pm.find(self.w0), "base")
            self.assertEqual(f.call_count, 1)
Exemplo n.º 5
0
class TestProcessMatcher(unittest.TestCase):

    def setUp(self):
        self.pm = ProcessMatcher()
        self.w0_cmdlines = [
            "/usr/bin/python2 cmsWorker 0",
            "/usr/bin/python2 cmsWorker",
            "python2 cmsWorker 0 -c 1",
            "python2 cmsWorker -c 1",
            "python2 cmsWorker -c 1 0",
            "/usr/bin/env python2 cmsWorker 0",
            "/usr/bin/env python2 cmsWorker",
            "/usr/bin/env python2 cmsWorker 0 -c 1",
            "/usr/bin/env python2 cmsWorker -c 1",
            "/usr/bin/env python2 cmsWorker -c 1 0",
            sys.executable + " cmsWorker",
            sys.executable + " cmsWorker 0",
            sys.executable + " cmsWorker 0 -c 1",
            sys.executable + " cmsWorker -c 1",
            sys.executable + " cmsWorker -c 1 0",
        ]
        self.bad_cmdlines = [
            "ps",
            "less cmsWorker 0",
            "less /usr/bin/python2 cmsWorker 0",
            "/usr/bin/python2 cmsWorker 1",
            "/usr/bin/python2 cmsAdminWebServer 0",
        ]
        self.w0 = ServiceCoord("Worker", 0)

    @staticmethod
    def _get_all_processes_ret(cmdlines_and_maybe_procs):
        ret = []
        for c in cmdlines_and_maybe_procs:
            if isinstance(c, tuple):
                ret.append((c[0].split(), c[1]))
            else:
                ret.append((c.split(), "base"))
        return ret

    def test_find_works(self):
        for c in self.w0_cmdlines:
            with patch.object(ProcessMatcher, '_get_all_processes') as f:
                f.return_value = (TestProcessMatcher._get_all_processes_ret(
                    self.bad_cmdlines + [(c, "good")] + self.bad_cmdlines))
                self.assertEquals(self.pm.find(self.w0), "good")

    def test_find_fails(self):
        service = ServiceCoord("EvaluationService", 0)
        for c in self.w0_cmdlines:
            with patch.object(ProcessMatcher, '_get_all_processes') as f:
                f.return_value = (TestProcessMatcher._get_all_processes_ret(
                    self.bad_cmdlines + [(c, "good")] + self.bad_cmdlines))
                self.assertIsNone(self.pm.find(service))

    def test_get_all_processes_is_called_once(self):
        with patch.object(ProcessMatcher, '_get_all_processes') as f:
            f.return_value = (TestProcessMatcher._get_all_processes_ret(
                self.w0_cmdlines + self.bad_cmdlines))
            self.assertEqual(self.pm.find(self.w0), "base")
            self.assertEqual(self.pm.find(self.w0), "base")
            self.assertEqual(f.call_count, 1)