mirror of
https://github.com/ansible-collections/community.general.git
synced 2026-05-06 21:32:49 +00:00
cloud: huawei: Add new module hwc_network_vpc (#54102)
This commit is contained in:
10
test/integration/cloud-config-hwc.yml.template
Normal file
10
test/integration/cloud-config-hwc.yml.template
Normal file
@@ -0,0 +1,10 @@
|
||||
# This is the configuration template for ansible-test HWC integration tests.
|
||||
# Please fill in the @VAR placeholders below and save this file without the
|
||||
# .template extension.
|
||||
|
||||
identity_endpoint: @identity_endpoint
|
||||
user: @user
|
||||
password: @password
|
||||
domain: @domain
|
||||
project: @project
|
||||
region: @region
|
||||
1
test/integration/targets/hwc_network_vpc/aliases
Normal file
1
test/integration/targets/hwc_network_vpc/aliases
Normal file
@@ -0,0 +1 @@
|
||||
unsupported
|
||||
96
test/integration/targets/hwc_network_vpc/tasks/main.yml
Normal file
96
test/integration/targets/hwc_network_vpc/tasks/main.yml
Normal file
@@ -0,0 +1,96 @@
|
||||
---
|
||||
# ----------------------------------------------------------------------------
|
||||
#
|
||||
# *** AUTO GENERATED CODE *** AUTO GENERATED CODE ***
|
||||
#
|
||||
# ----------------------------------------------------------------------------
|
||||
#
|
||||
# This file is automatically generated by Magic Modules and manual
|
||||
# changes will be clobbered when the file is regenerated.
|
||||
#
|
||||
# Please read more about how to change this file at
|
||||
# https://www.github.com/huaweicloud/magic-modules
|
||||
#
|
||||
# ----------------------------------------------------------------------------
|
||||
# Pre-test setup
|
||||
- name: delete a vpc
|
||||
hwc_network_vpc:
|
||||
identity_endpoint: "{{ identity_endpoint }}"
|
||||
user: "{{ user }}"
|
||||
password: "{{ password }}"
|
||||
domain: "{{ domain }}"
|
||||
project: "{{ project }}"
|
||||
region: "{{ region }}"
|
||||
name: "vpc_1"
|
||||
cidr: "192.168.100.0/24"
|
||||
state: absent
|
||||
#----------------------------------------------------------
|
||||
- name: create a vpc
|
||||
hwc_network_vpc:
|
||||
identity_endpoint: "{{ identity_endpoint }}"
|
||||
user: "{{ user }}"
|
||||
password: "{{ password }}"
|
||||
domain: "{{ domain }}"
|
||||
project: "{{ project }}"
|
||||
region: "{{ region }}"
|
||||
name: "vpc_1"
|
||||
cidr: "192.168.100.0/24"
|
||||
state: present
|
||||
register: result
|
||||
- name: assert changed is true
|
||||
assert:
|
||||
that:
|
||||
- result is changed
|
||||
# ----------------------------------------------------------------------------
|
||||
- name: create a vpc that already exists
|
||||
hwc_network_vpc:
|
||||
identity_endpoint: "{{ identity_endpoint }}"
|
||||
user: "{{ user }}"
|
||||
password: "{{ password }}"
|
||||
domain: "{{ domain }}"
|
||||
project: "{{ project }}"
|
||||
region: "{{ region }}"
|
||||
name: "vpc_1"
|
||||
cidr: "192.168.100.0/24"
|
||||
state: present
|
||||
register: result
|
||||
- name: assert changed is false
|
||||
assert:
|
||||
that:
|
||||
- result.failed == 0
|
||||
- result.changed == false
|
||||
#----------------------------------------------------------
|
||||
- name: delete a vpc
|
||||
hwc_network_vpc:
|
||||
identity_endpoint: "{{ identity_endpoint }}"
|
||||
user: "{{ user }}"
|
||||
password: "{{ password }}"
|
||||
domain: "{{ domain }}"
|
||||
project: "{{ project }}"
|
||||
region: "{{ region }}"
|
||||
name: "vpc_1"
|
||||
cidr: "192.168.100.0/24"
|
||||
state: absent
|
||||
register: result
|
||||
- name: assert changed is true
|
||||
assert:
|
||||
that:
|
||||
- result is changed
|
||||
# ----------------------------------------------------------------------------
|
||||
- name: delete a vpc that does not exist
|
||||
hwc_network_vpc:
|
||||
identity_endpoint: "{{ identity_endpoint }}"
|
||||
user: "{{ user }}"
|
||||
password: "{{ password }}"
|
||||
domain: "{{ domain }}"
|
||||
project: "{{ project }}"
|
||||
region: "{{ region }}"
|
||||
name: "vpc_1"
|
||||
cidr: "192.168.100.0/24"
|
||||
state: absent
|
||||
register: result
|
||||
- name: assert changed is false
|
||||
assert:
|
||||
that:
|
||||
- result.failed == 0
|
||||
- result.changed == false
|
||||
192
test/units/module_utils/hwc/test_dict_comparison.py
Normal file
192
test/units/module_utils/hwc/test_dict_comparison.py
Normal file
@@ -0,0 +1,192 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# 2018.07.26 --- use DictComparison instead of GcpRequest
|
||||
#
|
||||
# (c) 2016, Tom Melendez <tom@supertom.com>
|
||||
#
|
||||
# This file is part of Ansible
|
||||
#
|
||||
# Ansible is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# Ansible is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
|
||||
import os
|
||||
import sys
|
||||
|
||||
from units.compat import unittest
|
||||
from ansible.module_utils.hwc_utils import DictComparison
|
||||
|
||||
|
||||
class HwcDictComparisonTestCase(unittest.TestCase):
|
||||
def test_simple_no_difference(self):
|
||||
value1 = {
|
||||
'foo': 'bar',
|
||||
'test': 'original'
|
||||
}
|
||||
d = DictComparison(value1)
|
||||
d_ = d
|
||||
self.assertTrue(d == d_)
|
||||
|
||||
def test_simple_different(self):
|
||||
value1 = {
|
||||
'foo': 'bar',
|
||||
'test': 'original'
|
||||
}
|
||||
value2 = {
|
||||
'foo': 'bar',
|
||||
'test': 'different'
|
||||
}
|
||||
value3 = {
|
||||
'test': 'original'
|
||||
}
|
||||
dict1 = DictComparison(value1)
|
||||
dict2 = DictComparison(value2)
|
||||
dict3 = DictComparison(value3)
|
||||
self.assertFalse(dict1 == dict2)
|
||||
self.assertFalse(dict1 == dict3)
|
||||
self.assertFalse(dict2 == dict3)
|
||||
|
||||
def test_nested_dictionaries_no_difference(self):
|
||||
value1 = {
|
||||
'foo': {
|
||||
'quiet': {
|
||||
'tree': 'test'
|
||||
},
|
||||
'bar': 'baz'
|
||||
},
|
||||
'test': 'original'
|
||||
}
|
||||
d = DictComparison(value1)
|
||||
d_ = d
|
||||
self.assertTrue(d == d_)
|
||||
|
||||
def test_nested_dictionaries_with_difference(self):
|
||||
value1 = {
|
||||
'foo': {
|
||||
'quiet': {
|
||||
'tree': 'test'
|
||||
},
|
||||
'bar': 'baz'
|
||||
},
|
||||
'test': 'original'
|
||||
}
|
||||
value2 = {
|
||||
'foo': {
|
||||
'quiet': {
|
||||
'tree': 'baz'
|
||||
},
|
||||
'bar': 'hello'
|
||||
},
|
||||
'test': 'original'
|
||||
}
|
||||
value3 = {
|
||||
'foo': {
|
||||
'quiet': {
|
||||
'tree': 'test'
|
||||
},
|
||||
'bar': 'baz'
|
||||
}
|
||||
}
|
||||
|
||||
dict1 = DictComparison(value1)
|
||||
dict2 = DictComparison(value2)
|
||||
dict3 = DictComparison(value3)
|
||||
self.assertFalse(dict1 == dict2)
|
||||
self.assertFalse(dict1 == dict3)
|
||||
self.assertFalse(dict2 == dict3)
|
||||
|
||||
def test_arrays_strings_no_difference(self):
|
||||
value1 = {
|
||||
'foo': [
|
||||
'baz',
|
||||
'bar'
|
||||
]
|
||||
}
|
||||
d = DictComparison(value1)
|
||||
d_ = d
|
||||
self.assertTrue(d == d_)
|
||||
|
||||
def test_arrays_strings_with_difference(self):
|
||||
value1 = {
|
||||
'foo': [
|
||||
'baz',
|
||||
'bar',
|
||||
]
|
||||
}
|
||||
|
||||
value2 = {
|
||||
'foo': [
|
||||
'baz',
|
||||
'hello'
|
||||
]
|
||||
}
|
||||
value3 = {
|
||||
'foo': [
|
||||
'bar',
|
||||
]
|
||||
}
|
||||
|
||||
dict1 = DictComparison(value1)
|
||||
dict2 = DictComparison(value2)
|
||||
dict3 = DictComparison(value3)
|
||||
self.assertFalse(dict1 == dict2)
|
||||
self.assertFalse(dict1 == dict3)
|
||||
self.assertFalse(dict2 == dict3)
|
||||
|
||||
def test_arrays_dicts_with_no_difference(self):
|
||||
value1 = {
|
||||
'foo': [
|
||||
{
|
||||
'test': 'value',
|
||||
'foo': 'bar'
|
||||
},
|
||||
{
|
||||
'different': 'dict'
|
||||
}
|
||||
]
|
||||
}
|
||||
d = DictComparison(value1)
|
||||
d_ = d
|
||||
self.assertTrue(d == d_)
|
||||
|
||||
def test_arrays_dicts_with_difference(self):
|
||||
value1 = {
|
||||
'foo': [
|
||||
{
|
||||
'test': 'value',
|
||||
'foo': 'bar'
|
||||
},
|
||||
{
|
||||
'different': 'dict'
|
||||
}
|
||||
]
|
||||
}
|
||||
value2 = {
|
||||
'foo': [
|
||||
{
|
||||
'test': 'value2',
|
||||
'foo': 'bar2'
|
||||
},
|
||||
]
|
||||
}
|
||||
value3 = {
|
||||
'foo': [
|
||||
{
|
||||
'test': 'value',
|
||||
'foo': 'bar'
|
||||
}
|
||||
]
|
||||
}
|
||||
dict1 = DictComparison(value1)
|
||||
dict2 = DictComparison(value2)
|
||||
dict3 = DictComparison(value3)
|
||||
self.assertFalse(dict1 == dict2)
|
||||
self.assertFalse(dict1 == dict3)
|
||||
self.assertFalse(dict2 == dict3)
|
||||
109
test/units/module_utils/hwc/test_hwc_utils.py
Normal file
109
test/units/module_utils/hwc/test_hwc_utils.py
Normal file
@@ -0,0 +1,109 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
import os
|
||||
import sys
|
||||
|
||||
from units.compat import unittest
|
||||
from ansible.module_utils.hwc_utils import (navigate_hash,
|
||||
remove_empty_from_dict,
|
||||
remove_nones_from_dict,
|
||||
replace_resource_dict)
|
||||
|
||||
|
||||
class HwcUtilsTestCase(unittest.TestCase):
|
||||
def test_navigate_hash(self):
|
||||
value = {
|
||||
'foo': {
|
||||
'quiet': {
|
||||
'tree': 'test'
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
self.assertEquals(navigate_hash(value, ["foo", "quiet", "tree"]),
|
||||
"test")
|
||||
|
||||
self.assertEquals(navigate_hash(value, ["foo", "q", "tree"], 123),
|
||||
123)
|
||||
|
||||
self.assertIsNone(navigate_hash(value, [], 123))
|
||||
|
||||
def test_remove_empty_from_dict(self):
|
||||
value = {
|
||||
'foo': {
|
||||
'quiet': {
|
||||
'tree': 'test',
|
||||
'tree1': [
|
||||
None,
|
||||
{},
|
||||
[],
|
||||
'test'
|
||||
],
|
||||
'tree2': {},
|
||||
'tree3': []
|
||||
},
|
||||
},
|
||||
'foo1': [],
|
||||
'foo2': {},
|
||||
'foo3': None,
|
||||
}
|
||||
|
||||
expect = {
|
||||
'foo': {
|
||||
'quiet': {
|
||||
'tree': 'test',
|
||||
'tree1': [
|
||||
'test'
|
||||
]
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
self.assertEqual(remove_empty_from_dict(value), expect)
|
||||
|
||||
def test_remove_nones_from_dict(self):
|
||||
value = {
|
||||
'foo': {
|
||||
'quiet': {
|
||||
'tree': 'test',
|
||||
'tree1': [
|
||||
None,
|
||||
{},
|
||||
[],
|
||||
'test'
|
||||
],
|
||||
'tree2': {},
|
||||
'tree3': []
|
||||
},
|
||||
},
|
||||
'foo1': [],
|
||||
'foo2': {},
|
||||
'foo3': None,
|
||||
}
|
||||
|
||||
expect = {
|
||||
'foo': {
|
||||
'quiet': {
|
||||
'tree': 'test',
|
||||
'tree1': [
|
||||
{},
|
||||
[],
|
||||
'test'
|
||||
],
|
||||
'tree2': {},
|
||||
'tree3': []
|
||||
},
|
||||
},
|
||||
'foo1': [],
|
||||
'foo2': {},
|
||||
}
|
||||
|
||||
self.assertEqual(remove_nones_from_dict(value), expect)
|
||||
|
||||
def test_replace_resource_dict(self):
|
||||
self.assertEqual(replace_resource_dict({'foo': 'quiet'}, 'foo'), 'quiet')
|
||||
|
||||
self.assertEqual(replace_resource_dict({}, 'foo'), {})
|
||||
|
||||
self.assertEqual(replace_resource_dict([[{'foo': 'quiet'}]], 'foo'),
|
||||
[['quiet']])
|
||||
Reference in New Issue
Block a user