[PATCH v2][Kimchi 0/2] Allow vm update graphics type

Changes: v2: Fix typos Add tests Ramon Medeiros (2): Issue #836: Allow user change guest graphics type Create test to verify graphics type change API.json | 6 ++++++ docs/API.md | 1 + i18n.py | 2 +- model/vms.py | 10 ++++++++++ tests/test_model.py | 18 +++++++----------- 5 files changed, 25 insertions(+), 12 deletions(-) -- 2.5.5

Allow vm to choose between spice and vnc Signed-off-by: Ramon Medeiros <ramonn@linux.vnet.ibm.com> --- API.json | 6 ++++++ docs/API.md | 1 + i18n.py | 2 +- model/vms.py | 10 ++++++++++ 4 files changed, 18 insertions(+), 1 deletion(-) diff --git a/API.json b/API.json index a3af02d..dca6840 100644 --- a/API.json +++ b/API.json @@ -377,6 +377,12 @@ "description": "Life time for the graphics password.", "type": "number", "error": "KCHVM0032E" + }, + "type": { + "description": "Graphics type", + "type": "string", + "enum": ["spice", "vnc"], + "error": "KCHVM0054E" } } }, diff --git a/docs/API.md b/docs/API.md index 7bd677f..093acb4 100644 --- a/docs/API.md +++ b/docs/API.md @@ -166,6 +166,7 @@ server. * passwdValidTo *(optional)*: lifetime for the console password. When omitted the password will be valid just for 30 seconds. + * type *(optional)*: graphics type. VNC or Spice. * cpu_info *(optional)*: CPU-specific information. * maxvcpus *(optional)*: The maximum number of vCPUs that can be assigned to the VM. If topology is specified, maxvcpus must be a diff --git a/i18n.py b/i18n.py index e8d9c05..4cc931b 100644 --- a/i18n.py +++ b/i18n.py @@ -106,7 +106,7 @@ messages = { "KCHVM0051E": _("Cannot reset %(name)s. Virtual machine is already shut off."), "KCHVM0052E": _("Boot order must be a list. Devices accepted: hd, cdrom, fd or network."), "KCHVM0053E": _("Bootmenu must be boolean. Values accepted: true of false."), - + "KCHVM0054E": _("Graphic type not valid. Values accepted: vnc or spice."), "KCHVM0055E": _("Migrate to localhost %(host)s is not allowed."), "KCHVM0056E": _("To migrate a virtual machine to the remote host %(host)s the user %(user)s must have password-less login to the remote host."), "KCHVM0057E": _("Can not migrate virtual machine %(name)s when its in %(state)s state."), diff --git a/model/vms.py b/model/vms.py index 3380278..cdcb501 100644 --- a/model/vms.py +++ b/model/vms.py @@ -290,6 +290,12 @@ class VMModel(object): # GRAPHICS can be updated offline or online if 'graphics' in params: + + # some parameters cannot change while vm is running + if DOM_STATE_MAP[dom.info()[0]] != 'shutoff': + if 'type' in params['graphics']: + raise InvalidParameter('KCHVM0074E', + {'params': 'graphics type'}) dom = self._update_graphics(dom, params) # Live updates @@ -701,6 +707,10 @@ class VMModel(object): valid_to = time.strftime('%Y-%m-%dT%H:%M:%S', expire_time) graphics.attrib['passwdValidTo'] = valid_to + gtype = params['graphics'].get('type') + if gtype is not None: + graphics.attrib['type'] = gtype + conn = self.conn.get() if not dom.isActive(): return conn.defineXML(ET.tostring(root, encoding="utf-8")) -- 2.5.5

Signed-off-by: Ramon Medeiros <ramonn@linux.vnet.ibm.com> --- tests/test_model.py | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/tests/test_model.py b/tests/test_model.py index e77d4fd..45498e7 100644 --- a/tests/test_model.py +++ b/tests/test_model.py @@ -324,25 +324,21 @@ class ModelTests(unittest.TestCase): 'source_media': {'type': 'disk', 'path': UBUNTU_ISO}} inst.templates_create(params) with RollbackContext() as rollback: - params = {'name': 'kimchi-vnc', + params = {'name': 'kimchi-graphics', 'template': '/plugins/kimchi/templates/test'} task1 = inst.vms_create(params) inst.task_wait(task1['id']) - rollback.prependDefer(inst.vm_delete, 'kimchi-vnc') + rollback.prependDefer(inst.vm_delete, 'kimchi-graphics') - info = inst.vm_lookup('kimchi-vnc') + info = inst.vm_lookup('kimchi-graphics') self.assertEquals('vnc', info['graphics']['type']) self.assertEquals('127.0.0.1', info['graphics']['listen']) - graphics = {'type': 'spice', 'listen': '127.0.0.1'} - params = {'name': 'kimchi-spice', - 'template': '/plugins/kimchi/templates/test', - 'graphics': graphics} - task2 = inst.vms_create(params) - inst.task_wait(task2['id']) - rollback.prependDefer(inst.vm_delete, 'kimchi-spice') + graphics = {'type': 'spice'} + params = {'graphics': graphics} + inst.vm_update('kimchi-graphics', params) - info = inst.vm_lookup('kimchi-spice') + info = inst.vm_lookup('kimchi-graphics') self.assertEquals('spice', info['graphics']['type']) self.assertEquals('127.0.0.1', info['graphics']['listen']) -- 2.5.5

Please, also add tests to cover the new API. You can add the tests in test_rest.py file. On 08/23/2016 01:47 PM, Ramon Medeiros wrote:
Signed-off-by: Ramon Medeiros <ramonn@linux.vnet.ibm.com> --- tests/test_model.py | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-)
diff --git a/tests/test_model.py b/tests/test_model.py index e77d4fd..45498e7 100644 --- a/tests/test_model.py +++ b/tests/test_model.py @@ -324,25 +324,21 @@ class ModelTests(unittest.TestCase): 'source_media': {'type': 'disk', 'path': UBUNTU_ISO}} inst.templates_create(params) with RollbackContext() as rollback: - params = {'name': 'kimchi-vnc', + params = {'name': 'kimchi-graphics', 'template': '/plugins/kimchi/templates/test'} task1 = inst.vms_create(params) inst.task_wait(task1['id']) - rollback.prependDefer(inst.vm_delete, 'kimchi-vnc') + rollback.prependDefer(inst.vm_delete, 'kimchi-graphics')
- info = inst.vm_lookup('kimchi-vnc') + info = inst.vm_lookup('kimchi-graphics') self.assertEquals('vnc', info['graphics']['type']) self.assertEquals('127.0.0.1', info['graphics']['listen'])
- graphics = {'type': 'spice', 'listen': '127.0.0.1'} - params = {'name': 'kimchi-spice', - 'template': '/plugins/kimchi/templates/test', - 'graphics': graphics} - task2 = inst.vms_create(params) - inst.task_wait(task2['id']) - rollback.prependDefer(inst.vm_delete, 'kimchi-spice') + graphics = {'type': 'spice'} + params = {'graphics': graphics} + inst.vm_update('kimchi-graphics', params)
- info = inst.vm_lookup('kimchi-spice') + info = inst.vm_lookup('kimchi-graphics') self.assertEquals('spice', info['graphics']['type']) self.assertEquals('127.0.0.1', info['graphics']['listen'])

Reviewed-by: Paulo Ricardo Paz Vital <pvital@linux.vnet.ibm.com> On Aug 23 01:47PM, Ramon Medeiros wrote:
Changes:
v2: Fix typos Add tests
Ramon Medeiros (2): Issue #836: Allow user change guest graphics type Create test to verify graphics type change
API.json | 6 ++++++ docs/API.md | 1 + i18n.py | 2 +- model/vms.py | 10 ++++++++++ tests/test_model.py | 18 +++++++----------- 5 files changed, 25 insertions(+), 12 deletions(-)
-- 2.5.5
_______________________________________________ Kimchi-devel mailing list Kimchi-devel@ovirt.org http://lists.ovirt.org/mailman/listinfo/kimchi-devel
-- Paulo Ricardo Paz Vital Linux Technology Center, IBM Systems http://www.ibm.com/linux/ltc/

Hi Ramon, Maybe something else is needed here. When I have a guest configured with SPICE console, the guest XML is something like below: <graphics type='spice' autoport='yes' listen='127.0.0.1'> <channel type='spicevmc'> <target type='virtio' name='com.redhat.spice.0'/> </channel> And for a guest with VNC console, the guest XML has: <graphics type='vnc' port='-1' autoport='yes' listen='127.0.0.1'> From this patch, I am seeing you changing only the type parameter in the graphics tag. Shouldn't the <channel type='spicevmc'> node be removed when changing from SPICE to VNC? What about the port number needed for VNC configuration? Is all that being done automatically through libvirt? Have you confirmed that the console kept working after changing the console type? Regards, Aline Manera On 08/23/2016 01:47 PM, Ramon Medeiros wrote:
Changes:
v2: Fix typos Add tests
Ramon Medeiros (2): Issue #836: Allow user change guest graphics type Create test to verify graphics type change
API.json | 6 ++++++ docs/API.md | 1 + i18n.py | 2 +- model/vms.py | 10 ++++++++++ tests/test_model.py | 18 +++++++----------- 5 files changed, 25 insertions(+), 12 deletions(-)

Just retest right now to make sure. I have a opensuse vm running on spice. 1) turned off it 2) Run PUT on REST API to update it to vnc 3) Turn on 4) opened console on vnc without issues. 5) turned off again 6) Switch to spice 7) running without issues again Tested on my laptop: Fedora 23 x86_64 On 08/30/2016 01:23 PM, Aline Manera wrote:
Hi Ramon,
Maybe something else is needed here.
When I have a guest configured with SPICE console, the guest XML is something like below:
<graphics type='spice' autoport='yes' listen='127.0.0.1'> <channel type='spicevmc'> <target type='virtio' name='com.redhat.spice.0'/> </channel>
And for a guest with VNC console, the guest XML has:
<graphics type='vnc' port='-1' autoport='yes' listen='127.0.0.1'>
From this patch, I am seeing you changing only the type parameter in the graphics tag.
Shouldn't the <channel type='spicevmc'> node be removed when changing from SPICE to VNC? What about the port number needed for VNC configuration?
Is all that being done automatically through libvirt? Have you confirmed that the console kept working after changing the console type?
Regards, Aline Manera
On 08/23/2016 01:47 PM, Ramon Medeiros wrote:
Changes:
v2: Fix typos Add tests
Ramon Medeiros (2): Issue #836: Allow user change guest graphics type Create test to verify graphics type change
API.json | 6 ++++++ docs/API.md | 1 + i18n.py | 2 +- model/vms.py | 10 ++++++++++ tests/test_model.py | 18 +++++++----------- 5 files changed, 25 insertions(+), 12 deletions(-)
-- Ramon Nunes Medeiros Kimchi Developer Linux Technology Center Brazil IBM Systems & Technology Group Phone : +55 19 2132 7878 ramonn@br.ibm.com

On 08/30/2016 01:43 PM, Ramon Medeiros wrote:
Just retest right now to make sure.
I have a opensuse vm running on spice.
1) turned off it 2) Run PUT on REST API to update it to vnc 3) Turn on 4) opened console on vnc without issues. 5) turned off again 6) Switch to spice 7) running without issues again
Tested on my laptop: Fedora 23 x86_64
Please, check if the guest XML does not have any leftover related to those console type changes.
On 08/30/2016 01:23 PM, Aline Manera wrote:
Hi Ramon,
Maybe something else is needed here.
When I have a guest configured with SPICE console, the guest XML is something like below:
<graphics type='spice' autoport='yes' listen='127.0.0.1'> <channel type='spicevmc'> <target type='virtio' name='com.redhat.spice.0'/> </channel>
And for a guest with VNC console, the guest XML has:
<graphics type='vnc' port='-1' autoport='yes' listen='127.0.0.1'>
From this patch, I am seeing you changing only the type parameter in the graphics tag.
Shouldn't the <channel type='spicevmc'> node be removed when changing from SPICE to VNC? What about the port number needed for VNC configuration?
Is all that being done automatically through libvirt? Have you confirmed that the console kept working after changing the console type?
Regards, Aline Manera
On 08/23/2016 01:47 PM, Ramon Medeiros wrote:
Changes:
v2: Fix typos Add tests
Ramon Medeiros (2): Issue #836: Allow user change guest graphics type Create test to verify graphics type change
API.json | 6 ++++++ docs/API.md | 1 + i18n.py | 2 +- model/vms.py | 10 ++++++++++ tests/test_model.py | 18 +++++++----------- 5 files changed, 25 insertions(+), 12 deletions(-)

Hi, just confirmed here: if you switch or create the vm with SPICE, the trash will stay there, even you changing to vnc. The only change in xml is this line: @@ -75,7 +73,7 @@ </channel> <input type='mouse' bus='ps2'/> <input type='keyboard' bus='ps2'/> - <graphics type='spice' autoport='yes' listen='127.0.0.1'> + <graphics type='vnc' port='-1' autoport='yes' listen='127.0.0.1'> The "trash", is this line: <channel type='spicevmc'> <target type='virtio' name='com.redhat.spice.0'/> <address type='virtio-serial' controller='0' bus='0' port='1'/> </channel> That stays in xml, but seems to no make trouble on guest. On 08/30/2016 01:49 PM, Aline Manera wrote:
On 08/30/2016 01:43 PM, Ramon Medeiros wrote:
Just retest right now to make sure.
I have a opensuse vm running on spice.
1) turned off it 2) Run PUT on REST API to update it to vnc 3) Turn on 4) opened console on vnc without issues. 5) turned off again 6) Switch to spice 7) running without issues again
Tested on my laptop: Fedora 23 x86_64
Please, check if the guest XML does not have any leftover related to those console type changes.
On 08/30/2016 01:23 PM, Aline Manera wrote:
Hi Ramon,
Maybe something else is needed here.
When I have a guest configured with SPICE console, the guest XML is something like below:
<graphics type='spice' autoport='yes' listen='127.0.0.1'> <channel type='spicevmc'> <target type='virtio' name='com.redhat.spice.0'/> </channel>
And for a guest with VNC console, the guest XML has:
<graphics type='vnc' port='-1' autoport='yes' listen='127.0.0.1'>
From this patch, I am seeing you changing only the type parameter in the graphics tag.
Shouldn't the <channel type='spicevmc'> node be removed when changing from SPICE to VNC? What about the port number needed for VNC configuration?
Is all that being done automatically through libvirt? Have you confirmed that the console kept working after changing the console type?
Regards, Aline Manera
On 08/23/2016 01:47 PM, Ramon Medeiros wrote:
Changes:
v2: Fix typos Add tests
Ramon Medeiros (2): Issue #836: Allow user change guest graphics type Create test to verify graphics type change
API.json | 6 ++++++ docs/API.md | 1 + i18n.py | 2 +- model/vms.py | 10 ++++++++++ tests/test_model.py | 18 +++++++----------- 5 files changed, 25 insertions(+), 12 deletions(-)
-- Ramon Nunes Medeiros Kimchi Developer Linux Technology Center Brazil IBM Systems & Technology Group Phone : +55 19 2132 7878 ramonn@br.ibm.com
participants (3)
-
Aline Manera
-
Paulo Ricardo Paz Vital
-
Ramon Medeiros