~peter-sabaini/charm-helpers/bcache-helpers

« back to all changes in this revision

Viewing changes to tests/contrib/openstack/test_os_contexts.py

  • Committer: james.page at ubuntu
  • Date: 2017-03-30 09:00:57 UTC
  • mfrom: (728.1.1 sane-default-workers)
  • Revision ID: james.page@ubuntu.com-20170330090057-vf4i5n3525i5mspr
[james-page,r=icey] Rework default worker-multiplier behaviour

Show diffs side-by-side

added added

removed removed

Lines of Context:
589
589
    'kv',
590
590
    'pwgen',
591
591
    'lsb_release',
 
592
    'is_container',
592
593
]
593
594
 
594
595
 
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
644
646
 
645
647
    def _patch(self, method):
646
648
        _m = patch('charmhelpers.contrib.openstack.context.' + method)
2720
2722
 
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())
 
2728
 
 
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())
 
2735
 
 
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())
 
2742
 
 
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())
2726
2748
 
2727
2749
    def test_workerconfig_context_withconfig(self):
2728
2750
        self.config.side_effect = fake_config({