-
Notifications
You must be signed in to change notification settings - Fork 63
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ADD]Integration and Unit test cases for extensible attribute.
- Loading branch information
1 parent
d0dd285
commit 1d35b3a
Showing
8 changed files
with
335 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
--- | ||
|
||
- hosts: localhost | ||
vars: | ||
nios_provider: | ||
host: 10.120.1.11 | ||
username: admin | ||
password: infoblox | ||
|
||
connection: local | ||
tasks: | ||
- name: Create INT extensible attribute | ||
infoblox.nios_modules.nios_extensible_attribute: | ||
name: integer_ea | ||
type: INTEGER | ||
default_value: 11 | ||
comment: Created with Ansible | ||
flags: 'I' | ||
state: present | ||
provider: "{{ nios_provider }}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
shippable/cloud/group1 | ||
cloud/nios | ||
destructive |
3 changes: 3 additions & 0 deletions
3
tests/integration/targets/nios_extensible_attribute/defaults/main.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
--- | ||
testcase: "*" | ||
test_items: [] |
2 changes: 2 additions & 0 deletions
2
tests/integration/targets/nios_extensible_attribute/meta/main.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
dependencies: | ||
- prepare_nios_tests |
1 change: 1 addition & 0 deletions
1
tests/integration/targets/nios_extensible_attribute/tasks/main.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
- include_tasks: nios_extensible_attribute.yaml |
147 changes: 147 additions & 0 deletions
147
tests/integration/targets/nios_extensible_attribute/tasks/nios_extensible_attribute.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,147 @@ | ||
- name: Clean up existing EA | ||
infoblox.nios_modules.nios_extensible_attribute: | ||
name: stringEA | ||
type: STRING | ||
state: absent | ||
provider: "{{ nios_provider }}" | ||
|
||
- name: Create STRING EA | ||
infoblox.nios_modules.nios_extensible_attribute: | ||
name: stringEA | ||
type: STRING | ||
default_value: "string" | ||
min: 1 | ||
max: 15 | ||
comment: Created string EA with Ansible | ||
state: present | ||
provider: "{{ nios_provider }}" | ||
register: create_string_ea | ||
|
||
- name: Update STRING EA Comment | ||
infoblox.nios_modules.nios_extensible_attribute: | ||
name: stringEA | ||
type: STRING | ||
default_value: "string" | ||
min: 1 | ||
max: 15 | ||
comment: Updated string EA with Ansible | ||
state: present | ||
provider: "{{ nios_provider }}" | ||
register: update_string_ea | ||
|
||
- name: Create Integer EA | ||
infoblox.nios_modules.nios_extensible_attribute: | ||
name: IntegerEA | ||
type: INTEGER | ||
default_value: "15" | ||
min: 1 | ||
max: 15 | ||
flags: 'I' | ||
comment: Created string EA with Ansible | ||
state: present | ||
provider: "{{ nios_provider }}" | ||
register: create_integer_ea | ||
|
||
- name: Update Integer EA value | ||
infoblox.nios_modules.nios_extensible_attribute: | ||
name: IntegerEA | ||
type: INTEGER | ||
default_value: "14" | ||
min: 1 | ||
max: 15 | ||
flags: 'I' | ||
comment: Created string EA with Ansible | ||
state: present | ||
provider: "{{ nios_provider }}" | ||
register: update_integer_ea | ||
|
||
- name: Remove STRING EA Comment | ||
infoblox.nios_modules.nios_extensible_attribute: | ||
name: stringEA | ||
type: STRING | ||
default_value: "string" | ||
min: 1 | ||
max: 15 | ||
state: present | ||
provider: "{{ nios_provider }}" | ||
register: remove_string_ea | ||
|
||
- name: Remove Integer EA definition | ||
infoblox.nios_modules.nios_extensible_attribute: | ||
name: IntegerEA | ||
type: INTEGER | ||
default_value: "14" | ||
min: 1 | ||
max: 15 | ||
flags: 'I' | ||
comment: Created string EA with Ansible | ||
state: absent | ||
provider: "{{ nios_provider }}" | ||
register: remove_integer_ea | ||
|
||
- name: Create ENUM EA | ||
infoblox.nios_modules.nios_extensible_attribute: | ||
name: enumEA | ||
type: ENUM | ||
list_values: | ||
- option1 | ||
- option2 | ||
default_value: "option1" | ||
comment: Created enum EA with Ansible | ||
state: present | ||
provider: "{{ nios_provider }}" | ||
register: create_enum_ea | ||
|
||
- name: Update ENUM EA default value | ||
infoblox.nios_modules.nios_extensible_attribute: | ||
name: enumEA | ||
type: ENUM | ||
list_values: | ||
- option1 | ||
- option2 | ||
default_value: "option2" | ||
comment: Updated enum EA default value with Ansible | ||
state: present | ||
provider: "{{ nios_provider }}" | ||
register: update_enum_ea | ||
|
||
- name: Create DATE EA | ||
infoblox.nios_modules.nios_extensible_attribute: | ||
name: dateEA | ||
type: DATE | ||
default_value: "2023-01-01" | ||
comment: Created date EA with Ansible | ||
state: present | ||
provider: "{{ nios_provider }}" | ||
register: create_date_ea | ||
|
||
- name: Update DATE EA default value | ||
infoblox.nios_modules.nios_extensible_attribute: | ||
name: dateEA | ||
type: DATE | ||
default_value: "2023-12-31" | ||
comment: Updated date EA default value with Ansible | ||
state: present | ||
provider: "{{ nios_provider }}" | ||
register: update_date_ea | ||
|
||
- name: Check if the EA already exists | ||
infoblox.nios_modules.nios_extensible_attribute: | ||
name: existEA | ||
state: present | ||
provider: "{{ nios_provider }}" | ||
register: ea_exists | ||
|
||
- name: Verify outcomes including new tests | ||
ansible.builtin.assert: | ||
that: | ||
- "create_string_ea.changed" | ||
- "update_string_ea.changed" | ||
- "create_integer_ea.changed" | ||
- "update_integer_ea.changed" | ||
- "remove_string_ea.changed" | ||
- "remove_integer_ea.changed" | ||
- "create_enum_ea.changed" | ||
- "update_enum_ea.changed" | ||
- "create_date_ea.changed" | ||
- "update_date_ea.changed" |
159 changes: 159 additions & 0 deletions
159
tests/unit/plugins/modules/test_extensible_attribute.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,159 @@ | ||
# 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/>. | ||
|
||
# Make coding more python3-ish | ||
|
||
|
||
from __future__ import (absolute_import, division, print_function) | ||
__metaclass__ = type | ||
|
||
|
||
from ansible_collections.infoblox.nios_modules.plugins.modules import nios_extensible_attribute | ||
from ansible_collections.infoblox.nios_modules.plugins.module_utils import api | ||
from ansible_collections.infoblox.nios_modules.tests.unit.compat.mock import patch, MagicMock, Mock | ||
from .test_nios_module import TestNiosModule, load_fixture | ||
|
||
|
||
class TestNiosExtensibleAttributeModule(TestNiosModule): | ||
|
||
module = nios_extensible_attribute | ||
|
||
def setUp(self): | ||
super(TestNiosExtensibleAttributeModule, self).setUp() | ||
self.module = MagicMock(name='ansible_collections.infoblox.nios_modules.plugins.modules.nios_extensible_attribute.WapiModule') | ||
self.module.check_mode = False | ||
self.module.params = {'provider': None} | ||
self.mock_wapi = patch('ansible_collections.infoblox.nios_modules.plugins.modules.nios_extensible_attribute.WapiModule') | ||
self.exec_command = self.mock_wapi.start() | ||
self.mock_wapi_run = patch('ansible_collections.infoblox.nios_modules.plugins.modules.nios_extensible_attribute.WapiModule.run') | ||
self.mock_wapi_run.start() | ||
self.load_config = self.mock_wapi_run.start() | ||
self.mock_check_type_dict = patch('ansible.module_utils.common.validation.check_type_dict') | ||
self.mock_check_type_dict_obj = self.mock_check_type_dict.start() | ||
|
||
def tearDown(self): | ||
super(TestNiosExtensibleAttributeModule, self).tearDown() | ||
self.mock_wapi.stop() | ||
self.mock_wapi_run.stop() | ||
self.mock_check_type_dict.stop() | ||
|
||
def _get_wapi(self, test_object): | ||
wapi = api.WapiModule(self.module) | ||
wapi.get_object = Mock(name='get_object', return_value=test_object) | ||
wapi.create_object = Mock(name='create_object') | ||
wapi.update_object = Mock(name='update_object') | ||
wapi.delete_object = Mock(name='delete_object') | ||
return wapi | ||
|
||
def load_fixtures(self, commands=None): | ||
self.exec_command.return_value = (0, load_fixture('nios_result.txt').strip(), None) | ||
self.load_config.return_value = dict(diff=None, session='session') | ||
|
||
def test_create_extensible_attribute(self): | ||
self.module.params = { | ||
'name': 'my_string', | ||
'type': 'STRING', | ||
'comment': 'Created by ansible', | ||
'state': 'present', | ||
'provider': None | ||
} | ||
|
||
test_object = None | ||
|
||
test_spec = { | ||
"name": {"ib_req": True}, | ||
"type": {"ib_req": True}, | ||
"comment": {}, | ||
} | ||
|
||
wapi = self._get_wapi(test_object) | ||
print("WAPI: ", wapi.__dict__) | ||
res = wapi.run('testobject', test_spec) | ||
|
||
self.assertEqual(res['changed'], True) | ||
wapi.create_object.assert_called_once_with('testobject', {'name': 'my_string', | ||
'type': 'STRING', | ||
'comment': 'Created by ansible'}) | ||
|
||
def test_nios_ea_update_comment(self): | ||
self.module.params = { | ||
'provider': None, | ||
'state': 'present', | ||
'name': 'testStringEA', | ||
'type': 'STRING', | ||
'flag': 'I', | ||
'default_value': 'test', | ||
'comment': 'Update comment' | ||
} | ||
|
||
ref = "extensibleattributedef/b25lLmV4dGVuc2libGVfYXR0cmlidXRlc19kZWYkLlRlcnJhZm9ybSBJbnRlcm5hbCBJRA:testStringEA" | ||
|
||
test_object = [ | ||
{ | ||
"comment": "test comment", | ||
"_ref": ref, | ||
"name": "testStringEA", | ||
"flag": "I", | ||
"type": "STRING", | ||
"default_value": "test" | ||
} | ||
] | ||
|
||
test_spec = { | ||
"name": {"ib_req": True}, | ||
"type": {"ib_req": True}, | ||
"comment": {}, | ||
"flag": {}, | ||
"default_value": {} | ||
} | ||
|
||
wapi = self._get_wapi(test_object) | ||
res = wapi.run('testobject', test_spec) | ||
self.assertTrue(res['changed']) | ||
wapi.update_object.assert_called_once_with( | ||
ref, {'comment': 'Update comment', 'type': 'STRING', 'name': 'testStringEA', 'flag': 'I', 'default_value': 'test'} | ||
) | ||
|
||
|
||
def test_remove_extensible_attribute(self): | ||
self.module.params = {'provider': None, 'state': 'absent', 'name': 'testStringEA', 'type': 'STRING', | ||
'flag': None, 'default_value': None, 'comment': None} | ||
|
||
ref = "extensibleattributedef/b25lLmV4dGVuc2libGVfYXR0cmlidXRlc19kZWYkLlRlcnJhZm9ybSBJbnRlcm5hbCBJRA:testStringEA" | ||
|
||
test_object = [ | ||
{ | ||
"comment": "test comment", | ||
"_ref": ref, | ||
"name": "testStringEA", | ||
"flag": "I", | ||
"type": "STRING", | ||
"default_value": "test" | ||
} | ||
] | ||
|
||
test_spec = { | ||
"name": {"ib_req": True}, | ||
"type": {"ib_req": True}, | ||
"comment": {}, | ||
"flag": {}, | ||
"default_value": {} | ||
} | ||
|
||
wapi = self._get_wapi(test_object) | ||
res = wapi.run('testobject', test_spec) | ||
|
||
self.assertTrue(res['changed']) | ||
wapi.delete_object.assert_called_once_with(ref) |