def test_setUp_allocates_resources(self): # We need a new ConfigFixture, and create a # LibrarianServerFixture using it. We can then confirm that new # resources have been allocated by comparing with the currently # in use ConfigFixture and config. config_fixture = ConfigFixture( 'foo', BaseLayer.config_fixture.instance_name) self.addCleanup(config_fixture.cleanUp) config_fixture.setUp() fixture = LibrarianServerFixture(config_fixture) self.skip_if_persistent(fixture) with fixture: try: self.assertNotEqual(config.librarian_server.root, fixture.root) self.assertNotEqual( config.librarian.download_port, fixture.download_port) self.assertNotEqual( config.librarian.upload_port, fixture.upload_port) self.assertNotEqual( config.librarian.restricted_download_port, fixture.restricted_download_port) self.assertNotEqual( config.librarian.restricted_upload_port, fixture.restricted_upload_port) # And it exposes a config fragment (but it is not activated). expected_config = dedent("""\ [librarian_server] root: %s [librarian] download_port: %s upload_port: %s download_url: http://%s:%s/ restricted_download_port: %s restricted_upload_port: %s restricted_download_url: http://%s:%s/ """) % ( fixture.root, fixture.download_port, fixture.upload_port, config.librarian.download_host, fixture.download_port, fixture.restricted_download_port, fixture.restricted_upload_port, config.librarian.restricted_download_host, fixture.restricted_download_port, ) self.assertEqual(expected_config, fixture.service_config) except: self.attachLibrarianLog(fixture) raise
def set_config_parameters(self, **kwargs): config_name = self.getUniqueString() config_fixture = self.useFixture( ConfigFixture( config_name, LaunchpadFunctionalLayer.config_fixture.instance_name)) setting_lines = ['[launchpad]'] + \ ['%s: %s' % (k, v) for k, v in kwargs.items()] config_fixture.add_section('\n'.join(setting_lines)) self.useFixture(ConfigUseFixture(config_name))
def test_copies_and_derives(self): fixture = ConfigFixture('testtestconfig', 'testrunner') to_copy = [ 'launchpad.conf', 'test-process-lazr.conf', ] fixture.setUp() try: for base in to_copy: path = 'configs/testtestconfig/' + base source = 'configs/testrunner/' + base old = open(source, 'rb').read() new = open(path, 'rb').read() self.assertEqual(old, new) confpath = 'configs/testtestconfig/launchpad-lazr.conf' lazr_config = open(confpath, 'rb').read() self.assertEqual( "[meta]\n" "extends: ../testrunner/launchpad-lazr.conf", lazr_config.strip()) finally: fixture.cleanUp()
def makeTurnipServer(self): turnip_server = FakeTurnipServer() config_name = self.factory.getUniqueString() config_fixture = self.useFixture( ConfigFixture(config_name, config.instance_name)) setting_lines = [ '[codehosting]', 'internal_git_api_endpoint: %s' % turnip_server.getURL(), ] config_fixture.add_section('\n' + '\n'.join(setting_lines)) self.useFixture(ConfigUseFixture(config_name)) turnip_server.start() self.addCleanup(turnip_server.stop) return turnip_server
def makeTargetGitServer(self): """Set up a target Git server that can receive imports.""" self.target_store = tempfile.mkdtemp() self.addCleanup(shutil.rmtree, self.target_store) self.target_git_server = GitServer(self.target_store, use_server=True) self.target_git_server.start_server() self.addCleanup(self.target_git_server.stop_server) config_name = self.getUniqueString() config_fixture = self.useFixture( ConfigFixture(config_name, self.layer.config_fixture.instance_name)) setting_lines = [ "[codehosting]", "git_browse_root: %s" % self.target_git_server.get_url(""), "", "[launchpad]", "internal_macaroon_secret_key: some-secret", ] config_fixture.add_section("\n" + "\n".join(setting_lines)) self.useFixture(ConfigUseFixture(config_name)) self.useFixture(GitHostingFixture())