[PATCH] [Kimchi] Issue #919: Deactivate a storagepool makes the list of templates blank

- This commit fixes cases when a storage pools is deativated or removed. Instead of let a blank interface it displays all templates filling the javascript field 'invalid' with the name of the invalid storage. Signed-off-by: Jose Ricardo Ziviani <joserz@linux.vnet.ibm.com> --- i18n.py | 1 - model/templates.py | 29 ++++++++++++++++++++--------- vmtemplate.py | 9 ++++++--- 3 files changed, 26 insertions(+), 13 deletions(-) diff --git a/i18n.py b/i18n.py index 6214687..1061aeb 100644 --- a/i18n.py +++ b/i18n.py @@ -157,7 +157,6 @@ messages = { "KCHTMPL0001E": _("Template %(name)s already exists"), "KCHTMPL0003E": _("Network '%(network)s' specified for template %(template)s does not exist"), "KCHTMPL0004E": _("Storage pool %(pool)s specified for template %(template)s does not exist"), - "KCHTMPL0005E": _("Storage pool %(pool)s specified for template %(template)s is not active"), "KCHTMPL0006E": _("Invalid parameter '%(param)s' specified for CDROM."), "KCHTMPL0007E": _("Network %(network)s specified for template %(template)s is not active"), "KCHTMPL0008E": _("Template name must be a string"), diff --git a/model/templates.py b/model/templates.py index 92705b6..9294be2 100644 --- a/model/templates.py +++ b/model/templates.py @@ -271,19 +271,16 @@ class LibvirtVMTemplate(VMTemplate): # validate CPU info values - will raise appropriate exceptions cpu_model.check_cpu_info(self.info['cpu_info']) - def _storage_validate(self, pool_uri): + def _get_storage_pool(self, pool_uri): pool_name = pool_name_from_uri(pool_uri) try: conn = self.conn.get() pool = conn.storagePoolLookupByName(pool_name.encode("utf-8")) + except libvirt.libvirtError: raise InvalidParameter("KCHTMPL0004E", {'pool': pool_uri, 'template': self.name}) - if not pool.isActive(): - raise InvalidParameter("KCHTMPL0005E", {'pool': pool_name, - 'template': self.name}) - return pool def _get_all_networks_name(self): @@ -295,6 +292,11 @@ class LibvirtVMTemplate(VMTemplate): names = conn.listStoragePools() + conn.listDefinedStoragePools() return sorted(map(lambda x: x.decode('utf-8'), names)) + def _get_active_storagepools_name(self): + conn = self.conn.get() + names = conn.listStoragePools() + return sorted(map(lambda x: x.decode('utf-8'), names)) + def _network_validate(self): names = self.info['networks'] for name in names: @@ -310,17 +312,26 @@ class LibvirtVMTemplate(VMTemplate): 'template': self.name}) def _get_storage_path(self, pool_uri=None): - pool = self._storage_validate(pool_uri) + try: + pool = self._get_storage_pool(pool_uri) + + except: + return '' + xml = pool.XMLDesc(0) return xpath_get_text(xml, "/pool/target/path")[0] def _get_storage_type(self, pool_uri=None): - pool = self._storage_validate(pool_uri) + try: + pool = self._get_storage_pool(pool_uri) + + except: + return '' xml = pool.XMLDesc(0) return xpath_get_text(xml, "/pool/@type")[0] def _get_volume_path(self, pool, vol): - pool = self._storage_validate(pool) + pool = self._get_storage_pool(pool) try: return pool.storageVolLookupByName(vol).path() except: @@ -332,7 +343,7 @@ class LibvirtVMTemplate(VMTemplate): vol_list = self.to_volume_list(vm_uuid) try: for v in vol_list: - pool = self._storage_validate(v['pool']) + pool = self._get_storage_pool(v['pool']) # outgoing text to libvirt, encode('utf-8') pool.createXML(v['xml'].encode('utf-8'), 0) except libvirt.libvirtError as e: diff --git a/vmtemplate.py b/vmtemplate.py index b71cf23..4470be4 100644 --- a/vmtemplate.py +++ b/vmtemplate.py @@ -441,7 +441,7 @@ class VMTemplate(object): def validate(self): for disk in self.info.get('disks'): pool_uri = disk.get('pool', {}).get('name') - self._storage_validate(pool_uri) + self._get_storage_pool(pool_uri) self._network_validate() self._iso_validate() self.cpuinfo_validate() @@ -456,7 +456,7 @@ class VMTemplate(object): def _network_validate(self): pass - def _storage_validate(self): + def _get_storage_pool(self): pass def fork_vm_storage(self, vm_uuid): @@ -477,6 +477,9 @@ class VMTemplate(object): def _get_all_storagepools_name(self): return [] + def _get_active_storagepools_name(self): + return [] + def validate_integrity(self): invalid = {} # validate networks integrity @@ -489,7 +492,7 @@ class VMTemplate(object): for disk in self.info['disks']: pool_uri = disk['pool']['name'] pool_name = pool_name_from_uri(pool_uri) - if pool_name not in self._get_all_storagepools_name(): + if pool_name not in self._get_active_storagepools_name(): invalid['storagepools'] = [pool_name] # validate iso integrity -- 1.9.1

Reviewed-By: Lucio Correia <luciojhc@linux.vnet.ibm.com> On 07-04-2016 10:57, Jose Ricardo Ziviani wrote:
- This commit fixes cases when a storage pools is deativated or removed. Instead of let a blank interface it displays all templates filling the javascript field 'invalid' with the name of the invalid storage.
Signed-off-by: Jose Ricardo Ziviani <joserz@linux.vnet.ibm.com> --- i18n.py | 1 - model/templates.py | 29 ++++++++++++++++++++--------- vmtemplate.py | 9 ++++++--- 3 files changed, 26 insertions(+), 13 deletions(-)
diff --git a/i18n.py b/i18n.py index 6214687..1061aeb 100644 --- a/i18n.py +++ b/i18n.py @@ -157,7 +157,6 @@ messages = { "KCHTMPL0001E": _("Template %(name)s already exists"), "KCHTMPL0003E": _("Network '%(network)s' specified for template %(template)s does not exist"), "KCHTMPL0004E": _("Storage pool %(pool)s specified for template %(template)s does not exist"), - "KCHTMPL0005E": _("Storage pool %(pool)s specified for template %(template)s is not active"), "KCHTMPL0006E": _("Invalid parameter '%(param)s' specified for CDROM."), "KCHTMPL0007E": _("Network %(network)s specified for template %(template)s is not active"), "KCHTMPL0008E": _("Template name must be a string"), diff --git a/model/templates.py b/model/templates.py index 92705b6..9294be2 100644 --- a/model/templates.py +++ b/model/templates.py @@ -271,19 +271,16 @@ class LibvirtVMTemplate(VMTemplate): # validate CPU info values - will raise appropriate exceptions cpu_model.check_cpu_info(self.info['cpu_info'])
- def _storage_validate(self, pool_uri): + def _get_storage_pool(self, pool_uri): pool_name = pool_name_from_uri(pool_uri) try: conn = self.conn.get() pool = conn.storagePoolLookupByName(pool_name.encode("utf-8")) + except libvirt.libvirtError: raise InvalidParameter("KCHTMPL0004E", {'pool': pool_uri, 'template': self.name})
- if not pool.isActive(): - raise InvalidParameter("KCHTMPL0005E", {'pool': pool_name, - 'template': self.name}) - return pool
def _get_all_networks_name(self): @@ -295,6 +292,11 @@ class LibvirtVMTemplate(VMTemplate): names = conn.listStoragePools() + conn.listDefinedStoragePools() return sorted(map(lambda x: x.decode('utf-8'), names))
+ def _get_active_storagepools_name(self): + conn = self.conn.get() + names = conn.listStoragePools() + return sorted(map(lambda x: x.decode('utf-8'), names)) + def _network_validate(self): names = self.info['networks'] for name in names: @@ -310,17 +312,26 @@ class LibvirtVMTemplate(VMTemplate): 'template': self.name})
def _get_storage_path(self, pool_uri=None): - pool = self._storage_validate(pool_uri) + try: + pool = self._get_storage_pool(pool_uri) + + except: + return '' + xml = pool.XMLDesc(0) return xpath_get_text(xml, "/pool/target/path")[0]
def _get_storage_type(self, pool_uri=None): - pool = self._storage_validate(pool_uri) + try: + pool = self._get_storage_pool(pool_uri) + + except: + return '' xml = pool.XMLDesc(0) return xpath_get_text(xml, "/pool/@type")[0]
def _get_volume_path(self, pool, vol): - pool = self._storage_validate(pool) + pool = self._get_storage_pool(pool) try: return pool.storageVolLookupByName(vol).path() except: @@ -332,7 +343,7 @@ class LibvirtVMTemplate(VMTemplate): vol_list = self.to_volume_list(vm_uuid) try: for v in vol_list: - pool = self._storage_validate(v['pool']) + pool = self._get_storage_pool(v['pool']) # outgoing text to libvirt, encode('utf-8') pool.createXML(v['xml'].encode('utf-8'), 0) except libvirt.libvirtError as e: diff --git a/vmtemplate.py b/vmtemplate.py index b71cf23..4470be4 100644 --- a/vmtemplate.py +++ b/vmtemplate.py @@ -441,7 +441,7 @@ class VMTemplate(object): def validate(self): for disk in self.info.get('disks'): pool_uri = disk.get('pool', {}).get('name') - self._storage_validate(pool_uri) + self._get_storage_pool(pool_uri) self._network_validate() self._iso_validate() self.cpuinfo_validate() @@ -456,7 +456,7 @@ class VMTemplate(object): def _network_validate(self): pass
- def _storage_validate(self): + def _get_storage_pool(self): pass
def fork_vm_storage(self, vm_uuid): @@ -477,6 +477,9 @@ class VMTemplate(object): def _get_all_storagepools_name(self): return []
+ def _get_active_storagepools_name(self): + return [] + def validate_integrity(self): invalid = {} # validate networks integrity @@ -489,7 +492,7 @@ class VMTemplate(object): for disk in self.info['disks']: pool_uri = disk['pool']['name'] pool_name = pool_name_from_uri(pool_uri) - if pool_name not in self._get_all_storagepools_name(): + if pool_name not in self._get_active_storagepools_name(): invalid['storagepools'] = [pool_name]
# validate iso integrity
-- Lucio Correia Software Engineer IBM LTC Brazil

Applied. Thanks. Regards, Aline Manera
participants (3)
-
Aline Manera
-
Jose Ricardo Ziviani
-
Lucio Correia