Esempio n. 1
0
    def testActionInfo(self):
        """Test the ActionInfo RPC to collect information on a repair action."""
        cfm = manager.CheckFileManager(checkdir=CHECKDIR)

        hcobj = TestHealthCheckMultipleActions()
        hcname = hcobj.__class__.__name__
        actions = [
            hcobj.NoParams, hcobj.PositionalParams, hcobj.DefaultParams,
            hcobj.MixedParams
        ]

        cfm.service_checks[TEST_SERVICE_NAME] = {hcname: (TEST_MTIME, hcobj)}

        unhealthy_status = manager.SERVICE_STATUS(TEST_SERVICE_NAME, False, [
            manager.HEALTHCHECK_STATUS(hcname, False, 'Always fails', actions)
        ])
        cfm.service_states[TEST_SERVICE_NAME] = unhealthy_status

        # Test ActionInfo when the action has no parameters.
        expect = manager.ACTION_INFO('NoParams', 'NoParams Action.', [], {})
        self.assertEquals(
            expect, cfm.ActionInfo(TEST_SERVICE_NAME, hcname, 'NoParams'))

        # Test ActionInfo when the action has only positional parameters.
        expect = manager.ACTION_INFO('PositionalParams',
                                     'PositionalParams Action.',
                                     ['x', 'y', 'z'], {})
        self.assertEquals(
            expect,
            cfm.ActionInfo(TEST_SERVICE_NAME, hcname, 'PositionalParams'))

        # Test ActionInfo when the action has only default parameters.
        expect = manager.ACTION_INFO('DefaultParams', 'DefaultParams Action.',
                                     [], {
                                         'x': 1,
                                         'y': 2,
                                         'z': 3
                                     })
        self.assertEquals(
            expect, cfm.ActionInfo(TEST_SERVICE_NAME, hcname, 'DefaultParams'))

        # Test ActionInfo when the action has positional and default parameters.
        expect = manager.ACTION_INFO('MixedParams', 'MixedParams Action.',
                                     ['x', 'y'], {'z': 1})
        self.assertEquals(
            expect, cfm.ActionInfo(TEST_SERVICE_NAME, hcname, 'MixedParams'))
Esempio n. 2
0
    def __init__(self):
        failed_check = manager.HEALTHCHECK_STATUS('hc1', False, 'Failed', [])

        self.service_statuses = [
            manager.SERVICE_STATUS('service1', True, []),
            manager.SERVICE_STATUS('service2', False, [failed_check])
        ]

        self.action_info = manager.ACTION_INFO('DummyAction', '', ['x'], {})
Esempio n. 3
0
    def testActionInfoServiceNonExistent(self):
        """Test the ActionInfo RPC when the service does not exist."""
        cfm = manager.CheckFileManager(checkdir=CHECKDIR)

        self.assertFalse(TEST_SERVICE_NAME in cfm.service_states)

        expect = manager.ACTION_INFO('test', 'Service not recognized.', [], {})
        result = cfm.ActionInfo(TEST_SERVICE_NAME, 'test', 'test')
        self.assertEquals(expect, result)
Esempio n. 4
0
    def testActionInfoServiceHealthy(self):
        """Test the ActionInfo RPC when the service is healthy."""
        cfm = manager.CheckFileManager(checkdir=CHECKDIR)

        healthy_status = manager.SERVICE_STATUS(TEST_SERVICE_NAME, True, [])
        cfm.service_states[TEST_SERVICE_NAME] = healthy_status

        expect = manager.ACTION_INFO('test', 'Service is healthy.', [], {})
        result = cfm.ActionInfo(TEST_SERVICE_NAME, 'test', 'test')
        self.assertEquals(expect, result)
Esempio n. 5
0
 def testMapActionInfoToDict(self):
     """Test mapping a manager.ACTION_INFO to a dict."""
     actioninfo = manager.ACTION_INFO('test', 'test', [1], {'a': 1})
     expect = {
         'action': 'test',
         'info': 'test',
         'args': [1],
         'kwargs': {
             'a': 1
         }
     }
     self.assertEquals(expect, manager.MapActionInfoToDict(actioninfo))
Esempio n. 6
0
  def testActionInfoActionNonExistent(self):
    """Test the ActionInfo RPC when the action does not exist."""
    cfm = manager.CheckFileManager(checkdir=CHECKDIR)

    hcobj = TestHealthCheckUnhealthy()
    cfm.service_checks[TEST_SERVICE_NAME] = {
        hcobj.__class__.__name__: (TEST_MTIME, hcobj)}

    unhealthy_status = manager.SERVICE_STATUS(
        TEST_SERVICE_NAME, False,
        [manager.HEALTHCHECK_STATUS(hcobj.__class__.__name__,
                                    False, 'Always fails', [hcobj.Repair])])
    cfm.service_states[TEST_SERVICE_NAME] = unhealthy_status

    expect = manager.ACTION_INFO('test', 'Action not recognized.', [], {})
    result = cfm.ActionInfo(TEST_SERVICE_NAME, hcobj.__class__.__name__,
                            'test')
    self.assertEquals(expect, result)