def test_uninstall_remove_node_oir_success2(caplog): with patch(PATCH_NODE_STATUS, MagicMock(return_value=0)): uninstall.remove_node_cmk_oir() caplog_tuple = caplog.record_tuples patch_path = '/status/capacity/pod.alpha.kubernetes.' \ 'io~1opaque-int-resource-cmk' assert \ caplog_tuple[-1][2] == "Removed node oir " \ "\"{}\".".format(patch_path)
def test_uninstall_remove_node_cmk_oir_failure(caplog): fake_http_resp = FakeHTTPResponse(500, FAKE_REASON, FAKE_MESSAGE) fake_api_exception = K8sApiException(http_resp=fake_http_resp) with patch(PATCH_NODE_STATUS, MagicMock(side_effect=fake_api_exception)): with pytest.raises(SystemExit): uninstall.remove_node_cmk_oir() patch_path = "/status/capacity/" \ "pod.alpha.kubernetes.io~1opaque-int-resource-cmk" exp_err = "Aborting uninstall: " \ "Exception when removing OIR \"{}\"".format(patch_path) exp_log_err = get_expected_log_error(exp_err, fake_http_resp) caplog_tuple = caplog.record_tuples assert caplog_tuple[-1][2] == exp_log_err
def test_uninstall_remove_node_oir_success(caplog): fake_http_resp = FakeHTTPResponse(500, FAKE_REASON, NON_EXISTANT_MGS) fake_api_exception = K8sApiException(http_resp=fake_http_resp) with patch(PATCH_NODE_STATUS, MagicMock(side_effect=fake_api_exception)): uninstall.remove_node_cmk_oir() caplog_tuple = caplog.record_tuples patch_path = '/status/capacity/pod.alpha.kubernetes.' \ 'io~1opaque-int-resource-cmk' assert \ caplog_tuple[-2][2] == "CMK oir \"{}\" does not " \ "exist.".format(patch_path) assert \ caplog_tuple[-1][2] == "Removed node oir " \ "\"{}\".".format(patch_path)
def test_uninstall_remove_node_cmk_oir_failure(caplog): fake_http_resp = FakeHTTPResponse(500, "fake reason", "{\"message\":\"fake message\"}") fake_api_exception = K8sApiException(http_resp=fake_http_resp) with patch('intel.discover.patch_k8s_node_status', MagicMock(side_effect=fake_api_exception)): with pytest.raises(SystemExit): uninstall.remove_node_cmk_oir() patch_path = "/status/capacity/" \ "pod.alpha.kubernetes.io~1opaque-int-resource-cmk" exp_err = "Aborting uninstall: " \ "Exception when removing OIR \"{}\"".format(patch_path) exp_log_err = get_expected_log_error(exp_err, fake_http_resp) caplog_tuple = caplog.record_tuples assert caplog_tuple[-1][2] == exp_log_err
def test_uninstall_remove_node_oir_success(caplog): fake_http_resp = FakeHTTPResponse(500, "fake reason", "{\"message\":\"nonexistant\"}") fake_api_exception = K8sApiException(http_resp=fake_http_resp) with patch('intel.discover.patch_k8s_node_status', MagicMock(side_effect=fake_api_exception)): uninstall.remove_node_cmk_oir() caplog_tuple = caplog.record_tuples patch_path = '/status/capacity/pod.alpha.kubernetes.' \ 'io~1opaque-int-resource-cmk' assert \ caplog_tuple[-2][2] == "CMK oir \"{}\" does not " \ "exist.".format(patch_path) assert \ caplog_tuple[-1][2] == "Removed node oir " \ "\"{}\".".format(patch_path)