641
642
self.kv.side_effect = TestDB
642
643
self.pwgen.return_value = 'testpassword'
643
644
self.lsb_release.return_value = {'DISTRIB_RELEASE': '16.04'}
645
self.is_container.return_value = False
645
647
def _patch(self, method):
646
648
_m = patch('charmhelpers.contrib.openstack.context.' + method)
2721
2723
def test_workerconfig_context_noconfig(self):
2722
2724
self.config.return_value = None
2723
with patch.object(context.WorkerConfigContext, 'num_cpus', 2):
2724
worker = context.WorkerConfigContext()
2725
self.assertEqual({'workers': 0}, worker())
2725
with patch.object(context.WorkerConfigContext, 'num_cpus', 1):
2726
worker = context.WorkerConfigContext()
2727
self.assertEqual({'workers': 2}, worker())
2729
def test_workerconfig_context_noconfig_container(self):
2730
self.config.return_value = None
2731
self.is_container.return_value = True
2732
with patch.object(context.WorkerConfigContext, 'num_cpus', 1):
2733
worker = context.WorkerConfigContext()
2734
self.assertEqual({'workers': 2}, worker())
2736
def test_workerconfig_context_noconfig_lotsa_cpus_container(self):
2737
self.config.return_value = None
2738
self.is_container.return_value = True
2739
with patch.object(context.WorkerConfigContext, 'num_cpus', 32):
2740
worker = context.WorkerConfigContext()
2741
self.assertEqual({'workers': 4}, worker())
2743
def test_workerconfig_context_noconfig_lotsa_cpus_not_container(self):
2744
self.config.return_value = None
2745
with patch.object(context.WorkerConfigContext, 'num_cpus', 32):
2746
worker = context.WorkerConfigContext()
2747
self.assertEqual({'workers': 64}, worker())
2727
2749
def test_workerconfig_context_withconfig(self):
2728
2750
self.config.side_effect = fake_config({