From 14731bf485e56f675ce993e708feff4eeede4933 Mon Sep 17 00:00:00 2001 From: Felix Fontein Date: Mon, 30 Mar 2020 09:24:27 +0200 Subject: [PATCH] Fix even more tests (#69) * Remove meraki unit tests. * Reenable disabled tests. * Re-disable xfs_quota tests - depend on ansible/ansible#68223. * Fix FQCNs. * More FQCNs. * Fix typo. --- .../targets/cloud_init_data_facts/aliases | 1 - .../targets/connection_chroot/aliases | 1 - .../test_connection.inventory | 2 +- .../targets/filter_random_mac/aliases | 1 - .../targets/filter_random_mac/tasks/main.yml | 18 +- .../module_utils/network/meraki/__init__.py | 0 .../network/meraki/fixtures/orgs.json | 6 - .../network/meraki/test_meraki.py | 160 ------------------ 8 files changed, 10 insertions(+), 179 deletions(-) delete mode 100644 tests/unit/module_utils/network/meraki/__init__.py delete mode 100644 tests/unit/module_utils/network/meraki/fixtures/orgs.json delete mode 100644 tests/unit/module_utils/network/meraki/test_meraki.py diff --git a/tests/integration/targets/cloud_init_data_facts/aliases b/tests/integration/targets/cloud_init_data_facts/aliases index db81969f35..e93cd86b56 100644 --- a/tests/integration/targets/cloud_init_data_facts/aliases +++ b/tests/integration/targets/cloud_init_data_facts/aliases @@ -3,4 +3,3 @@ shippable/posix/group1 skip/aix skip/osx skip/freebsd -disabled #fixme diff --git a/tests/integration/targets/connection_chroot/aliases b/tests/integration/targets/connection_chroot/aliases index 6a0591c038..bd318e6146 100644 --- a/tests/integration/targets/connection_chroot/aliases +++ b/tests/integration/targets/connection_chroot/aliases @@ -1,3 +1,2 @@ needs/root shippable/posix/group3 -disabled #fixme diff --git a/tests/integration/targets/connection_chroot/test_connection.inventory b/tests/integration/targets/connection_chroot/test_connection.inventory index 5f78393f21..db13a110fb 100644 --- a/tests/integration/targets/connection_chroot/test_connection.inventory +++ b/tests/integration/targets/connection_chroot/test_connection.inventory @@ -3,5 +3,5 @@ chroot-pipelining ansible_ssh_pipelining=true chroot-no-pipelining ansible_ssh_pipelining=false [chroot:vars] ansible_host=/ -ansible_connection=chroot +ansible_connection=community.general.chroot ansible_python_interpreter="{{ ansible_playbook_python }}" diff --git a/tests/integration/targets/filter_random_mac/aliases b/tests/integration/targets/filter_random_mac/aliases index fe3a893139..1603f4351b 100644 --- a/tests/integration/targets/filter_random_mac/aliases +++ b/tests/integration/targets/filter_random_mac/aliases @@ -1,4 +1,3 @@ shippable/posix/group2 skip/python2.6 # filters are controller only, and we no longer support Python 2.6 on the controller skip/aix -disabled # fixme diff --git a/tests/integration/targets/filter_random_mac/tasks/main.yml b/tests/integration/targets/filter_random_mac/tasks/main.yml index c652fd52bf..1b089aa810 100644 --- a/tests/integration/targets/filter_random_mac/tasks/main.yml +++ b/tests/integration/targets/filter_random_mac/tasks/main.yml @@ -20,7 +20,7 @@ - name: Test random_mac filter bad argument value debug: - var: "'dummy' | community.generalrandom_mac" + var: "'dummy' | community.general.random_mac" register: _bad_random_mac_filter ignore_errors: yes @@ -45,15 +45,15 @@ - name: Verify random_mac filter assert: that: - - "'00' | random_mac is match('^00:[a-f0-9][a-f0-9]:[a-f0-9][a-f0-9]:[a-f0-9][a-f0-9]:[a-f0-9][a-f0-9]:[a-f0-9][a-f0-9]$')" - - "'00:00' | random_mac is match('^00:00:[a-f0-9][a-f0-9]:[a-f0-9][a-f0-9]:[a-f0-9][a-f0-9]:[a-f0-9][a-f0-9]$')" - - "'00:00:00' | random_mac is match('^00:00:00:[a-f0-9][a-f0-9]:[a-f0-9][a-f0-9]:[a-f0-9][a-f0-9]$')" - - "'00:00:00:00' | random_mac is match('^00:00:00:[a-f0-9][a-f0-9]:[a-f0-9][a-f0-9]:[a-f0-9][a-f0-9]$')" - - "'00:00:00:00:00' | random_mac is match('^00:00:00:00:00:[a-f0-9][a-f0-9]$')" - - "'00:00:00' | random_mac != '00:00:00' | random_mac" + - "'00' | community.general.random_mac is match('^00:[a-f0-9][a-f0-9]:[a-f0-9][a-f0-9]:[a-f0-9][a-f0-9]:[a-f0-9][a-f0-9]:[a-f0-9][a-f0-9]$')" + - "'00:00' | community.general.random_mac is match('^00:00:[a-f0-9][a-f0-9]:[a-f0-9][a-f0-9]:[a-f0-9][a-f0-9]:[a-f0-9][a-f0-9]$')" + - "'00:00:00' | community.general.random_mac is match('^00:00:00:[a-f0-9][a-f0-9]:[a-f0-9][a-f0-9]:[a-f0-9][a-f0-9]$')" + - "'00:00:00:00' | community.general.random_mac is match('^00:00:00:[a-f0-9][a-f0-9]:[a-f0-9][a-f0-9]:[a-f0-9][a-f0-9]$')" + - "'00:00:00:00:00' | community.general.random_mac is match('^00:00:00:00:00:[a-f0-9][a-f0-9]$')" + - "'00:00:00' | community.general.random_mac != '00:00:00' | community.general.random_mac" - name: Verify random_mac filter with seed assert: that: - - "'00:00:00' | communit.general.random_mac(seed='test') == '00:00:00' | random_mac(seed='test')" - - "'00:00:00' | community.general.random_mac(seed='test') != '00:00:00' | random_mac(seed='another_test')" + - "'00:00:00' | community.general.random_mac(seed='test') == '00:00:00' | community.general.random_mac(seed='test')" + - "'00:00:00' | community.general.random_mac(seed='test') != '00:00:00' | community.general.random_mac(seed='another_test')" diff --git a/tests/unit/module_utils/network/meraki/__init__.py b/tests/unit/module_utils/network/meraki/__init__.py deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/tests/unit/module_utils/network/meraki/fixtures/orgs.json b/tests/unit/module_utils/network/meraki/fixtures/orgs.json deleted file mode 100644 index 087db0f244..0000000000 --- a/tests/unit/module_utils/network/meraki/fixtures/orgs.json +++ /dev/null @@ -1,6 +0,0 @@ -[ - { - "id": 2930418, - "name": "My organization" - } -] \ No newline at end of file diff --git a/tests/unit/module_utils/network/meraki/test_meraki.py b/tests/unit/module_utils/network/meraki/test_meraki.py deleted file mode 100644 index 0717c18ac4..0000000000 --- a/tests/unit/module_utils/network/meraki/test_meraki.py +++ /dev/null @@ -1,160 +0,0 @@ -# -*- coding: utf-8 -*- - -# Copyright 2019 Kevin Breit - -# This file is part of Ansible by Red Hat -# -# 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 . - -from __future__ import (absolute_import, division, print_function) -__metaclass__ = type - -import json -import os -import pytest - -from ansible_collections.community.general.tests.unit.compat import unittest, mock -from ansible.module_utils.basic import AnsibleModule -from ansible_collections.cisco.meraki.plugins.module_utils.network.meraki.meraki import MerakiModule, meraki_argument_spec, HTTPError, RateLimitException -from ansible.module_utils.six import PY2, PY3 -from ansible.module_utils._text import to_native, to_bytes -from ansible_collections.community.general.tests.unit.modules.utils import set_module_args - -fixture_path = os.path.join(os.path.dirname(__file__), 'fixtures') -fixture_data = {} -testcase_data = { - "params": {'orgs': ['orgs.json'], - } -} - - -def load_fixture(name): - path = os.path.join(fixture_path, name) - - if path in fixture_data: - return fixture_data[path] - - with open(path) as f: - data = f.read() - - # try: - data = json.loads(data) - # except Exception: - # pass - - fixture_data[path] = data - return data - - -@pytest.fixture(scope="module") -def module(): - argument_spec = meraki_argument_spec() - set_module_args({'auth_key': 'abc123', - }) - module = AnsibleModule(argument_spec=argument_spec, - supports_check_mode=False) - return MerakiModule(module) - - -def mocked_fetch_url(*args, **kwargs): - print(args) - if args[1] == 'https://api.meraki.com/api/v0/404': - info = {'status': 404, - 'msg': '404 - Page is missing', - 'url': 'https://api.meraki.com/api/v0/404', - } - info['body'] = '404' - elif args[1] == 'https://api.meraki.com/api/v0/429': - info = {'status': 429, - 'msg': '429 - Rate limit hit', - 'url': 'https://api.meraki.com/api/v0/429', - } - info['body'] = '429' - return (None, info) - - -def mocked_fetch_url_rate_success(module, *args, **kwargs): - if module.retry_count == 5: - info = {'status': 200, - 'url': 'https://api.meraki.com/api/organization', - } - resp = {'body': 'Succeeded'} - else: - info = {'status': 429, - 'msg': '429 - Rate limit hit', - 'url': 'https://api.meraki.com/api/v0/429', - } - info['body'] = '429' - return (resp, info) - - -def mocked_fail_json(*args, **kwargs): - pass - - -def mocked_sleep(*args, **kwargs): - pass - - -def test_fetch_url_404(module, mocker): - url = '404' - mocker.patch('ansible_collections.cisco.meraki.plugins.module_utils.network.meraki.meraki.fetch_url', side_effect=mocked_fetch_url) - mocker.patch('ansible_collections.cisco.meraki.plugins.module_utils.network.meraki.meraki.MerakiModule.fail_json', side_effect=mocked_fail_json) - with pytest.raises(HTTPError): - data = module.request(url, method='GET') - assert module.status == 404 - - -def test_fetch_url_429(module, mocker): - url = '429' - mocker.patch('ansible_collections.cisco.meraki.plugins.module_utils.network.meraki.meraki.fetch_url', side_effect=mocked_fetch_url) - mocker.patch('ansible_collections.cisco.meraki.plugins.module_utils.network.meraki.meraki.MerakiModule.fail_json', side_effect=mocked_fail_json) - mocker.patch('time.sleep', return_value=None) - with pytest.raises(RateLimitException): - data = module.request(url, method='GET') - assert module.status == 429 - - -def test_fetch_url_429_success(module, mocker): - url = '429' - mocker.patch('ansible_collections.cisco.meraki.plugins.module_utils.network.meraki.meraki.fetch_url', side_effect=mocked_fetch_url_rate_success) - mocker.patch('ansible_collections.cisco.meraki.plugins.module_utils.network.meraki.meraki.MerakiModule.fail_json', side_effect=mocked_fail_json) - mocker.patch('time.sleep', return_value=None) - # assert module.status == 200 - - -def test_define_protocol_https(module): - module.params['use_https'] = True - module.define_protocol() - testdata = module.params['protocol'] - assert testdata == 'https' - - -def test_define_protocol_http(module): - module.params['use_https'] = False - module.define_protocol() - testdata = module.params['protocol'] - assert testdata == 'http' - - -def test_is_org_valid_org_name(module): - data = load_fixture('orgs.json') - org_count = module.is_org_valid(data, org_name="My organization") - assert org_count == 1 - - -def test_is_org_valid_org_id(module): - data = load_fixture('orgs.json') - org_count = module.is_org_valid(data, org_id=2930418) - assert org_count == 1