From d36aa7fbaf4f3ba7394c9ec69faf9675232fa21d Mon Sep 17 00:00:00 2001 From: Cole Robinson Date: Thu, 11 Oct 2018 19:20:46 -0400 Subject: [PATCH] device: disk: Move last host touching to diskbackend This just conceptually makes more sense to keep it all in one file, and DeviceDisk is the API for the rest of the code to deal with any host storage state --- virtinst/devices/disk.py | 18 +----------------- virtinst/diskbackend.py | 26 ++++++++++++++++++++++++-- 2 files changed, 25 insertions(+), 19 deletions(-) diff --git a/virtinst/devices/disk.py b/virtinst/devices/disk.py index 26b4a489..38f3f3a8 100644 --- a/virtinst/devices/disk.py +++ b/virtinst/devices/disk.py @@ -8,7 +8,6 @@ # See the COPYING file in the top-level directory. import logging -import os from .. import diskbackend from .. import util @@ -149,22 +148,7 @@ class DeviceDisk(Device): may have disappeared behind our back, but that shouldn't have bad effects in practice.) """ - if path is None: - return False - - try: - (vol, pool) = diskbackend.check_if_path_managed(conn, path) - ignore = pool - - if vol: - return True - - if not conn.is_remote(): - return os.path.exists(path) - except Exception: - pass - - return False + return diskbackend.path_definitely_exists(conn, path) @staticmethod def check_path_search(conn, path): diff --git a/virtinst/diskbackend.py b/virtinst/diskbackend.py index d81c7a80..f1ea0c0b 100644 --- a/virtinst/diskbackend.py +++ b/virtinst/diskbackend.py @@ -86,7 +86,7 @@ def _stat_disk(path): return True, 0 -def check_if_path_managed(conn, path): +def _check_if_path_managed(conn, path): """ Try to lookup storage objects for the passed path. @@ -147,7 +147,7 @@ def manage_path(conn, path): if not path_is_url(path): path = os.path.abspath(path) - vol, pool = check_if_path_managed(conn, path) + vol, pool = _check_if_path_managed(conn, path) if vol or pool or not _can_auto_manage(path): return vol, pool @@ -223,6 +223,28 @@ def _get_dev_type(path, vol_xml, vol_object, pool_xml, remote): return "file" +def path_definitely_exists(conn, path): + """ + Return True if the path certainly exists, False if we are unsure. + See DeviceDisk entry point for more details + """ + if path is None: + return False + + try: + (vol, pool) = _check_if_path_managed(conn, path) + ignore = pool + if vol: + return True + + if not conn.is_remote(): + return os.path.exists(path) + except Exception: + pass + + return False + + ######################### # ACL/path perm helpers # #########################