def _base_negative_testcase(self, cdh_response_mock, return_value, msg, col, service, postfix=None): if not postfix: postfix = "" cdh_response_mock.return_value = return_value exc = (base_health.YellowHealthError if col == 'YELLOW' else base_health.RedHealthError) with testtools.ExpectedException(exc): try: pr = health.HealthStatusProvider(mock.Mock(), mock.Mock()) health.ServiceHealthCheck(mock.Mock(), provider=pr, service=service).check_health() except Exception as e: msg = "%s%s" % (msg, postfix) all_message = "Cluster health is %(col)s. Reason: %(msg)s" % { 'col': col, 'msg': msg } self.assertEqual(all_message, six.text_type(e)) raise
def test_check_health_availability(self): cluster = mock.Mock(plugin_name='cdh', hadoop_version='5.11.0') self.assertTrue( health.ClouderaManagerHealthCheck(cluster, mock.Mock()).is_available()) cluster = mock.Mock(plugin_name='cdh', hadoop_version='5.11.0') self.assertTrue( health.ServiceHealthCheck(cluster, mock.Mock(), mock.Mock()).is_available())
def test_health_calculation(self, important_stuff, cdh_response): important_stuff.return_value = ['yarn01', 'hdfs01', 'oozie01'] cdh_response.return_value = { 'yarn01': { 'summary': 'GOOD', }, 'hdfs01': { 'summary': 'GOOD', } } msg = ("Cloudera Manager has responded that service is in " "the %s state") pr = health.HealthStatusProvider(mock.Mock(), mock.Mock()) self.assertEqual( msg % 'GOOD', health.ServiceHealthCheck( mock.Mock(), provider=pr, service='hdfs01').check_health()) self._base_negative_testcase(cdh_response, { 'yarn01': {'summary': 'GOOD'}, 'hdfs01': {'summary': 'BAD'} }, msg % 'BAD', 'RED', service='hdfs01') self._base_negative_testcase(cdh_response, { 'yarn01': {'summary': 'CONCERNING'}, 'hdfs01': {'summary': 'BAD'} }, msg % 'CONCERNING', 'YELLOW', service='yarn01') # not important service, only yellow health self._base_negative_testcase(cdh_response, { 'yarn01': {'summary': 'CONCERNING'}, 'hdfs01': {'summary': 'BAD'}, 'some_service01': {'summary': 'BAD'} }, msg % 'BAD', 'YELLOW', service='some_service01') self._base_negative_testcase(cdh_response, { 'yarn01': {'summary': 'UNKNOWN_STATE'}, 'hdfs01': {'summary': 'BAD'}, 'some_service01': {'summary': 'BAD'} }, msg % 'UNKNOWN_STATE', 'RED', service='yarn01') # test additional info postfix = (". The following checks did not " "pass: SUPER_HEALTH_CHECK - BAD state") self._base_negative_testcase(cdh_response, { 'yarn01': {'summary': 'UNKNOWN_STATE'}, 'hdfs01': {'summary': 'BAD', 'checks': [ {'name': 'SUPER_HEALTH_CHECK', 'summary': 'BAD'}]}, 'some_service01': {'summary': 'BAD'} }, msg % 'BAD', 'RED', service='hdfs01', postfix=postfix)