diff --git a/hooks/nova_cc_context.py b/hooks/nova_cc_context.py index 109e3248..54a817ee 100644 --- a/hooks/nova_cc_context.py +++ b/hooks/nova_cc_context.py @@ -458,7 +458,7 @@ class InstanceConsoleContext(ch_context.OSContextGenerator): ctxt = {} # Configure nova-novncproxy https if nova-api is using https. if ch_cluster.https(): - cn = ch_ip.resolve_address(endpoint_type=ch_ip.INTERNAL) + cn = ch_ip.resolve_address(endpoint_type=ch_ip.PUBLIC) if cn: cert_filename = 'cert_{}'.format(cn) key_filename = 'key_{}'.format(cn) diff --git a/unit_tests/test_nova_cc_contexts.py b/unit_tests/test_nova_cc_contexts.py index 520a12af..1c1c3f23 100644 --- a/unit_tests/test_nova_cc_contexts.py +++ b/unit_tests/test_nova_cc_contexts.py @@ -484,6 +484,41 @@ class NovaComputeContextTests(CharmTestCase): mock_resolve_address.assert_called_with( endpoint_type=context.ch_ip.PUBLIC) + @mock.patch.object(context, 'ch_cluster') + @mock.patch('os.path.exists') + @mock.patch('charmhelpers.contrib.openstack.ip.resolve_address') + def test_instance_console_context(self, + mock_resolve_address, + mock_os_path_exists, + mock_ch_cluster): + mock_os_path_exists.return_value = True + mock_resolve_address.return_value = "10.20.30.40" + mock_ch_cluster.https.return_value = True + ctxt = context.InstanceConsoleContext()() + self.assertEqual( + ctxt, + {'ssl_cert': '/etc/apache2/ssl/nova/cert_10.20.30.40', + 'ssl_key': '/etc/apache2/ssl/nova/key_10.20.30.40'} + ) + mock_resolve_address.assert_called_once_with( + endpoint_type=context.ch_ip.PUBLIC + ) + + @mock.patch.object(context, 'ch_cluster') + @mock.patch('os.path.exists') + @mock.patch('charmhelpers.contrib.openstack.ip.resolve_address') + def test_instance_console_context_no_https(self, + mock_resolve_address, + mock_os_path_exists, + mock_ch_cluster): + mock_os_path_exists.return_value = True + mock_resolve_address.return_value = "10.20.30.40" + mock_ch_cluster.https.return_value = False + ctxt = context.InstanceConsoleContext()() + self.assertEqual( + ctxt, {} + ) + def test_nova_cellv2_shared_db_context(self): self.relation_ids.return_value = ['shared-db:0'] self.related_units.return_value = ['mysql/0']