def test_uninstall_remove_node_label_success2(caplog): with patch('intel.discover.patch_k8s_node', MagicMock(return_value=0)): uninstall.remove_node_label() caplog_tuple = caplog.record_tuples patch_path = '/metadata/labels/cmk.intel.com~1cmk-node' exp_str = "Removed node label \"{}\".".format(patch_path) assert caplog_tuple[-1][2] == exp_str
def test_uninstall_remove_node_label_success2(caplog): with patch(DISCOVER_PATCH_K8S_NODE, MagicMock(return_value=0)): uninstall.remove_node_label() caplog_tuple = caplog.record_tuples patch_path = MATADATA_LABELS_CMK_NODE exp_str = "Removed node label \"{}\".".format(patch_path) assert caplog_tuple[-1][2] == exp_str
def test_uninstall_remove_node_label_success(caplog): fake_http_resp = FakeHTTPResponse(500, FAKE_REASON, NON_EXISTANT_MGS) fake_api_exception = K8sApiException(http_resp=fake_http_resp) with patch(DISCOVER_PATCH_K8S_NODE, MagicMock(side_effect=fake_api_exception)): uninstall.remove_node_label() caplog_tuple = caplog.record_tuples patch_path = MATADATA_LABELS_CMK_NODE exp_str = "Removed node label \"{}\".".format(patch_path) exp_str2 = "Label \"{}\" does not exist.".format(patch_path) assert caplog_tuple[-2][2] == exp_str2 assert caplog_tuple[-1][2] == exp_str
def test_uninstall_remove_node_label_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', MagicMock(side_effect=fake_api_exception)): uninstall.remove_node_label() caplog_tuple = caplog.record_tuples patch_path = '/metadata/labels/cmk.intel.com~1cmk-node' exp_str = "Removed node label \"{}\".".format(patch_path) exp_str2 = "Label \"{}\" does not exist.".format(patch_path) assert caplog_tuple[-2][2] == exp_str2 assert caplog_tuple[-1][2] == exp_str
def test_uninstall_remove_node_label_failure(caplog): fake_http_resp = FakeHTTPResponse(500, FAKE_REASON, FAKE_MESSAGE) fake_api_exception = K8sApiException(http_resp=fake_http_resp) with patch(DISCOVER_PATCH_K8S_NODE, MagicMock(side_effect=fake_api_exception)): with pytest.raises(SystemExit): uninstall.remove_node_label() patch_path = MATADATA_LABELS_CMK_NODE exp_err = "Aborting uninstall: Exception when removing node label" \ " \"{}\"".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_label_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', MagicMock(side_effect=fake_api_exception)): with pytest.raises(SystemExit): uninstall.remove_node_label() patch_path = '/metadata/labels/cmk.intel.com~1cmk-node' exp_err = "Aborting uninstall: Exception when removing node label" \ " \"{}\"".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