def setUp(self, spew=False, umask=None): # Pick a random, free port. if self.daemon_port is None: sock = socket.socket() sock.bind(('', 0)) self.daemon_port = sock.getsockname()[1] sock.close() self.logfile = os.path.join(config.root, 'logs', 'fakeswift-%s.log' % self.daemon_port) self.pidfile = os.path.join(config.root, 'logs', 'fakeswift-%s.pid' % self.daemon_port) assert self.daemon_port is not None super(SwiftFixture, self).setUp(spew, umask, os.path.join(config.root, 'bin', 'py'), os.path.join(config.root, 'bin', 'twistd')) logfile = self.logfile self.addCleanup(lambda: os.path.exists(logfile) and os.unlink(logfile)) testtools.content.attach_file(self, logfile, 'swift-log', testtools.content_type.UTF8_TEXT) service_config = dedent("""\ [librarian_server] os_auth_url: http://localhost:{0}/keystone/v2.0/ os_username: {1} os_password: {2} os_tenant_name: {3} """.format(self.daemon_port, fakeswift.DEFAULT_USERNAME, fakeswift.DEFAULT_PASSWORD, fakeswift.DEFAULT_TENANT_NAME)) BaseLayer.config_fixture.add_section(service_config) config.reloadConfig() assert config.librarian_server.os_tenant_name == 'test'
def __init__(self, template=None, dbname=dynamic, dbuser=None, host=None, port=None, reset_sequences_sql=None): '''Construct the PgTestSetup Note that dbuser is not used for setting up or tearing down the database - it is only used by the connect() method ''' if template is not None: self.template = template if dbname is PgTestSetup.dynamic: from lp.testing.layers import BaseLayer if os.environ.get('LP_TEST_INSTANCE'): self.dbname = "%s_%s" % (self.__class__.dbname, os.environ.get('LP_TEST_INSTANCE')) # Stash the name we use in the config if a writable config is # available. # Avoid circular imports section = """[database] rw_main_master: dbname=%s host=localhost rw_main_slave: dbname=%s host=localhost """ % (self.dbname, self.dbname) if BaseLayer.config_fixture is not None: BaseLayer.config_fixture.add_section(section) if BaseLayer.appserver_config_fixture is not None: BaseLayer.appserver_config_fixture.add_section(section) if config.instance_name in (BaseLayer.config_name, BaseLayer.appserver_config_name): config.reloadConfig() else: # Fallback to the class name. self.dbname = self.__class__.dbname elif dbname is not None: self.dbname = dbname else: # Fallback to the class name. self.dbname = self.__class__.dbname if dbuser is not None: self.dbuser = dbuser if host is not None: self.host = host if port is not None: self.port = port self.reset_sequences_sql = reset_sequences_sql
def __init__(self, template=None, dbname=dynamic, dbuser=None, host=None, port=None, reset_sequences_sql=None): '''Construct the PgTestSetup Note that dbuser is not used for setting up or tearing down the database - it is only used by the connect() method ''' if template is not None: self.template = template if dbname is PgTestSetup.dynamic: from lp.testing.layers import BaseLayer if os.environ.get('LP_TEST_INSTANCE'): self.dbname = "%s_%s" % ( self.__class__.dbname, os.environ.get('LP_TEST_INSTANCE')) # Stash the name we use in the config if a writable config is # available. # Avoid circular imports section = """[database] rw_main_master: dbname=%s host=localhost rw_main_slave: dbname=%s host=localhost """ % (self.dbname, self.dbname) if BaseLayer.config_fixture is not None: BaseLayer.config_fixture.add_section(section) if BaseLayer.appserver_config_fixture is not None: BaseLayer.appserver_config_fixture.add_section(section) if config.instance_name in ( BaseLayer.config_name, BaseLayer.appserver_config_name): config.reloadConfig() else: # Fallback to the class name. self.dbname = self.__class__.dbname elif dbname is not None: self.dbname = dbname else: # Fallback to the class name. self.dbname = self.__class__.dbname if dbuser is not None: self.dbuser = dbuser if host is not None: self.host = host if port is not None: self.port = port self.reset_sequences_sql = reset_sequences_sql
def setUp(self): """Start both librarian instances.""" if (self._persistent_servers() and self.pid): return else: # self.pid may have been evaluated - nuke it. self._pid = None # The try:except here can be removed if someone audits the callers to # make sure that they call cleanUp if setUp fails. try: TacTestSetup.setUp(self) except TacException: self.cleanUp() raise else: self._pid = self._read_pid() self._setup = True self.addCleanup(setattr, self, '_setup', False) # Update the config our tests are using to know about the # correct ports. self.config_fixture.add_section(self.service_config) config.reloadConfig()