Log the current version of the product before configuring

There are situations where we need to know the version of cloudbaseinit
which was used for configuring a host, which helps when debugging
a problem.

Change-Id: If1a2084763cdb74f1d78196a65512cddf26200df
This commit is contained in:
Claudiu Popa
2015-06-19 14:38:24 +03:00
parent ae15fee086
commit 77414c0523
4 changed files with 72 additions and 4 deletions

View File

@@ -21,6 +21,7 @@ from cloudbaseinit.openstack.common import log as logging
from cloudbaseinit.osutils import factory as osutils_factory
from cloudbaseinit.plugins.common import base as plugins_base
from cloudbaseinit.plugins.common import factory as plugins_factory
from cloudbaseinit import version
opts = [
cfg.BoolOpt('allow_reboot', default=True, help='Allows OS reboots '
@@ -94,6 +95,8 @@ class InitManager(object):
return supported
def configure_host(self):
LOG.info('Cloudbase-Init version: %s', version.get_version())
osutils = osutils_factory.get_os_utils()
osutils.wait_for_boot_completion()

View File

@@ -23,6 +23,7 @@ from oslo.config import cfg
from cloudbaseinit import init
from cloudbaseinit.plugins.common import base
from cloudbaseinit.tests import testutils
CONF = cfg.CONF
@@ -135,6 +136,7 @@ class InitManagerTest(unittest.TestCase):
def test_check_plugin_os_requirements_other_requirenments(self):
self._test_check_plugin_os_requirements(('linux', (5, 2)))
@mock.patch('cloudbaseinit.version.get_version')
@mock.patch('cloudbaseinit.init.InitManager'
'._check_plugin_os_requirements')
@mock.patch('cloudbaseinit.init.InitManager._exec_plugin')
@@ -144,16 +146,28 @@ class InitManagerTest(unittest.TestCase):
def test_configure_host(self, mock_get_metadata_service,
mock_get_os_utils, mock_load_plugins,
mock_exec_plugin,
mock_check_os_requirements):
mock_check_os_requirements,
mock_get_version):
instance_id = 'fake id'
name = 'fake name'
version = 'version'
mock_get_version.return_value = version
fake_service = mock.MagicMock()
fake_plugin = mock.MagicMock()
mock_load_plugins.return_value = [fake_plugin]
mock_get_os_utils.return_value = self.osutils
mock_get_metadata_service.return_value = fake_service
fake_service.get_name.return_value = 'fake name'
fake_service.get_instance_id.return_value = 'fake id'
fake_service.get_name.return_value = name
fake_service.get_instance_id.return_value = instance_id
expected_logging = [
'Cloudbase-Init version: %s' % version,
'Metadata service loaded: %r' % name,
'Instance id: %s' % instance_id
]
self._init.configure_host()
with testutils.LogSnatcher('cloudbaseinit.init') as snatcher:
self._init.configure_host()
self.assertEqual(expected_logging, snatcher.output)
self.osutils.wait_for_boot_completion.assert_called_once_with()
mock_get_metadata_service.assert_called_once_with()

View File

@@ -0,0 +1,30 @@
# Copyright 2015 Cloudbase Solutions Srl
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
import unittest
import mock
from cloudbaseinit import version
class TestVersion(unittest.TestCase):
@mock.patch('pbr.version.VersionInfo')
def test_get_version(self, mock_version_info):
package_version = version.get_version()
mock_version_info.assert_called_once_with('cloudbase-init')
release_string = mock_version_info.return_value.release_string
self.assertEqual(release_string.return_value, package_version)

21
cloudbaseinit/version.py Normal file
View File

@@ -0,0 +1,21 @@
# Copyright 2015 Cloudbase Solutions Srl
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
import pbr.version
def get_version():
"""Obtain the project version."""
version = pbr.version.VersionInfo('cloudbase-init')
return version.release_string()