New module: management of the Nuage Networks VSP SDN solution (network/nuage/nuage_vspk) (#24895)
* Nuage module and unit tests with requested changes
* Cleanup of imports
* Adding check on python version
* Adding import try and catch wrappers
* Cleanup of requirements and adding integration tests
* Using pypi package for simulator
* Cleanup of requirements and adding integration tests
* Adding aliases for integration tests
* Adding module to import sanity test skip list
* Revert "Adding module to import sanity test skip list"
This reverts commit eab23af8c5
.
* Adding check for importlib and cleanup of requirements
This commit is contained in:
parent
e37e736ddb
commit
c00554735f
13 changed files with 2804 additions and 0 deletions
0
lib/ansible/modules/network/nuage/__init__.py
Normal file
0
lib/ansible/modules/network/nuage/__init__.py
Normal file
1046
lib/ansible/modules/network/nuage/nuage_vspk.py
Normal file
1046
lib/ansible/modules/network/nuage/nuage_vspk.py
Normal file
File diff suppressed because it is too large
Load diff
|
@ -11,3 +11,4 @@
|
||||||
- { include: dellos10.yaml }
|
- { include: dellos10.yaml }
|
||||||
- { include: dellos9.yaml }
|
- { include: dellos9.yaml }
|
||||||
- { include: dellos6.yaml }
|
- { include: dellos6.yaml }
|
||||||
|
- { include: nuage.yaml }
|
||||||
|
|
11
test/integration/nuage.yaml
Normal file
11
test/integration/nuage.yaml
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
---
|
||||||
|
- hosts: nuage
|
||||||
|
gather_facts: no
|
||||||
|
connection: local
|
||||||
|
|
||||||
|
vars:
|
||||||
|
limit_to: "*"
|
||||||
|
debug: false
|
||||||
|
|
||||||
|
roles:
|
||||||
|
- { role: nuage_vspk, when: "limit_to in ['*', 'nuage_vspk']" }
|
1
test/integration/targets/nuage_vspk/aliases
Normal file
1
test/integration/targets/nuage_vspk/aliases
Normal file
|
@ -0,0 +1 @@
|
||||||
|
skip/python3
|
9
test/integration/targets/nuage_vspk/defaults/main.yaml
Normal file
9
test/integration/targets/nuage_vspk/defaults/main.yaml
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
---
|
||||||
|
testcase: "*"
|
||||||
|
test_items: []
|
||||||
|
nuage_auth:
|
||||||
|
api_username: csproot
|
||||||
|
api_password: csproot
|
||||||
|
api_enterprise: csp
|
||||||
|
api_url: http://localhost:5000
|
||||||
|
api_version: v5_0
|
2
test/integration/targets/nuage_vspk/meta/main.yaml
Normal file
2
test/integration/targets/nuage_vspk/meta/main.yaml
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
dependencies:
|
||||||
|
- prepare_nuage_tests
|
17
test/integration/targets/nuage_vspk/tasks/main.yaml
Normal file
17
test/integration/targets/nuage_vspk/tasks/main.yaml
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
---
|
||||||
|
|
||||||
|
- name: collect all test cases
|
||||||
|
find:
|
||||||
|
paths: "{{ role_path }}/tests"
|
||||||
|
patterns: "{{ testcase }}.yaml"
|
||||||
|
delegate_to: localhost
|
||||||
|
register: test_cases
|
||||||
|
|
||||||
|
- name: set test_items
|
||||||
|
set_fact: test_items="{{ test_cases.files | map(attribute='path') | list }}"
|
||||||
|
|
||||||
|
- name: run test case
|
||||||
|
include: "{{ test_case_to_run }}"
|
||||||
|
with_items: "{{ test_items }}"
|
||||||
|
loop_control:
|
||||||
|
loop_var: test_case_to_run
|
226
test/integration/targets/nuage_vspk/tests/basic.yaml
Normal file
226
test/integration/targets/nuage_vspk/tests/basic.yaml
Normal file
|
@ -0,0 +1,226 @@
|
||||||
|
---
|
||||||
|
# Getting the CSP enterprise
|
||||||
|
- name: Get CSP Enterprise
|
||||||
|
nuage_vspk:
|
||||||
|
auth: "{{ nuage_auth }}"
|
||||||
|
type: Enterprise
|
||||||
|
command: get_csp_enterprise
|
||||||
|
register: nuage_csp_enterprise
|
||||||
|
|
||||||
|
- name: Check if CSP enterprise was found
|
||||||
|
assert:
|
||||||
|
that:
|
||||||
|
- nuage_csp_enterprise.id is defined
|
||||||
|
- nuage_csp_enterprise.entities is defined
|
||||||
|
- nuage_csp_enterprise.entities[0].name == "CSP"
|
||||||
|
|
||||||
|
- name: Create Enterprise
|
||||||
|
nuage_vspk:
|
||||||
|
auth: "{{ nuage_auth }}"
|
||||||
|
type: Enterprise
|
||||||
|
state: present
|
||||||
|
properties:
|
||||||
|
name: "Ansible-Enterprise"
|
||||||
|
register: nuage_enterprise
|
||||||
|
|
||||||
|
- name: Check Enterprise was created
|
||||||
|
assert:
|
||||||
|
that:
|
||||||
|
- nuage_enterprise.changed
|
||||||
|
- nuage_enterprise.id is defined
|
||||||
|
- nuage_enterprise.entities is defined
|
||||||
|
- nuage_enterprise.entities[0].name == "Ansible-Enterprise"
|
||||||
|
|
||||||
|
- name: Finding Enterprise
|
||||||
|
nuage_vspk:
|
||||||
|
auth: "{{ nuage_auth }}"
|
||||||
|
type: Enterprise
|
||||||
|
command: find
|
||||||
|
properties:
|
||||||
|
name: "Ansible-Enterprise"
|
||||||
|
register: nuage_enterprise
|
||||||
|
|
||||||
|
- name: Check Enterprise was found
|
||||||
|
assert:
|
||||||
|
that:
|
||||||
|
- not nuage_enterprise.changed
|
||||||
|
- nuage_enterprise.id is defined
|
||||||
|
- nuage_enterprise.entities is defined
|
||||||
|
- nuage_enterprise.entities[0].name == "Ansible-Enterprise"
|
||||||
|
|
||||||
|
- name: Create Enterprise again to confirm idempoteny
|
||||||
|
nuage_vspk:
|
||||||
|
auth: "{{ nuage_auth }}"
|
||||||
|
type: Enterprise
|
||||||
|
state: present
|
||||||
|
properties:
|
||||||
|
name: "Ansible-Enterprise"
|
||||||
|
register: nuage_enterprise
|
||||||
|
|
||||||
|
- name: Check Enterprise was not created again
|
||||||
|
assert:
|
||||||
|
that:
|
||||||
|
- not nuage_enterprise.changed
|
||||||
|
- nuage_enterprise.id is defined
|
||||||
|
- nuage_enterprise.entities is defined
|
||||||
|
- nuage_enterprise.entities[0].name == "Ansible-Enterprise"
|
||||||
|
|
||||||
|
- name: Create admin user
|
||||||
|
nuage_vspk:
|
||||||
|
auth: "{{ nuage_auth }}"
|
||||||
|
type: User
|
||||||
|
parent_id: "{{ nuage_enterprise.id }}"
|
||||||
|
parent_type: Enterprise
|
||||||
|
state: present
|
||||||
|
match_filter: "userName == 'ansible-admin'"
|
||||||
|
properties:
|
||||||
|
email: "ansible@localhost.local"
|
||||||
|
first_name: "Ansible"
|
||||||
|
last_name: "Admin"
|
||||||
|
password: "ansible-password"
|
||||||
|
user_name: "ansible-admin"
|
||||||
|
register: nuage_user
|
||||||
|
|
||||||
|
- name: Check the user was created
|
||||||
|
assert:
|
||||||
|
that:
|
||||||
|
- nuage_user.changed
|
||||||
|
- nuage_user.id is defined
|
||||||
|
- nuage_user.entities is defined
|
||||||
|
- nuage_user.entities[0].userName == "ansible-admin"
|
||||||
|
|
||||||
|
- name: Update admin password
|
||||||
|
nuage_vspk:
|
||||||
|
auth: "{{ nuage_auth }}"
|
||||||
|
type: User
|
||||||
|
id: "{{ nuage_user.id }}"
|
||||||
|
command: change_password
|
||||||
|
properties:
|
||||||
|
password: "ansible-new-password"
|
||||||
|
ignore_errors: yes
|
||||||
|
|
||||||
|
- name: Check the user was created
|
||||||
|
assert:
|
||||||
|
that:
|
||||||
|
- nuage_user.changed
|
||||||
|
- nuage_user.id is defined
|
||||||
|
- nuage_user.entities is defined
|
||||||
|
- nuage_user.entities[0].userName == "ansible-admin"
|
||||||
|
|
||||||
|
- name: Create group in Enterprise
|
||||||
|
nuage_vspk:
|
||||||
|
auth: "{{ nuage_auth }}"
|
||||||
|
type: Group
|
||||||
|
parent_id: "{{ nuage_enterprise.id }}"
|
||||||
|
parent_type: Enterprise
|
||||||
|
state: present
|
||||||
|
properties:
|
||||||
|
name: "Ansible-Group"
|
||||||
|
register: nuage_group
|
||||||
|
|
||||||
|
- name: Check the group was created
|
||||||
|
assert:
|
||||||
|
that:
|
||||||
|
- nuage_group.changed
|
||||||
|
- nuage_group.id is defined
|
||||||
|
- nuage_group.entities is defined
|
||||||
|
- nuage_group.entities[0].name == "Ansible-Group"
|
||||||
|
|
||||||
|
- name: Assign admin user to group
|
||||||
|
nuage_vspk:
|
||||||
|
auth: "{{ nuage_auth }}"
|
||||||
|
type: User
|
||||||
|
id: "{{ nuage_user.id }}"
|
||||||
|
parent_id: "{{ nuage_group.id }}"
|
||||||
|
parent_type: Group
|
||||||
|
state: present
|
||||||
|
register: nuage_assign
|
||||||
|
|
||||||
|
- name: Check the admin was added to the group
|
||||||
|
assert:
|
||||||
|
that:
|
||||||
|
- nuage_assign.changed
|
||||||
|
|
||||||
|
- name: Assign admin user to administrators again to test idempotency
|
||||||
|
nuage_vspk:
|
||||||
|
auth: "{{ nuage_auth }}"
|
||||||
|
type: User
|
||||||
|
id: "{{ nuage_user.id }}"
|
||||||
|
parent_id: "{{ nuage_group.id }}"
|
||||||
|
parent_type: Group
|
||||||
|
state: present
|
||||||
|
register: nuage_assign
|
||||||
|
|
||||||
|
- name: Check the group was not changed
|
||||||
|
assert:
|
||||||
|
that:
|
||||||
|
- not nuage_assign.changed
|
||||||
|
|
||||||
|
- name: Unassign admin user to administrators
|
||||||
|
nuage_vspk:
|
||||||
|
auth: "{{ nuage_auth }}"
|
||||||
|
type: User
|
||||||
|
id: "{{ nuage_user.id }}"
|
||||||
|
parent_id: "{{ nuage_group.id }}"
|
||||||
|
parent_type: Group
|
||||||
|
state: absent
|
||||||
|
register: nuage_unassign
|
||||||
|
|
||||||
|
- name: Check the admin was removed from the group
|
||||||
|
assert:
|
||||||
|
that:
|
||||||
|
- nuage_unassign.changed
|
||||||
|
|
||||||
|
- name: Unassign admin user to administrators again to test idempotency
|
||||||
|
nuage_vspk:
|
||||||
|
auth: "{{ nuage_auth }}"
|
||||||
|
type: User
|
||||||
|
id: "{{ nuage_user.id }}"
|
||||||
|
parent_id: "{{ nuage_group.id }}"
|
||||||
|
parent_type: Group
|
||||||
|
state: absent
|
||||||
|
register: nuage_unassign
|
||||||
|
|
||||||
|
- name: Check the group was not changed
|
||||||
|
assert:
|
||||||
|
that:
|
||||||
|
- not nuage_unassign.changed
|
||||||
|
|
||||||
|
- name: Delete User
|
||||||
|
nuage_vspk:
|
||||||
|
auth: "{{ nuage_auth }}"
|
||||||
|
type: User
|
||||||
|
id: "{{ nuage_user.id }}"
|
||||||
|
state: absent
|
||||||
|
register: nuage_user
|
||||||
|
|
||||||
|
- name: Check the user was deleted
|
||||||
|
assert:
|
||||||
|
that:
|
||||||
|
- nuage_user.changed
|
||||||
|
|
||||||
|
- name: Delete Enterprise
|
||||||
|
nuage_vspk:
|
||||||
|
auth: "{{ nuage_auth }}"
|
||||||
|
type: Enterprise
|
||||||
|
id: "{{ nuage_enterprise.id }}"
|
||||||
|
state: absent
|
||||||
|
register: nuage_enterprise
|
||||||
|
|
||||||
|
- name: Check the enterprise was deleted
|
||||||
|
assert:
|
||||||
|
that:
|
||||||
|
- nuage_enterprise.changed
|
||||||
|
|
||||||
|
- name: Delete Enterprise again to test idempotency
|
||||||
|
nuage_vspk:
|
||||||
|
auth: "{{ nuage_auth }}"
|
||||||
|
type: Enterprise
|
||||||
|
match_filter: 'name == "Ansible-Enterprise"'
|
||||||
|
state: absent
|
||||||
|
register: nuage_enterprise
|
||||||
|
|
||||||
|
- name: Check the delete idempotency
|
||||||
|
assert:
|
||||||
|
that:
|
||||||
|
- not nuage_enterprise.changed
|
|
@ -0,0 +1,9 @@
|
||||||
|
---
|
||||||
|
- name: Install Nuage VSD API Simulator
|
||||||
|
pip:
|
||||||
|
name: nuage-vsd-sim
|
||||||
|
|
||||||
|
- name: Start Nuage VSD API Simulator
|
||||||
|
shell: "(cd /; nuage-vsd-sim >/dev/null 2>&1 &)"
|
||||||
|
async: 10
|
||||||
|
poll: 0
|
0
test/units/modules/network/nuage/__init__.py
Normal file
0
test/units/modules/network/nuage/__init__.py
Normal file
100
test/units/modules/network/nuage/nuage_module.py
Normal file
100
test/units/modules/network/nuage/nuage_module.py
Normal file
|
@ -0,0 +1,100 @@
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
|
# (c) 2017, Nokia
|
||||||
|
# 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 json
|
||||||
|
from ansible.compat.tests import unittest
|
||||||
|
from ansible.compat.tests.mock import patch
|
||||||
|
from ansible.module_utils import basic
|
||||||
|
from ansible.module_utils._text import to_bytes
|
||||||
|
|
||||||
|
from nose.plugins.skip import SkipTest
|
||||||
|
try:
|
||||||
|
from vspk import v5_0 as vsdk
|
||||||
|
from bambou import nurest_session
|
||||||
|
except ImportError:
|
||||||
|
raise SkipTest('Nuage Ansible modules requires the vspk and bambou python libraries')
|
||||||
|
|
||||||
|
|
||||||
|
def set_module_args(args):
|
||||||
|
set_module_args_custom_auth(args=args, auth={
|
||||||
|
'api_username': 'csproot',
|
||||||
|
'api_password': 'csproot',
|
||||||
|
'api_enterprise': 'csp',
|
||||||
|
'api_url': 'https://localhost:8443',
|
||||||
|
'api_version': 'v5_0'
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
|
def set_module_args_custom_auth(args, auth):
|
||||||
|
args['auth'] = auth
|
||||||
|
args = json.dumps({'ANSIBLE_MODULE_ARGS': args})
|
||||||
|
basic._ANSIBLE_ARGS = to_bytes(args)
|
||||||
|
|
||||||
|
|
||||||
|
class AnsibleExitJson(Exception):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
class AnsibleFailJson(Exception):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
class MockNuageResponse(object):
|
||||||
|
def __init__(self, status_code, reason, errors):
|
||||||
|
self.status_code = status_code
|
||||||
|
self.reason = reason
|
||||||
|
self.errors = errors
|
||||||
|
|
||||||
|
|
||||||
|
class MockNuageConnection(object):
|
||||||
|
def __init__(self, status_code, reason, errors):
|
||||||
|
self.response = MockNuageResponse(status_code, reason, errors)
|
||||||
|
|
||||||
|
|
||||||
|
class TestNuageModule(unittest.TestCase):
|
||||||
|
|
||||||
|
def setUp(self):
|
||||||
|
|
||||||
|
def session_start(self):
|
||||||
|
self._root_object = vsdk.NUMe()
|
||||||
|
self._root_object.enterprise_id = 'enterprise-id'
|
||||||
|
nurest_session._NURESTSessionCurrentContext.session = self
|
||||||
|
return self
|
||||||
|
|
||||||
|
self.session_mock = patch('vspk.v5_0.NUVSDSession.start', new=session_start)
|
||||||
|
self.session_mock.start()
|
||||||
|
|
||||||
|
def fail_json(*args, **kwargs):
|
||||||
|
kwargs['failed'] = True
|
||||||
|
raise AnsibleFailJson(kwargs)
|
||||||
|
|
||||||
|
self.fail_json_mock = patch('ansible.module_utils.basic.AnsibleModule.fail_json', new=fail_json)
|
||||||
|
self.fail_json_mock.start()
|
||||||
|
|
||||||
|
def exit_json(*args, **kwargs):
|
||||||
|
if 'changed' not in kwargs:
|
||||||
|
kwargs['changed'] = False
|
||||||
|
raise AnsibleExitJson(kwargs)
|
||||||
|
|
||||||
|
self.exit_json_mock = patch('ansible.module_utils.basic.AnsibleModule.exit_json', new=exit_json)
|
||||||
|
self.exit_json_mock.start()
|
||||||
|
|
||||||
|
def tearDown(self):
|
||||||
|
self.session_mock.stop()
|
||||||
|
self.fail_json_mock.stop()
|
||||||
|
self.exit_json_mock.stop()
|
1382
test/units/modules/network/nuage/test_nuage_vspk.py
Normal file
1382
test/units/modules/network/nuage/test_nuage_vspk.py
Normal file
File diff suppressed because it is too large
Load diff
Loading…
Reference in a new issue