mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-08-12 09:04:21 -07:00
[PR #5812/8818a6f2 backport][stable-6] OpenNebula/one_vm implement the one.vm.updateconf API call (#5905)
OpenNebula/one_vm implement the one.vm.updateconf API call (#5812)
* opennebula: Add template manipulation helpers
* one_vm: Use 'updateconf' API call to modify running VMs
* one_vm: Emulate 'updateconf' API call for newly created VMs
* opennebula/one_vm: Satisfy linter checks
* opennebula/one_vm: Apply suggestions from code review
Co-authored-by: Alexei Znamensky <103110+russoz@users.noreply.github.com>
* opennebula/one_vm: Drop 'extend' function, use 'dict_merge' instead
* Add changelog fragment
* one_vm: Refactor 'parse_updateconf' function
* opennebula/one_vm: Apply suggestions from code review
Co-authored-by: Felix Fontein <felix@fontein.de>
* one_vm: Allow for using updateconf in all scenarios
---------
Co-authored-by: Alexei Znamensky <103110+russoz@users.noreply.github.com>
Co-authored-by: Felix Fontein <felix@fontein.de>
(cherry picked from commit 8818a6f242
)
Co-authored-by: Michal Opala <mopala@opennebula.io>
This commit is contained in:
parent
9d99ccef2d
commit
99336ba5fe
5 changed files with 364 additions and 80 deletions
91
tests/unit/plugins/module_utils/test_opennebula.py
Normal file
91
tests/unit/plugins/module_utils/test_opennebula.py
Normal file
|
@ -0,0 +1,91 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
# Copyright (c) 2023, Michal Opala <mopala@opennebula.io>
|
||||
# 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 os
|
||||
import textwrap
|
||||
|
||||
import pytest
|
||||
|
||||
from ansible_collections.community.general.plugins.module_utils.opennebula import flatten, render
|
||||
|
||||
|
||||
FLATTEN_VALID = [
|
||||
(
|
||||
[[[1]], [2], 3],
|
||||
False,
|
||||
[1, 2, 3]
|
||||
),
|
||||
(
|
||||
[[[1]], [2], 3],
|
||||
True,
|
||||
[1, 2, 3]
|
||||
),
|
||||
(
|
||||
[[1]],
|
||||
False,
|
||||
[1]
|
||||
),
|
||||
(
|
||||
[[1]],
|
||||
True,
|
||||
1
|
||||
),
|
||||
(
|
||||
1,
|
||||
False,
|
||||
[1]
|
||||
),
|
||||
(
|
||||
1,
|
||||
True,
|
||||
1
|
||||
),
|
||||
]
|
||||
|
||||
RENDER_VALID = [
|
||||
(
|
||||
{
|
||||
"NIC": {"NAME": "NIC0", "NETWORK_ID": 0},
|
||||
"CPU": 1,
|
||||
"MEMORY": 1024,
|
||||
},
|
||||
textwrap.dedent('''
|
||||
CPU="1"
|
||||
MEMORY="1024"
|
||||
NIC=[NAME="NIC0",NETWORK_ID="0"]
|
||||
''').strip()
|
||||
),
|
||||
(
|
||||
{
|
||||
"NIC": [
|
||||
{"NAME": "NIC0", "NETWORK_ID": 0},
|
||||
{"NAME": "NIC1", "NETWORK_ID": 1},
|
||||
],
|
||||
"CPU": 1,
|
||||
"MEMORY": 1024,
|
||||
},
|
||||
textwrap.dedent('''
|
||||
CPU="1"
|
||||
MEMORY="1024"
|
||||
NIC=[NAME="NIC0",NETWORK_ID="0"]
|
||||
NIC=[NAME="NIC1",NETWORK_ID="1"]
|
||||
''').strip()
|
||||
),
|
||||
]
|
||||
|
||||
|
||||
@pytest.mark.parametrize('to_flatten,extract,expected_result', FLATTEN_VALID)
|
||||
def test_flatten(to_flatten, extract, expected_result):
|
||||
result = flatten(to_flatten, extract)
|
||||
assert result == expected_result, repr(result)
|
||||
|
||||
|
||||
@pytest.mark.parametrize('to_render,expected_result', RENDER_VALID)
|
||||
def test_render(to_render, expected_result):
|
||||
result = render(to_render)
|
||||
assert result == expected_result, repr(result)
|
62
tests/unit/plugins/modules/test_one_vm.py
Normal file
62
tests/unit/plugins/modules/test_one_vm.py
Normal file
|
@ -0,0 +1,62 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
# Copyright (c) 2023, Michal Opala <mopala@opennebula.io>
|
||||
# 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 os
|
||||
|
||||
import pytest
|
||||
|
||||
from ansible_collections.community.general.plugins.modules.one_vm import parse_updateconf
|
||||
|
||||
|
||||
PARSE_UPDATECONF_VALID = [
|
||||
(
|
||||
{
|
||||
"CPU": 1,
|
||||
"OS": {"ARCH": 2},
|
||||
},
|
||||
{
|
||||
"OS": {"ARCH": 2},
|
||||
}
|
||||
),
|
||||
(
|
||||
{
|
||||
"OS": {"ARCH": 1, "ASD": 2}, # "ASD" is an invalid attribute, we ignore it
|
||||
},
|
||||
{
|
||||
"OS": {"ARCH": 1},
|
||||
}
|
||||
),
|
||||
(
|
||||
{
|
||||
"OS": {"ASD": 1}, # "ASD" is an invalid attribute, we ignore it
|
||||
},
|
||||
{
|
||||
}
|
||||
),
|
||||
(
|
||||
{
|
||||
"MEMORY": 1,
|
||||
"CONTEXT": {
|
||||
"PASSWORD": 2,
|
||||
"SSH_PUBLIC_KEY": 3,
|
||||
},
|
||||
},
|
||||
{
|
||||
"CONTEXT": {
|
||||
"PASSWORD": 2,
|
||||
"SSH_PUBLIC_KEY": 3,
|
||||
},
|
||||
}
|
||||
),
|
||||
]
|
||||
|
||||
|
||||
@pytest.mark.parametrize('vm_template,expected_result', PARSE_UPDATECONF_VALID)
|
||||
def test_parse_updateconf(vm_template, expected_result):
|
||||
result = parse_updateconf(vm_template)
|
||||
assert result == expected_result, repr(result)
|
Loading…
Add table
Add a link
Reference in a new issue