24
24
from maasserver import start_up
25
from maasserver.models.nodegroup import NodeGroup
25
from maasserver.components import (
26
discard_persistent_error,
27
register_persistent_error,
29
from maasserver.enum import COMPONENT
30
from maasserver.models import (
34
from maasserver.testing.factory import factory
26
35
from maastesting.celery import CeleryFixture
27
36
from maastesting.fakemethod import FakeMethod
28
37
from maastesting.testcase import TestCase
65
74
def test_start_up_refreshes_workers(self):
66
75
patched_handlers = tasks.refresh_functions.copy()
67
patched_handlers['nodegroup_name'] = Mock()
76
patched_handlers['nodegroup_uuid'] = Mock()
68
77
self.patch(tasks, 'refresh_functions', patched_handlers)
69
78
start_up.start_up()
70
patched_handlers['nodegroup_name'].assert_called_once_with(
71
NodeGroup.objects.ensure_master().name)
79
patched_handlers['nodegroup_uuid'].assert_called_once_with(
80
NodeGroup.objects.ensure_master().uuid)
73
82
def test_start_up_runs_in_exclusion(self):
74
83
called = Value('b', False)
98
107
self.assertRaises(LockTimeout, start_up.start_up)
99
108
self.assertEqual(0, recorder.call_count)
110
def test_start_up_warns_about_missing_boot_images(self):
111
# If no boot images have been registered yet, that may mean that
112
# the import script has not been successfully run yet, or that
113
# the master worker is having trouble reporting its images. And
114
# so start_up registers a persistent warning about this.
115
BootImage.objects.all().delete()
116
discard_persistent_error(COMPONENT.IMPORT_PXE_FILES)
117
recorder = self.patch(start_up, 'register_persistent_error')
122
COMPONENT.IMPORT_PXE_FILES,
123
[args[0][0] for args in recorder.call_args_list])
125
def test_start_up_does_not_warn_if_boot_images_are_known(self):
126
# If boot images are known, there is no warning about the import
128
factory.make_boot_image()
129
recorder = self.patch(start_up, 'register_persistent_error')
134
COMPONENT.IMPORT_PXE_FILES,
135
[args[0][0] for args in recorder.call_args_list])
137
def test_start_up_does_not_warn_if_already_warning(self):
138
# If there already is a warning about missing boot images, it is
139
# based on more precise knowledge of whether we ever heard from
140
# the region worker at all. It will not be replaced by a less
141
# knowledgeable warning.
142
BootImage.objects.all().delete()
143
register_persistent_error(
144
COMPONENT.IMPORT_PXE_FILES, factory.getRandomString())
145
recorder = self.patch(start_up, 'register_persistent_error')
150
COMPONENT.IMPORT_PXE_FILES,
151
[args[0][0] for args in recorder.call_args_list])