[Kimchi-devel] [PATCH] [Kimchi 9/9] Virt-Viewer launcher: changes after adding libvirt event listening

Lucio Correia luciojhc at linux.vnet.ibm.com
Thu Jul 7 15:25:28 UTC 2016


My suggestion is to test it with a vm with special characters in name, 
since there is name reading from libvirt in backend.

On 07-07-2016 09:57, dhbarboza82 at gmail.com wrote:
> From: Daniel Henrique Barboza <danielhb at linux.vnet.ibm.com>
>
> This patch changes existing tests and add a new test to
> assert that the latest changes with FirewallManager and
> libvirt event listening in virtviewerfile.py is working
> properly.
>
> Signed-off-by: Daniel Henrique Barboza <danielhb at linux.vnet.ibm.com>
> ---
>   tests/test_model.py | 53 ++++++++++++++++++++++++++++++++++++++++++++++++++++-
>   1 file changed, 52 insertions(+), 1 deletion(-)
>
> diff --git a/tests/test_model.py b/tests/test_model.py
> index 1162d2c..44358a5 100644
> --- a/tests/test_model.py
> +++ b/tests/test_model.py
> @@ -371,8 +371,13 @@ class ModelTests(unittest.TestCase):
>       @mock.patch('wok.plugins.kimchi.model.virtviewerfile.'
>                   'VMModel.get_graphics')
>       @mock.patch('wok.plugins.kimchi.model.virtviewerfile.'
> +                'FirewallManager.add_vm_graphics_port')
> +    @mock.patch('wok.plugins.kimchi.model.virtviewerfile.'
> +                'VMVirtViewerFileModel.handleVMShutdownPowerOff')
> +    @mock.patch('wok.plugins.kimchi.model.virtviewerfile.'
>                   'VMVirtViewerFileModel._check_if_vm_running')
> -    def test_vm_virtviewerfile_vnc(self, mock_vm_running, mock_get_graphics,
> +    def test_vm_virtviewerfile_vnc(self, mock_vm_running, mock_handleVMOff,
> +                                   mock_add_port, mock_get_graphics,
>                                      mock_get_host):
>
>           mock_get_host.return_value = 'kimchi-test-host'
> @@ -398,13 +403,21 @@ class ModelTests(unittest.TestCase):
>
>           mock_get_graphics.assert_called_once_with('kimchi-vm', None)
>           mock_vm_running.assert_called_once_with('kimchi-vm')
> +        mock_handleVMOff.assert_called_once_with('kimchi-vm')
> +        mock_add_port.assert_called_once_with('kimchi-vm', '5999')
>
>       @mock.patch('wok.plugins.kimchi.model.virtviewerfile._get_request_host')
>       @mock.patch('wok.plugins.kimchi.model.virtviewerfile.'
>                   'VMModel.get_graphics')
>       @mock.patch('wok.plugins.kimchi.model.virtviewerfile.'
> +                'FirewallManager.add_vm_graphics_port')
> +    @mock.patch('wok.plugins.kimchi.model.virtviewerfile.'
> +                'VMVirtViewerFileModel.handleVMShutdownPowerOff')
> +    @mock.patch('wok.plugins.kimchi.model.virtviewerfile.'
>                   'VMVirtViewerFileModel._check_if_vm_running')
>       def test_vm_virtviewerfile_spice_passwd(self, mock_vm_running,
> +                                            mock_handleVMOff,
> +                                            mock_add_port,
>                                               mock_get_graphics,
>                                               mock_get_host):
>
> @@ -433,6 +446,8 @@ class ModelTests(unittest.TestCase):
>
>           mock_get_graphics.assert_called_once_with('kimchi-vm', None)
>           mock_vm_running.assert_called_once_with('kimchi-vm')
> +        mock_handleVMOff.assert_called_once_with('kimchi-vm')
> +        mock_add_port.assert_called_once_with('kimchi-vm', '6660')
>
>       @mock.patch('wok.plugins.kimchi.model.virtviewerfile.run_command')
>       def test_firewall_provider_firewallcmd(self, mock_run_cmd):
> @@ -504,6 +519,42 @@ class ModelTests(unittest.TestCase):
>               ]
>           )
>
> +    @unittest.skipUnless(utils.running_as_root(), 'Must be run as root')
> +    @mock.patch('wok.plugins.kimchi.model.virtviewerfile.'
> +                'FirewallManager.remove_vm_graphics_port')
> +    @mock.patch('wok.plugins.kimchi.model.virtviewerfile.'
> +                'FirewallManager.add_vm_graphics_port')
> +    def test_vm_virtviewerfile_vmlifecycle(self, mock_add_port,
> +                                           mock_remove_port):
> +
> +        inst = model.Model(objstore_loc=self.tmp_store)
> +        params = {'name': 'test',
> +                  'source_media': {'type': 'disk', 'path': UBUNTU_ISO}}
> +        inst.templates_create(params)
> +
> +        with RollbackContext() as rollback:
> +            params = {'name': 'kimchi-vnc',
> +                      'template': '/plugins/kimchi/templates/test'}
> +            task1 = inst.vms_create(params)
> +            inst.task_wait(task1['id'])
> +            rollback.prependDefer(inst.vm_delete, 'kimchi-vnc')
> +
> +            inst.vm_start('kimchi-vnc')
> +
> +            graphics_info = VMModel.get_graphics('kimchi-vnc', inst.conn)
> +            graphics_port = graphics_info[2]
> +
> +            vvmodel = VMVirtViewerFileModel(conn=inst.conn)
> +            vvmodel.lookup('kimchi-vnc')
> +
> +            inst.vm_poweroff('kimchi-vnc')
> +            time.sleep(5)
> +
> +            mock_add_port.assert_called_once_with('kimchi-vnc', graphics_port)
> +            mock_remove_port.assert_called_once_with('kimchi-vnc')
> +
> +        inst.template_delete('test')
> +
>       @unittest.skipUnless(utils.running_as_root(), "Must be run as root")
>       def test_vm_serial(self):
>           inst = model.Model(objstore_loc=self.tmp_store)
>


-- 
Lucio Correia
Software Engineer
IBM LTC Brazil




More information about the Kimchi-devel mailing list