def setUp(self): """Run before each test method to initialize test environment.""" super(TestCase, self).setUp() test_timeout = os.environ.get('OS_TEST_TIMEOUT', 0) try: test_timeout = int(test_timeout) except ValueError: # If timeout value is invalid do not set a timeout. test_timeout = 0 if test_timeout > 0: self.useFixture(fixtures.Timeout(test_timeout, gentle=True)) self.useFixture(fixtures.NestedTempfile()) self.useFixture(fixtures.TempHomeDir()) if (os.environ.get('OS_STDOUT_CAPTURE') == 'True' or os.environ.get('OS_STDOUT_CAPTURE') == '1'): stdout = self.useFixture(fixtures.StringStream('stdout')).stream self.useFixture(fixtures.MonkeyPatch('sys.stdout', stdout)) if (os.environ.get('OS_STDERR_CAPTURE') == 'True' or os.environ.get('OS_STDERR_CAPTURE') == '1'): stderr = self.useFixture(fixtures.StringStream('stderr')).stream self.useFixture(fixtures.MonkeyPatch('sys.stderr', stderr)) self.log_fixture = self.useFixture(fixtures.FakeLogger()) self.useFixture(conf_fixture.ConfFixture(CONF))
def setUp(self): """Run before each test method to initialize test environment.""" super(TestCase, self).setUp() self.mox = mox.Mox() self.setup_config() self.addCleanup(cfg.CONF.reset) config.setup_logging() test_timeout = os.environ.get('OS_TEST_TIMEOUT', 0) try: test_timeout = int(test_timeout) except ValueError: # If timeout value is invalid do not set a timeout. test_timeout = 0 if test_timeout > 0: self.useFixture(fixtures.Timeout(test_timeout, gentle=True)) self.useFixture(fixtures.NestedTempfile()) self.useFixture(fixtures.TempHomeDir()) self.addCleanup(mock.patch.stopall) if os.environ.get('OS_STDOUT_CAPTURE') in _TRUE_VALUES: stdout = self.useFixture(fixtures.StringStream('stdout')).stream self.useFixture(fixtures.MonkeyPatch('sys.stdout', stdout)) if os.environ.get('OS_STDERR_CAPTURE') in _TRUE_VALUES: stderr = self.useFixture(fixtures.StringStream('stderr')).stream self.useFixture(fixtures.MonkeyPatch('sys.stderr', stderr)) self.log_fixture = self.useFixture(fixtures.FakeLogger()) self.policy = self.useFixture(policy_fixture.PolicyFixture())
def setUp(self): super(BaseTestCase, self).setUp() if not self.setUpClassCalled: raise RuntimeError("setUpClass does not calls the super's" "setUpClass in the " + self.__class__.__name__) at_exit_set.add(self.__class__) test_timeout = os.environ.get('OS_TEST_TIMEOUT', 0) try: test_timeout = int(test_timeout) except ValueError: test_timeout = 0 if test_timeout > 0: self.useFixture(fixtures.Timeout(test_timeout, gentle=True)) if (os.environ.get('OS_STDOUT_CAPTURE') == 'True' or os.environ.get('OS_STDOUT_CAPTURE') == '1'): stdout = self.useFixture(fixtures.StringStream('stdout')).stream self.useFixture(fixtures.MonkeyPatch('sys.stdout', stdout)) if (os.environ.get('OS_STDERR_CAPTURE') == 'True' or os.environ.get('OS_STDERR_CAPTURE') == '1'): stderr = self.useFixture(fixtures.StringStream('stderr')).stream self.useFixture(fixtures.MonkeyPatch('sys.stderr', stderr)) if (os.environ.get('OS_LOG_CAPTURE') != 'False' and os.environ.get('OS_LOG_CAPTURE') != '0'): self.useFixture(fixtures.LoggerFixture(nuke_handlers=False, format=self.log_format, level=None))
def setUp(self): try: super(BayTest, self).setUp() (self.creds, self.keypair) = self.get_credentials_with_keypair( type_of_creds='default') (self.baymodel_client, self.keypairs_client) = self.get_clients_with_existing_creds( creds=self.creds, type_of_creds='default', request_type='baymodel') (self.bay_client, _) = self.get_clients_with_existing_creds(creds=self.creds, type_of_creds='default', request_type='bay') (self.cert_client, _) = self.get_clients_with_existing_creds(creds=self.creds, type_of_creds='default', request_type='cert') model = datagen.valid_swarm_baymodel() _, self.baymodel = self._create_baymodel(model) # NOTE (dimtruck) by default tempest sets timeout to 20 mins. # We need more time. test_timeout = 1800 self.useFixture(fixtures.Timeout(test_timeout, gentle=True)) except Exception: self.tearDown() raise
def setUp(self): super(MigrationCheckersMixin, self).setUp() self.engine = enginefacade.writer.get_engine() self.config = migration._alembic_config() self.migration_api = migration self.useFixture(fixtures.Timeout(MIGRATIONS_TIMEOUT, gentle=True))
def setUp(self): """Run before each test method to initialize test environment.""" super(TestCase, self).setUp() test_timeout = os.environ.get('OS_TEST_TIMEOUT', 0) try: test_timeout = int(test_timeout) except ValueError: # If timeout value is invalid do not set a timeout. test_timeout = 0 if test_timeout > 0: self.useFixture(fixtures.Timeout(test_timeout, gentle=True)) self.useFixture(fixtures.NestedTempfile()) self.useFixture(fixtures.TempHomeDir()) environ_enabled = (lambda var_name: strutils.bool_from_string( os.environ.get(var_name))) if environ_enabled('OS_STDOUT_CAPTURE'): stdout = self.useFixture(fixtures.StringStream('stdout')).stream self.useFixture(fixtures.MonkeyPatch('sys.stdout', stdout)) if environ_enabled('OS_STDERR_CAPTURE'): stderr = self.useFixture(fixtures.StringStream('stderr')).stream self.useFixture(fixtures.MonkeyPatch('sys.stderr', stderr)) if environ_enabled('OS_LOG_CAPTURE'): log_format = '%(levelname)s [%(name)s] %(message)s' if environ_enabled('OS_DEBUG'): level = logging.DEBUG else: level = logging.INFO self.useFixture( fixtures.LoggerFixture(nuke_handlers=False, format=log_format, level=level))
def setUp(self): super(BaseTestCase, self).setUp() test_timeout = os.environ.get('OS_TEST_TIMEOUT', 0) try: test_timeout = int(test_timeout) except ValueError: # If timeout value is invalid do not set a timeout. test_timeout = 0 if test_timeout > 0: self.useFixture(fixtures.Timeout(test_timeout, gentle=False)) if (os.environ.get('OS_STDOUT_CAPTURE') == 'True' or os.environ.get('OS_STDOUT_CAPTURE') == '1'): stdout = self.useFixture(fixtures.StringStream('stdout')).stream self.useFixture(fixtures.MonkeyPatch('sys.stdout', stdout)) if (os.environ.get('OS_STDERR_CAPTURE') == 'True' or os.environ.get('OS_STDERR_CAPTURE') == '1'): stderr = self.useFixture(fixtures.StringStream('stderr')).stream self.useFixture(fixtures.MonkeyPatch('sys.stderr', stderr)) if (os.environ.get('OS_LOG_CAPTURE') == 'True' or os.environ.get('OS_LOG_CAPTURE') == '1'): self.useFixture(fixtures.FakeLogger( level=logging.DEBUG, format='%(asctime)s %(name)-32s ' '%(levelname)-8s %(message)s'))
def setUp(self): super(BaseTestCase, self).setUp() # Configure this first to ensure pm debugging support for setUp() if os.environ.get('OS_POST_MORTEM_DEBUG') in TRUE_STRING: self.addOnException(post_mortem_debug.exception_handler) if os.environ.get('OS_DEBUG') in TRUE_STRING: _level = logging.DEBUG else: _level = logging.INFO capture_logs = os.environ.get('OS_LOG_CAPTURE') in TRUE_STRING if not capture_logs: logging.basicConfig(format=LOG_FORMAT, level=_level) self.log_fixture = self.useFixture( fixtures.FakeLogger( format=LOG_FORMAT, level=_level, nuke_handlers=capture_logs, )) # suppress all but errors here self.useFixture( fixtures.FakeLogger( name='neutron.api.extensions', format=LOG_FORMAT, level=logging.ERROR, nuke_handlers=capture_logs, )) test_timeout = int(os.environ.get('OS_TEST_TIMEOUT', 0)) if test_timeout == -1: test_timeout = 0 if test_timeout > 0: self.useFixture(fixtures.Timeout(test_timeout, gentle=True)) # If someone does use tempfile directly, ensure that it's cleaned up self.useFixture(fixtures.NestedTempfile()) self.useFixture(fixtures.TempHomeDir()) self.temp_dir = self.useFixture(fixtures.TempDir()).path cfg.CONF.set_override('state_path', self.temp_dir) self.addCleanup(mock.patch.stopall) self.addCleanup(CONF.reset) if os.environ.get('OS_STDOUT_CAPTURE') in TRUE_STRING: stdout = self.useFixture(fixtures.StringStream('stdout')).stream self.useFixture(fixtures.MonkeyPatch('sys.stdout', stdout)) if os.environ.get('OS_STDERR_CAPTURE') in TRUE_STRING: stderr = self.useFixture(fixtures.StringStream('stderr')).stream self.useFixture(fixtures.MonkeyPatch('sys.stderr', stderr)) self.useFixture( fixtures.MonkeyPatch( 'neutron.common.exceptions.NeutronException.use_fatal_exceptions', fake_use_fatal_exceptions)) if sys.version_info < (2, 7) and getattr(self, 'fmt', '') == 'xml': raise self.skipException('XML Testing Skipped in Py26')
def delete_resource(self, method, *args, **kwargs): with fixtures.Timeout( timeouts.Defaults.instance.timeout_delete_resource, gentle=True): while True: if self.is_resource_deleted(method, *args, **kwargs): break time.sleep(5)
def check_transient(self): # TODO(sreshetniak): make timeout configurable with fixtures.Timeout(300, gentle=True): while True: if self.sahara.is_resource_deleted( self.sahara.get_cluster_status, self.cluster_id): break time.sleep(5)
def setUp(self): """Run before each test method to initialize test environment.""" super(TestCase, self).setUp() test_timeout = os.environ.get('OS_TEST_TIMEOUT', 0) try: test_timeout = int(test_timeout) except ValueError: # If timeout value is invalid do not set a timeout. test_timeout = 0 if test_timeout > 0: self.useFixture(fixtures.Timeout(test_timeout, gentle=True)) self.useFixture(fixtures.NestedTempfile()) self.useFixture(fixtures.TempHomeDir()) self.useFixture(TranslationFixture()) if (os.environ.get('OS_STDOUT_CAPTURE') == 'True' or os.environ.get('OS_STDOUT_CAPTURE') == '1'): stdout = self.useFixture(fixtures.StringStream('stdout')).stream self.useFixture(fixtures.MonkeyPatch('sys.stdout', stdout)) if (os.environ.get('OS_STDERR_CAPTURE') == 'True' or os.environ.get('OS_STDERR_CAPTURE') == '1'): stderr = self.useFixture(fixtures.StringStream('stderr')).stream self.useFixture(fixtures.MonkeyPatch('sys.stderr', stderr)) fs = '%(levelname)s [%(name)s] %(message)s' self.log_fixture = self.useFixture(fixtures.FakeLogger(format=fs)) self.useFixture(conf_fixture.ConfFixture(CONF)) if self.USES_DB: global _DB_CACHE if not _DB_CACHE: _DB_CACHE = Database(session, migration, sql_connection=CONF.database.connection, sqlite_db=CONF.sqlite_db, sqlite_clean_db=CONF.sqlite_clean_db) self.useFixture(_DB_CACHE) # NOTE(danms): Make sure to reset us back to non-remote objects # for each test to avoid interactions. Also, backup the object # registry. objects_base.NovaObject.indirection_api = None self._base_test_obj_backup = copy.copy( objects_base.NovaObject._obj_classes) self.addCleanup(self._restore_obj_registry) mox_fixture = self.useFixture(moxstubout.MoxStubout()) self.mox = mox_fixture.mox self.stubs = mox_fixture.stubs self.addCleanup(self._clear_attrs) self.useFixture(fixtures.EnvironmentVariable('http_proxy')) self.policy = self.useFixture(policy_fixture.PolicyFixture()) CONF.set_override('fatal_exception_format_errors', True) CONF.set_override('enabled', True, 'osapi_v3') CONF.set_override('force_dhcp_release', False) # This will be cleaned up by the NestedTempfile fixture CONF.set_override('lock_path', tempfile.mkdtemp())
def setUp(self, conf=cfg.CONF): super(BaseTestCase, self).setUp() self.conf = conf self.addCleanup(self.conf.reset) self.useFixture(fixtures.FakeLogger('openstack.common')) self.useFixture(fixtures.Timeout(30, True)) self.config(fatal_exception_format_errors=True) self.useFixture(fixtures.NestedTempfile()) self.tempdirs = []
def _set_timeout(self): test_timeout = os.environ.get('OS_TEST_TIMEOUT', 0) try: test_timeout = int(test_timeout) except ValueError: # If timeout value is invalid do not set a timeout. test_timeout = 0 if test_timeout > 0: self.useFixture(fixtures.Timeout(test_timeout, gentle=True))
def check_transient(self): with fixtures.Timeout( timeouts.Defaults.instance.timeout_check_transient, gentle=True): while True: if self.sahara.is_resource_deleted( self.sahara.get_cluster_status, self.cluster_id): break time.sleep(5)
def setUp(self): """Run before each test method to initialize test environment.""" super(TestCase, self).setUp() test_timeout = os.environ.get('OS_TEST_TIMEOUT', 0) try: test_timeout = int(test_timeout) except ValueError: # If timeout value is invalid do not set a timeout. test_timeout = 0 if self.TIMEOUT_SCALING_FACTOR >= 0: test_timeout *= self.TIMEOUT_SCALING_FACTOR else: raise ValueError('TIMEOUT_SCALING_FACTOR value must be >= 0') if test_timeout > 0: self.useFixture(fixtures.Timeout(test_timeout, gentle=True)) self.useFixture(fixtures.NestedTempfile()) self.useFixture(fixtures.TempHomeDir()) self.useFixture(TranslationFixture()) self.useFixture(log_fixture.get_logging_handle_error_fixture()) if os.environ.get('OS_STDOUT_CAPTURE') in _TRUE_VALUES: stdout = self.useFixture(fixtures.StringStream('stdout')).stream self.useFixture(fixtures.MonkeyPatch('sys.stdout', stdout)) if os.environ.get('OS_STDERR_CAPTURE') in _TRUE_VALUES: stderr = self.useFixture(fixtures.StringStream('stderr')).stream self.useFixture(fixtures.MonkeyPatch('sys.stderr', stderr)) fs = '%(levelname)s [%(name)s] %(message)s' self.log_fixture = self.useFixture(fixtures.FakeLogger( level=logging.DEBUG, format=fs)) self.useFixture(conf_fixture.ConfFixture(CONF)) self.messaging_conf = messaging_conffixture.ConfFixture(CONF) self.messaging_conf.transport_driver = 'fake' self.messaging_conf.response_timeout = 15 self.useFixture(self.messaging_conf) if self.USES_DB: global _DB_CACHE if not _DB_CACHE: _DB_CACHE = Database(session, migration, sql_connection=CONF.database.connection, sqlite_db=CONF.database.sqlite_db, sqlite_clean_db=CONF.sqlite_clean_db) self.useFixture(_DB_CACHE) mox_fixture = self.useFixture(moxstubout.MoxStubout()) self.mox = mox_fixture.mox self.stubs = mox_fixture.stubs self.addCleanup(self._clear_attrs) self.useFixture(fixtures.EnvironmentVariable('http_proxy')) self.policy = self.useFixture(policy_fixture.PolicyFixture()) CONF.set_override('fatal_exception_format_errors', True)
def setUp(self): """Configure testing environment. Prepare directory for the testing and clone test Git repository. Require Gerrit war file in the .gerrit directory to run Gerrit local. """ super(BaseGitReviewTestCase, self).setUp() self.useFixture(fixtures.Timeout(2 * 60, True)) BaseGitReviewTestCase._test_counter += 1 # ensures git-review command runs in local mode (for functional tests) self.useFixture( fixtures.EnvironmentVariable('GITREVIEW_LOCAL_MODE', '')) self.init_dirs() ssh_addr, ssh_port, http_addr, http_port, self.site_dir = \ self._pick_gerrit_port_and_dir() self.gerrit_host, self.gerrit_port = ssh_addr, ssh_port self.test_dir = self._dir('site', 'tmp', 'test_project') self.ssh_dir = self._dir('site', 'tmp', 'ssh') self.project_ssh_uri = ('ssh://test_user@%s:%s/test/test_project.git' % (ssh_addr, ssh_port)) self.project_http_uri = ( 'http://*****:*****@%s:%s/test/test_project.git' % (http_addr, http_port)) self._run_gerrit(ssh_addr, ssh_port, http_addr, http_port) self._configure_ssh(ssh_addr, ssh_port) # create Gerrit empty project self._run_gerrit_cli('create-project', '--empty-commit', '--name', 'test/test_project') # ensure user proxy conf doesn't interfere with tests os.environ['no_proxy'] = os.environ['NO_PROXY'] = '*' # prepare repository for the testing self._run_git('clone', self.project_uri) utils.write_to_file(self._dir('test', 'test_file.txt'), 'test file created'.encode()) self._create_gitreview_file() # push changes to the Gerrit self._run_git('add', '--all') self._run_git('commit', '-m', 'Test file and .gitreview added.') self._run_git('push', 'origin', 'master') shutil.rmtree(self.test_dir) # go to the just cloned test Git repository self._run_git('clone', self.project_uri) self._run_git('remote', 'add', 'gerrit', self.project_uri) self.addCleanup(shutil.rmtree, self.test_dir) # ensure user is configured for all tests self._configure_gitreview_username()
def _poll_cluster_status(self, cluster_name): with fixtures.Timeout(TEMPEST_CONF.data_processing.cluster_timeout, gentle=True): while True: status = self._get_cluster_status(cluster_name) if status == 'Active': break if status == 'Error': raise exc.TempestException("Cluster in %s state" % status) time.sleep(3)
def _poll_cluster_status(self, cluster_id): # TODO(sreshetniak): make timeout configurable with fixtures.Timeout(1800, gentle=True): while True: status = self.sahara.get_cluster_status(cluster_id) if status == 'Active': break if status == 'Error': raise exc.TempestException("Cluster in %s state" % status) time.sleep(3)
def openstack_cluster_scale(self, cluster_name, ng_worker): with fixtures.Timeout(300, gentle=True): scale_cluster = self.listing_result( ''.join(['cluster scale --instances ', ng_worker, ':2 --wait ', cluster_name])) self.assertTableStruct(scale_cluster, [ 'Field', 'Value' ]) self._poll_cluster_status(cluster_name)
def setUp(self): """Run before each test method to initialize test environment.""" super(TestCase, self).setUp() self.mock_helm_refresh = self.helm_refresh_patcher.start() self.dbapi = dbapi.get_instance() test_timeout = os.environ.get('OS_TEST_TIMEOUT', 0) try: test_timeout = int(test_timeout) except ValueError: # If timeout value is invalid do not set a timeout. test_timeout = 0 if test_timeout > 0: self.useFixture(fixtures.Timeout(test_timeout, gentle=True)) self.useFixture(fixtures.NestedTempfile()) self.useFixture(fixtures.TempHomeDir()) if (os.environ.get('OS_STDOUT_CAPTURE') == 'True' or os.environ.get('OS_STDOUT_CAPTURE') == '1'): stdout = self.useFixture(fixtures.StringStream('stdout')).stream self.useFixture(fixtures.MonkeyPatch('sys.stdout', stdout)) if (os.environ.get('OS_STDERR_CAPTURE') == 'True' or os.environ.get('OS_STDERR_CAPTURE') == '1'): stderr = self.useFixture(fixtures.StringStream('stderr')).stream self.useFixture(fixtures.MonkeyPatch('sys.stderr', stderr)) self.log_fixture = self.useFixture(fixtures.FakeLogger()) self.useFixture(conf_fixture.ConfFixture(CONF)) global _DB_CACHE if not _DB_CACHE: engine = enginefacade.get_legacy_facade().get_engine() _DB_CACHE = Database(engine, migration, sql_connection=CONF.database.connection, sqlite_db='sysinv.sqlite', sqlite_clean_db='clean.sqlite') self.useFixture(_DB_CACHE) # NOTE(danms): Make sure to reset us back to non-remote objects # for each test to avoid interactions. Also, backup the object # registry objects_base.SysinvObject.indirection_api = None self._base_test_obj_backup = copy.copy( objects_base.SysinvObject._obj_classes) self.addCleanup(self._restore_obj_registry) mox_fixture = self.useFixture(moxstubout.MoxStubout()) self.mox = mox_fixture.mox self.stubs = mox_fixture.stubs self.addCleanup(self._clear_attrs) self.useFixture(fixtures.EnvironmentVariable('http_proxy')) self.policy = self.useFixture(policy_fixture.PolicyFixture()) CONF.set_override('fatal_exception_format_errors', True)
def _poll_cluster_status(self, cluster_id): with fixtures.Timeout( timeouts.Defaults.instance.timeout_poll_cluster_status, gentle=True): while True: status = self.sahara.get_cluster_status(cluster_id) if status == CLUSTER_STATUS_ACTIVE: break if status == CLUSTER_STATUS_ERROR: raise exc.TempestException("Cluster in %s state" % status) time.sleep(3)
def _poll_cluster_status(self, cluster_id): with fixtures.Timeout( timeouts.Defaults.instance.timeout_poll_cluster_status, gentle=True): while True: status = self.sahara.get_cluster_status(cluster_id) if status == 'Active': break if status == 'Error': raise exc.TempestException("Cluster in %s state" % status) time.sleep(3)
def wait_for_resource_deletion(self, name, type): # type can be cluster, cluster template or node group template string name_exist = False # if name exists in the command "type list" than tests should fail with fixtures.Timeout(300, gentle=True): while True: list_of_types = self.listing_result(''.join([type, ' list'])) list_names = [p['Name'] for p in list_of_types] if name in list_names: name_exist = True if not name_exist: break
def setUp(self): super(ModelsMigrationsSync, self).setUp() self.useFixture(fixtures.Timeout(120, gentle=True)) self.db = mock.Mock() self.conf.set_override( 'url', sqlalchemy.SQLAlchemyIndexer._create_new_database( self.conf.indexer.url), 'indexer') self.index = indexer.get_driver(self.conf) self.index.upgrade(nocreate=True) self.addCleanup(self._drop_database)
def setUp(self): super(BaseTestCase, self).setUp() test_timeout = os.environ.get('OS_TEST_TIMEOUT', 60) try: test_timeout = int(test_timeout) except ValueError: # If timeout value is invalid, fail hard. print("OS_TEST_TIMEOUT set to invalid value" " defaulting to no timeout") test_timeout = 0 if test_timeout > 0: self.useFixture(fixtures.Timeout(test_timeout, gentle=True)) if os.environ.get('OS_STDOUT_CAPTURE') in TRUE_VALUES: stdout = self.useFixture(fixtures.StringStream('stdout')).stream self.useFixture(fixtures.MonkeyPatch('sys.stdout', stdout)) if os.environ.get('OS_STDERR_CAPTURE') in TRUE_VALUES: stderr = self.useFixture(fixtures.StringStream('stderr')).stream self.useFixture(fixtures.MonkeyPatch('sys.stderr', stderr)) if os.environ.get('OS_LOG_CAPTURE') in TRUE_VALUES: fs = '%(asctime)s %(levelname)s [%(name)s] %(message)s' self.useFixture(fixtures.FakeLogger(level=logging.DEBUG, format=fs)) else: logging.basicConfig(level=logging.DEBUG) l = logging.getLogger('kazoo') l.setLevel(logging.INFO) l.propagate = False l = logging.getLogger('stevedore') l.setLevel(logging.INFO) l.propagate = False self.useFixture(fixtures.NestedTempfile()) self.subprocesses = [] def LoggingPopenFactory(*args, **kw): p = LoggingPopen(*args, **kw) self.subprocesses.append(p) return p self.statsd = StatsdFixture() self.useFixture(self.statsd) # note, use 127.0.0.1 rather than localhost to avoid getting ipv6 # see: https://github.com/jsocol/pystatsd/issues/61 os.environ['STATSD_HOST'] = '127.0.0.1' os.environ['STATSD_PORT'] = str(self.statsd.port) self.useFixture( fixtures.MonkeyPatch('subprocess.Popen', LoggingPopenFactory)) self.setUpFakes() self.addCleanup(self._cleanup)
def setUp(self): super(DietTestCase, self).setUp() # FIXME(amuller): this must be called in the Neutron unit tests base # class to initialize the DB connection string. Moving this may cause # non-deterministic failures. Bug #1489098 for more info. config.set_db_defaults() # Configure this first to ensure pm debugging support for setUp() debugger = os.environ.get('OS_POST_MORTEM_DEBUGGER') if debugger: self.addOnException(post_mortem_debug.get_exception_handler( debugger)) # Make sure we see all relevant deprecation warnings when running tests self.useFixture(tools.WarningsFixture()) if bool_from_env('OS_DEBUG'): _level = std_logging.DEBUG else: _level = std_logging.INFO capture_logs = bool_from_env('OS_LOG_CAPTURE') if not capture_logs: std_logging.basicConfig(format=LOG_FORMAT, level=_level) self.log_fixture = self.useFixture( fixtures.FakeLogger( format=LOG_FORMAT, level=_level, nuke_handlers=capture_logs, )) test_timeout = get_test_timeout() if test_timeout == -1: test_timeout = 0 if test_timeout > 0: self.useFixture(fixtures.Timeout(test_timeout, gentle=True)) # If someone does use tempfile directly, ensure that it's cleaned up self.useFixture(fixtures.NestedTempfile()) self.useFixture(fixtures.TempHomeDir()) self.addCleanup(mock.patch.stopall) if bool_from_env('OS_STDOUT_CAPTURE'): stdout = self.useFixture(fixtures.StringStream('stdout')).stream self.useFixture(fixtures.MonkeyPatch('sys.stdout', stdout)) if bool_from_env('OS_STDERR_CAPTURE'): stderr = self.useFixture(fixtures.StringStream('stderr')).stream self.useFixture(fixtures.MonkeyPatch('sys.stderr', stderr)) self.addOnException(self.check_for_systemexit) self.orig_pid = os.getpid()
def _poll_verification_status(self, cluster_id): with fixtures.Timeout( timeouts.Defaults.instance.timeout_poll_cluster_status, gentle=True): while True: cluster = self.sahara.get_cluster(cluster_id) status = self._get_health_status(cluster) if status == 'UNKNOWN': print("Cluster verification did not start") break if status in HEALTH_CHECKS: break time.sleep(3)
def _poll_jobs_status(self, exec_ids): # TODO(sreshetniak): make timeout configurable with fixtures.Timeout(1800, gentle=True): success = False while not success: success = True for exec_id in exec_ids: status = self.sahara.get_job_status(exec_id) if status in ['FAILED', 'KILLED', 'DONEWITHERROR']: self.fail("Job %s in %s status" % (exec_id, status)) if status != 'SUCCEEDED': success = False time.sleep(5)
def setUp(self): """Configure testing environment. Prepare directory for the testing and clone test Git repository. Require Gerrit war file in the .gerrit directory to run Gerrit local. """ super(BaseGitReviewTestCase, self).setUp() self.useFixture(fixtures.Timeout(2 * 60, True)) BaseGitReviewTestCase._test_counter += 1 self.init_dirs() ssh_addr, ssh_port, http_addr, http_port, self.site_dir = \ self._pick_gerrit_port_and_dir() self.gerrit_host, self.gerrit_port = ssh_addr, ssh_port self.test_dir = self._dir('site', 'tmp', 'test_project') self.ssh_dir = self._dir('site', 'tmp', 'ssh') self.project_ssh_uri = ('ssh://test_user@%s:%s/test/test_project.git' % (ssh_addr, ssh_port)) self.project_http_uri = ( 'http://*****:*****@%s:%s/test/test_project.git' % (http_addr, http_port)) self._run_gerrit(ssh_addr, ssh_port, http_addr, http_port) self._configure_ssh(ssh_addr, ssh_port) # create Gerrit empty project self._run_gerrit_cli('create-project', '--empty-commit', '--name', 'test/test_project') # prepare repository for the testing self._run_git('clone', self.project_uri) utils.write_to_file(self._dir('test', 'test_file.txt'), 'test file created'.encode()) cfg = ('[gerrit]\n' 'host=%s\n' 'port=%s\n' 'project=test/test_project.git' % (ssh_addr, ssh_port)) utils.write_to_file(self._dir('test', '.gitreview'), cfg.encode()) # push changes to the Gerrit self._run_git('add', '--all') self._run_git('commit', '-m', 'Test file and .gitreview added.') self._run_git('push', 'origin', 'master') shutil.rmtree(self.test_dir) # go to the just cloned test Git repository self._run_git('clone', self.project_uri) self._run_git('remote', 'add', 'gerrit', self.project_uri) self.addCleanup(shutil.rmtree, self.test_dir)
def setUp(self): super(BaseTestCase, self).setUp() test_timeout = os.environ.get('OS_TEST_TIMEOUT', 30) try: test_timeout = int(test_timeout) except ValueError: # If timeout value is invalid, fail hard. print("OS_TEST_TIMEOUT set to invalid value" " defaulting to no timeout") test_timeout = 0 if test_timeout > 0: self.useFixture(fixtures.Timeout(test_timeout, gentle=True)) if os.environ.get('OS_STDOUT_CAPTURE') in options.TRUE_VALUES: stdout = self.useFixture(fixtures.StringStream('stdout')).stream self.useFixture(fixtures.MonkeyPatch('sys.stdout', stdout)) if os.environ.get('OS_STDERR_CAPTURE') in options.TRUE_VALUES: stderr = self.useFixture(fixtures.StringStream('stderr')).stream self.useFixture(fixtures.MonkeyPatch('sys.stderr', stderr)) self.log_fixture = self.useFixture( fixtures.FakeLogger('pbr')) # Older git does not have config --local, so create a temporary home # directory to permit using git config --global without stepping on # developer configuration. self.useFixture(fixtures.TempHomeDir()) self.useFixture(fixtures.NestedTempfile()) self.useFixture(fixtures.FakeLogger()) # TODO(lifeless) we should remove PBR_VERSION from the environment. # rather than setting it, because thats not representative - we need to # test non-preversioned codepaths too! self.useFixture(fixtures.EnvironmentVariable('PBR_VERSION', '0.0')) self.temp_dir = self.useFixture(fixtures.TempDir()).path self.package_dir = os.path.join(self.temp_dir, 'testpackage') shutil.copytree(os.path.join(os.path.dirname(__file__), 'testpackage'), self.package_dir) self.addCleanup(os.chdir, os.getcwd()) os.chdir(self.package_dir) self.addCleanup(self._discard_testpackage) # Tests can opt into non-PBR_VERSION by setting preversioned=False as # an attribute. if not getattr(self, 'preversioned', True): self.useFixture(fixtures.EnvironmentVariable('PBR_VERSION')) setup_cfg_path = os.path.join(self.package_dir, 'setup.cfg') with open(setup_cfg_path, 'rt') as cfg: content = cfg.read() content = content.replace(u'version = 0.1.dev', u'') with open(setup_cfg_path, 'wt') as cfg: cfg.write(content)