collection 교체

This commit is contained in:
정훈 변
2024-02-23 16:37:40 +09:00
parent b494779b5b
commit 3fd554eee9
38862 changed files with 220204 additions and 6600073 deletions

View File

@@ -1,79 +0,0 @@
# Copyright (c) 2017 Ansible Project
# 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
import json
import sys
from io import BytesIO
import pytest
import ansible.module_utils.basic
from ansible.module_utils.six import PY3, string_types
from ansible.module_utils._text import to_bytes
from ansible.module_utils.common._collections_compat import MutableMapping
@pytest.fixture
def stdin(mocker, request):
old_args = ansible.module_utils.basic._ANSIBLE_ARGS
ansible.module_utils.basic._ANSIBLE_ARGS = None
old_argv = sys.argv
sys.argv = ["ansible_unittest"]
if isinstance(request.param, string_types):
args = request.param
elif isinstance(request.param, MutableMapping):
if "ANSIBLE_MODULE_ARGS" not in request.param:
request.param = {"ANSIBLE_MODULE_ARGS": request.param}
if "_ansible_remote_tmp" not in request.param["ANSIBLE_MODULE_ARGS"]:
request.param["ANSIBLE_MODULE_ARGS"][
"_ansible_remote_tmp"
] = "/tmp"
if (
"_ansible_keep_remote_files"
not in request.param["ANSIBLE_MODULE_ARGS"]
):
request.param["ANSIBLE_MODULE_ARGS"][
"_ansible_keep_remote_files"
] = False
args = json.dumps(request.param)
else:
raise Exception("Malformed data to the stdin pytest fixture")
fake_stdin = BytesIO(to_bytes(args, errors="surrogate_or_strict"))
if PY3:
mocker.patch(
"ansible.module_utils.basic.sys.stdin", mocker.MagicMock()
)
mocker.patch("ansible.module_utils.basic.sys.stdin.buffer", fake_stdin)
else:
mocker.patch("ansible.module_utils.basic.sys.stdin", fake_stdin)
yield fake_stdin
ansible.module_utils.basic._ANSIBLE_ARGS = old_args
sys.argv = old_argv
@pytest.fixture
def am(stdin, request):
old_args = ansible.module_utils.basic._ANSIBLE_ARGS
ansible.module_utils.basic._ANSIBLE_ARGS = None
old_argv = sys.argv
sys.argv = ["ansible_unittest"]
argspec = {}
if hasattr(request, "param"):
if isinstance(request.param, dict):
argspec = request.param
am = ansible.module_utils.basic.AnsibleModule(argument_spec=argspec)
am._name = "ansible_unittest"
yield am
ansible.module_utils.basic._ANSIBLE_ARGS = old_args
sys.argv = old_argv

View File

@@ -1,34 +1,20 @@
# -*- coding: utf-8 -*-
#
# (c) 2017 Red Hat, Inc.
#
# 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/>.
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
# SPDX-License-Identifier: GPL-3.0-or-later
# Make coding more python3-ish
from __future__ import absolute_import, division, print_function
__metaclass__ = type
import re
import pytest
from ansible_collections.ansible.netcommon.plugins.module_utils.network.common import (
config,
)
from ansible_collections.ansible.netcommon.plugins.module_utils.network.common import config
RUNNING = """interface Ethernet1
@@ -109,9 +95,7 @@ def test_config_items():
net_config = config.NetworkConfig(indent=3, contents=RUNNING)
assert len(net_config.items) == 10
net_config = config.NetworkConfig(
indent=3, contents=RUNNING, ignore_lines=[r"\s*no .*"]
)
net_config = config.NetworkConfig(indent=3, contents=RUNNING, ignore_lines=[r"\s*no .*"])
assert len(net_config.items) == 6
net_config = config.NetworkConfig(
@@ -126,9 +110,7 @@ def test_config_items():
def test_config_get_block():
net_config = config.NetworkConfig(indent=3, contents=RUNNING)
with pytest.raises(
AssertionError, match="path argument must be a list object"
):
with pytest.raises(AssertionError, match="path argument must be a list object"):
net_config.get_block("interface Ethernet2")
with pytest.raises(ValueError, match="path does not exist in config"):
@@ -157,9 +139,7 @@ def test_updates_repeat_lines():
configdiffobjs = candidate_obj.difference(running_obj)
diff_list = config.dumps(configdiffobjs, "commands").split("\n")
want_src_list = WANT_SRC_1.strip().split("\n")
for generated_diff_line, candidate_diff_line in zip(
diff_list, want_src_list
):
for generated_diff_line, candidate_diff_line in zip(diff_list, want_src_list):
assert generated_diff_line == candidate_diff_line.strip()
@@ -189,8 +169,6 @@ def test_updates_repeat_parents():
configdiffobjs = candidate_obj.difference(running_obj)
diff_list = config.dumps(configdiffobjs, "commands").split("\n")
for generated_diff_line, candidate_diff_line in zip(
diff_list, expected_diff
):
for generated_diff_line, candidate_diff_line in zip(diff_list, expected_diff):
print(generated_diff_line, candidate_diff_line)
assert generated_diff_line == candidate_diff_line.strip()

View File

@@ -1,31 +1,21 @@
# -*- coding: utf-8 -*-
#
# (c) 2017 Red Hat, Inc.
#
# 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/>.
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
# SPDX-License-Identifier: GPL-3.0-or-later
from __future__ import absolute_import, division, print_function
__metaclass__ = type
from ansible_collections.ansible.netcommon.tests.unit.compat import unittest
import unittest
from ansible_collections.ansible.netcommon.plugins.module_utils.network.common.parsing import (
Conditional,
)
test_results = ["result_1", "result_2", "result_3"]
c1 = Conditional("result[1] == result_2")
c2 = Conditional("result[2] not == result_2")
@@ -43,7 +33,3 @@ class TestNotKeyword(unittest.TestCase):
def test_conditionals_w_not_keyword(self):
assert c1(test_results) and c2(test_results) and c3(test_results)
if __name__ == "__main__":
unittest.main()

View File

@@ -1,46 +1,32 @@
# -*- coding: utf-8 -*-
#
# (c) 2017 Red Hat, Inc.
#
# 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/>.
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
# SPDX-License-Identifier: GPL-3.0-or-later
# Make coding more python3-ish
from __future__ import absolute_import, division, print_function
__metaclass__ = type
import pytest
from copy import deepcopy
from unittest.mock import MagicMock
import pytest
from ansible_collections.ansible.netcommon.tests.unit.compat.mock import (
MagicMock,
)
from ansible_collections.ansible.netcommon.plugins.module_utils.network.common import (
utils,
)
from ansible.module_utils.common.network import (
is_masklen,
is_netmask,
to_ipv6_network,
to_ipv6_subnet,
to_masklen,
to_netmask,
to_subnet,
to_ipv6_network,
to_ipv6_subnet,
is_masklen,
is_netmask,
)
from ansible_collections.ansible.netcommon.plugins.module_utils.network.common import utils
def test_to_list():
for scalar in ("string", 1, True, False, None):
@@ -180,9 +166,7 @@ def test_dict_diff():
with pytest.raises(AssertionError, match="`base` must be of type <dict>"):
utils.dict_diff(None, {})
with pytest.raises(
AssertionError, match="`comparable` must be of type <dict>"
):
with pytest.raises(AssertionError, match="`comparable` must be of type <dict>"):
utils.dict_diff({}, object())
# But None is okay
@@ -336,9 +320,7 @@ def test_param_list_to_dict():
dict(vlan_id=10, name="voice"),
dict(vlan_id=99, name="guest"),
]
assert utils.param_list_to_dict(
params, unique_key="vlan_id", remove_key=False
) == {
assert utils.param_list_to_dict(params, unique_key="vlan_id", remove_key=False) == {
1: dict(vlan_id=1, name="management"),
10: dict(vlan_id=10, name="voice"),
99: dict(vlan_id=99, name="guest"),
@@ -384,9 +366,7 @@ def test_conditional():
assert utils.conditional("max(1)", 1)
assert utils.conditional("exactly(1)", 1)
assert utils.conditional("gt(5)", "7", int)
with pytest.raises(
AssertionError, match="invalid expression: cannot contain spaces"
):
with pytest.raises(AssertionError, match="invalid expression: cannot contain spaces"):
utils.conditional("1 ", 1)
with pytest.raises(ValueError, match="unknown operator: floop"):
utils.conditional("floop(4)", 4)
@@ -470,19 +450,11 @@ def test_is_netmask():
def test_to_ipv6_network():
assert "2001:db8::" == to_ipv6_network("2001:db8::")
assert "2001:0db8:85a3::" == to_ipv6_network(
"2001:0db8:85a3:0000:0000:8a2e:0370:7334"
)
assert "2001:0db8:85a3::" == to_ipv6_network(
"2001:0db8:85a3:0:0:8a2e:0370:7334"
)
assert "2001:0db8:85a3::" == to_ipv6_network("2001:0db8:85a3:0000:0000:8a2e:0370:7334")
assert "2001:0db8:85a3::" == to_ipv6_network("2001:0db8:85a3:0:0:8a2e:0370:7334")
def test_to_ipv6_subnet():
assert "2001:db8::" == to_ipv6_subnet("2001:db8::")
assert "2001:0db8:85a3:4242::" == to_ipv6_subnet(
"2001:0db8:85a3:4242:0000:8a2e:0370:7334"
)
assert "2001:0db8:85a3:4242::" == to_ipv6_subnet(
"2001:0db8:85a3:4242:0:8a2e:0370:7334"
)
assert "2001:0db8:85a3:4242::" == to_ipv6_subnet("2001:0db8:85a3:4242:0000:8a2e:0370:7334")
assert "2001:0db8:85a3:4242::" == to_ipv6_subnet("2001:0db8:85a3:4242:0:8a2e:0370:7334")