mirror of
				https://github.com/ansible-collections/community.general.git
				synced 2025-10-24 21:14:00 -07:00 
			
		
		
		
	[PR #9437/96f465dd backport][stable-10] Add module proxmox_backup_info (#9635)
Add module proxmox_backup_info  (#9437)
* Create proxmox_backup_info.py
The `proxmox_backup_info` module displays information such as backup times, VM name, VM ID, mode, backup type, and backup schedule using the Proxmox Server API.
* Create test_proxmox_backup_info.py
create test for proxmox_backup_info.py module
* Update plugins/modules/proxmox_backup_info.py
Co-authored-by: Alexei Znamensky <103110+russoz@users.noreply.github.com>
* check tests proxmox_backup_info.py
* check tests test_proxmox_backup_info.py
* Update check tests test_proxmox_backup_info.py
* Update check tests proxmox_backup_info.py
* Update authors proxmox_backup_info.py
* Update active maintainers for proxmox_backup_info module
* Update add proxmox_backup_info module in proxmox group
* edit timestamp to UTC test_proxmox_backup_info.py
* Update vm name or vmid to VM name or VM id proxmox_backup_info.py
* update  documentation in proxmox_backup_info.py
* Update backup_section decription in proxmox_backup_info.py
* Update plugins/modules/proxmox_backup_info.py
Co-authored-by: Felix Fontein <felix@fontein.de>
* change backup_section to backup_jobs
* change backup_section to backup_jobs
* remove whitespace in line 35 and 36
* improve descriptions
* check again proxmox_backup_info.py module
* change vmid type and some descriptions proxmox_backup_info.py
* delete comment #if ...
* solve trailing whitespace error
* Update the name of the functions
* Update proxmox_backup_info.py
* Update proxmox_backup_info.py
* Update tests/unit/plugins/modules/test_proxmox_backup_info.py
Co-authored-by: Felix Fontein <felix@fontein.de>
* Update test_proxmox_backup_info.py
* Update runtime.yml
* add proxmox_backup_schedule module in runtime.yml
* add proxmox_backup_schedule.py module in BOTMETA.yml
* remove proxmox_backup_schedule module runtime.yml
* remove proxmox_backup_schedule.py module in BOTMETA.yml
* change some id to ID proxmox_backup_info.py
* Update proxmox_backup_info.py
* remove required: falsefrom documentations
* change vimd values to str format
* add samples to output documentations
* the exact output of vimd in endpoint of proxmox resoures is like int
---------
Co-authored-by: Alexei Znamensky <103110+russoz@users.noreply.github.com>
Co-authored-by: Felix Fontein <felix@fontein.de>
Co-authored-by: mmayabi <137920552+mmayabi@users.noreply.github.com>
(cherry picked from commit 96f465ddf8)
Co-authored-by: raoufnezhad <72685312+raoufnezhad@users.noreply.github.com>
	
	
This commit is contained in:
		
					parent
					
						
							
								f79aa6f63f
							
						
					
				
			
			
				commit
				
					
						e255e5ed0c
					
				
			
		
					 4 changed files with 522 additions and 0 deletions
				
			
		
							
								
								
									
										275
									
								
								tests/unit/plugins/modules/test_proxmox_backup_info.py
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										275
									
								
								tests/unit/plugins/modules/test_proxmox_backup_info.py
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,275 @@ | |||
| # -*- coding: utf-8 -*- | ||||
| # | ||||
| # Copyright (c) 2024 Marzieh Raoufnezhad <raoufnezhad at gmail.com> | ||||
| # Copyright (c) 2024 Maryam Mayabi <mayabi.ahm at gmail.com> | ||||
| # GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt) | ||||
| # SPDX-License-Identifier: GPL-3.0-or-later | ||||
| 
 | ||||
| from __future__ import absolute_import, division, print_function | ||||
| 
 | ||||
| __metaclass__ = type | ||||
| 
 | ||||
| import pytest | ||||
| 
 | ||||
| proxmoxer = pytest.importorskip("proxmoxer") | ||||
| 
 | ||||
| from ansible_collections.community.general.plugins.modules import proxmox_backup_info | ||||
| from ansible_collections.community.general.tests.unit.compat.mock import patch | ||||
| from ansible_collections.community.general.tests.unit.plugins.modules.utils import ( | ||||
|     AnsibleExitJson, | ||||
|     AnsibleFailJson, | ||||
|     ModuleTestCase, | ||||
|     set_module_args, | ||||
| ) | ||||
| import ansible_collections.community.general.plugins.module_utils.proxmox as proxmox_utils | ||||
| 
 | ||||
| RESOURCE_LIST = [ | ||||
|     { | ||||
|         "uptime": 0, | ||||
|         "diskwrite": 0, | ||||
|         "name": "test01", | ||||
|         "maxcpu": 0, | ||||
|         "node": "NODE1", | ||||
|         "mem": 0, | ||||
|         "netout": 0, | ||||
|         "netin": 0, | ||||
|         "maxmem": 0, | ||||
|         "diskread": 0, | ||||
|         "disk": 0, | ||||
|         "maxdisk": 0, | ||||
|         "status": "running", | ||||
|         "cpu": 0, | ||||
|         "id": "qemu/100", | ||||
|         "template": 0, | ||||
|         "vmid": 100, | ||||
|         "type": "qemu" | ||||
|     }, | ||||
|     { | ||||
|         "uptime": 0, | ||||
|         "diskwrite": 0, | ||||
|         "name": "test02", | ||||
|         "maxcpu": 0, | ||||
|         "node": "NODE1", | ||||
|         "mem": 0, | ||||
|         "netout": 0, | ||||
|         "netin": 0, | ||||
|         "maxmem": 0, | ||||
|         "diskread": 0, | ||||
|         "disk": 0, | ||||
|         "maxdisk": 0, | ||||
|         "status": "running", | ||||
|         "cpu": 0, | ||||
|         "id": "qemu/101", | ||||
|         "template": 0, | ||||
|         "vmid": 101, | ||||
|         "type": "qemu" | ||||
|     }, | ||||
|     { | ||||
|         "uptime": 0, | ||||
|         "diskwrite": 0, | ||||
|         "name": "test03", | ||||
|         "maxcpu": 0, | ||||
|         "node": "NODE2", | ||||
|         "mem": 0, | ||||
|         "netout": 0, | ||||
|         "netin": 0, | ||||
|         "maxmem": 0, | ||||
|         "diskread": 0, | ||||
|         "disk": 0, | ||||
|         "maxdisk": 0, | ||||
|         "status": "running", | ||||
|         "cpu": 0, | ||||
|         "id": "qemu/102", | ||||
|         "template": 0, | ||||
|         "vmid": 102, | ||||
|         "type": "qemu" | ||||
|     } | ||||
| ] | ||||
| BACKUP_JOBS = [ | ||||
|     { | ||||
|         "type": "vzdump", | ||||
|         "id": "backup-83831498-c631", | ||||
|         "storage": "local", | ||||
|         "vmid": "100", | ||||
|         "enabled": 1, | ||||
|         "next-run": 1735138800, | ||||
|         "mailnotification": "always", | ||||
|         "schedule": "06,18:30", | ||||
|         "mode": "snapshot", | ||||
|         "notes-template": "guestname" | ||||
|     }, | ||||
|     { | ||||
|         "schedule": "sat 15:00", | ||||
|         "notes-template": "guestname", | ||||
|         "mode": "snapshot", | ||||
|         "mailnotification": "always", | ||||
|         "next-run": 1735385400, | ||||
|         "type": "vzdump", | ||||
|         "enabled": 1, | ||||
|         "vmid": "100,101,102", | ||||
|         "storage": "local", | ||||
|         "id": "backup-70025700-2302", | ||||
|     } | ||||
| ] | ||||
| 
 | ||||
| EXPECTED_BACKUP_OUTPUT = [ | ||||
|     { | ||||
|         "bktype": "vzdump", | ||||
|         "enabled": 1, | ||||
|         "id": "backup-83831498-c631", | ||||
|         "mode": "snapshot", | ||||
|         "next-run": "2024-12-25 15:00:00", | ||||
|         "schedule": "06,18:30", | ||||
|         "storage": "local", | ||||
|         "vm_name": "test01", | ||||
|         "vmid": "100" | ||||
|     }, | ||||
|     { | ||||
|         "bktype": "vzdump", | ||||
|         "enabled": 1, | ||||
|         "id": "backup-70025700-2302", | ||||
|         "mode": "snapshot", | ||||
|         "next-run": "2024-12-28 11:30:00", | ||||
|         "schedule": "sat 15:00", | ||||
|         "storage": "local", | ||||
|         "vm_name": "test01", | ||||
|         "vmid": "100" | ||||
|     }, | ||||
|     { | ||||
|         "bktype": "vzdump", | ||||
|         "enabled": 1, | ||||
|         "id": "backup-70025700-2302", | ||||
|         "mode": "snapshot", | ||||
|         "next-run": "2024-12-28 11:30:00", | ||||
|         "schedule": "sat 15:00", | ||||
|         "storage": "local", | ||||
|         "vm_name": "test02", | ||||
|         "vmid": "101" | ||||
|     }, | ||||
|     { | ||||
|         "bktype": "vzdump", | ||||
|         "enabled": 1, | ||||
|         "id": "backup-70025700-2302", | ||||
|         "mode": "snapshot", | ||||
|         "next-run": "2024-12-28 11:30:00", | ||||
|         "schedule": "sat 15:00", | ||||
|         "storage": "local", | ||||
|         "vm_name": "test03", | ||||
|         "vmid": "102" | ||||
|     } | ||||
| ] | ||||
| EXPECTED_BACKUP_JOBS_OUTPUT = [ | ||||
|     { | ||||
|         "enabled": 1, | ||||
|         "id": "backup-83831498-c631", | ||||
|         "mailnotification": "always", | ||||
|         "mode": "snapshot", | ||||
|         "next-run": 1735138800, | ||||
|         "notes-template": "guestname", | ||||
|         "schedule": "06,18:30", | ||||
|         "storage": "local", | ||||
|         "type": "vzdump", | ||||
|         "vmid": "100" | ||||
|     }, | ||||
|     { | ||||
|         "enabled": 1, | ||||
|         "id": "backup-70025700-2302", | ||||
|         "mailnotification": "always", | ||||
|         "mode": "snapshot", | ||||
|         "next-run": 1735385400, | ||||
|         "notes-template": "guestname", | ||||
|         "schedule": "sat 15:00", | ||||
|         "storage": "local", | ||||
|         "type": "vzdump", | ||||
|         "vmid": "100,101,102" | ||||
|     } | ||||
| ] | ||||
| 
 | ||||
| 
 | ||||
| class TestProxmoxBackupInfoModule(ModuleTestCase): | ||||
|     def setUp(self): | ||||
|         super(TestProxmoxBackupInfoModule, self).setUp() | ||||
|         proxmox_utils.HAS_PROXMOXER = True | ||||
|         self.module = proxmox_backup_info | ||||
|         self.connect_mock = patch( | ||||
|             "ansible_collections.community.general.plugins.module_utils.proxmox.ProxmoxAnsible._connect", | ||||
|         ).start() | ||||
|         self.connect_mock.return_value.cluster.resources.get.return_value = ( | ||||
|             RESOURCE_LIST | ||||
|         ) | ||||
|         self.connect_mock.return_value.cluster.backup.get.return_value = ( | ||||
|             BACKUP_JOBS | ||||
|         ) | ||||
| 
 | ||||
|     def tearDown(self): | ||||
|         self.connect_mock.stop() | ||||
|         super(TestProxmoxBackupInfoModule, self).tearDown() | ||||
| 
 | ||||
|     def test_module_fail_when_required_args_missing(self): | ||||
|         with pytest.raises(AnsibleFailJson) as exc_info: | ||||
|             set_module_args({}) | ||||
|             self.module.main() | ||||
| 
 | ||||
|         result = exc_info.value.args[0] | ||||
|         assert result["msg"] == "missing required arguments: api_host, api_user" | ||||
| 
 | ||||
|     def test_get_all_backups_information(self): | ||||
|         with pytest.raises(AnsibleExitJson) as exc_info: | ||||
|             set_module_args({ | ||||
|                 'api_host': 'proxmoxhost', | ||||
|                 'api_user': 'root@pam', | ||||
|                 'api_password': 'supersecret' | ||||
|             }) | ||||
|             self.module.main() | ||||
| 
 | ||||
|         result = exc_info.value.args[0] | ||||
|         assert result["backup_info"] == EXPECTED_BACKUP_OUTPUT | ||||
| 
 | ||||
|     def test_get_specific_backup_information_by_vmname(self): | ||||
|         with pytest.raises(AnsibleExitJson) as exc_info: | ||||
|             vmname = 'test01' | ||||
|             expected_output = [ | ||||
|                 backup for backup in EXPECTED_BACKUP_OUTPUT if backup["vm_name"] == vmname | ||||
|             ] | ||||
|             set_module_args({ | ||||
|                 'api_host': 'proxmoxhost', | ||||
|                 'api_user': 'root@pam', | ||||
|                 'api_password': 'supersecret', | ||||
|                 'vm_name': vmname | ||||
|             }) | ||||
|             self.module.main() | ||||
| 
 | ||||
|         result = exc_info.value.args[0] | ||||
|         assert result["backup_info"] == expected_output | ||||
|         assert len(result["backup_info"]) == 2 | ||||
| 
 | ||||
|     def test_get_specific_backup_information_by_vmid(self): | ||||
|         with pytest.raises(AnsibleExitJson) as exc_info: | ||||
|             vmid = "101" | ||||
|             expected_output = [ | ||||
|                 backup for backup in EXPECTED_BACKUP_OUTPUT if backup["vmid"] == vmid | ||||
|             ] | ||||
|             set_module_args({ | ||||
|                 'api_host': 'proxmoxhost', | ||||
|                 'api_user': 'root@pam', | ||||
|                 'api_password': 'supersecret', | ||||
|                 'vm_id': vmid | ||||
|             }) | ||||
|             self.module.main() | ||||
|         result = exc_info.value.args[0] | ||||
|         assert result["backup_info"] == expected_output | ||||
|         assert len(result["backup_info"]) == 1 | ||||
| 
 | ||||
|     def test_get_specific_backup_information_by_backupjobs(self): | ||||
|         with pytest.raises(AnsibleExitJson) as exc_info: | ||||
|             backupjobs = True | ||||
|             set_module_args({ | ||||
|                 'api_host': 'proxmoxhost', | ||||
|                 'api_user': 'root@pam', | ||||
|                 'api_password': 'supersecret', | ||||
|                 'backup_jobs': backupjobs | ||||
|             }) | ||||
|             self.module.main() | ||||
| 
 | ||||
|         result = exc_info.value.args[0] | ||||
|         assert result["backup_info"] == EXPECTED_BACKUP_JOBS_OUTPUT | ||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue