def test_takes_lock_when_running(self): clock = Clock() deferToThread = self.patch(boot_images, "deferToThread") deferToThread.return_value = pause(1, clock) # Lock is acquired when import is started. import_boot_images(sentinel.sources, factory.make_simple_http_url()) self.assertTrue(concurrency.boot_images.locked) # Lock is released once the download is done. clock.advance(1) self.assertFalse(concurrency.boot_images.locked)
def test__never_more_than_one_waiting(self): yield concurrency.boot_images.acquire() deferToThread = self.patch(boot_images, 'deferToThread') deferToThread.return_value = defer.succeed(None) d = import_boot_images(sentinel.sources) self.assertIsNone(import_boot_images(sentinel.sources)) self.assertEqual(1, len(concurrency.boot_images.waiting)) concurrency.boot_images.release() yield d self.assertThat( deferToThread, MockCalledOnceWith(_run_import, sentinel.sources, http_proxy=None, https_proxy=None))
def _start_download(self): client = None # Retry a few times, since this service usually comes up before # the RPC service. for elapsed, remaining, wait in retries(15, 5, self.clock): try: client = yield self.client_service.getClientNow() break except NoConnectionsAvailable: yield pause(wait, self.clock) else: maaslog.error( "Can't initiate image download, no RPC connection to region.") return # Get sources from region sources = yield self._get_boot_sources(client) # Get http proxy from region proxies = yield client(GetProxies) def get_proxy_url(scheme): url = proxies.get(scheme) # url is a ParsedResult. return None if url is None else url.geturl() yield import_boot_images( sources.get("sources"), get_proxy_url("http"), get_proxy_url("https"))
def test_update_last_image_sync_end_to_end_import_not_performed(self): self.useFixture(ClusterConfigurationFixture()) fixture = self.useFixture(MockLiveClusterToRegionRPCFixture()) protocol, connecting = fixture.makeEventLoop( region.UpdateLastImageSync) protocol.UpdateLastImageSync.return_value = succeed({}) self.addCleanup((yield connecting)) self.patch_autospec(boot_resources, 'import_images') boot_resources.import_images.return_value = False sources, hosts = make_sources() yield boot_images.import_boot_images(sources) self.assertThat(boot_resources.import_images, MockCalledOnceWith(sources)) self.assertThat(protocol.UpdateLastImageSync, MockNotCalled())
def test_update_last_image_sync_end_to_end_import_not_performed(self): fixture = self.useFixture(MockLiveClusterToRegionRPCFixture()) protocol, connecting = fixture.makeEventLoop( region.UpdateLastImageSync) protocol.UpdateLastImageSync.return_value = succeed({}) self.addCleanup((yield connecting)) self.patch_autospec(boot_resources, "import_images") boot_resources.import_images.return_value = False sources, hosts = make_sources() maas_url = factory.make_simple_http_url() yield boot_images.import_boot_images(sources, maas_url) self.assertThat( boot_resources.import_images, MockCalledOnceWith(fix_sources_for_cluster(sources, maas_url)), ) self.assertThat(protocol.UpdateLastImageSync, MockNotCalled())
def test__add_to_waiting_if_lock_already_held(self): yield concurrency.boot_images.acquire() deferToThread = self.patch(boot_images, 'deferToThread') deferToThread.return_value = defer.succeed(None) maas_url = factory.make_simple_http_url() d = import_boot_images(sentinel.sources, maas_url) self.assertEqual(1, len(concurrency.boot_images.waiting)) concurrency.boot_images.release() yield d self.assertThat( deferToThread, MockCalledOnceWith(_run_import, sentinel.sources, maas_url, http_proxy=None, https_proxy=None))
def test_update_last_image_sync_end_to_end(self): get_maas_id = self.patch(boot_images, "get_maas_id") get_maas_id.return_value = factory.make_string() self.useFixture(ClusterConfigurationFixture()) fixture = self.useFixture(MockLiveClusterToRegionRPCFixture()) protocol, connecting = fixture.makeEventLoop( region.UpdateLastImageSync) protocol.UpdateLastImageSync.return_value = succeed({}) self.addCleanup((yield connecting)) self.patch_autospec(boot_resources, 'import_images') boot_resources.import_images.return_value = True sources, hosts = make_sources() yield boot_images.import_boot_images(sources) self.assertThat(boot_resources.import_images, MockCalledOnceWith(sources)) self.assertThat(protocol.UpdateLastImageSync, MockCalledOnceWith(protocol, system_id=get_maas_id()))