moar fixes.

This commit is contained in:
Alberto Donato 2015-08-26 15:40:05 +03:00
parent 253af72cdf
commit b383a1d1e7

View File

@ -1,7 +1,6 @@
from mock import patch, MagicMock
with patch('charmhelpers.core.hookenv.config') as config:
from hooks import glance_contexts as contexts
from hooks import glance_contexts as contexts
from test_utils import (
@ -9,6 +8,7 @@ from test_utils import (
)
TO_PATCH = [
"config",
'relation_ids',
'is_relation_made',
'service_name',
@ -21,6 +21,9 @@ class TestGlanceContexts(CharmTestCase):
def setUp(self):
super(TestGlanceContexts, self).setUp(contexts, TO_PATCH)
from charmhelpers.core.hookenv import cache
self.cache = cache
cache.clear()
def test_swift_not_related(self):
self.relation_ids.return_value = []
@ -58,48 +61,38 @@ class TestGlanceContexts(CharmTestCase):
{'known_stores': "glance.store.filesystem.Store,"
"glance.store.http.Store"})
@patch('charmhelpers.contrib.openstack.context.config')
@patch('charmhelpers.contrib.openstack.context.is_clustered')
@patch('charmhelpers.contrib.openstack.context.determine_apache_port')
@patch('charmhelpers.contrib.openstack.context.determine_api_port')
@patch('charmhelpers.contrib.openstack.context.unit_get')
@patch('charmhelpers.contrib.hahelpers.cluster.config_get')
@patch('charmhelpers.contrib.openstack.context.https')
def test_apache_ssl_context_service_enabled(self, mock_https,
mock_unit_get,
mock_determine_api_port,
mock_determine_apache_port,
mock_is_clustered,
mock_config):
mock_config.return_value = 'true'
mock_https.return_value = True
mock_unit_get.return_value = '1.2.3.4'
mock_determine_api_port.return_value = '12'
mock_determine_apache_port.return_value = '34'
mock_is_clustered.return_value = False
ctxt = contexts.ApacheSSLContext()
ctxt.enable_modules = MagicMock()
ctxt.configure_cert = MagicMock()
ctxt.configure_ca = MagicMock()
ctxt.canonical_names = MagicMock()
self.assertEquals(ctxt(), {'endpoints': [('1.2.3.4', '1.2.3.4',
34, 12)],
'ext_ports': [34],
'namespace': 'glance'})
self.assertTrue(mock_https.called)
mock_unit_get.assert_called_with('private-address')
ctxt.get_network_addresses = MagicMock()
ctxt.get_network_addresses.return_value = [('1.2.3.4', '1.2.3.4')]
@patch('hooks.glance_contexts.config')
def test_glance_ipv6_context_service_enabled(self, mock_context_config):
config.return_value = True
mock_context_config.return_value = True
self.assertEquals(ctxt(), {'endpoints': [('1.2.3.4', '1.2.3.4',
9282, 9272)],
'ext_ports': [9282],
'namespace': 'glance'})
@patch("charmhelpers.core.hookenv.subprocess.check_output")
def test_glance_ipv6_context_service_enabled(self, mock_subprocess):
self.config.return_value = True
mock_subprocess.return_value = 'true'
ctxt = contexts.GlanceIPv6Context()
self.assertEquals(ctxt(), {'bind_host': '::',
'registry_host': '[::]'})
@patch('hooks.glance_contexts.config')
def test_glance_ipv6_context_service_disabled(self, mock_context_config):
config.return_value = False
mock_context_config.return_value = False
@patch("charmhelpers.core.hookenv.subprocess.check_output")
def test_glance_ipv6_context_service_disabled(self, mock_subprocess):
self.config.return_value = False
mock_subprocess.return_value = 'false'
ctxt = contexts.GlanceIPv6Context()
self.assertEquals(ctxt(), {'bind_host': '0.0.0.0',
'registry_host': '0.0.0.0'})