|
| 1 | +# Licensed under the Apache License, Version 2.0 (the "License"); you may |
| 2 | +# not use this file except in compliance with the License. You may obtain |
| 3 | +# a copy of the License at |
| 4 | +# |
| 5 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 6 | +# |
| 7 | +# Unless required by applicable law or agreed to in writing, software |
| 8 | +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 9 | +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| 10 | +# License for the specific language governing permissions and limitations |
| 11 | +# under the License. |
| 12 | + |
| 13 | +from oslo_utils.fixture import uuidsentinel as uuids |
| 14 | + |
| 15 | +from nova import context |
| 16 | +from nova import objects |
| 17 | +from nova import test |
| 18 | +from nova.tests.unit import fake_notifier |
| 19 | + |
| 20 | + |
| 21 | +class ImageCacheTest(test.TestCase): |
| 22 | + NUMBER_OF_CELLS = 2 |
| 23 | + |
| 24 | + def setUp(self): |
| 25 | + super(ImageCacheTest, self).setUp() |
| 26 | + |
| 27 | + self.flags(compute_driver='fake.FakeDriverWithCaching') |
| 28 | + |
| 29 | + fake_notifier.stub_notifier(self) |
| 30 | + self.addCleanup(fake_notifier.reset) |
| 31 | + self.context = context.get_admin_context() |
| 32 | + |
| 33 | + self.conductor = self.start_service('conductor') |
| 34 | + self.compute1 = self.start_service('compute', host='compute1') |
| 35 | + self.compute2 = self.start_service('compute', host='compute2') |
| 36 | + self.compute3 = self.start_service('compute', host='compute3', |
| 37 | + cell='cell2') |
| 38 | + self.compute4 = self.start_service('compute', host='compute4', |
| 39 | + cell='cell2') |
| 40 | + self.compute5 = self.start_service('compute', host='compute5', |
| 41 | + cell='cell2') |
| 42 | + |
| 43 | + cell2 = self.cell_mappings['cell2'] |
| 44 | + with context.target_cell(self.context, cell2) as cctxt: |
| 45 | + srv = objects.Service.get_by_compute_host(cctxt, 'compute5') |
| 46 | + srv.forced_down = True |
| 47 | + srv.save() |
| 48 | + |
| 49 | + def test_cache_image(self): |
| 50 | + """Test caching images by injecting the request directly to |
| 51 | + the conductor service and making sure it fans out and calls |
| 52 | + the expected nodes. |
| 53 | + """ |
| 54 | + |
| 55 | + aggregate = objects.Aggregate(name='test', |
| 56 | + uuid=uuids.aggregate, |
| 57 | + id=1, |
| 58 | + hosts=['compute1', 'compute3', |
| 59 | + 'compute4', 'compute5']) |
| 60 | + self.conductor.compute_task_mgr.cache_images( |
| 61 | + self.context, aggregate, ['an-image']) |
| 62 | + |
| 63 | + # NOTE(danms): We expect only three image cache attempts because |
| 64 | + # compute5 is marked as forced-down and compute2 is not in the |
| 65 | + # requested aggregate. |
| 66 | + for host in ['compute1', 'compute3', 'compute4']: |
| 67 | + mgr = getattr(self, host) |
| 68 | + self.assertEqual(set(['an-image']), mgr.driver.cached_images) |
| 69 | + for host in ['compute2', 'compute5']: |
| 70 | + mgr = getattr(self, host) |
| 71 | + self.assertEqual(set(), mgr.driver.cached_images) |
| 72 | + |
| 73 | + fake_notifier.wait_for_versioned_notifications( |
| 74 | + 'aggregate.cache_images.start') |
| 75 | + fake_notifier.wait_for_versioned_notifications( |
| 76 | + 'aggregate.cache_images.end') |
0 commit comments