Пример #1
0
    def configure_host(self):
        osutils = osutils_factory.get_os_utils()
        osutils.wait_for_boot_completion()

        service = metadata_factory.get_metadata_service()
        LOG.info('Metadata service loaded: \'%s\'' % service.get_name())

        instance_id = service.get_instance_id()
        LOG.debug('Instance id: %s', instance_id)

        plugins = plugins_factory.load_plugins()
        plugins_shared_data = {}

        reboot_required = False
        try:
            for plugin in plugins:
                if self._check_plugin_os_requirements(osutils, plugin):
                    if self._exec_plugin(osutils, service, plugin, instance_id,
                                         plugins_shared_data):
                        reboot_required = True
                        if CONF.allow_reboot:
                            break
        finally:
            service.cleanup()

        if reboot_required and CONF.allow_reboot:
            try:
                osutils.reboot()
            except Exception as ex:
                LOG.error('reboot failed with error \'%s\'' % ex)
        elif CONF.stop_service_on_exit:
            osutils.terminate()
Пример #2
0
 def test_load_plugins(self, mock_load_class):
     expected = []
     for path in CONF.plugins:
         expected.append(mock.call(path))
     response = factory.load_plugins()
     self.assertEqual(expected, mock_load_class.call_args_list)
     self.assertTrue(response is not None)
Пример #3
0
    def configure_host(self):
        osutils = osutils_factory.get_os_utils()
        osutils.wait_for_boot_completion()

        service = metadata_factory.get_metadata_service()
        LOG.info('Metadata service loaded: \'%s\'' %
                 service.get_name())

        instance_id = service.get_instance_id()
        LOG.debug('Instance id: %s', instance_id)

        plugins = plugins_factory.load_plugins()
        plugins_shared_data = {}

        reboot_required = False
        try:
            for plugin in plugins:
                if self._check_plugin_os_requirements(osutils, plugin):
                    if self._exec_plugin(osutils, service, plugin,
                                         instance_id, plugins_shared_data):
                        reboot_required = True
                        if CONF.allow_reboot:
                            break
        finally:
            service.cleanup()

        if reboot_required and CONF.allow_reboot:
            try:
                osutils.reboot()
            except Exception as ex:
                LOG.error('reboot failed with error \'%s\'' % ex)
        elif CONF.stop_service_on_exit:
            osutils.terminate()
Пример #4
0
 def test_load_plugins(self, mock_load_class):
     expected = []
     for path in CONF.plugins:
         expected.append(mock.call(path))
     response = factory.load_plugins()
     self.assertEqual(expected, mock_load_class.call_args_list)
     self.assertTrue(response is not None)
Пример #5
0
    def test_old_plugin_mapping(self, mock_load_class):
        with testutils.LogSnatcher('cloudbaseinit.plugins.common.'
                                   'factory') as snatcher:
            factory.load_plugins()

        expected = [
            "Old plugin module 'cloudbaseinit.plugins.windows."
            "localscripts.LocalScriptsPlugin' was found. "
            "The new name is 'cloudbaseinit.plugins.common."
            "localscripts.LocalScriptsPlugin'. The old name will not "
            "be supported starting with cloudbaseinit 1.0",
        ]
        expected_call = mock.call('cloudbaseinit.plugins.common.'
                                  'localscripts.LocalScriptsPlugin')
        self.assertEqual(expected, snatcher.output)
        called = mock_load_class.mock_calls[0]
        self.assertEqual(expected_call, called)
Пример #6
0
    def test_load_plugins_plugin_failed(self):
        with testutils.LogSnatcher('cloudbaseinit.plugins.'
                                   'common.factory') as snatcher:
            plugins = factory.load_plugins()

        self.assertEqual([], plugins)
        self.assertEqual(["Could not import plugin module 'missing.plugin'"],
                         snatcher.output)