def main(): """ This is the high level entry method. It does logging if any Exceptions are raised. """ if os.getuid() == 0: print >> sys.stderr, _( 'This must not be run as root, but as the same user apache runs as.' ) return os.EX_USAGE try: options = parse_args() _start_logging() connection.initialize(max_timeout=1) active_workers = None if not options.dry_run: active_workers = status.get_workers() if active_workers: last_worker_time = max( [worker['last_heartbeat'] for worker in active_workers]) time_from_last = UTCDateTimeField().to_python( datetime.utcnow()) - last_worker_time wait_time = timedelta( seconds=constants.MIGRATION_WAIT_TIME) - time_from_last if wait_time > timedelta(0): print _('\nThe following processes might still be running:') for worker in active_workers: print _('\t%s' % worker['name']) for i in range(wait_time.seconds, 0, -1): print _( '\rPlease wait %s seconds while Pulp confirms this.' % i), sys.stdout.flush() time.sleep(1) still_active_workers = [ worker for worker in status.get_workers() if worker['last_heartbeat'] > last_worker_time ] if still_active_workers: print >> sys.stderr, _( '\n\nThe following processes are still running, please' ' stop the running workers before retrying the' ' pulp-manage-db command.') for worker in still_active_workers: print _('\t%s' % worker['name']) return os.EX_SOFTWARE return _auto_manage_db(options) except UnperformedMigrationException: return 1 except DataError, e: _logger.critical(str(e)) _logger.critical(''.join(traceback.format_exception(*sys.exc_info()))) return os.EX_DATAERR
def main(): """ This is the high level entry method. It does logging if any Exceptions are raised. """ if os.getuid() == 0: print >> sys.stderr, _('This must not be run as root, but as the same user apache runs as.') return os.EX_USAGE try: options = parse_args() _start_logging() connection.initialize(max_timeout=1) active_workers = None if not options.dry_run: active_workers = status.get_workers() if active_workers: last_worker_time = max([worker['last_heartbeat'] for worker in active_workers]) time_from_last = UTCDateTimeField().to_python(datetime.utcnow()) - last_worker_time wait_time = timedelta(seconds=constants.MIGRATION_WAIT_TIME) - time_from_last if wait_time > timedelta(0): print _('\nThe following processes might still be running:') for worker in active_workers: print _('\t%s' % worker['name']) for i in range(wait_time.seconds, 0, -1): print _('\rPlease wait %s seconds while Pulp confirms this.' % i), sys.stdout.flush() time.sleep(1) still_active_workers = [worker for worker in status.get_workers() if worker['last_heartbeat'] > last_worker_time] if still_active_workers: print >> sys.stderr, _('\n\nThe following processes are still running, please' ' stop the running workers before retrying the' ' pulp-manage-db command.') for worker in still_active_workers: print _('\t%s' % worker['name']) return os.EX_SOFTWARE return _auto_manage_db(options) except UnperformedMigrationException: return 1 except DataError, e: _logger.critical(str(e)) _logger.critical(''.join(traceback.format_exception(*sys.exc_info()))) return os.EX_DATAERR
def main(): """ This is the high level entry method. It does logging if any Exceptions are raised. """ if os.getuid() == 0: print >> sys.stderr, _( 'This must not be run as root, but as the same user apache runs as.' ) return os.EX_USAGE try: options = parse_args() _start_logging() connection.initialize(max_timeout=1) # Prompt the user if there are workers that have not timed out if filter( lambda worker: (UTCDateTimeField().to_python(datetime.now()) - worker['last_heartbeat']) < timedelta( seconds=constants.CELERY_TIMEOUT_SECONDS), status.get_workers()): if not _user_input_continue( 'There are still running workers, continuing could ' 'corrupt your Pulp installation. Are you sure you wish ' 'to continue?'): return os.EX_OK return _auto_manage_db(options) except UnperformedMigrationException: return 1 except DataError, e: _logger.critical(str(e)) _logger.critical(''.join(traceback.format_exception(*sys.exc_info()))) return os.EX_DATAERR
def get(self, request): """ Show current status of pulp server. :param request: WSGI request object :type request: django.core.handlers.wsgi.WSGIRequest :return: Response showing surrent server status :rtype: django.http.HttpResponse """ pulp_version = status_manager.get_version() pulp_db_connection = status_manager.get_mongo_conn_status() pulp_messaging_connection = status_manager.get_broker_conn_status() # do not ask for the worker list unless we have a DB connection if pulp_db_connection['connected']: # convert Worker documents to dicts pulp_workers = [w.to_mongo().to_dict() for w in status_manager.get_workers()] else: pulp_workers = [] # 'api_version' is deprecated and can go away in 3.0, bz #1171763 status_data = {'api_version': '2', 'versions': pulp_version, 'database_connection': pulp_db_connection, 'messaging_connection': pulp_messaging_connection, 'known_workers': pulp_workers} return generate_json_response_with_pulp_encoder(status_data)
def get(self, request): """ Show current status of pulp server. :param request: WSGI request object :type request: django.core.handlers.wsgi.WSGIRequest :return: Response showing surrent server status :rtype: django.http.HttpResponse """ pulp_version = status_manager.get_version() pulp_db_connection = status_manager.get_mongo_conn_status() pulp_messaging_connection = status_manager.get_broker_conn_status() # do not ask for the worker list unless we have a DB connection if pulp_db_connection['connected']: # convert Worker documents to dicts pulp_workers = [ w.to_mongo().to_dict() for w in status_manager.get_workers() ] else: pulp_workers = [] # 'api_version' is deprecated and can go away in 3.0, bz #1171763 status_data = { 'api_version': '2', 'versions': pulp_version, 'database_connection': pulp_db_connection, 'messaging_connection': pulp_messaging_connection, 'known_workers': pulp_workers } return generate_json_response_with_pulp_encoder(status_data)
def main(): """ This is the high level entry method. It does logging if any Exceptions are raised. """ if os.getuid() == 0: print >> sys.stderr, _('This must not be run as root, but as the same user apache runs as.') return os.EX_USAGE try: options = parse_args() _start_logging() connection.initialize(max_timeout=1) # Prompt the user if there are workers that have not timed out if filter(lambda worker: (UTCDateTimeField().to_python(datetime.now()) - worker['last_heartbeat']) < timedelta(seconds=constants.CELERY_TIMEOUT_SECONDS), status.get_workers()): if not _user_input_continue('There are still running workers, continuing could ' 'corrupt your Pulp installation. Are you sure you wish ' 'to continue?'): return os.EX_OK return _auto_manage_db(options) except UnperformedMigrationException: return 1 except DataError, e: _logger.critical(str(e)) _logger.critical(''.join(traceback.format_exception(*sys.exc_info()))) return os.EX_DATAERR
def test_get_workers(self, mock_worker_objects): mock_worker_objects.return_value = [{"last_heartbeat": "123456", "name": "some_worker_1"}, {"last_heartbeat": "123456", "name": "some_worker_2"}] self.assertEquals(status_manager.get_workers(), [{"last_heartbeat": "123456", "name": "some_worker_1"}, {"last_heartbeat": "123456", "name": "some_worker_2"}])
def test_get_workers(self, mock_worker_objects): get_online = mock_worker_objects.get_online get_online.return_value = [{"last_heartbeat": "123456", "name": "some_worker_1"}, {"last_heartbeat": "123456", "name": "some_worker_2"}] self.assertEquals(status_manager.get_workers(), [{"last_heartbeat": "123456", "name": "some_worker_1"}, {"last_heartbeat": "123456", "name": "some_worker_2"}])
def test_get_workers(self, mock_filter_workers): mock_filter_workers.return_value = [{ "last_heartbeat": "123456", "name": "some_worker_1" }, { "last_heartbeat": "123456", "name": "some_worker_2" }] self.assertEquals(status_manager.get_workers(), [{ "last_heartbeat": "123456", "name": "some_worker_1" }, { "last_heartbeat": "123456", "name": "some_worker_2" }])
def GET(self): pulp_version = status_manager.get_version() pulp_db_connection = status_manager.get_mongo_conn_status() pulp_messaging_connection = status_manager.get_broker_conn_status() # do not ask for the worker list unless we have a DB connection if pulp_db_connection['connected']: pulp_workers = [w for w in status_manager.get_workers()] else: pulp_workers = [] # 'api_version' is deprecated and can go away in 3.0, bz #1171763 status_data = {'api_version': '2', 'versions': pulp_version, 'database_connection': pulp_db_connection, 'messaging_connection': pulp_messaging_connection, 'known_workers': pulp_workers} return self.ok(status_data)
def GET(self): pulp_version = status_manager.get_version() pulp_db_connection = status_manager.get_mongo_conn_status() pulp_messaging_connection = status_manager.get_broker_conn_status() # do not ask for the worker list unless we have a DB connection if pulp_db_connection['connected']: pulp_workers = [w for w in status_manager.get_workers()] else: pulp_workers = [] # 'api_version' is deprecated and can go away in 3.0, bz #1171763 status_data = { 'api_version': '2', 'versions': pulp_version, 'database_connection': pulp_db_connection, 'messaging_connection': pulp_messaging_connection, 'known_workers': pulp_workers } return self.ok(status_data)