XenStorage make sure subdirs exist in pool dir

This commit is contained in:
Bahtiar `kalkin-` Gadimov 2015-11-07 22:38:34 +01:00
parent 58f23ca392
commit 0bc0bc9045
2 changed files with 19 additions and 3 deletions

View File

@ -271,8 +271,14 @@ class XenPool(Pool):
assert vm is not None
assert dir is not None
if not os.path.exists(dir):
os.mkdir(dir)
appvms_path = os.path.join(dir, 'appvms')
servicevms_path = os.path.join(dir, 'servicevms')
vm_templates_path = os.path.join(dir, 'vm-templates')
self._create_dir_if_not_exists(dir)
self._create_dir_if_not_exists(appvms_path)
self._create_dir_if_not_exists(servicevms_path)
self._create_dir_if_not_exists(vm_templates_path)
self.vmdir = self._vmdir_path(vm, dir)
self.vm = vm
@ -314,3 +320,10 @@ class XenPool(Pool):
return os.path.join(pool_dir, subdir, vm.name)
def _create_dir_if_not_exists(self, path):
""" Check if a directory exists in if not it is created.
This method does not create any parent directories.
"""
if not os.path.exists(path):
os.mkdir(path)

View File

@ -134,7 +134,7 @@ class TC_01_Pool(SystemTestsMixin, QubesTestCase):
self.assertTrue(qubes.storage.pool_exists('test-pool'))
def test_002_pool_dir_create(self):
""" Check if the storage pool dir was created """
""" Check if the storage pool dir and subdirs were created """
# The dir should not exists before
self.assertFalse(os.path.exists(self.POOL_DIR))
@ -145,6 +145,9 @@ class TC_01_Pool(SystemTestsMixin, QubesTestCase):
pool_name='test-pool')
self.assertTrue(os.path.exists(self.POOL_DIR))
self.assertTrue(os.path.exists(self.APPVMS_DIR))
self.assertTrue(os.path.exists(self.SERVICE_DIR))
self.assertTrue(os.path.exists(self.TEMPLATES_DIR))
def test_003_pool_dir(self):
""" Check if the vm storage pool_dir is the same as specified """