mirror of https://github.com/ansible/ansible.git
Unit test cleanup to assist with migration. (#67920)
* Move linode unit tests to match module layout. * Fix location of netapp module_utils unit tests. * Update sanity ignores.pull/67944/head
parent
3383dc8c02
commit
7c493577ba
@ -1,68 +0,0 @@
|
|||||||
import pytest
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
|
||||||
def access_token(monkeypatch):
|
|
||||||
monkeypatch.setenv('LINODE_ACCESS_TOKEN', 'barfoo')
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
|
||||||
def no_access_token_in_env(monkeypatch):
|
|
||||||
try:
|
|
||||||
monkeypatch.delenv('LINODE_ACCESS_TOKEN')
|
|
||||||
except KeyError:
|
|
||||||
pass
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
|
||||||
def default_args():
|
|
||||||
return {'state': 'present', 'label': 'foo'}
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
|
||||||
def mock_linode():
|
|
||||||
class Linode():
|
|
||||||
def delete(self, *args, **kwargs):
|
|
||||||
pass
|
|
||||||
|
|
||||||
@property
|
|
||||||
def _raw_json(self):
|
|
||||||
return {
|
|
||||||
"alerts": {
|
|
||||||
"cpu": 90,
|
|
||||||
"io": 10000,
|
|
||||||
"network_in": 10,
|
|
||||||
"network_out": 10,
|
|
||||||
"transfer_quota": 80
|
|
||||||
},
|
|
||||||
"backups": {
|
|
||||||
"enabled": False,
|
|
||||||
"schedule": {
|
|
||||||
"day": None,
|
|
||||||
"window": None,
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"created": "2018-09-26T08:12:33",
|
|
||||||
"group": "Foobar Group",
|
|
||||||
"hypervisor": "kvm",
|
|
||||||
"id": 10480444,
|
|
||||||
"image": "linode/centos7",
|
|
||||||
"ipv4": [
|
|
||||||
"130.132.285.233"
|
|
||||||
],
|
|
||||||
"ipv6": "2a82:7e00::h03c:46ff:fe04:5cd2/64",
|
|
||||||
"label": "lin-foo",
|
|
||||||
"region": "eu-west",
|
|
||||||
"specs": {
|
|
||||||
"disk": 25600,
|
|
||||||
"memory": 1024,
|
|
||||||
"transfer": 1000,
|
|
||||||
"vcpus": 1
|
|
||||||
},
|
|
||||||
"status": "running",
|
|
||||||
"tags": [],
|
|
||||||
"type": "g6-nanode-1",
|
|
||||||
"updated": "2018-09-26T10:10:14",
|
|
||||||
"watchdog_enabled": True
|
|
||||||
}
|
|
||||||
return Linode()
|
|
@ -1,62 +0,0 @@
|
|||||||
# Copyright (c) 2018 NetApp
|
|
||||||
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
|
|
||||||
|
|
||||||
''' unit tests for module_utils netapp.py '''
|
|
||||||
from __future__ import absolute_import, division, print_function
|
|
||||||
|
|
||||||
import pytest
|
|
||||||
|
|
||||||
from ansible.module_utils.ansible_release import __version__ as ansible_version
|
|
||||||
|
|
||||||
import ansible.module_utils.netapp as netapp_utils
|
|
||||||
|
|
||||||
if not netapp_utils.has_netapp_lib():
|
|
||||||
pytestmark = pytest.mark.skip("skipping as missing required netapp_lib")
|
|
||||||
|
|
||||||
|
|
||||||
class MockONTAPConnection(object):
|
|
||||||
''' mock a server connection to ONTAP host '''
|
|
||||||
|
|
||||||
def __init__(self, kind=None, parm1=None):
|
|
||||||
''' save arguments '''
|
|
||||||
self.type = kind
|
|
||||||
self.parm1 = parm1
|
|
||||||
self.xml_in = None
|
|
||||||
self.xml_out = None
|
|
||||||
|
|
||||||
def invoke_successfully(self, xml, enable_tunneling): # pylint: disable=unused-argument
|
|
||||||
''' mock invoke_successfully returning xml data '''
|
|
||||||
self.xml_in = xml
|
|
||||||
if self.type == 'vserver':
|
|
||||||
xml = self.build_vserver_info(self.parm1)
|
|
||||||
self.xml_out = xml
|
|
||||||
return xml
|
|
||||||
|
|
||||||
@staticmethod
|
|
||||||
def build_vserver_info(vserver):
|
|
||||||
''' build xml data for vserser-info '''
|
|
||||||
xml = netapp_utils.zapi.NaElement('xml')
|
|
||||||
attributes = netapp_utils.zapi.NaElement('attributes-list')
|
|
||||||
attributes.add_node_with_children('vserver-info',
|
|
||||||
**{'vserver-name': vserver})
|
|
||||||
xml.add_child_elem(attributes)
|
|
||||||
return xml
|
|
||||||
|
|
||||||
|
|
||||||
def test_ems_log_event_version():
|
|
||||||
''' validate Ansible version is correctly read '''
|
|
||||||
source = 'unittest'
|
|
||||||
server = MockONTAPConnection()
|
|
||||||
netapp_utils.ems_log_event(source, server)
|
|
||||||
xml = server.xml_in
|
|
||||||
version = xml.get_child_content('app-version')
|
|
||||||
assert version == ansible_version
|
|
||||||
print("Ansible version: %s" % ansible_version)
|
|
||||||
|
|
||||||
|
|
||||||
def test_get_cserver():
|
|
||||||
''' validate cluster vserser name is correctly retrieved '''
|
|
||||||
svm_name = 'svm1'
|
|
||||||
server = MockONTAPConnection('vserver', svm_name)
|
|
||||||
cserver = netapp_utils.get_cserver(server)
|
|
||||||
assert cserver == svm_name
|
|
Loading…
Reference in New Issue