Adding worker multiplier support

- adding a worker_config property to the API version of the Config Adapter class

Related-Bug: 1677543
Change-Id: Iad6051db742c56817b10eaa08cdc3894626e134f
This commit is contained in:
Vincenzo Di Somma 2017-04-14 17:34:53 +02:00
parent 509bfdab2e
commit 32abfe1733
3 changed files with 24 additions and 1 deletions

View File

@ -26,6 +26,7 @@ import charms.reactive.bus
import charmhelpers.contrib.hahelpers.cluster as ch_cluster
import charmhelpers.contrib.network.ip as ch_ip
import charmhelpers.contrib.openstack.utils as ch_utils
import charmhelpers.contrib.openstack.context as ch_context
import charmhelpers.core.hookenv as hookenv
import charmhelpers.core.host as ch_host
import charms_openstack.ip as os_ip
@ -487,7 +488,7 @@ class APIConfigurationAdapter(ConfigurationAdapter):
def __init__(self, port_map=None, service_name=None, charm_instance=None):
"""
Note passing port_map and service_name is deprecated, but supporte for
Note passing port_map and service_name is deprecated, but supported for
backwards compatibility. The port_map and service_name can be got from
the self.charm_instance weak reference.
:param port_map: Map containing service names and the ports used e.g.
@ -529,6 +530,14 @@ class APIConfigurationAdapter(ConfigurationAdapter):
self.service_name = None
self.__network_addresses = None
@property
def worker_config(self):
"""Return the worker configuration used service templates"""
return {
k: v for k, v in ch_context.WSGIWorkerConfigContext()().items()
if k in ('processes',
'admin_processes', 'public_processes')}
@property
def network_addresses(self):
"""Return the network_addresses as a property for a consuming template.

View File

@ -28,6 +28,8 @@ sys.modules['charmhelpers.core.templating'] = charmhelpers.core.templating
sys.modules['charmhelpers.core.unitdata'] = charmhelpers.core.unitdata
sys.modules['charmhelpers.contrib'] = charmhelpers.contrib
sys.modules['charmhelpers.contrib.openstack'] = charmhelpers.contrib.openstack
sys.modules['charmhelpers.contrib.openstack.context'] = (
charmhelpers.contrib.openstack.context)
sys.modules['charmhelpers.contrib.openstack.utils'] = (
charmhelpers.contrib.openstack.utils)
sys.modules['charmhelpers.contrib.openstack.templating'] = (

View File

@ -26,6 +26,8 @@ import mock
import charms_openstack.adapters as adapters
from charmhelpers.contrib.openstack import context
class TestCustomProperties(unittest.TestCase):
@ -406,6 +408,16 @@ class TestAPIConfigurationAdapter(unittest.TestCase):
'internal': 9002,
}}
def test_worker_config(self):
worker_config = {'processes': 1.0, 'admin_processes': 0.75,
'public_processes': 0.25}
__call__mock = mock.Mock(return_value=worker_config)
context.WSGIWorkerConfigContext.return_value = __call__mock
wc = adapters.APIConfigurationAdapter().worker_config
self.assertEqual(wc['processes'], 1.0)
self.assertEqual(wc['admin_processes'], 0.75)
self.assertEqual(wc['public_processes'], 0.25)
def test_class(self):
test_config = {
'prefer-ipv6': False,