[Kimchi-devel] [PATCH 4/4] Live migration: unit tests for the new features

Paulo Ricardo Paz Vital pvital at linux.vnet.ibm.com
Tue Nov 17 11:24:51 UTC 2015


Reviewed-By: Paulo Vital <pvital at linux.vnet.ibm.com>

On Mon, 2015-11-16 at 21:04 -0200, dhbarboza82 at gmail.com wrote:
> From: Daniel Henrique Barboza <dhbarboza82 at gmail.com>
> 
> Using python mock allowed to make unit test for otherwise
> invasive and arch dependent features that live migration
> now supports.
> 
> Signed-off-by: Daniel Henrique Barboza <dhbarboza82 at gmail.com>
> ---
>  src/wok/plugins/kimchi/tests/test_livemigration.py | 81
> +++++++++++++++++++++-
>  1 file changed, 78 insertions(+), 3 deletions(-)
> 
> diff --git a/src/wok/plugins/kimchi/tests/test_livemigration.py
> b/src/wok/plugins/kimchi/tests/test_livemigration.py
> index b9eb9a4..34c0b7e 100644
> --- a/src/wok/plugins/kimchi/tests/test_livemigration.py
> +++ b/src/wok/plugins/kimchi/tests/test_livemigration.py
> @@ -19,6 +19,7 @@
> 
>  import json
>  import libvirt
> +import mock
>  import os
>  import socket
>  import unittest
> @@ -77,7 +78,11 @@ def running_root_and_remoteserver_defined():
>  def check_if_vm_migration_test_possible():
>      inst = model.Model(objstore_loc='/tmp/kimchi-store-test')
>      try:
> -        inst.vm_migration_pre_check(KIMCHI_LIVE_MIGRATION_TEST,
> 'root')
> +        inst.vm_migration_pre_check(
> +            KIMCHI_LIVE_MIGRATION_TEST,
> +            'root',
> +            None
> +        )
>      except:
>          return False
>      return True
> @@ -169,8 +174,58 @@ class LiveMigrationTests(unittest.TestCase):
>              self.assertRaises(OperationFailed,
>                                self.inst.vm_migrate,
>                                'test_vm_migrate',
> -                              KIMCHI_LIVE_MIGRATION_TEST,
> -                              user='test_vm_migrate_fake_user')
> +                              'this_is_a_fake_remote_host')
> +
> +    @mock.patch('wok.plugins.kimchi.model.vms.VMModel.'
> +                '_get_remote_libvirt_conn')
> +    def test_vm_migrate_fails_different_remote_hypervisor(
> +            self, mock_get_remote_conn):
> +
> +        class MockRemoteConnObj(object):
> +            def getType(self):
> +                return 'another_hypervisor'
> +
> +            def close(self):
> +                pass
> +
> +        mock_get_remote_conn.return_value = MockRemoteConnObj()
> +
> +        with RollbackContext() as rollback:
> +            self.create_vm_test()
> +            rollback.prependDefer(utils.rollback_wrapper,
> self.inst.vm_delete,
> +                                  u'test_vm_migrate')
> +
> +            self.assertRaises(OperationFailed,
> +                              self.inst.vm_migrate,
> +                              'test_vm_migrate',
> +                              KIMCHI_LIVE_MIGRATION_TEST)
> +
> +    @mock.patch('wok.plugins.kimchi.model.vms.VMModel.'
> +                '_get_remote_libvirt_conn')
> +    def test_vm_migrate_fails_different_remote_arch(
> +            self, mock_get_remote_conn):
> +
> +        class MockRemoteConnObj(object):
> +            def getType(self):
> +                return 'QEMU'
> +
> +            def getInfo(self):
> +                return ['another_arch', 'QEMU']
> +
> +            def close(self):
> +                pass
> +
> +        mock_get_remote_conn.return_value = MockRemoteConnObj()
> +
> +        with RollbackContext() as rollback:
> +            self.create_vm_test()
> +            rollback.prependDefer(utils.rollback_wrapper,
> self.inst.vm_delete,
> +                                  u'test_vm_migrate')
> +
> +            self.assertRaises(OperationFailed,
> +                              self.inst.vm_migrate,
> +                              'test_vm_migrate',
> +                              KIMCHI_LIVE_MIGRATION_TEST)
> 
>      def get_remote_conn(self):
>          remote_uri = 'qemu+ssh://%s@%s/system' % \
> @@ -411,3 +466,23 @@ class LiveMigrationTests(unittest.TestCase):
>                  remote_vm.undefine()
>              except Exception, e:
>                  self.fail('Migration test failed: %s' % e.message)
> +
> +    @mock.patch('wok.plugins.kimchi.model.vms.VMModel.'
> +                '_set_password_less_login')
> +    @mock.patch('wok.plugins.kimchi.model.vms.VMModel.'
> +                '_check_if_migrating_same_arch_hypervisor')
> +    @mock.patch('wok.plugins.kimchi.model.vms.VMModel.'
> +                '_check_ppc64_subcores_per_core')
> +    def test_set_passwordless_login(self, mock_ppc64_subpercore,
> +                                    mock_same_arch,
> +                                    mock_password_less_login):
> +        self.inst.vm_migration_pre_check(
> +            'this_is_a_fake_remote_host',
> +            'test_vm_migrate_fake_user',
> +            'fake_password'
> +        )
> +        mock_password_less_login.assert_called_once_with(
> +            'this_is_a_fake_remote_host',
> +            'test_vm_migrate_fake_user',
> +            'fake_password'
> +        )




More information about the Kimchi-devel mailing list