Add caching for knownhost private-address lookups

This change adds caching for the host look ups associated with a
private-address of a unit.  This cache is maintained across hook
invocations, and is designed to reduce the time spent in
cloud-compute-relation-changed hooks (which occur as nova-compute units
join and update on the cloud-compute relation).

The feature has been added under an EXPERIMENTAL config flag (with the
default being "don't use the cached values") in case there are any
corner cases around DNS resolution in the deploying cloud during
deployment.

An action is included to allow clearing of the cache at unit,
application and whole relation level.  This clears the cache and
re-triggers the host resolution, and relation updates.  This is in case
of either 1) DNS changed during the deployment, 2) DNS has been altered
during the running of the cloud.

Change-Id: I5a68bf4c30bf1591184d660d50559c969822ddcf
This commit is contained in:
Alex Kavanagh
2019-07-16 14:27:30 +01:00
parent 4d9b4a2600
commit fe65e12b31
8 changed files with 296 additions and 38 deletions

View File

@@ -68,7 +68,7 @@ TO_PATCH = [
'hooks.nova_cc_utils.serial_console_settings',
'hooks.nova_cc_utils.services',
'hooks.nova_cc_utils.ssh_authorized_keys_lines',
'hooks.nova_cc_utils.ssh_resolve_compute_hosts',
'hooks.nova_cc_utils.ssh_compute_add_known_hosts',
'hooks.nova_cc_utils.ssh_known_hosts_lines',
'uuid',
]
@@ -425,14 +425,14 @@ class NovaCCHooksTests(CharmTestCase):
hooks._goal_state_achieved_for_relid('aservice', None))
@patch('hooks.nova_cc_utils.add_authorized_key_if_doesnt_exist')
@patch('hooks.nova_cc_utils.ssh_resolve_compute_hosts')
@patch('hooks.nova_cc_utils.ssh_compute_add_known_hosts')
@patch('hooks.nova_cc_hooks._goal_state_achieved_for_relid')
@patch('hooks.nova_cc_utils.remote_service_from_unit')
def test_update_ssh_keys_and_notify_compute_units_ssh_migration(
self,
mock_remote_service_from_unit,
mock__goal_state_achieved_for_relid,
mock_ssh_resolve_compute_hosts,
mock_ssh_compute_add_known_hosts,
mock_add_authorized_key_if_doesnt_exist):
mock_remote_service_from_unit.return_value = 'aservice'
mock__goal_state_achieved_for_relid.return_value = True
@@ -444,8 +444,8 @@ class NovaCCHooksTests(CharmTestCase):
self.ssh_authorized_keys_lines.return_value = [
'auth_0', 'auth_1', 'auth_2']
hooks.update_ssh_keys_and_notify_compute_units()
mock_ssh_resolve_compute_hosts.assert_called_once_with(
'aservice', '10.0.0.1', '', user=None)
mock_ssh_compute_add_known_hosts.assert_called_once_with(
'aservice', ['10.0.0.1'], user=None)
mock_add_authorized_key_if_doesnt_exist.assert_called_once_with(
'fookey', 'aservice', '10.0.0.1', user=None)
expected_relations = [
@@ -470,14 +470,14 @@ class NovaCCHooksTests(CharmTestCase):
'cloud-compute', None)
@patch('hooks.nova_cc_utils.add_authorized_key_if_doesnt_exist')
@patch('hooks.nova_cc_utils.ssh_resolve_compute_hosts')
@patch('hooks.nova_cc_utils.ssh_compute_add_known_hosts')
@patch('hooks.nova_cc_hooks._goal_state_achieved_for_relid')
@patch('hooks.nova_cc_utils.remote_service_from_unit')
def test_update_ssh_keys_and_notify_compute_units_nova_public_key(
self,
mock_remote_service_from_unit,
mock__goal_state_achieved_for_relid,
mock_ssh_resolve_compute_hosts,
mock_ssh_compute_add_known_hosts,
mock_add_authorized_key_if_doesnt_exist):
mock_remote_service_from_unit.return_value = 'aservice'
mock__goal_state_achieved_for_relid.return_value = True
@@ -489,8 +489,8 @@ class NovaCCHooksTests(CharmTestCase):
self.ssh_authorized_keys_lines.return_value = [
'auth_0', 'auth_1', 'auth_2']
hooks.update_ssh_keys_and_notify_compute_units()
mock_ssh_resolve_compute_hosts.assert_called_once_with(
'aservice', '10.0.0.1', '', user='nova')
mock_ssh_compute_add_known_hosts.assert_called_once_with(
'aservice', ['10.0.0.1'], user='nova')
mock_add_authorized_key_if_doesnt_exist.assert_called_once_with(
'fookey', 'aservice', '10.0.0.1', user='nova')
expected_relations = [