def setUp(self): """Setup for testing.""" # make sure we start with clean state yield super(BaseProtocolTestCase, self).setUp() log.info("starting test %s.%s", self.__class__.__name__, self._testMethodName) self.s4_site = site = s4.server.Site(s4.Root()) self.ssl_cert = crypto.load_certificate( crypto.FILETYPE_PEM, server_crt) if server_crt_chain: self.ssl_cert_chain = crypto.load_certificate( crypto.FILETYPE_PEM, server_crt_chain) else: self.ssl_cert_chain = None self.ssl_key = crypto.load_privatekey(crypto.FILETYPE_PEM, server_key) if self.s4_use_ssl: ssl_context_factory = s4.ContextFactory( self.ssl_cert, self.ssl_key) self.s4_conn = reactor.listenSSL(0, site, ssl_context_factory) else: self.s4_conn = reactor.listenTCP(0, site) if self.createOOPSFiles: location = self.mktemp() self.patch(config.oops, 'path', location) oops_config = configure_oops() try: os.mkdir(location) except OSError: for path in self.get_oops(): os.unlink(path) else: # we don't need a real oops serializer, just dump all oops data to # stderr for the test run oops_config = configure_oops() def publish(report): report.setdefault("id", uuid.uuid4()) serializer_rfc822.write(report, sys.stderr) oops_config.publishers = [publish] self._state = State() self.service = StorageServerService( 0, "localhost", self.s4_port, self.s4_use_ssl, s4.AWS_DEFAULT_ACCESS_KEY_ID, s4.AWS_DEFAULT_SECRET_ACCESS_KEY, auth_provider_class=self.auth_provider_class, oops_config=oops_config, status_port=0, heartbeat_interval=self.heartbeat_interval) yield self.service.startService()
def setUp(self): """Setup for testing.""" # make sure we start with clean state yield super(BaseProtocolTestCase, self).setUp() log.info("starting test %s.%s", self.__class__.__name__, self._testMethodName) self.s4_site = site = s4.server.Site(s4.Root()) self.ssl_cert = crypto.load_certificate( crypto.FILETYPE_PEM, server_crt) if server_crt_chain: self.ssl_cert_chain = crypto.load_certificate( crypto.FILETYPE_PEM, server_crt_chain) else: self.ssl_cert_chain = None self.ssl_key = crypto.load_privatekey(crypto.FILETYPE_PEM, server_key) if self.s4_use_ssl: ssl_context_factory = s4.ContextFactory( self.ssl_cert, self.ssl_key) self.s4_conn = reactor.listenSSL(0, site, ssl_context_factory) else: self.s4_conn = reactor.listenTCP(0, site) if self.createOOPSFiles: location = self.mktemp() self.patch(settings, 'OOPS_PATH', location) oops_config = configure_oops() try: os.mkdir(location) except OSError: for path in self.get_oops(): os.unlink(path) else: # we don't need a real oops serializer, just dump all oops data to # stderr for the test run oops_config = configure_oops() def publish(report): report.setdefault("id", uuid.uuid4()) serializer_rfc822.write(report, sys.stderr) oops_config.publishers = [publish] self._state = State() self.service = StorageServerService( 0, "localhost", self.s4_port, self.s4_use_ssl, s4.AWS_DEFAULT_ACCESS_KEY_ID, s4.AWS_DEFAULT_SECRET_ACCESS_KEY, auth_provider_class=self.auth_provider_class, oops_config=oops_config, status_port=0, heartbeat_interval=self.heartbeat_interval) yield self.service.startService()
class BaseProtocolTestCase(TwistedTestCase): """ Reusable part of ProtocolTestCase """ # do we need to create oops files? createOOPSFiles = False # should we use s4 with ssl? s4_use_ssl = False heartbeat_interval = 0 timeout = 120 @property def port(self): """The TCP port where the server listens.""" return self.service.port @property def s4_port(self): """The port where S4 listens.""" return self.s4_conn.getHost().port def get_oops(self): """get the oops generated by this test.""" for date in os.listdir(settings.OOPS_PATH): for file in os.listdir(settings.OOPS_PATH + "/" + date): yield settings.OOPS_PATH + "/" + date + "/" + file @defer.inlineCallbacks def setUp(self): """Setup for testing.""" # make sure we start with clean state yield super(BaseProtocolTestCase, self).setUp() log.info("starting test %s.%s", self.__class__.__name__, self._testMethodName) self.s4_site = site = s4.server.Site(s4.Root()) self.ssl_cert = crypto.load_certificate( crypto.FILETYPE_PEM, server_crt) if server_crt_chain: self.ssl_cert_chain = crypto.load_certificate( crypto.FILETYPE_PEM, server_crt_chain) else: self.ssl_cert_chain = None self.ssl_key = crypto.load_privatekey(crypto.FILETYPE_PEM, server_key) if self.s4_use_ssl: ssl_context_factory = s4.ContextFactory( self.ssl_cert, self.ssl_key) self.s4_conn = reactor.listenSSL(0, site, ssl_context_factory) else: self.s4_conn = reactor.listenTCP(0, site) if self.createOOPSFiles: location = self.mktemp() self.patch(settings, 'OOPS_PATH', location) oops_config = configure_oops() try: os.mkdir(location) except OSError: for path in self.get_oops(): os.unlink(path) else: # we don't need a real oops serializer, just dump all oops data to # stderr for the test run oops_config = configure_oops() def publish(report): report.setdefault("id", uuid.uuid4()) serializer_rfc822.write(report, sys.stderr) oops_config.publishers = [publish] self._state = State() self.service = StorageServerService( 0, "localhost", self.s4_port, self.s4_use_ssl, s4.AWS_DEFAULT_ACCESS_KEY_ID, s4.AWS_DEFAULT_SECRET_ACCESS_KEY, auth_provider_class=self.auth_provider_class, oops_config=oops_config, status_port=0, heartbeat_interval=self.heartbeat_interval) yield self.service.startService() @defer.inlineCallbacks def tearDown(self): """Tear down after testing.""" yield self.service.stopService() yield self.s4_conn.stopListening() log.info("finished test %s.%s", self.__class__.__name__, self._testMethodName) yield super(BaseProtocolTestCase, self).tearDown()
class BaseProtocolTestCase(TwistedTestCase): """ Reusable part of ProtocolTestCase """ # do we need to create oops files? createOOPSFiles = False # should we use s4 with ssl? s4_use_ssl = False heartbeat_interval = 0 timeout = 120 @property def port(self): """The TCP port where the server listens.""" return self.service.port @property def s4_port(self): """The port where S4 listens.""" return self.s4_conn.getHost().port def get_oops(self): """get the oops generated by this test.""" for date in os.listdir(config.oops.path): for file in os.listdir(config.oops.path + "/" + date): yield config.oops.path + "/" + date + "/" + file @defer.inlineCallbacks def setUp(self): """Setup for testing.""" # make sure we start with clean state yield super(BaseProtocolTestCase, self).setUp() log.info("starting test %s.%s", self.__class__.__name__, self._testMethodName) self.s4_site = site = s4.server.Site(s4.Root()) self.ssl_cert = crypto.load_certificate( crypto.FILETYPE_PEM, server_crt) if server_crt_chain: self.ssl_cert_chain = crypto.load_certificate( crypto.FILETYPE_PEM, server_crt_chain) else: self.ssl_cert_chain = None self.ssl_key = crypto.load_privatekey(crypto.FILETYPE_PEM, server_key) if self.s4_use_ssl: ssl_context_factory = s4.ContextFactory( self.ssl_cert, self.ssl_key) self.s4_conn = reactor.listenSSL(0, site, ssl_context_factory) else: self.s4_conn = reactor.listenTCP(0, site) if self.createOOPSFiles: location = self.mktemp() self.patch(config.oops, 'path', location) oops_config = configure_oops() try: os.mkdir(location) except OSError: for path in self.get_oops(): os.unlink(path) else: # we don't need a real oops serializer, just dump all oops data to # stderr for the test run oops_config = configure_oops() def publish(report): report.setdefault("id", uuid.uuid4()) serializer_rfc822.write(report, sys.stderr) oops_config.publishers = [publish] self._state = State() self.service = StorageServerService( 0, "localhost", self.s4_port, self.s4_use_ssl, s4.AWS_DEFAULT_ACCESS_KEY_ID, s4.AWS_DEFAULT_SECRET_ACCESS_KEY, auth_provider_class=self.auth_provider_class, oops_config=oops_config, status_port=0, heartbeat_interval=self.heartbeat_interval) yield self.service.startService() @defer.inlineCallbacks def tearDown(self): """Tear down after testing.""" yield self.service.stopService() yield self.s4_conn.stopListening() log.info("finished test %s.%s", self.__class__.__name__, self._testMethodName) yield super(BaseProtocolTestCase, self).tearDown()