mirror of https://github.com/ansible/ansible.git
Make get_bin_path() always raise an exception (#56813)
This makes it behave in a more idiomatic way * Fix bug in Darwin facts for free memory If the vm_stat command is not found, fact gathering would fail with an unhelpful error message. Handle this gracefully and return a default value for free memory. * Add unit testspull/66964/head
parent
c9a34ae33e
commit
5112feeace
@ -0,0 +1,2 @@
|
||||
minor_changes:
|
||||
- get_bin_path() - change the interface to always raise ``ValueError`` if the command is not found (https://github.com/ansible/ansible/pull/56813)
|
@ -0,0 +1,33 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# Copyright (c) 2020 Ansible Project
|
||||
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||
|
||||
from __future__ import absolute_import, division, print_function
|
||||
__metaclass__ = type
|
||||
|
||||
import pytest
|
||||
|
||||
from ansible.module_utils.common.process import get_bin_path
|
||||
|
||||
|
||||
def test_get_bin_path(mocker):
|
||||
path = '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin'
|
||||
mocker.patch.dict('os.environ', {'PATH': path})
|
||||
mocker.patch('os.pathsep', ':')
|
||||
|
||||
mocker.patch('os.path.exists', side_effect=[False, True])
|
||||
mocker.patch('os.path.isdir', return_value=False)
|
||||
mocker.patch('ansible.module_utils.common.process.is_executable', return_value=True)
|
||||
|
||||
assert '/usr/local/bin/notacommand' == get_bin_path('notacommand')
|
||||
|
||||
|
||||
def test_get_path_path_raise_valueerror(mocker):
|
||||
mocker.patch.dict('os.environ', {'PATH': ''})
|
||||
|
||||
mocker.patch('os.path.exists', return_value=False)
|
||||
mocker.patch('os.path.isdir', return_value=False)
|
||||
mocker.patch('ansible.module_utils.common.process.is_executable', return_value=True)
|
||||
|
||||
with pytest.raises(ValueError, match='Failed to find required executable notacommand'):
|
||||
get_bin_path('notacommand')
|
Loading…
Reference in New Issue