[PATCH v2][Kimchi 0/2] Bug fix #1029: Unable to create a snapshot on a running guest

Changes: v2: Add unit tests Ramon Medeiros (2): Bug fix #1029: Unable to create a snapshot on a running guest Add test to live snapshot i18n.py | 1 - model/vmsnapshots.py | 7 ++----- tests/test_model.py | 6 ++++-- tests/test_rest.py | 19 +++++++++++++++++++ ui/js/src/kimchi.guest_edit_main.js | 3 --- 5 files changed, 25 insertions(+), 11 deletions(-) -- 2.7.4

Libvirt supports live snapshot. This patch just removes the limitation to run snapshot only on turned off guests Signed-off-by: Ramon Medeiros <ramonn@linux.vnet.ibm.com> --- i18n.py | 1 - model/vmsnapshots.py | 7 ++----- ui/js/src/kimchi.guest_edit_main.js | 3 --- 3 files changed, 2 insertions(+), 9 deletions(-) diff --git a/i18n.py b/i18n.py index 6e2daa8..f505693 100644 --- a/i18n.py +++ b/i18n.py @@ -344,7 +344,6 @@ messages = { "KCHVMSTOR0020E": _("On s390x arch 'format' must be specified while attaching disk to virtual machine"), "KCHVMSTOR0021E": _("Virtual disk already exists on the system: %(disk_path)s"), - "KCHSNAP0001E": _("Virtual machine '%(vm)s' must be stopped before creating a snapshot of it."), "KCHSNAP0002E": _("Unable to create snapshot '%(name)s' on virtual machine '%(vm)s'. Details: %(err)s"), "KCHSNAP0003E": _("Snapshot '%(name)s' does not exist on virtual machine '%(vm)s'."), "KCHSNAP0004E": _("Unable to retrieve snapshot '%(name)s' on virtual machine '%(vm)s'. Details: %(err)s"), diff --git a/model/vmsnapshots.py b/model/vmsnapshots.py index 6589306..8c30a53 100644 --- a/model/vmsnapshots.py +++ b/model/vmsnapshots.py @@ -1,7 +1,7 @@ # # Project Kimchi # -# Copyright IBM Corp, 2015-2016 +# Copyright IBM Corp, 2015-2017 # # This library is free software; you can redistribute it and/or # modify it under the terms of the GNU Lesser General Public @@ -28,7 +28,7 @@ from wok.exception import InvalidOperation, NotFoundError, OperationFailed from wok.xmlutils.utils import xpath_get_text from wok.model.tasks import TaskModel -from wok.plugins.kimchi.model.vms import DOM_STATE_MAP, VMModel +from wok.plugins.kimchi.model.vms import VMModel from wok.plugins.kimchi.model.vmstorages import VMStorageModel, VMStoragesModel @@ -57,9 +57,6 @@ class VMSnapshotsModel(object): """ if params is None: params = {} - vir_dom = VMModel.get_vm(vm_name, self.conn) - if DOM_STATE_MAP[vir_dom.info()[0]] != u'shutoff': - raise InvalidOperation('KCHSNAP0001E', {'vm': vm_name}) # if the VM has a non-CDROM disk with type 'raw', abort. for storage_name in self.vmstorages.get_list(vm_name): diff --git a/ui/js/src/kimchi.guest_edit_main.js b/ui/js/src/kimchi.guest_edit_main.js index 1682a58..b47d293 100644 --- a/ui/js/src/kimchi.guest_edit_main.js +++ b/ui/js/src/kimchi.guest_edit_main.js @@ -961,9 +961,6 @@ kimchi.guest_edit_main = function() { addOngoingItem(task); }); }); - if (kimchi.thisVMState === "running") { - $("button", "#form-guest-edit-snapshot").remove(); - } }; var initContent = function(guest) { -- 2.7.4

Signed-off-by: Ramon Medeiros <ramonn@linux.vnet.ibm.com> --- tests/test_model.py | 6 ++++-- tests/test_rest.py | 19 +++++++++++++++++++ 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/tests/test_model.py b/tests/test_model.py index f3da835..af69254 100644 --- a/tests/test_model.py +++ b/tests/test_model.py @@ -204,8 +204,10 @@ class ModelTests(unittest.TestCase): info = inst.vm_lookup('kimchi-vm') self.assertEquals('running', info['state']) - self.assertRaises(InvalidOperation, inst.vmsnapshots_create, - u'kimchi-vm') + task = inst.vmsnapshots_create(u'kimchi-vm') + inst.task_wait(task['id']) + task = inst.task_lookup(task['id']) + self.assertEquals('finished', task['status']) inst.vm_poweroff(u'kimchi-vm') vm = inst.vm_lookup(u'kimchi-vm') diff --git a/tests/test_rest.py b/tests/test_rest.py index 56b8a89..2af465c 100644 --- a/tests/test_rest.py +++ b/tests/test_rest.py @@ -403,6 +403,25 @@ class RestTests(unittest.TestCase): resp = self.request('/plugins/kimchi/vms/test-vm/clone', '{}', 'POST') self.assertEquals(400, resp.status) + # Create a snapshot on running vm VM + params = {'name': 'test-snap2'} + resp = self.request('/plugins/kimchi/vms/test-vm/snapshots', + json.dumps(params), + 'POST') + self.assertEquals(202, resp.status) + task = json.loads(resp.read()) + wait_task(self._task_lookup, task['id']) + task = json.loads( + self.request('/plugins/kimchi/tasks/%s' % task['id']).read() + ) + self.assertEquals('finished', task['status']) + + # Delete a snapshot + resp = self.request('/plugins/kimchi/vms/test-vm/snapshots/%s' % + params['name'], '{}', 'DELETE') + self.assertEquals(204, resp.status) + + # Force poweroff the VM resp = self.request('/plugins/kimchi/vms/test-vm/poweroff', '{}', 'POST') -- 2.7.4

Applied. Thanks. Regards, Aline Manera
participants (2)
-
Aline Manera
-
Ramon Medeiros