def test_remove_all_pods(mocker): list_pods_val = dict_to_simple_namespace({ 'items': [{ 'metadata': { 'uid': 'aaa', 'name': 'test_pod1', 'namespace': 'test_ns', 'annotations': None, 'owner_references': None } }, { 'metadata': { 'uid': 'bbb', 'name': 'test_pod2', 'namespace': 'test_ns', 'annotations': None, 'owner_references': None } }] }) empty_list_pods_val = dict_to_simple_namespace({'items': []}) mock_api = mocker.Mock( **{ 'list_pod_for_all_namespaces.side_effect': [list_pods_val, empty_list_pods_val] }) remove_all_pods(mock_api, 'test_node') mock_api.list_pod_for_all_namespaces.assert_called_with( watch=False, include_uninitialized=True, field_selector='spec.nodeName=test_node') mock_arg = { 'apiVersion': 'policy/v1beta1', 'kind': 'Eviction', 'deleteOptions': {}, 'metadata': { 'name': 'test_pod1', 'namespace': 'test_ns' } } mock_arg1 = { 'apiVersion': 'policy/v1beta1', 'kind': 'Eviction', 'deleteOptions': {}, 'metadata': { 'name': 'test_pod2', 'namespace': 'test_ns' } } mock_api.create_namespaced_pod_eviction.assert_any_call( 'test_pod1', 'test_ns', mock_arg) mock_api.create_namespaced_pod_eviction.assert_any_call( 'test_pod2', 'test_ns', mock_arg1)
def test_remove_all_pods(mocker): list_pods_val = dict_to_simple_namespace({ 'items': [{ 'metadata': { 'name': 'test_pod1', 'namespace': 'test_ns' } }, { 'metadata': { 'name': 'test_pod2', 'namespace': 'test_ns' } }] }) mock_api = mocker.Mock( **{'list_pod_for_all_namespaces.return_value': list_pods_val}) remove_all_pods(mock_api, 'test_node') mock_api.list_pod_for_all_namespaces.assert_called_with( watch=False, field_selector='spec.nodeName=test_node') mock_arg = { 'apiVersion': 'policy/v1beta1', 'kind': 'Eviction', 'metadata': { 'name': 'test_pod1', 'namespace': 'test_ns' } } mock_arg1 = { 'apiVersion': 'policy/v1beta1', 'kind': 'Eviction', 'metadata': { 'name': 'test_pod2', 'namespace': 'test_ns' } } mock_api.create_namespaced_pod_eviction.assert_any_call( 'test_pod1-eviction', 'test_ns', mock_arg) mock_api.create_namespaced_pod_eviction.assert_any_call( 'test_pod2-eviction', 'test_ns', mock_arg1)