def test_remove_report_crd_success(caplog): fake_crd_report = MagicMock() fake_crd_report.remove.return_value = 0 with patch('kubernetes.config.load_incluster_config', MagicMock(return_value=0)),\ patch('kubernetes.client.ExtensionsV1beta1Api', MagicMock(return_value=0)), \ patch.object(custom_resource.CustomResourceDefinitionType, 'create', MagicMock(return_value=fake_crd_report)): uninstall.remove_report_crd("cmk-nodereport", ["cmk-nr"]) caplog_tuple = caplog.record_tuples assert caplog_tuple[-1][2] == "\"cmk-nodereport\" for node \"{}\" " \ "removed.".format(os.getenv("NODE_NAME"))
def test_remove_report_crd_success(caplog): fake_crd_report = MagicMock() fake_crd_report.remove.return_value = 0 with patch(KUBERNETES_LOAD_INCLUSTER, MagicMock(return_value=0)),\ patch(KUBERNETES_CLIENT_EXTENSIONS, MagicMock(return_value=0)), \ patch.object(custom_resource.CustomResourceDefinitionType, 'create', MagicMock(return_value=fake_crd_report)): uninstall.remove_report_crd("cmk-nodereport", ["cmk-nr"]) caplog_tuple = caplog.record_tuples assert caplog_tuple[-1][2] == \ CMK_NODEREPORT_REMOVED.format(os.getenv("NODE_NAME"))
def test_remove_report_crd_failure(caplog): fake_http_resp = FakeHTTPResponse(500, FAKE_MESSAGE, WRONG_REASON) fake_api_exception = K8sApiException(http_resp=fake_http_resp) fake_crd_report = MagicMock() fake_crd_report.remove.side_effect = fake_api_exception with patch(KUBERNETES_LOAD_INCLUSTER, MagicMock(return_value=0)),\ patch(KUBERNETES_CLIENT_EXTENSIONS, MagicMock(return_value=0)), \ patch.object(custom_resource.CustomResourceDefinitionType, 'create', MagicMock(return_value=fake_crd_report)): with pytest.raises(SystemExit): uninstall.remove_report_crd("cmk-nodereport", ["cmk-nr"]) caplog_tuple = caplog.record_tuples exp_err = "Aborting uninstall: " \ "Exception when removing custom resource definition " \ "\"cmk-nodereport\"" exp_log_err = get_expected_log_error(exp_err, fake_http_resp) assert caplog_tuple[-1][2] == exp_log_err
def test_remove_report_crd_failure(caplog): fake_http_resp = FakeHTTPResponse(500, "{\"message\":\"fake message\"}", "{\"reason\":\"WrongReason\"}") fake_api_exception = K8sApiException(http_resp=fake_http_resp) fake_crd_report = MagicMock() fake_crd_report.remove.side_effect = fake_api_exception with patch('kubernetes.config.load_incluster_config', MagicMock(return_value=0)),\ patch('kubernetes.client.ExtensionsV1beta1Api', MagicMock(return_value=0)), \ patch.object(custom_resource.CustomResourceDefinitionType, 'create', MagicMock(return_value=fake_crd_report)): with pytest.raises(SystemExit): uninstall.remove_report_crd("cmk-nodereport", ["cmk-nr"]) caplog_tuple = caplog.record_tuples exp_err = "Aborting uninstall: " \ "Exception when removing custom resource definition " \ "\"cmk-nodereport\"" exp_log_err = get_expected_log_error(exp_err, fake_http_resp) assert caplog_tuple[-1][2] == exp_log_err
def test_remove_report_crd_success2(caplog): fake_http_resp = FakeHTTPResponse(500, FAKE_MESSAGE, REASON_NOT_FOUND) fake_api_exception = K8sApiException(http_resp=fake_http_resp) fake_crd_report = MagicMock() fake_crd_report.remove.side_effect = fake_api_exception with patch(KUBERNETES_LOAD_INCLUSTER, MagicMock(return_value=0)),\ patch(KUBERNETES_CLIENT_EXTENSIONS, MagicMock(return_value=0)), \ patch.object(custom_resource.CustomResourceDefinitionType, 'create', MagicMock(return_value=fake_crd_report)): uninstall.remove_report_crd("cmk-nodereport", ["cmk-nr"]) caplog_tuple = caplog.record_tuples assert \ caplog_tuple[-2][2] == "\"cmk-nodereport\" for node \"{}\" does "\ "not exist.".format(os.getenv("NODE_NAME")) assert \ caplog_tuple[-1][2] == \ CMK_NODEREPORT_REMOVED.format(os.getenv("NODE_NAME"))
def test_remove_report_crd_success2(caplog): fake_http_resp = FakeHTTPResponse(500, "{\"message\":\"fake message\"}", "{\"reason\":\"NotFound\"}") fake_api_exception = K8sApiException(http_resp=fake_http_resp) fake_crd_report = MagicMock() fake_crd_report.remove.side_effect = fake_api_exception with patch('kubernetes.config.load_incluster_config', MagicMock(return_value=0)),\ patch('kubernetes.client.ExtensionsV1beta1Api', MagicMock(return_value=0)), \ patch.object(custom_resource.CustomResourceDefinitionType, 'create', MagicMock(return_value=fake_crd_report)): uninstall.remove_report_crd("cmk-nodereport", ["cmk-nr"]) caplog_tuple = caplog.record_tuples assert \ caplog_tuple[-2][2] == "\"cmk-nodereport\" for node \"{}\" does "\ "not exist.".format(os.getenv("NODE_NAME")) assert \ caplog_tuple[-1][2] == "\"cmk-nodereport\" for node \"{}\" " \ "removed.".format(os.getenv("NODE_NAME"))