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
Matt Clay 5 years ago committed by GitHub
parent 3383dc8c02
commit 7c493577ba
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -8381,7 +8381,6 @@ test/units/module_utils/test_hetzner.py future-import-boilerplate
test/units/module_utils/test_hetzner.py metaclass-boilerplate test/units/module_utils/test_hetzner.py metaclass-boilerplate
test/units/module_utils/test_kubevirt.py future-import-boilerplate test/units/module_utils/test_kubevirt.py future-import-boilerplate
test/units/module_utils/test_kubevirt.py metaclass-boilerplate test/units/module_utils/test_kubevirt.py metaclass-boilerplate
test/units/module_utils/test_netapp.py future-import-boilerplate
test/units/module_utils/test_text.py future-import-boilerplate test/units/module_utils/test_text.py future-import-boilerplate
test/units/module_utils/test_utm_utils.py future-import-boilerplate test/units/module_utils/test_utm_utils.py future-import-boilerplate
test/units/module_utils/test_utm_utils.py metaclass-boilerplate test/units/module_utils/test_utm_utils.py metaclass-boilerplate
@ -8404,9 +8403,7 @@ test/units/modules/cloud/kubevirt/test_kubevirt_vm.py metaclass-boilerplate
test/units/modules/cloud/linode/conftest.py future-import-boilerplate test/units/modules/cloud/linode/conftest.py future-import-boilerplate
test/units/modules/cloud/linode/conftest.py metaclass-boilerplate test/units/modules/cloud/linode/conftest.py metaclass-boilerplate
test/units/modules/cloud/linode/test_linode.py metaclass-boilerplate test/units/modules/cloud/linode/test_linode.py metaclass-boilerplate
test/units/modules/cloud/linode_v4/conftest.py future-import-boilerplate test/units/modules/cloud/linode/test_linode_v4.py metaclass-boilerplate
test/units/modules/cloud/linode_v4/conftest.py metaclass-boilerplate
test/units/modules/cloud/linode_v4/test_linode_v4.py metaclass-boilerplate
test/units/modules/cloud/misc/test_terraform.py future-import-boilerplate test/units/modules/cloud/misc/test_terraform.py future-import-boilerplate
test/units/modules/cloud/misc/test_terraform.py metaclass-boilerplate test/units/modules/cloud/misc/test_terraform.py metaclass-boilerplate
test/units/modules/cloud/misc/virt_net/conftest.py future-import-boilerplate test/units/modules/cloud/misc/virt_net/conftest.py future-import-boilerplate
@ -8690,7 +8687,6 @@ test/units/modules/storage/netapp/test_na_ontap_vscan_on_demand_task.py future-i
test/units/modules/storage/netapp/test_na_ontap_vscan_on_demand_task.py metaclass-boilerplate test/units/modules/storage/netapp/test_na_ontap_vscan_on_demand_task.py metaclass-boilerplate
test/units/modules/storage/netapp/test_na_ontap_vscan_scanner_pool.py future-import-boilerplate test/units/modules/storage/netapp/test_na_ontap_vscan_scanner_pool.py future-import-boilerplate
test/units/modules/storage/netapp/test_na_ontap_vscan_scanner_pool.py metaclass-boilerplate test/units/modules/storage/netapp/test_na_ontap_vscan_scanner_pool.py metaclass-boilerplate
test/units/modules/storage/netapp/test_netapp.py metaclass-boilerplate
test/units/modules/storage/netapp/test_netapp_e_alerts.py future-import-boilerplate test/units/modules/storage/netapp/test_netapp_e_alerts.py future-import-boilerplate
test/units/modules/storage/netapp/test_netapp_e_asup.py future-import-boilerplate test/units/modules/storage/netapp/test_netapp_e_asup.py future-import-boilerplate
test/units/modules/storage/netapp/test_netapp_e_auditlog.py future-import-boilerplate test/units/modules/storage/netapp/test_netapp_e_auditlog.py future-import-boilerplate

@ -2,8 +2,15 @@
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
from __future__ import absolute_import, division, print_function
__metaclass__ = type __metaclass__ = type
import pytest
from ansible.module_utils.ansible_release import __version__ as ansible_version
import ansible.module_utils.netapp as netapp_utils
try: try:
from unittest.mock import patch, mock_open from unittest.mock import patch, mock_open
except ImportError: except ImportError:
@ -104,3 +111,53 @@ class NetappTest(ModuleTestCase):
with self.assertRaisesRegexp(AnsibleFailJson, r"Protocol must be http or https."): with self.assertRaisesRegexp(AnsibleFailJson, r"Protocol must be http or https."):
base = StubNetAppESeriesModule() base = StubNetAppESeriesModule()
base._check_web_services_version() base._check_web_services_version()
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
@pytest.mark.skipif(not netapp_utils.has_netapp_lib(), reason="skipping as missing required netapp_lib")
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)
@pytest.mark.skipif(not netapp_utils.has_netapp_lib(), reason="skipping as missing required netapp_lib")
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

@ -11,3 +11,70 @@ def auth(monkeypatch):
def patched_test_echo(dummy): def patched_test_echo(dummy):
return [] return []
monkeypatch.setattr('linode.api.Api.test_echo', patched_test_echo) monkeypatch.setattr('linode.api.Api.test_echo', patched_test_echo)
@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,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…
Cancel
Save