def test_remove_report_tpr_success(caplog): fake_tpr_report = MagicMock() fake_tpr_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(third_party.ThirdPartyResourceType, 'create', MagicMock(return_value=fake_tpr_report)): uninstall.remove_report_tpr("NodeReport") caplog_tuple = caplog.record_tuples assert caplog_tuple[-1][2] == "\"NodeReport\" for node \"{}\" " \ "removed.".format(os.getenv("NODE_NAME"))
def test_remove_report_tpr_success(caplog): fake_tpr_report = MagicMock() fake_tpr_report.remove.return_value = 0 with patch(KUBERNETES_LOAD_INCLUSTER, MagicMock(return_value=0)),\ patch(KUBERNETES_CLIENT_EXTENSIONS, MagicMock(return_value=0)), \ patch.object(third_party.ThirdPartyResourceType, 'create', MagicMock(return_value=fake_tpr_report)): uninstall.remove_report_tpr("NodeReport") caplog_tuple = caplog.record_tuples assert caplog_tuple[-1][2] == \ NODEREPORT_REMOVED.format(os.getenv("NODE_NAME"))
def test_remove_report_tpr_failure(caplog): fake_http_resp = FakeHTTPResponse(500, FAKE_MESSAGE, WRONG_REASON) fake_api_exception = K8sApiException(http_resp=fake_http_resp) fake_tpr_report = MagicMock() fake_tpr_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(third_party.ThirdPartyResourceType, 'create', MagicMock(return_value=fake_tpr_report)): with pytest.raises(SystemExit): uninstall.remove_report_tpr("NodeReport") caplog_tuple = caplog.record_tuples exp_err = "Aborting uninstall: " \ "Exception when removing third party resource \"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_tpr_failure(caplog): fake_http_resp = FakeHTTPResponse(500, "{\"message\":\"fake message\"}", "{\"reason\":\"WrongReason\"}") fake_api_exception = K8sApiException(http_resp=fake_http_resp) fake_tpr_report = MagicMock() fake_tpr_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(third_party.ThirdPartyResourceType, 'create', MagicMock(return_value=fake_tpr_report)): with pytest.raises(SystemExit): uninstall.remove_report_tpr("NodeReport") caplog_tuple = caplog.record_tuples exp_err = "Aborting uninstall: " \ "Exception when removing third party resource \"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_tpr_success2(caplog): fake_http_resp = FakeHTTPResponse(500, FAKE_MESSAGE, REASON_NOT_FOUND) fake_api_exception = K8sApiException(http_resp=fake_http_resp) fake_tpr_report = MagicMock() fake_tpr_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(third_party.ThirdPartyResourceType, 'create', MagicMock(return_value=fake_tpr_report)): uninstall.remove_report_tpr("NodeReport") caplog_tuple = caplog.record_tuples assert \ caplog_tuple[-2][2] == "\"NodeReport\" for node \"{}\" does" \ " not exist.".format(os.getenv("NODE_NAME")) assert \ caplog_tuple[-1][2] == \ NODEREPORT_REMOVED.format(os.getenv("NODE_NAME"))
def test_remove_report_tpr_success2(caplog): fake_http_resp = FakeHTTPResponse(500, "{\"message\":\"fake message\"}", "{\"reason\":\"NotFound\"}") fake_api_exception = K8sApiException(http_resp=fake_http_resp) fake_tpr_report = MagicMock() fake_tpr_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(third_party.ThirdPartyResourceType, 'create', MagicMock(return_value=fake_tpr_report)): uninstall.remove_report_tpr("NodeReport") caplog_tuple = caplog.record_tuples assert \ caplog_tuple[-2][2] == "\"NodeReport\" for node \"{}\" does" \ " not exist.".format(os.getenv("NODE_NAME")) assert \ caplog_tuple[-1][2] == "\"NodeReport\" for node \"{}\" " \ "removed.".format(os.getenv("NODE_NAME"))