[PATCHv2 0/3] Add out of box ISO storage pool

From: Royce Lv <lvroyce@linux.vnet.ibm.com> As libvirt has dynamic permission configuration, we do not need watch the iso added to storage pool any more, we just need to make sure storage pool can be accessed and libvirt will change its own/grp to the right one. so after found this feature, notification is deleted and create iso pool is retained. Royce Lv (3): Dedicated ISO pool: create an out of box ISO pool Store qemu user name in class attribute Add doc and test case for dedicate iso pool docs/README.md | 5 +++++ src/kimchi/kvmusertests.py | 22 ++++++++++++---------- src/kimchi/model/model.py | 25 ++++++++++++++----------- tests/test_model.py | 3 +++ 4 files changed, 34 insertions(+), 21 deletions(-) -- 1.8.3.2

From: Royce Lv <lvroyce@linux.vnet.ibm.com> An out of box ISO pool is created to make sure user will find a well known place to put his ISO. Signed-off-by: Royce Lv <lvroyce@linux.vnet.ibm.com> --- src/kimchi/model/model.py | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/src/kimchi/model/model.py b/src/kimchi/model/model.py index a766ca5..579f2d1 100644 --- a/src/kimchi/model/model.py +++ b/src/kimchi/model/model.py @@ -24,6 +24,8 @@ import sys import cherrypy import libvirt +import lxml.etree as ET +from lxml.builder import E from kimchi.basemodel import BaseModel from kimchi.model.libvirtconnection import LibvirtConnection @@ -31,6 +33,9 @@ from kimchi.objectstore import ObjectStore from kimchi.utils import import_module, listPathModules +DEFAULT_POOLS = {'default': {'path': '/var/lib/libvirt/images'}, + 'ISO': {'path': '/var/lib/libvirt/isos'}} + class Model(BaseModel): def __init__(self, libvirt_uri='qemu:///system', objstore_loc=None): self.objstore = ObjectStore(objstore_loc) @@ -38,7 +43,8 @@ class Model(BaseModel): kargs = {'objstore': self.objstore, 'conn': self.conn} if 'qemu:///' in libvirt_uri: - self._default_pool_check() + for pool_name, pool_arg in DEFAULT_POOLS.iteritems(): + self._default_pool_check(pool_name, pool_arg) this = os.path.basename(__file__) this_mod = os.path.splitext(this)[0] @@ -57,21 +63,18 @@ class Model(BaseModel): return super(Model, self).__init__(models) - def _default_pool_check(self): + def _default_pool_check(self, pool_name, pool_arg): conn = self.conn.get() - xml = """ - <pool type='dir'> - <name>default</name> - <target> - <path>/var/lib/libvirt/images</path> - </target> - </pool> - """ + pool = E.pool(E.name(pool_name), type='dir') + pool.append(E.target(E.path(pool_arg['path']))) + xml = ET.tostring(pool) try: - pool = conn.storagePoolLookupByName("default") + pool = conn.storagePoolLookupByName(pool_name) except libvirt.libvirtError: try: pool = conn.storagePoolDefineXML(xml, 0) + # Add build step to make sure target directory created + pool.build(libvirt.VIR_STORAGE_POOL_BUILD_NEW) pool.setAutostart(1) except libvirt.libvirtError, e: cherrypy.log.error("Fatal: Cannot create default pool because " -- 1.8.3.2

From: Royce Lv <lvroyce@linux.vnet.ibm.com> To prevent qemu user be probed multiple times, store it in class attribute so that next time we don't need to create vm. Signed-off-by: ShaoHe Feng <shaohef@linux.vnet.ibm.com> Signed-off-by: Royce Lv <lvroyce@linux.vnet.ibm.com> --- src/kimchi/kvmusertests.py | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/src/kimchi/kvmusertests.py b/src/kimchi/kvmusertests.py index 4884ccf..30c287a 100644 --- a/src/kimchi/kvmusertests.py +++ b/src/kimchi/kvmusertests.py @@ -37,14 +37,16 @@ class UserTests(object): <boot dev='hd'/> </os> </domain>""" + user = None + @classmethod + def probe_user(cls): + if cls.user: + return cls.user - def __init__(self): - self.vm_uuid = uuid.uuid1() - self.vm_name = "kimchi_test_%s" % self.vm_uuid + vm_uuid = uuid.uuid1() + vm_name = "kimchi_test_%s" % vm_uuid - def probe_user(self): - xml = self.SIMPLE_VM_XML % (self.vm_name, self.vm_uuid) - user = None + xml = cls.SIMPLE_VM_XML % (vm_name, vm_uuid) with RollbackContext() as rollback: conn = libvirt.open('qemu:///system') rollback.prependDefer(conn.close) @@ -52,7 +54,7 @@ class UserTests(object): rollback.prependDefer(dom.undefine) dom.create() rollback.prependDefer(dom.destroy) - with open('/var/run/libvirt/qemu/%s.pid' % self.vm_name) as f: + with open('/var/run/libvirt/qemu/%s.pid' % vm_name) as f: pidStr = f.read() p = psutil.Process(int(pidStr)) @@ -60,11 +62,11 @@ class UserTests(object): # in psutil 2.0 and above versions, username will be a method, # not a string if callable(p.username): - user = p.username() + cls.user = p.username() else: - user = p.username + cls.user = p.username - return user + return cls.user if __name__ == '__main__': -- 1.8.3.2

From: Royce Lv <lvroyce@linux.vnet.ibm.com> Add doc for user to upload the iso to a dedicate pool, add testcase to validate correctness. Signed-off-by: Royce Lv <lvroyce@linux.vnet.ibm.com> --- docs/README.md | 5 +++++ tests/test_model.py | 3 +++ 2 files changed, 8 insertions(+) diff --git a/docs/README.md b/docs/README.md index c658637..2591f7c 100644 --- a/docs/README.md +++ b/docs/README.md @@ -143,6 +143,11 @@ The template screen looks like: From this view, you can change the parameters of a template or create a new template using the "+" button in the upper right corner. +To create a template, you need an ISO on your host or using remote one. +If you are willing to use your own ISO, +please copy it to out of box storage pool (default path is: +/var/lib/libvirt/isos). + Known Issues ------------ diff --git a/tests/test_model.py b/tests/test_model.py index 142e4fc..ea38f59 100644 --- a/tests/test_model.py +++ b/tests/test_model.py @@ -416,6 +416,9 @@ class ModelTests(unittest.TestCase): self.assertIn('default', pools) poolinfo = inst.storagepool_lookup('default') self.assertEquals('active', poolinfo['state']) + self.assertIn('ISO', pools) + poolinfo = inst.storagepool_lookup('ISO') + self.assertEquals('active', poolinfo['state']) self.assertEquals((num - 1), len(pools)) @unittest.skipUnless(utils.running_as_root(), 'Must be run as root') -- 1.8.3.2

On 06/12/2014 05:03 AM, lvroyce@linux.vnet.ibm.com wrote:
From: Royce Lv <lvroyce@linux.vnet.ibm.com>
Add doc for user to upload the iso to a dedicate pool, add testcase to validate correctness.
Signed-off-by: Royce Lv <lvroyce@linux.vnet.ibm.com> --- docs/README.md | 5 +++++ tests/test_model.py | 3 +++ 2 files changed, 8 insertions(+)
diff --git a/docs/README.md b/docs/README.md index c658637..2591f7c 100644 --- a/docs/README.md +++ b/docs/README.md @@ -143,6 +143,11 @@ The template screen looks like: From this view, you can change the parameters of a template or create a new template using the "+" button in the upper right corner.
+To create a template, you need an ISO on your host or using remote one. +If you are willing to use your own ISO, +please copy it to out of box storage pool (default path is: +/var/lib/libvirt/isos). +
Royce, add it to the help page as well. ui/pages/help/*/storage.dita
Known Issues ------------
diff --git a/tests/test_model.py b/tests/test_model.py index 142e4fc..ea38f59 100644 --- a/tests/test_model.py +++ b/tests/test_model.py @@ -416,6 +416,9 @@ class ModelTests(unittest.TestCase): self.assertIn('default', pools) poolinfo = inst.storagepool_lookup('default') self.assertEquals('active', poolinfo['state']) + self.assertIn('ISO', pools) + poolinfo = inst.storagepool_lookup('ISO') + self.assertEquals('active', poolinfo['state']) self.assertEquals((num - 1), len(pools))
@unittest.skipUnless(utils.running_as_root(), 'Must be run as root')
participants (2)
-
Aline Manera
-
lvroyce@linux.vnet.ibm.com