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,40 +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 pytest
from ansible.module_utils.six import string_types
from ansible.module_utils._text import to_bytes
from ansible.module_utils.common._collections_compat import MutableMapping
@pytest.fixture
def patch_ansible_module(request, mocker):
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 patch_ansible_module pytest fixture"
)
mocker.patch("ansible.module_utils.basic._ANSIBLE_ARGS", to_bytes(args))

View File

@@ -1,23 +1,11 @@
# (c) 2016 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 json
@@ -53,10 +41,7 @@ def load_fixture(name):
class TestCliModule(ModuleTestCase):
def execute_module(
self, failed=False, changed=False, commands=None, sort=True
):
def execute_module(self, failed=False, changed=False, commands=None, sort=True):
self.load_fixtures(commands)
if failed:
@@ -74,9 +59,7 @@ class TestCliModule(ModuleTestCase):
result["commands"],
)
else:
self.assertEqual(
commands, result["commands"], result["commands"]
)
self.assertEqual(commands, result["commands"], result["commands"])
return result

View File

@@ -1,38 +1,22 @@
# (c) 2016 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
from ansible_collections.ansible.netcommon.tests.unit.compat.mock import (
patch,
MagicMock,
)
from unittest.mock import MagicMock, patch
from ansible_collections.ansible.netcommon.plugins.modules import cli_config
from ansible_collections.ansible.netcommon.tests.unit.modules.utils import (
set_module_args,
)
from ansible_collections.ansible.netcommon.tests.unit.modules.utils import set_module_args
from .cli_module import TestCliModule
class TestCliConfigModule(TestCliModule):
module = cli_config
def setUp(self):
@@ -51,9 +35,7 @@ class TestCliConfigModule(TestCliModule):
self.mock_connection.stop()
@patch(
"ansible_collections.ansible.netcommon.plugins.modules.cli_config.run"
)
@patch("ansible_collections.ansible.netcommon.plugins.modules.cli_config.run")
def test_cli_config_backup_returns__backup__(self, run_mock):
args = dict(backup=True)
set_module_args(args)
@@ -84,9 +66,7 @@ class TestCliConfigModule(TestCliModule):
diff.get.side_effect = ["set interface eth0 ip address dhcp", None]
self.conn.get_diff.return_value = diff
set_module_args({"config": "set interface eth0 ip address dhcp"})
self.execute_module(
changed=True, commands=["set interface eth0 ip address dhcp"]
)
self.execute_module(changed=True, commands=["set interface eth0 ip address dhcp"])
self.conn.edit_config.assert_called_once_with(
candidate=["set interface eth0 ip address dhcp"],
commit=True,
@@ -98,9 +78,7 @@ class TestCliConfigModule(TestCliModule):
self.conn.get_diff.return_value = diff
set_module_args({"config": "set banner\nnew banner"})
self.execute_module(changed=True)
self.conn.edit_banner.assert_called_once_with(
candidate='"new banner"', commit=True
)
self.conn.edit_banner.assert_called_once_with(candidate='"new banner"', commit=True)
def test_cli_config_replace(self):
self.conn.get_capabilities.return_value = """{
@@ -109,9 +87,7 @@ class TestCliConfigModule(TestCliModule):
"supports_replace": true
}
}"""
self.conn.edit_config.return_value = {
"diff": "set interface eth0 ip address dhcp"
}
self.conn.edit_config.return_value = {"diff": "set interface eth0 ip address dhcp"}
args = {"config": "set interface eth0 ip address dhcp"}
@@ -149,9 +125,7 @@ class TestCliConfigModule(TestCliModule):
}
set_module_args(args)
result = self.execute_module(failed=True)
self.assertEqual(
result["msg"], "Option replace is not supported on this platform"
)
self.assertEqual(result["msg"], "Option replace is not supported on this platform")
def test_cli_config_replace_unspecified(self):
self.conn.get_capabilities.return_value = """{
@@ -172,9 +146,7 @@ class TestCliConfigModule(TestCliModule):
)
def test_cli_config_rollback(self):
self.conn.rollback.return_value = {
"diff": "set interface eth0 ip address dhcp"
}
self.conn.rollback.return_value = {"diff": "set interface eth0 ip address dhcp"}
args = {"rollback": 123456}
set_module_args(args)

View File

@@ -1,10 +1,12 @@
from __future__ import absolute_import, division, print_function
__metaclass__ = type
import json
import unittest
from unittest.mock import patch
from ansible_collections.ansible.netcommon.tests.unit.compat import unittest
from ansible_collections.ansible.netcommon.tests.unit.compat.mock import patch
from ansible.module_utils import basic
from ansible.module_utils._text import to_bytes