1#!/usr/bin/python
2
3import unittest
4import common
5from autotest_lib.client.virt import installer
6from autotest_lib.client.common_lib import cartesian_config
7
8class installer_test(unittest.TestCase):
9
10    def setUp(self):
11        self.registry = installer.InstallerRegistry()
12
13
14    def test_register_get_installer(self):
15        install_mode = 'custom_install_mode'
16        virt_type = 'custom_virt_type'
17
18        class CustomVirtInstaller:
19            pass
20
21        self.registry.register(install_mode, CustomVirtInstaller, virt_type)
22        klass = self.registry.get_installer(install_mode, virt_type)
23        self.assertIs(klass, CustomVirtInstaller)
24
25
26    def test_register_get_installer_default(self):
27        install_mode = 'base_install_mode'
28
29        class BaseVirtInstaller:
30            pass
31
32        self.registry.register(install_mode, BaseVirtInstaller)
33        klass = self.registry.get_installer(install_mode,
34                                            get_default_virt=True)
35        self.assertIs(klass, BaseVirtInstaller)
36
37        klass = self.registry.get_installer(install_mode,
38                                            virt=None,
39                                            get_default_virt=True)
40        self.assertIs(klass, BaseVirtInstaller)
41
42
43    def test_make_installer(self):
44        config = """install_mode = test_install_mode
45vm_type = test"""
46
47        class Installer:
48            def __init__(self, mode, name, test, params):
49                pass
50
51        installer.INSTALLER_REGISTRY.register('test_install_mode',
52                                              Installer,
53                                              'test')
54
55        config_parser = cartesian_config.Parser()
56        config_parser.parse_string(config)
57        params = config_parser.get_dicts().next()
58
59        instance = installer.make_installer("test_install_mode_test", params)
60        self.assertIsInstance(instance, Installer)
61
62
63if __name__ == '__main__':
64    unittest.main()
65