From cb52a905d9a2c3c889deeb1885699ddbeb3a4d84 Mon Sep 17 00:00:00 2001 From: Yann Dirson Date: Tue, 11 Jun 2024 17:03:24 +0200 Subject: [PATCH] vm cache: shorten vm description by stripping .xva suffix With install tests the description becomes really long, use chars sparingly. Signed-off-by: Yann Dirson --- lib/common.py | 15 +++++++++++++++ lib/host.py | 4 ++-- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/lib/common.py b/lib/common.py index 66c8e4b09..d840304f2 100644 --- a/lib/common.py +++ b/lib/common.py @@ -1,6 +1,7 @@ import getpass import inspect import logging +import sys import time import traceback from enum import Enum @@ -75,6 +76,20 @@ def safe_split(text, sep=','): """ A split function that returns an empty list if the input string is empty. """ return text.split(sep) if len(text) > 0 else [] +def strip_prefix(string, prefix): + if sys.version_info >= (3, 9): + return string.removeprefix(prefix) + if string.startswith(prefix): + return string[len(prefix):] + return string + +def strip_suffix(string, suffix): + if sys.version_info >= (3, 9): + return string.removesuffix(suffix) + if string.endswith(suffix): + return string[:-len(suffix)] + return string + def setup_formatted_and_mounted_disk(host, sr_disk, fs_type, mountpoint): if fs_type == 'ext4': option_force = '-F' diff --git a/lib/host.py b/lib/host.py index 474ac0cb4..80d16ff93 100644 --- a/lib/host.py +++ b/lib/host.py @@ -8,7 +8,7 @@ import lib.commands as commands -from lib.common import _param_get, safe_split, to_xapi_bool, wait_for, wait_for_not +from lib.common import _param_get, safe_split, strip_suffix, to_xapi_bool, wait_for, wait_for_not from lib.common import prefix_object_name from lib.netutil import wrap_ip from lib.sr import SR @@ -202,7 +202,7 @@ def xo_server_reconnect(self): @staticmethod def vm_cache_key(uri): - return f"[Cache for {uri}]" + return f"[Cache for {strip_suffix(uri, '.xva')}]" def cached_vm(self, uri, sr_uuid): assert sr_uuid, "A SR UUID is necessary to use import cache"