2017-07-25 11:35:03 +00:00
|
|
|
# -*- 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/>.
|
|
|
|
|
2018-10-13 03:01:14 +00:00
|
|
|
from units.compat.mock import patch
|
2019-08-02 15:18:14 +00:00
|
|
|
from units.modules.utils import set_module_args as _set_module_args, ModuleTestCase
|
2017-07-25 11:35:03 +00:00
|
|
|
|
2018-11-20 21:58:46 +00:00
|
|
|
import pytest
|
|
|
|
|
2017-07-25 11:35:03 +00:00
|
|
|
try:
|
|
|
|
from vspk import v5_0 as vsdk
|
|
|
|
from bambou import nurest_session
|
|
|
|
except ImportError:
|
2018-11-20 21:58:46 +00:00
|
|
|
pytestmark = pytest.mark.skip('Nuage Ansible modules requires the vspk and bambou python libraries')
|
2017-07-25 11:35:03 +00:00
|
|
|
|
|
|
|
|
|
|
|
def set_module_args(args):
|
2017-11-17 17:17:07 +00:00
|
|
|
if 'auth' not in args:
|
|
|
|
args['auth'] = {
|
|
|
|
'api_username': 'csproot',
|
|
|
|
'api_password': 'csproot',
|
|
|
|
'api_enterprise': 'csp',
|
|
|
|
'api_url': 'https://localhost:8443',
|
|
|
|
'api_version': 'v5_0'
|
|
|
|
}
|
|
|
|
return _set_module_args(args)
|
2017-07-25 11:35:03 +00:00
|
|
|
|
|
|
|
|
|
|
|
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)
|
|
|
|
|
|
|
|
|
2017-11-17 17:17:07 +00:00
|
|
|
class TestNuageModule(ModuleTestCase):
|
2017-07-25 11:35:03 +00:00
|
|
|
|
|
|
|
def setUp(self):
|
2017-11-17 17:17:07 +00:00
|
|
|
super(TestNuageModule, self).setUp()
|
2017-07-25 11:35:03 +00:00
|
|
|
|
|
|
|
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 tearDown(self):
|
2017-11-17 17:17:07 +00:00
|
|
|
super(TestNuageModule, self).tearDown()
|
2017-07-25 11:35:03 +00:00
|
|
|
self.session_mock.stop()
|