|
10 | 10 | # License for the specific language governing permissions and limitations
|
11 | 11 | # under the License.
|
12 | 12 |
|
| 13 | +import functools |
13 | 14 | from unittest import mock
|
14 | 15 |
|
| 16 | +import fixtures |
| 17 | +from oslo_utils.fixture import uuidsentinel as uuids |
| 18 | + |
15 | 19 | from nova import context as nova_context
|
16 | 20 | from nova import exception
|
17 | 21 | from nova.objects import service
|
18 | 22 | from nova import test
|
19 | 23 | from nova.tests import fixtures as nova_fixtures
|
20 | 24 | from nova.tests.functional import fixtures as func_fixtures
|
21 | 25 | from nova.tests.functional import integrated_helpers
|
| 26 | +from nova.virt import node |
22 | 27 |
|
23 | 28 |
|
24 | 29 | class ServiceTestCase(test.TestCase,
|
@@ -137,3 +142,83 @@ def test_compute_fails_to_start_with_old_compute(self):
|
137 | 142 | return_value=old_version):
|
138 | 143 | self.assertRaises(
|
139 | 144 | exception.TooOldComputeService, self._start_compute, 'host1')
|
| 145 | + |
| 146 | + |
| 147 | +class TestComputeStartupChecks(test.TestCase): |
| 148 | + STUB_COMPUTE_ID = False |
| 149 | + |
| 150 | + def setUp(self): |
| 151 | + super().setUp() |
| 152 | + self.useFixture(nova_fixtures.RealPolicyFixture()) |
| 153 | + self.useFixture(nova_fixtures.NeutronFixture(self)) |
| 154 | + self.useFixture(nova_fixtures.GlanceFixture(self)) |
| 155 | + self.useFixture(func_fixtures.PlacementFixture()) |
| 156 | + |
| 157 | + self._local_uuid = str(uuids.node) |
| 158 | + |
| 159 | + self.useFixture(fixtures.MockPatch( |
| 160 | + 'nova.virt.node.get_local_node_uuid', |
| 161 | + functools.partial(self.local_uuid, True))) |
| 162 | + self.useFixture(fixtures.MockPatch( |
| 163 | + 'nova.virt.node.read_local_node_uuid', |
| 164 | + self.local_uuid)) |
| 165 | + self.useFixture(fixtures.MockPatch( |
| 166 | + 'nova.virt.node.write_local_node_uuid', |
| 167 | + mock.DEFAULT)) |
| 168 | + self.flags(compute_driver='fake.FakeDriverWithoutFakeNodes') |
| 169 | + |
| 170 | + def local_uuid(self, get=False): |
| 171 | + if get and not self._local_uuid: |
| 172 | + # Simulate the get_local_node_uuid behavior of calling write once |
| 173 | + self._local_uuid = str(uuids.node) |
| 174 | + node.write_local_node_uuid(self._local_uuid) |
| 175 | + return self._local_uuid |
| 176 | + |
| 177 | + def test_compute_node_identity_greenfield(self): |
| 178 | + # Level-set test case to show that starting and re-starting without |
| 179 | + # any error cases works as expected. |
| 180 | + |
| 181 | + # Start with no local compute_id |
| 182 | + self._local_uuid = None |
| 183 | + self.start_service('compute') |
| 184 | + |
| 185 | + # Start should have generated and written a compute id |
| 186 | + node.write_local_node_uuid.assert_called_once_with(str(uuids.node)) |
| 187 | + |
| 188 | + # Starting again should succeed and not cause another write |
| 189 | + self.start_service('compute') |
| 190 | + node.write_local_node_uuid.assert_called_once_with(str(uuids.node)) |
| 191 | + |
| 192 | + def test_compute_node_identity_deleted(self): |
| 193 | + self.start_service('compute') |
| 194 | + |
| 195 | + # Simulate the compute_id file being deleted |
| 196 | + self._local_uuid = None |
| 197 | + |
| 198 | + # Should refuse to start because it's not our first time and the file |
| 199 | + # being missing is a hard error. |
| 200 | + exc = self.assertRaises(exception.InvalidConfiguration, |
| 201 | + self.start_service, 'compute') |
| 202 | + self.assertIn('lost that state', str(exc)) |
| 203 | + |
| 204 | + def test_compute_node_hostname_changed(self): |
| 205 | + # Start our compute once to create the node record |
| 206 | + self.start_service('compute') |
| 207 | + |
| 208 | + # Starting with a different hostname should trigger the abort |
| 209 | + exc = self.assertRaises(exception.InvalidConfiguration, |
| 210 | + self.start_service, 'compute', host='other') |
| 211 | + self.assertIn('hypervisor_hostname', str(exc)) |
| 212 | + |
| 213 | + def test_compute_node_uuid_changed(self): |
| 214 | + # Start our compute once to create the node record |
| 215 | + self.start_service('compute') |
| 216 | + |
| 217 | + # Simulate a changed local compute_id file |
| 218 | + self._local_uuid = str(uuids.othernode) |
| 219 | + |
| 220 | + # We should fail to create the compute node record again, but with a |
| 221 | + # useful error message about why. |
| 222 | + exc = self.assertRaises(exception.InvalidConfiguration, |
| 223 | + self.start_service, 'compute') |
| 224 | + self.assertIn('Duplicate compute node record', str(exc)) |
0 commit comments