From 20253d1e75ec8ecffc8d9504307f1773a2e1ad60 Mon Sep 17 00:00:00 2001 From: Tom Haddon Date: Wed, 18 Jun 2014 12:34:19 +0100 Subject: [PATCH] Unit tests for the new worker multiplier and threads per disk config values --- hooks/swift_storage_context.py | 4 ++-- unit_tests/test_swift_storage_context.py | 8 +++++++- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/hooks/swift_storage_context.py b/hooks/swift_storage_context.py index 35c66da..87a2c6d 100644 --- a/hooks/swift_storage_context.py +++ b/hooks/swift_storage_context.py @@ -62,13 +62,13 @@ class SwiftStorageServerContext(OSContextGenerator): def __call__(self): import psutil - multiplier = config('worker-multiplier') or 1 + multiplier = int(config('worker-multiplier')) or 1 ctxt = { 'local_ip': unit_private_ip(), 'account_server_port': config('account-server-port'), 'container_server_port': config('container-server-port'), 'object_server_port': config('object-server-port'), - 'workers': psutil.NUM_CPUS * multiplier, + 'workers': str(psutil.NUM_CPUS * multiplier), 'object_server_threads_per_disk': config( 'object-server-threads-per-disk'), } diff --git a/unit_tests/test_swift_storage_context.py b/unit_tests/test_swift_storage_context.py index 6d165fa..471732e 100644 --- a/unit_tests/test_swift_storage_context.py +++ b/unit_tests/test_swift_storage_context.py @@ -56,16 +56,22 @@ class SwiftStorageContextTests(CharmTestCase): _file.write.assert_called_with('RSYNC_ENABLE=true\n') def test_swift_storage_server_context(self): + import psutil self.unit_private_ip.return_value = '10.0.0.5' self.test_config.set('account-server-port', '500') self.test_config.set('object-server-port', '501') self.test_config.set('container-server-port', '502') + self.test_config.set('object-server-threads-per-disk', '3') + self.test_config.set('worker-multiplier', '3') + num_workers = psutil.NUM_CPUS * 3 ctxt = swift_context.SwiftStorageServerContext() result = ctxt() ex = { 'container_server_port': '502', 'object_server_port': '501', 'account_server_port': '500', - 'local_ip': '10.0.0.5' + 'local_ip': '10.0.0.5', + 'object_server_threads_per_disk': '3', + 'workers': str(num_workers), } self.assertEquals(ex, result)