Skip to content

Commit

Permalink
Add a connection local deprecation warning (#664)
Browse files Browse the repository at this point in the history
* add a connection local deprecation warning

* add a changelog

* address comments and netconf action cleanup

* update changelog

* sanity happy

* sanity fix

Signed-off-by: NilashishC <[email protected]>

* typo fix

Signed-off-by: NilashishC <[email protected]>

---------

Signed-off-by: NilashishC <[email protected]>
Co-authored-by: NilashishC <[email protected]>
  • Loading branch information
KB-perByte and NilashishC authored Aug 29, 2024
1 parent daec4c2 commit 7cadfc0
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 79 deletions.
3 changes: 3 additions & 0 deletions changelogs/fragments/bye_connection_local.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
minor_changes:
- ansible.netcommon.persistent - Connection local is marked deprecated and all dependent collections are advised to move to a proper connection plugin, complete support of connection local will be removed in a release after 01-01-2027.
2 changes: 1 addition & 1 deletion changelogs/fragments/update_error_msg.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
---
trivial:
bugfixes:
- Updated the error message for the content_templates parser to include the correct parser name and detailed error information.
73 changes: 1 addition & 72 deletions plugins/action/netconf.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@

__metaclass__ = type

import copy
import sys

from ansible.utils.display import Display

from ansible_collections.ansible.netcommon.plugins.action.network import (
Expand All @@ -23,86 +20,18 @@

class ActionModule(ActionNetworkModule):
def run(self, tmp=None, task_vars=None):
del tmp # tmp no longer has any effect

module_name = self._task.action.split(".")[-1]
self._config_module = True if module_name == "netconf_config" else False
persistent_connection = self._play_context.connection.split(".")[-1]
warnings = []

if persistent_connection not in ["netconf", "local"] and module_name == "netconf_config":
return {
"failed": True,
"msg": "Connection type %s is not valid for netconf_config module. "
"Valid connection type is netconf or local (deprecated)"
% self._play_context.connection,
}
elif persistent_connection not in ["netconf"] and module_name != "netconf_config":
if persistent_connection != "netconf":
return {
"failed": True,
"msg": "Connection type %s is not valid for %s module. "
"Valid connection type is netconf." % (self._play_context.connection, module_name),
}

if self._play_context.connection == "local" and module_name == "netconf_config":
args = self._task.args
pc = copy.deepcopy(self._play_context)
pc.connection = "ansible.netcommon.netconf"
pc.port = int(args.get("port") or self._play_context.port or 830)

pc.remote_user = args.get("username") or self._play_context.connection_user
pc.password = args.get("password") or self._play_context.password
pc.private_key_file = args.get("ssh_keyfile") or self._play_context.private_key_file

connection = self._shared_loader_obj.connection_loader.get(
"ansible.netcommon.persistent",
pc,
sys.stdin,
task_uuid=self._task._uuid,
)

# TODO: Remove below code after ansible minimal is cut out
if connection is None:
pc.connection = "netconf"
connection = self._shared_loader_obj.connection_loader.get(
"persistent", pc, sys.stdin, task_uuid=self._task._uuid
)

display.vvv(
"using connection plugin %s (was local)" % pc.connection,
pc.remote_addr,
)

timeout = args.get("timeout")
command_timeout = (
int(timeout) if timeout else connection.get_option("persistent_command_timeout")
)
connection.set_options(
direct={
"persistent_command_timeout": command_timeout,
"look_for_keys": args.get("look_for_keys"),
"hostkey_verify": args.get("hostkey_verify"),
"allow_agent": args.get("allow_agent"),
}
)

socket_path = connection.run()
display.vvvv("socket_path: %s" % socket_path, pc.remote_addr)
if not socket_path:
return {
"failed": True,
"msg": "unable to open shell. Please see: "
+ "https://docs.ansible.com/ansible/network_debug_troubleshooting.html#unable-to-open-shell",
}

task_vars["ansible_socket"] = socket_path
warnings.append(
[
"connection local support for this module is deprecated and will be removed in version 2.14, use connection %s"
% pc.connection
]
)

result = super(ActionModule, self).run(task_vars=task_vars)
if warnings:
if "warnings" in result:
Expand Down
6 changes: 2 additions & 4 deletions plugins/connection/network_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -490,10 +490,8 @@ def get_prompt(self):
return self._matched_prompt

def exec_command(self, cmd, in_data=None, sudoable=True):
# this try..except block is just to handle the transition to supporting
# network_cli as a toplevel connection. Once connection=local is gone,
# this block can be removed as well and all calls passed directly to
# the local connection
# not accessible code alert can be taken out at around 01-01-2027,
# when connection local is removed
if self._ssh_shell:
try:
cmd = json.loads(to_text(cmd, errors="surrogate_or_strict"))
Expand Down
5 changes: 5 additions & 0 deletions plugins/connection/persistent.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,11 @@ def run(self):
"starting connection from persistent connection plugin",
host=self._play_context.remote_addr,
)
display.deprecated(
msg="support for connection local has been deprecated",
date="2027-01-01",
collection_name="ansible.netcommon",
)
variables = {"ansible_command_timeout": self.get_option("persistent_command_timeout")}
socket_path = start_connection(self._play_context, variables, self._task_uuid)
display.vvvv(
Expand Down
4 changes: 2 additions & 2 deletions plugins/module_utils/network/common/network.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,8 +202,8 @@ def get_resource_connection(module):
if network_api == "netconf":
module._connection = NetconfConnection(module._socket_path)
elif network_api == "local":
# This isn't supported, but we shouldn't fail here.
# Set the connection to a fake connection so it fails sensibly.
# not accessible code alert can be taken out at around 01-01-2027,
# when connection local is removed
module._connection = LocalResourceConnection(module)
else:
module._connection = Connection(module._socket_path)
Expand Down

0 comments on commit 7cadfc0

Please sign in to comment.