mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-07-23 05:10:22 -07:00
New module: proxmox_snap (#1135)
* Fresh branch to try this again * Fix typo * Fix sanity error * Redid some tests, not sure if this works... * Re-fixed documentation * Fixed linter * Update layout * Processed feedback * Processed feedback * Added check_mode * Run test with check mode * Fix layout * Fix more layout * Fixed last sanity errors (for now) * Check mode is not a module arg.. * Fix sanity-error * Reworked check_mode and adapted tests * Added extra test to also run through remove logic, added message for check_mode to show output is different, grabbed magicmock from different library to fix py2 errors * Remove unused function * Processed feedback * Processed feedback * Processed feedback
This commit is contained in:
parent
5ee5c004b4
commit
0d1417dcfa
3 changed files with 378 additions and 0 deletions
88
tests/unit/plugins/modules/cloud/misc/test_proxmox_snap.py
Normal file
88
tests/unit/plugins/modules/cloud/misc/test_proxmox_snap.py
Normal file
|
@ -0,0 +1,88 @@
|
|||
# Copyright: (c) 2019, 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 json
|
||||
import pytest
|
||||
|
||||
from ansible_collections.community.general.tests.unit.compat.mock import MagicMock
|
||||
from ansible_collections.community.general.plugins.modules.cloud.misc import proxmox_snap
|
||||
from ansible_collections.community.general.tests.unit.plugins.modules.utils import set_module_args
|
||||
|
||||
|
||||
def get_resources(type):
|
||||
return [{"diskwrite": 0,
|
||||
"vmid": 100,
|
||||
"node": "localhost",
|
||||
"id": "lxc/100",
|
||||
"maxdisk": 10000,
|
||||
"template": 0,
|
||||
"disk": 10000,
|
||||
"uptime": 10000,
|
||||
"maxmem": 10000,
|
||||
"maxcpu": 1,
|
||||
"netin": 10000,
|
||||
"type": "lxc",
|
||||
"netout": 10000,
|
||||
"mem": 10000,
|
||||
"diskread": 10000,
|
||||
"cpu": 0.01,
|
||||
"name": "test-lxc",
|
||||
"status": "running"}]
|
||||
|
||||
|
||||
def fake_api(api_host, api_user, api_password, validate_certs):
|
||||
r = MagicMock()
|
||||
r.cluster.resources.get = MagicMock(side_effect=get_resources)
|
||||
return r
|
||||
|
||||
|
||||
def test_proxmox_snap_without_argument(capfd):
|
||||
set_module_args({})
|
||||
with pytest.raises(SystemExit) as results:
|
||||
proxmox_snap.main()
|
||||
|
||||
out, err = capfd.readouterr()
|
||||
assert not err
|
||||
assert json.loads(out)['failed']
|
||||
|
||||
|
||||
def test_create_snapshot_check_mode(capfd, mocker):
|
||||
set_module_args({"hostname": "test-lxc",
|
||||
"api_user": "root@pam",
|
||||
"api_password": "secret",
|
||||
"api_host": "127.0.0.1",
|
||||
"state": "present",
|
||||
"snapname": "test",
|
||||
"timeout": "1",
|
||||
"force": True,
|
||||
"_ansible_check_mode": True})
|
||||
proxmox_snap.HAS_PROXMOXER = True
|
||||
proxmox_snap.setup_api = mocker.MagicMock(side_effect=fake_api)
|
||||
with pytest.raises(SystemExit) as results:
|
||||
proxmox_snap.main()
|
||||
|
||||
out, err = capfd.readouterr()
|
||||
assert not err
|
||||
assert not json.loads(out)['changed']
|
||||
|
||||
|
||||
def test_remove_snapshot_check_mode(capfd, mocker):
|
||||
set_module_args({"hostname": "test-lxc",
|
||||
"api_user": "root@pam",
|
||||
"api_password": "secret",
|
||||
"api_host": "127.0.0.1",
|
||||
"state": "absent",
|
||||
"snapname": "test",
|
||||
"timeout": "1",
|
||||
"force": True,
|
||||
"_ansible_check_mode": True})
|
||||
proxmox_snap.HAS_PROXMOXER = True
|
||||
proxmox_snap.setup_api = mocker.MagicMock(side_effect=fake_api)
|
||||
with pytest.raises(SystemExit) as results:
|
||||
proxmox_snap.main()
|
||||
|
||||
out, err = capfd.readouterr()
|
||||
assert not err
|
||||
assert not json.loads(out)['changed']
|
Loading…
Add table
Add a link
Reference in a new issue