[PATCH V2 0/3] template integrity verification: verify storagepool

From: ShaoHe Feng <shaohef@linux.vnet.ibm.com> V1 -> V2 rebase. remove model test. For commit c4c093e does not allow to delete pool kimchi-test-pool as it is associated with some templates. Sometimes, user create a template, storagepool will change later. So users can not create a vm from this template successfully. It is necessary to check storagepool of a template. ShaoHe Feng (3): template integrity verification: verify storagepool, update API.md template integrity verification: verify storagepool in backend template integrity verification: update test case to verify storagepool docs/API.md | 1 + src/kimchi/mockmodel.py | 3 +++ src/kimchi/model/templates.py | 5 +++++ src/kimchi/vmtemplate.py | 11 ++++++++++- tests/test_rest.py | 15 ++++++++++++++- 5 files changed, 33 insertions(+), 2 deletions(-) -- 1.8.4.2

From: ShaoHe Feng <shaohef@linux.vnet.ibm.com> Sometimes, user create a template, storagepool will change later. So users can not create a vm from this template successfully. It is necessary to check storagepool of a template. Signed-off-by: ShaoHe Feng <shaohef@linux.vnet.ibm.com> --- docs/API.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/API.md b/docs/API.md index fc39c65..834c861 100644 --- a/docs/API.md +++ b/docs/API.md @@ -252,6 +252,7 @@ A interface represents available network interface on VM. * networks *(optional)*: An array of invalid network names. * cdrom *(optional)*: An array of invalid cdrom names. * disks *(optional)*: An array of invalid volume names. + * storagepools *(optional)*: An array of invalid storagepool names. * **DELETE**: Remove the Template * **POST**: *See Template Actions* -- 1.8.4.2

From: ShaoHe Feng <shaohef@linux.vnet.ibm.com> update mockmodel and model Signed-off-by: ShaoHe Feng <shaohef@linux.vnet.ibm.com> --- src/kimchi/mockmodel.py | 3 +++ src/kimchi/model/templates.py | 5 +++++ src/kimchi/vmtemplate.py | 11 ++++++++++- 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/src/kimchi/mockmodel.py b/src/kimchi/mockmodel.py index f99b4cd..4ad6a30 100644 --- a/src/kimchi/mockmodel.py +++ b/src/kimchi/mockmodel.py @@ -862,6 +862,9 @@ class MockVMTemplate(VMTemplate): def _get_all_networks_name(self): return self.model.networks_get_list() + def _get_all_storagepools_name(self): + return self.model.storagepools_get_list() + def _storage_validate(self): pool_uri = self.info['storagepool'] pool_name = pool_name_from_uri(pool_uri) diff --git a/src/kimchi/model/templates.py b/src/kimchi/model/templates.py index 3062bd7..52e7eab 100644 --- a/src/kimchi/model/templates.py +++ b/src/kimchi/model/templates.py @@ -167,6 +167,11 @@ class LibvirtVMTemplate(VMTemplate): conn = self.conn.get() return sorted(conn.listNetworks() + conn.listDefinedNetworks()) + def _get_all_storagepools_name(self): + conn = self.conn.get() + names = conn.listStoragePools() + conn.listDefinedStoragePools() + return sorted(map(lambda x: x.decode('utf-8'), names)) + def _network_validate(self): names = self.info['networks'] for name in names: diff --git a/src/kimchi/vmtemplate.py b/src/kimchi/vmtemplate.py index e2d78a4..f092cf7 100644 --- a/src/kimchi/vmtemplate.py +++ b/src/kimchi/vmtemplate.py @@ -26,7 +26,7 @@ import urlparse from kimchi import osinfo from kimchi.exception import InvalidParameter, IsoFormatError from kimchi.isoinfo import IsoImage -from kimchi.utils import check_url_path +from kimchi.utils import check_url_path, pool_name_from_uri QEMU_NAMESPACE = "xmlns:qemu='http://libvirt.org/schemas/domain/qemu/1.0'" @@ -344,6 +344,9 @@ class VMTemplate(object): def _get_all_networks_name(self): return [] + def _get_all_storagepools_name(self): + return [] + def validate_integrity(self): invalid = {} # validate networks integrity @@ -352,6 +355,12 @@ class VMTemplate(object): if invalid_networks: invalid['networks'] = invalid_networks + # validate storagepools integrity + pool_uri = self.info['storagepool'] + pool_name = pool_name_from_uri(pool_uri) + if pool_name not in self._get_all_storagepools_name(): + invalid['storagepools'] = [pool_name] + # validate iso integrity # FIXME when we support multiples cdrom devices iso = self.info['cdrom'] -- 1.8.4.2

From: ShaoHe Feng <shaohef@linux.vnet.ibm.com> update test_rest.py do not update test_model.py. for commit c4c093e does not allow to delete pool kimchi-test-pool as it is associated with some templates Signed-off-by: ShaoHe Feng <shaohef@linux.vnet.ibm.com> --- tests/test_rest.py | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/tests/test_rest.py b/tests/test_rest.py index 54530f3..e5f50ae 100644 --- a/tests/test_rest.py +++ b/tests/test_rest.py @@ -1087,8 +1087,15 @@ class RestTests(unittest.TestCase): resp = request(host, port, '/networks', req, 'POST') self.assertEquals(201, resp.status) + req = json.dumps({'name': 'test-storagepool', + 'path': '/tmp/kimchi-images', + 'type': 'dir'}) + resp = request(host, port, '/storagepools', req, 'POST') + self.assertEquals(201, resp.status) + t = {'name': 'test', 'memory': 1024, 'cpus': 1, - 'networks': ['test-network'], 'cdrom': iso} + 'networks': ['test-network'], 'cdrom': iso, + 'storagepool': '/storagepools/test-storagepool'} req = json.dumps(t) resp = self.request('/templates', req, 'POST') @@ -1099,10 +1106,16 @@ class RestTests(unittest.TestCase): resp = request(host, port, '/networks/test-network', '{}', 'DELETE') self.assertEquals(204, resp.status) + # Delete the storagepool + resp = request(host, port, '/storagepools/test-storagepool', + '{}', 'DELETE') + self.assertEquals(204, resp.status) + # Verify the template res = json.loads(self.request('/templates/test').read()) self.assertEquals(res['invalid']['cdrom'], [iso]) self.assertEquals(res['invalid']['networks'], ['test-network']) + self.assertEquals(res['invalid']['storagepools'], ['test-storagepool']) # Delete the template resp = request(host, port, '/templates/test', '{}', 'DELETE') -- 1.8.4.2
participants (2)
-
Aline Manera
-
shaohef@linux.vnet.ibm.com