573
573
with self.assertRaises(NagiosCheckPhaseException):
574
574
phase.run_nagios_checks('postgresql/0')
576
@mock.patch('mojo.phase.NagiosCheckPhase.run_nagios_checks')
577
@mock.patch('mojo.juju.Status')
578
def test_all_checks_dispatched(self, _juju_status, _run_nagios_checks):
579
"""Test that all expected checks are dispatched."""
580
# Side effect that returns specific lists of machines for each service
581
def smn_side_effect(service):
582
machine_numbers = {'foo': [1, 2],
585
return machine_numbers[service]
587
# Side effect that returns specific units for each service
588
def su_side_effect(service):
589
service_units = {'foo': ['foo/0', 'foo/1'],
592
return service_units[service]
594
# Set up all the mockery
595
_juju_status().services_list.return_value = ['foo', 'bar', 'baz']
596
_juju_status().service_machine_numbers.side_effect = smn_side_effect
597
_juju_status().service_units.side_effect = su_side_effect
598
_run_nagios_checks.return_value = "", "Everything OK"
599
# Define a minimal, empty project and phase with 2 services to check
600
self.empty_project = Project('unused', 'trusty', '/tmp')
601
phase = NagiosCheckPhase()
602
phase.options.update({'services': 'foo,bar'})
603
workspace = self.create_workspace()
605
path=workspace.spec_dir,
606
configs=['collect', 'services.cfg'], stage='staging')
608
phase.run(self.empty_project, workspace, 'staging')
609
# Check expected tests were all dispatched, as seen by calls to
611
all_skip = ['check_etc_bzr', 'check_log_archive_status']
612
_run_nagios_checks.assert_has_calls([
613
mock.call('foo/0', all_skip),
614
mock.call('foo/1', all_skip),
615
mock.call('bar/2', all_skip),
618
@mock.patch('mojo.phase.ThreadPoolExecutor')
619
@mock.patch('mojo.juju.Status')
620
def test_max_worker_calculation(self, _juju_status, _executor):
621
"""Test that max_workers is properly calculated."""
622
# Side effect that returns specific lists of machines for each service
623
def smn_side_effect(service):
624
machine_numbers = {'foo': [1, 2],
627
return machine_numbers[service]
629
# Set up all the mockery
630
_juju_status().services_list.return_value = ['foo', 'bar', 'baz']
631
_juju_status().service_machine_numbers.side_effect = smn_side_effect
632
# Define a minimal, empty project and phase with 2 services to check
633
self.empty_project = Project('unused', 'trusty', '/tmp')
634
phase = NagiosCheckPhase()
635
phase.options.update({'services': 'foo,bar'})
636
workspace = self.create_workspace()
638
path=workspace.spec_dir,
639
configs=['collect', 'services.cfg'], stage='staging')
641
phase.run(self.empty_project, workspace, 'staging')
642
# Check call to ThreadPoolExecutor for max_workers value
643
# the value is "3", for the sum of machines in the "foo" and "bar"
645
_executor.assert_called_once_with(max_workers=3)
577
648
class CharmAuditPhaseTestCase(TestCase, utils.MojoTestCaseMixin):