Skip to content

Commit f578a18

Browse files
authored
add ssh-key-path to ydbd_slice (#14463)
1 parent 3e3115b commit f578a18

File tree

2 files changed

+17
-7
lines changed

2 files changed

+17
-7
lines changed

ydb/tools/ydbd_slice/__init__.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,7 @@ def deduce_components_from_args(args, cluster_details):
310310
return result
311311

312312

313-
def deduce_nodes_from_args(args, walle_provider, ssh_user):
313+
def deduce_nodes_from_args(args, walle_provider, ssh_user, ssh_key_path):
314314
cluster_hosts = safe_load_cluster_details(args.cluster, walle_provider).hosts_names
315315
result = cluster_hosts
316316

@@ -326,7 +326,7 @@ def deduce_nodes_from_args(args, walle_provider, ssh_user):
326326
sys.exit("unable to deduce hosts")
327327

328328
logger.info("use nodes '%s'", result)
329-
return nodes.Nodes(result, args.dry_run, ssh_user=ssh_user, queue_size=args.cmd_queue_size)
329+
return nodes.Nodes(result, args.dry_run, ssh_user=ssh_user, ssh_key_path=ssh_key_path, queue_size=args.cmd_queue_size)
330330

331331

332332
def ya_build(arcadia_root, artifact, opts, dry_run):
@@ -514,6 +514,12 @@ def ssh_args():
514514
help="user for ssh interaction with slice. Default value is $USER "
515515
"(which equals {user} now)".format(user=current_user),
516516
)
517+
args.add_argument(
518+
"--ssh-key-path",
519+
metavar="SSH_KEY_PATH",
520+
help="Path to ssh private key"
521+
"(which equals {user} now)".format(user=current_user),
522+
)
517523
return args
518524

519525

@@ -625,7 +631,7 @@ def dispatch_run(func, args, walle_provider, need_confirmation=False):
625631
cluster_details = safe_load_cluster_details(args.cluster, walle_provider)
626632
components = deduce_components_from_args(args, cluster_details)
627633

628-
nodes = deduce_nodes_from_args(args, walle_provider, args.ssh_user)
634+
nodes = deduce_nodes_from_args(args, walle_provider, args.ssh_user, args.ssh_key_path)
629635

630636
temp_dir = deduce_temp_dir_from_args(args)
631637
clear_tmp = not args.dry_run and args.temp_dir is None

ydb/tools/ydbd_slice/nodes.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,14 @@
99

1010

1111
class Nodes(object):
12-
def __init__(self, nodes, dry_run=False, ssh_user=None, queue_size=0):
12+
def __init__(self, nodes, dry_run=False, ssh_user=None, queue_size=0, ssh_key_path=None):
1313
assert isinstance(nodes, list)
1414
assert len(nodes) > 0
1515
assert isinstance(nodes[0], str)
1616
self._nodes = nodes
1717
self._dry_run = bool(dry_run)
1818
self._ssh_user = ssh_user
19+
self._ssh_key_path = ssh_key_path
1920
self._logger = logger.getChild(self.__class__.__name__)
2021
self._queue = queue.Queue(queue_size)
2122
self._qsize = queue_size
@@ -24,12 +25,15 @@ def __init__(self, nodes, dry_run=False, ssh_user=None, queue_size=0):
2425
def nodes_list(self):
2526
return self._nodes
2627

27-
def _get_ssh_command_prefix(self):
28+
def _get_ssh_command_prefix(self, remote=False):
2829
command = []
2930
command.extend(['ssh', '-o', 'StrictHostKeyChecking=no', '-o', 'UserKnownHostsFile=/dev/null', '-A'])
3031
if (self._ssh_user):
3132
command.extend(['-l', self._ssh_user])
3233

34+
if not remote and self._ssh_key_path:
35+
command.extend(['-i', self._ssh_key_path])
36+
3337
return command
3438

3539
def _check_async_execution(self, running_jobs, check_retcode=True, results=None):
@@ -144,9 +148,9 @@ def _copy_between_nodes(self, hub, hub_path, hosts, remote_path):
144148
if self._dry_run:
145149
continue
146150
cmd = self._get_ssh_command_prefix() + [dst]
147-
rsh = " ".join(self._get_ssh_command_prefix())
151+
rsh = " ".join(self._get_ssh_command_prefix(remote=True))
148152
cmd.extend([
149-
"sudo", "SSH_AUTH_SOCK=$SSH_AUTH_SOCK", "rsync", "-avqW", "--del", "--no-o", "--no-g",
153+
"sudo", "--preserve-env=SSH_AUTH_SOCK", "rsync", "-avqW", "--del", "--no-o", "--no-g",
150154
"--rsh='{}'".format(rsh),
151155
src, remote_path
152156
])

0 commit comments

Comments
 (0)