Check console enabled before starting console svc

Check if console is enabled in this deploy before trying to start
console service. As part of this add a functions to determine whether
console is enabled and change existing methods to use them.

Change-Id: I91e2654bb0c5f89f51c703330ae2bd0a64cc84f3
Closes-Bug: #1820266
This commit is contained in:
Liam Young 2019-03-15 13:44:17 +00:00
parent 370e4b8380
commit ba19f921c5
3 changed files with 71 additions and 3 deletions

View File

@ -289,7 +289,8 @@ def config_changed():
ncc_utils.set_shared_metadatasecret() ncc_utils.set_shared_metadatasecret()
for rid in hookenv.relation_ids('ha'): for rid in hookenv.relation_ids('ha'):
ha_joined(rid) ha_joined(rid)
if not ch_utils.is_unit_paused_set(): if (not ch_utils.is_unit_paused_set() and
ncc_utils.is_console_auth_enabled()):
ch_host.service_resume('nova-consoleauth') ch_host.service_resume('nova-consoleauth')

View File

@ -273,7 +273,7 @@ def resource_map(actual_services=True):
_resource_map[NOVA_CONF]['services'] += ( _resource_map[NOVA_CONF]['services'] += (
common.console_attributes('services')) common.console_attributes('services'))
if (hookenv.config('enable-serial-console') and cmp_os_release >= 'juno'): if is_serial_console_enabled(cmp_os_release):
_resource_map[NOVA_CONF]['services'] += SERIAL_CONSOLE['services'] _resource_map[NOVA_CONF]['services'] += SERIAL_CONSOLE['services']
# also manage any configs that are being updated by subordinates. # also manage any configs that are being updated by subordinates.
@ -390,7 +390,7 @@ def determine_packages():
pass pass
if common.console_attributes('packages'): if common.console_attributes('packages'):
packages.extend(common.console_attributes('packages')) packages.extend(common.console_attributes('packages'))
if (hookenv.config('enable-serial-console') and release >= 'juno'): if is_serial_console_enabled(release):
packages.extend(SERIAL_CONSOLE['packages']) packages.extend(SERIAL_CONSOLE['packages'])
packages.extend( packages.extend(
ch_utils.token_cache_pkgs(source=hookenv.config('openstack-origin'))) ch_utils.token_cache_pkgs(source=hookenv.config('openstack-origin')))
@ -523,6 +523,31 @@ def disable_policy_rcd():
os.unlink('/usr/sbin/policy-rc.d') os.unlink('/usr/sbin/policy-rc.d')
def is_serial_console_enabled(cmp_os_release=None):
"""Determine whether serial console is enabled in this deploy
:param cmp_os_release: Release comparison object.
:type cmp_os_release: charmhelpers.contrib.openstack.utils.
CompareOpenStackReleases
:returns: Whether serial console is enabled in this deploy
:rtype: bool
"""
if not cmp_os_release:
release = ch_utils.os_release('nova-common')
cmp_os_release = ch_utils.CompareOpenStackReleases(release)
return hookenv.config('enable-serial-console') and cmp_os_release >= 'juno'
def is_console_auth_enabled():
"""Determine whether console auth is enabled in this deploy
:returns: Whether console auth is enabled in this deploy
:rtype: bool
"""
return bool(is_serial_console_enabled() or
hookenv.config('console-access-protocol'))
def is_db_initialised(): def is_db_initialised():
if hookenv.relation_ids('cluster'): if hookenv.relation_ids('cluster'):
dbsync_state = ch_peerstorage.peer_retrieve('dbsync_state') dbsync_state = ch_peerstorage.peer_retrieve('dbsync_state')

View File

@ -1383,6 +1383,48 @@ class NovaCCUtilsTests(CharmTestCase):
with self.assertRaises(Exception): with self.assertRaises(Exception):
utils.archive_deleted_rows() utils.archive_deleted_rows()
def test_is_serial_console_enabled_on_juno(self):
self.os_release.return_value = 'juno'
self.test_config.set('enable-serial-console', True)
self.assertTrue(
utils.is_serial_console_enabled())
def test_is_serial_console_enabled_off_juno(self):
self.os_release.return_value = 'juno'
self.test_config.set('enable-serial-console', False)
self.assertFalse(
utils.is_serial_console_enabled())
def test_is_serial_console_enabled_on_icehouse(self):
self.os_release.return_value = 'icehouse'
self.test_config.set('enable-serial-console', True)
self.assertFalse(
utils.is_serial_console_enabled())
@patch.object(utils, 'is_serial_console_enabled')
def test_is_console_auth_enabled(self, is_serial_console_enabled):
is_serial_console_enabled.return_value = True
self.test_config.set('console-access-protocol', 'vnc')
self.assertTrue(
utils.is_console_auth_enabled())
@patch.object(utils, 'is_serial_console_enabled')
def test_is_console_auth_enabled_no_serial(self,
is_serial_console_enabled):
is_serial_console_enabled.return_value = False
self.test_config.set('console-access-protocol', 'vnc')
self.assertTrue(
utils.is_console_auth_enabled())
@patch.object(utils, 'is_serial_console_enabled')
def test_is_console_auth_enabled_no_serial_no_console(
self,
is_serial_console_enabled):
is_serial_console_enabled.return_value = False
self.test_config.set('console-access-protocol', None)
self.assertFalse(
utils.is_console_auth_enabled())
@patch.object(utils, 'get_cell_uuid') @patch.object(utils, 'get_cell_uuid')
@patch('subprocess.check_output') @patch('subprocess.check_output')
def test_add_hosts_to_cell(self, mock_check_output, mock_get_cell_uuid): def test_add_hosts_to_cell(self, mock_check_output, mock_get_cell_uuid):