diff --git a/lib/ansible/modules/cloud/linode/linode.py b/lib/ansible/modules/cloud/linode/linode.py index 2347635df36..187064410aa 100644 --- a/lib/ansible/modules/cloud/linode/linode.py +++ b/lib/ansible/modules/cloud/linode/linode.py @@ -30,6 +30,7 @@ options: description: - Name to give the instance (alphanumeric, dashes, underscore). - To keep sanity on the Linode Web Console, name is prepended with C(LinodeID_). + required: true displaygroup: description: - Add the instance to a Display Group in Linode Manager. @@ -148,6 +149,7 @@ author: - Vincent Viallet (@zbal) notes: - C(LINODE_API_KEY) env variable can be used instead. + - Please review U(https://www.linode.com/api/linode) for determining the required parameters. ''' EXAMPLES = ''' @@ -556,7 +558,7 @@ def main(): state=dict(type='str', default='present', choices=['absent', 'active', 'deleted', 'present', 'restarted', 'started', 'stopped']), api_key=dict(type='str', no_log=True), - name=dict(type='str'), + name=dict(type='str', required=True), alert_bwin_enabled=dict(type='bool'), alert_bwin_threshold=dict(type='int'), alert_bwout_enabled=dict(type='bool'), diff --git a/test/runner/requirements/units.txt b/test/runner/requirements/units.txt index a2fb5940268..d412d4383ea 100644 --- a/test/runner/requirements/units.txt +++ b/test/runner/requirements/units.txt @@ -30,4 +30,7 @@ pyfmg xmljson # requirement for winrm connection plugin tests -pexpect \ No newline at end of file +pexpect + +# requirement for the linode module +linode-python diff --git a/test/units/modules/cloud/linode/__init__.py b/test/units/modules/cloud/linode/__init__.py new file mode 100644 index 00000000000..e69de29bb2d diff --git a/test/units/modules/cloud/linode/conftest.py b/test/units/modules/cloud/linode/conftest.py new file mode 100644 index 00000000000..a7400b82db8 --- /dev/null +++ b/test/units/modules/cloud/linode/conftest.py @@ -0,0 +1,13 @@ +import pytest + + +@pytest.fixture +def api_key(monkeypatch): + monkeypatch.setenv('LINODE_API_KEY', 'foobar') + + +@pytest.fixture +def auth(monkeypatch): + def patched_test_echo(dummy): + return [] + monkeypatch.setattr('linode.api.Api.test_echo', patched_test_echo) diff --git a/test/units/modules/cloud/linode/test_linode.py b/test/units/modules/cloud/linode/test_linode.py new file mode 100644 index 00000000000..70e2dd90dca --- /dev/null +++ b/test/units/modules/cloud/linode/test_linode.py @@ -0,0 +1,15 @@ +from __future__ import (absolute_import, division, print_function) + +import pytest + +from ansible.modules.cloud.linode import linode +from units.modules.utils import set_module_args + +if not linode.HAS_LINODE: + pytestmark = pytest.mark.skip('test_linode.py requires the `linode-python` module') + + +def test_name_is_a_required_parameter(api_key, auth): + with pytest.raises(SystemExit): + set_module_args({}) + linode.main()