Use general BindHostContext().

This commit is contained in:
Hui Xiang 2014-09-25 14:36:13 +08:00
parent d04a03a5de
commit 20b6a8994c
8 changed files with 29 additions and 15 deletions

View File

@ -801,3 +801,16 @@ class SyslogContext(OSContextGenerator):
'use_syslog': config('use-syslog')
}
return ctxt
class BindHostContext(OSContextGenerator):
def __call__(self):
if config('prefer-ipv6'):
return {
'bind_host': '::'
}
else:
return {
'bind_host': '0.0.0.0'
}

View File

@ -71,11 +71,6 @@ class SwiftStorageServerContext(OSContextGenerator):
def __call__(self):
import psutil
multiplier = int(config('worker-multiplier')) or 1
if config('prefer-ipv6'):
bind_ip = '::'
else:
bind_ip = '0.0.0.0'
ctxt = {
'local_ip': unit_private_ip(),
'account_server_port': config('account-server-port'),
@ -84,6 +79,5 @@ class SwiftStorageServerContext(OSContextGenerator):
'workers': str(psutil.NUM_CPUS * multiplier),
'object_server_threads_per_disk': config(
'object-server-threads-per-disk'),
'bind_ip': bind_ip,
}
return ctxt

View File

@ -48,6 +48,7 @@ from charmhelpers.contrib.openstack.utils import (
from charmhelpers.contrib.openstack import (
templating,
context
)
PACKAGES = [
@ -106,7 +107,8 @@ def register_configs():
[RsyncContext()])
for server in ['account', 'object', 'container']:
configs.register('/etc/swift/%s-server.conf' % server,
[SwiftStorageServerContext()]),
[SwiftStorageServerContext(),
context.BindHostContext()]),
return configs

View File

@ -1,5 +1,5 @@
[DEFAULT]
bind_ip = {{ bind_ip }}
bind_ip = {{ bind_host }}
bind_port = {{ account_server_port }}
workers = {{ workers }}

View File

@ -1,5 +1,5 @@
[DEFAULT]
bind_ip = {{ bind_ip }}
bind_ip = {{ bind_host }}
bind_port = {{ container_server_port }}
workers = {{ workers }}

View File

@ -1,5 +1,5 @@
[DEFAULT]
bind_ip = {{ bind_ip }}
bind_ip = {{ bind_host }}
bind_port = {{ object_server_port }}
workers = {{ workers }}

View File

@ -68,7 +68,6 @@ class SwiftStorageContextTests(CharmTestCase):
ctxt = swift_context.SwiftStorageServerContext()
result = ctxt()
ex = {
'bind_ip': '0.0.0.0',
'container_server_port': '502',
'object_server_port': '501',
'account_server_port': '500',

View File

@ -194,15 +194,18 @@ class SwiftStorageUtilsTests(CharmTestCase):
renderer.assert_called_with(templates_dir=swift_utils.TEMPLATES,
openstack_release='essex')
@patch('charmhelpers.contrib.openstack.context.BindHostContext')
@patch.object(swift_utils, 'SwiftStorageContext')
@patch.object(swift_utils, 'RsyncContext')
@patch.object(swift_utils, 'SwiftStorageServerContext')
@patch('charmhelpers.contrib.openstack.templating.OSConfigRenderer')
def test_register_configs_post_install(self, renderer,
swift, rsync, server):
swift, rsync, server,
bind_context):
swift.return_value = 'swift_context'
rsync.return_value = 'rsync_context'
server.return_value = 'swift_server_context'
bind_context.return_value = 'bind_host_context'
self.get_os_codename_package.return_value = 'grizzly'
configs = MagicMock()
configs.register = MagicMock()
@ -213,9 +216,12 @@ class SwiftStorageUtilsTests(CharmTestCase):
ex = [
call('/etc/swift/swift.conf', ['swift_server_context']),
call('/etc/rsyncd.conf', ['rsync_context']),
call('/etc/swift/account-server.conf', ['swift_context']),
call('/etc/swift/object-server.conf', ['swift_context']),
call('/etc/swift/container-server.conf', ['swift_context'])
call('/etc/swift/account-server.conf', ['swift_context',
'bind_host_context']),
call('/etc/swift/object-server.conf', ['swift_context',
'bind_host_context']),
call('/etc/swift/container-server.conf', ['swift_context',
'bind_host_context'])
]
self.assertEquals(ex, configs.register.call_args_list)