Skip to content

Commit 3b078a5

Browse files
committed
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 <[email protected]>
1 parent 8fe0bac commit 3b078a5

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

lib/common.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import getpass
22
import inspect
33
import logging
4+
import sys
45
import time
56
import traceback
67
from enum import Enum
@@ -75,6 +76,20 @@ def safe_split(text, sep=','):
7576
""" A split function that returns an empty list if the input string is empty. """
7677
return text.split(sep) if len(text) > 0 else []
7778

79+
def strip_prefix(string, prefix):
80+
if sys.version_info >= (3, 9):
81+
return string.removeprefix(prefix)
82+
if string.startswith(prefix):
83+
return string[len(prefix):]
84+
return string
85+
86+
def strip_suffix(string, prefix):
87+
if sys.version_info >= (3, 9):
88+
return string.removesuffix(prefix)
89+
if string.endswith(prefix):
90+
return string[:-1 - len(prefix)]
91+
return string
92+
7893
def setup_formatted_and_mounted_disk(host, sr_disk, fs_type, mountpoint):
7994
if fs_type == 'ext4':
8095
option_force = '-F'

lib/host.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
import lib.commands as commands
1010

11-
from lib.common import _param_get, safe_split, to_xapi_bool, wait_for, wait_for_not
11+
from lib.common import _param_get, safe_split, strip_suffix, to_xapi_bool, wait_for, wait_for_not
1212
from lib.common import prefix_object_name
1313
from lib.netutil import wrap_ip
1414
from lib.sr import SR
@@ -203,7 +203,7 @@ def xo_server_reconnect(self):
203203
def import_vm(self, uri, sr_uuid=None, use_cache=False):
204204
if use_cache:
205205
assert sr_uuid, "A SR UUID is necessary to use import cache"
206-
cache_key = f"[Cache for {uri}]"
206+
cache_key = f"[Cache for {strip_suffix(uri, '.xva')}]"
207207
# Look for an existing cache VM
208208
vm_uuids = safe_split(self.xe('vm-list', {'name-description': cache_key}, minimal=True), ',')
209209

0 commit comments

Comments
 (0)