Do not hardcode default directories in storagepools and
osinfo code and at the same time make those directories
overwritable by tests.
Signed-off-by: Lucio Correia <luciojhc(a)linux.vnet.ibm.com>
---
model/storagepools.py | 5 +++--
osinfo.py | 12 +++++++++++-
2 files changed, 14 insertions(+), 3 deletions(-)
diff --git a/model/storagepools.py b/model/storagepools.py
index e6f5e58..3bd7086 100644
--- a/model/storagepools.py
+++ b/model/storagepools.py
@@ -31,6 +31,7 @@ from wok.plugins.kimchi.config import config, get_kimchi_version,
kimchiPaths
from wok.plugins.kimchi.model.config import CapabilitiesModel
from wok.plugins.kimchi.model.host import DeviceModel
from wok.plugins.kimchi.model.libvirtstoragepool import StoragePoolDef
+from wok.plugins.kimchi.osinfo import get_default_pools
from wok.plugins.kimchi.osinfo import defaults as tmpl_defaults
from wok.plugins.kimchi.scan import Scanner
from wok.plugins.kimchi.utils import pool_name_from_uri, is_s390x
@@ -83,10 +84,10 @@ class StoragePoolsModel(object):
pools[default_pool] = {}
if default_pool == 'default':
- pools[default_pool] = {'path': '/var/lib/libvirt/images'}
+ pools[default_pool] = {'path': get_default_pools()[default_pool]}
if config.get('kimchi', {}).get('create_iso_pool', False):
- pools['ISO'] = {'path': '/var/lib/kimchi/isos'}
+ pools['ISO'] = {'path': get_default_pools()['ISO']}
conn = self.conn.get()
for pool_name in pools:
diff --git a/osinfo.py b/osinfo.py
index 8de917f..60a454f 100644
--- a/osinfo.py
+++ b/osinfo.py
@@ -31,6 +31,11 @@ from wok.utils import wok_log
from wok.exception import InvalidParameter
from wok.plugins.kimchi.config import kimchiPaths
+
+DEFAULT_POOLS = {
+ 'default': '/var/lib/libvirt/images',
+ 'ISO': '/var/lib/kimchi/isos',
+}
SUPPORTED_ARCHS = {'x86': ('i386', 'i686', 'x86_64'),
'power': ('ppc', 'ppc64'),
'ppc64le': ('ppc64le'),
@@ -108,6 +113,10 @@ icon_available_distros = [icon[5:-4] for icon in
glob.glob1('%s/images/'
% PluginPaths('kimchi').ui_dir, 'icon-*.png')]
+def get_default_pools():
+ return DEFAULT_POOLS
+
+
def _get_arch():
for arch, sub_archs in SUPPORTED_ARCHS.iteritems():
if os.uname()[4] in sub_archs:
@@ -167,7 +176,8 @@ def _get_tmpl_defaults():
is_on_s390x = True if _get_arch() == 's390x' else False
if is_on_s390x:
- tmpl_defaults['storage']['disk.0']['path'] =
'/var/lib/libvirt/images/'
+ tmpl_defaults['storage']['disk.0']['path'] = \
+ get_default_pools()['default']
del tmpl_defaults['storage']['disk.0']['pool']
tmpl_defaults['processor']['vcpus'] = 1
--
2.7.4