Skip to content

Commit

Permalink
vm cache: shorten vm description by stripping .xva suffix
Browse files Browse the repository at this point in the history
With install tests the description becomes really long, use chars
sparingly.

Signed-off-by: Yann Dirson <[email protected]>
  • Loading branch information
ydirson committed Aug 28, 2024
1 parent 462ff23 commit cb52a90
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
15 changes: 15 additions & 0 deletions lib/common.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import getpass
import inspect
import logging
import sys
import time
import traceback
from enum import Enum
Expand Down Expand Up @@ -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'
Expand Down
4 changes: 2 additions & 2 deletions lib/host.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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"
Expand Down

0 comments on commit cb52a90

Please sign in to comment.