Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

issue-1751: add ability to run several qemu with mounted filestore in test recipes; extract ssh client to lib from qemu recipe #2994

Merged
merged 2 commits into from
Feb 11, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions cloud/filestore/tests/recipes/vhost-endpoint.inc
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ IF (FILESTORE_SHARD_COUNT)
SET_APPEND(RECIPE_ARGS --shard-count $FILESTORE_SHARD_COUNT)
ENDIF()

IF (FILESTORE_VHOST_ENDPOINT_COUNT)
SET_APPEND(RECIPE_ARGS --endpoint-count $FILESTORE_VHOST_ENDPOINT_COUNT)
ENDIF()

USE_RECIPE(
cloud/filestore/tests/recipes/vhost-endpoint/vhost-endpoint-recipe
${RECIPE_ARGS}
Expand Down
58 changes: 35 additions & 23 deletions cloud/filestore/tests/recipes/vhost-endpoint/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,13 @@
logger = logging.getLogger(__name__)


def env_with_index(env, index):
if index == 0:
return env

return "{}__{}".format(env, index)


def start(argv):
parser = argparse.ArgumentParser()
parser.add_argument("--filesystem", action="store", default="nfs_share")
Expand All @@ -21,6 +28,7 @@ def start(argv):
parser.add_argument("--shard-count", action="store", default=0, type=int)
parser.add_argument("--read-only", action="store_true", default=False)
parser.add_argument("--verbose", action="store_true", default=False)
parser.add_argument("--endpoint-count", action="store", default=1, type=int)
args = parser.parse_args(argv)

port = os.getenv("NFS_SERVER_PORT")
Expand Down Expand Up @@ -55,34 +63,38 @@ def start(argv):
"ShardFileSystemIds": shards,
})

socket = create_endpoint(
client,
args.filesystem,
args.socket_path,
args.socket_prefix,
os.getenv("NFS_VHOST_ENDPOINT_STORAGE_DIR", None),
args.mount_seqno,
args.read_only)
set_env("NFS_VHOST_SOCKET_COUNT", args.endpoint_count)
for i in range(args.endpoint_count):
socket = create_endpoint(
client,
args.filesystem,
args.socket_path,
args.socket_prefix,
os.getenv("NFS_VHOST_ENDPOINT_STORAGE_DIR", None),
args.mount_seqno,
args.read_only)

set_env("NFS_VHOST_SOCKET", socket)
set_env(env_with_index("NFS_VHOST_SOCKET", i), socket)


def stop(argv):
vhost_port = os.getenv("NFS_VHOST_PORT")
socket = os.getenv("NFS_VHOST_SOCKET")

if not vhost_port or not socket or not os.path.exists(socket):
return

client_path = common.binary_path(
"cloud/filestore/apps/client/filestore-client")

client = FilestoreCliClient(
client_path, port=None,
vhost_port=vhost_port,
verbose=True,
cwd=common.output_path())
client.stop_endpoint(socket)
endpoint_count = int(os.getenv("NFS_VHOST_SOCKET_COUNT"))
for i in range(endpoint_count):
socket = os.getenv(env_with_index("NFS_VHOST_SOCKET", i))

if not vhost_port or not socket or not os.path.exists(socket):
return

client_path = common.binary_path(
"cloud/filestore/apps/client/filestore-client")

client = FilestoreCliClient(
client_path, port=None,
vhost_port=vhost_port,
verbose=True,
cwd=common.output_path())
client.stop_endpoint(socket)


if __name__ == "__main__":
Expand Down
39 changes: 39 additions & 0 deletions cloud/storage/core/tools/testing/qemu/lib/common.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,45 @@
import os
import logging
import yatest.common as common

logger = logging.getLogger(__name__)


class SshToGuest(object):
def __init__(self, user, port, key):
self.user = user
self.port = port
self.key = key

def get_command(self, command, timeout=None):
cmd = []

if timeout is not None:
cmd = ["timeout", str(timeout)]

cmd += [
"ssh",
"-n",
"-F", os.devnull,
"-o", "StrictHostKeyChecking=no",
"-o", "UserKnownHostsFile=" + os.devnull,
"-o", "ConnectTimeout=10",
"-o", "ServerAliveInterval=10",
"-o", "ServerAliveCountMax=10",
"-i", self.key,
"-l", self.user,
"-p", str(self.port),
"127.0.0.1",
command
]

logger.info("ssh execute command: '{}'".format(" ".join(cmd)))

return cmd

def __call__(self, command, timeout=None):
common.execute(self.get_command(command, timeout))


def env_with_guest_index(env, guest_index):
if guest_index == 0:
Expand Down
41 changes: 3 additions & 38 deletions cloud/storage/core/tools/testing/qemu/lib/recipe.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import library.python.testing.recipe

from .qemu import Qemu
from .common import get_mount_paths, env_with_guest_index
from .common import SshToGuest, get_mount_paths, env_with_guest_index

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -68,7 +68,8 @@ def start_instance(args, inst_index):

vhost_socket = ""
if virtio == "fs":
vhost_socket = os.getenv("NFS_VHOST_SOCKET")
vhost_socket = os.getenv(
env_with_guest_index("NFS_VHOST_SOCKET", inst_index))
elif virtio == "blk":
vhost_socket = os.getenv("NBS_VHOST_SOCKET")

Expand Down Expand Up @@ -434,42 +435,6 @@ def _wait_ssh(daemon, ssh):
ssh("exit 0")


class SshToGuest(object):
def __init__(self, user, port, key):
self.user = user
self.port = port
self.key = key

def get_command(self, command, timeout=None):
cmd = []

if timeout is not None:
cmd = ["timeout", str(timeout)]

cmd += [
"ssh",
"-n",
"-F", os.devnull,
"-o", "StrictHostKeyChecking=no",
"-o", "UserKnownHostsFile=" + os.devnull,
"-o", "ConnectTimeout=10",
"-o", "ServerAliveInterval=10",
"-o", "ServerAliveCountMax=10",
"-i", self.key,
"-l", self.user,
"-p", str(self.port),
"127.0.0.1",
command
]

logger.info("ssh execute command: '{}'".format(" ".join(cmd)))

return cmd

def __call__(self, command, timeout=None):
yatest.common.execute(self.get_command(command, timeout))


def recipe_set_env(key, val, guest_index=0):
library.python.testing.recipe.set_env(env_with_guest_index(key, guest_index), val)

Expand Down
Loading