Ejemplo n.º 1
0
    def start(self, application, default_port):
        """
        Run a WSGI server with the given application.

        :param application: The application to be run in the WSGI server
        :param default_port: Port to bind to if none is specified in conf
        """
        pgid = os.getpid()
        try:
            # NOTE(flaper87): Make sure this process
            # runs in its own process group.
            os.setpgid(pgid, pgid)
        except OSError:
            # NOTE(flaper87): When running sps-control,
            # (sps's functional tests, for example)
            # setpgid fails with EPERM as sps-control
            # creates a fresh session, of which the newly
            # launched service becomes the leader (session
            # leaders may not change process groups)
            #
            # Running sps-(api|registry) is safe and
            # shouldn't raise any error here.
            pgid = 0

        def kill_children(*args):
            """Kills the entire process group."""
            signal.signal(signal.SIGTERM, signal.SIG_IGN)
            signal.signal(signal.SIGINT, signal.SIG_IGN)
            self.running = False
            os.killpg(pgid, signal.SIGTERM)

        def hup(*args):
            """
            Shuts down the server, but allows running requests to complete
            """
            signal.signal(signal.SIGHUP, signal.SIG_IGN)
            self.running = False

        self.application = application
        self.sock = get_socket(default_port)

        os.umask(0o27)  # ensure files are created with the correct privileges
        self.logger = logging.getLogger('sps.wsgi.server')

        if CONF.workers == 0:
            # Useful for profiling, test, debug etc.
            self.pool = self.create_pool()
            self.pool.spawn_n(self._single_run, self.application, self.sock)
            return
        else:
            self.logger.info(_("Starting %d workers") % CONF.workers)
            signal.signal(signal.SIGTERM, kill_children)
            signal.signal(signal.SIGINT, kill_children)
            signal.signal(signal.SIGHUP, hup)
            while len(self.children) < CONF.workers:
                self.run_child()
Ejemplo n.º 2
0
    def start(self, application, default_port):
        """
        Run a WSGI server with the given application.

        :param application: The application to be run in the WSGI server
        :param default_port: Port to bind to if none is specified in conf
        """
        pgid = os.getpid()
        try:
            # NOTE(flaper87): Make sure this process
            # runs in its own process group.
            os.setpgid(pgid, pgid)
        except OSError:
            # NOTE(flaper87): When running sps-control,
            # (sps's functional tests, for example)
            # setpgid fails with EPERM as sps-control
            # creates a fresh session, of which the newly
            # launched service becomes the leader (session
            # leaders may not change process groups)
            #
            # Running sps-(api|registry) is safe and
            # shouldn't raise any error here.
            pgid = 0

        def kill_children(*args):
            """Kills the entire process group."""
            signal.signal(signal.SIGTERM, signal.SIG_IGN)
            signal.signal(signal.SIGINT, signal.SIG_IGN)
            self.running = False
            os.killpg(pgid, signal.SIGTERM)

        def hup(*args):
            """
            Shuts down the server, but allows running requests to complete
            """
            signal.signal(signal.SIGHUP, signal.SIG_IGN)
            self.running = False

        self.application = application
        self.sock = get_socket(default_port)

        os.umask(0o27)  # ensure files are created with the correct privileges
        self.logger = logging.getLogger('sps.wsgi.server')

        if CONF.workers == 0:
            # Useful for profiling, test, debug etc.
            self.pool = self.create_pool()
            self.pool.spawn_n(self._single_run, self.application, self.sock)
            return
        else:
            self.logger.info(_("Starting %d workers") % CONF.workers)
            signal.signal(signal.SIGTERM, kill_children)
            signal.signal(signal.SIGINT, kill_children)
            signal.signal(signal.SIGHUP, hup)
            while len(self.children) < CONF.workers:
                self.run_child()
Ejemplo n.º 3
0
#    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
#    License for the specific language governing permissions and limitations
#    under the License.

from oslo.config import cfg

from sps.common import exception
from sps.common import wsgi
import sps.context
import sps.db.simple.api as simple_db
import sps.openstack.common.log as logging
import sps.store


CONF = cfg.CONF
LOG = logging.getLogger(__name__)

UUID1 = 'c80a1a6c-bd1f-41c5-90ee-81afedb1d58d'
UUID2 = '971ec09a-8067-4bc8-a91f-ae3557f1c4c7'

TENANT1 = '6838eb7b-6ded-434a-882c-b344c77fe8df'
TENANT2 = '2c014f32-55eb-467d-8fcb-4bd706012f81'

USER1 = '54492ba0-f4df-4e4e-be62-27f4d76b29cf'
USER2 = '0b3b3006-cb76-4517-ae32-51397e22c754'
USER3 = '2hss8dkl-d8jh-88yd-uhs9-879sdjsd8skd'

BASE_URI = 'http://storeurl.com/container'


def get_fake_request(path='', method='POST', is_admin=False, user=USER1,
Ejemplo n.º 4
0
possible_topdir = os.path.normpath(
    os.path.join(os.path.abspath(sys.argv[0]), os.pardir, os.pardir))
if os.path.exists(os.path.join(possible_topdir, 'sps', '__init__.py')):
    sys.path.insert(0, possible_topdir)

from oslo.config import cfg

from sps.common import config
from sps.common import exception
from sps.db import migration as db_migration
from sps.db.sqlalchemy import api as db_api
from sps.openstack.common.db.sqlalchemy import migration
from sps.openstack.common import log
from sps.openstack.common import strutils

LOG = log.getLogger(__name__)

manager_opts = [
    cfg.BoolOpt('db_enforce_mysql_charset',
                default=True,
                help=_('DEPRECATED. TO BE REMOVED IN THE JUNO RELEASE. '
                       'Whether or not to enforce that all DB tables have '
                       'charset utf8. If your database tables do not have '
                       'charset utf8 you will need to convert before this '
                       'option is removed. This option is only relevant if '
                       'your database engine is MySQL.'))
]

CONF = cfg.CONF
CONF.register_opts(manager_opts)
CONF.import_group("database", "sps.openstack.common.db.options")
Ejemplo n.º 5
0
from nova.openstack.common.db.sqlalchemy import session as db_session

from sps.common import exception
from sps.db.sqlalchemy import models
from sps.openstack.common.db import exception as db_exception
from sps.openstack.common.db.sqlalchemy import session
import sps.openstack.common.log as os_logging
from sps.openstack.common.gettextutils import _
from sps.openstack.common import timeutils
import sps.context
import sys


BASE = models.BASE
sa_logger = None
LOG = os_logging.getLogger(__name__)


STATUSES = ['active', 'saving', 'queued', 'killed', 'pending_delete',
            'deleted']

connection_opts = [
    cfg.StrOpt('slave_connection',
               secret=True,
               help='The SQLAlchemy connection string used to connect to the '
                    'slave database'),
]

CONF = cfg.CONF
CONF.import_opt('debug', 'sps.openstack.common.log')
CONF.import_opt('connection', 'sps.openstack.common.db.options',
Ejemplo n.º 6
0
import functools
from nova.openstack.common.db.sqlalchemy import session as db_session

from sps.common import exception
from sps.db.sqlalchemy import models
from sps.openstack.common.db import exception as db_exception
from sps.openstack.common.db.sqlalchemy import session
import sps.openstack.common.log as os_logging
from sps.openstack.common.gettextutils import _
from sps.openstack.common import timeutils
import sps.context
import sys

BASE = models.BASE
sa_logger = None
LOG = os_logging.getLogger(__name__)

STATUSES = [
    'active', 'saving', 'queued', 'killed', 'pending_delete', 'deleted'
]

connection_opts = [
    cfg.StrOpt('slave_connection',
               secret=True,
               help='The SQLAlchemy connection string used to connect to the '
               'slave database'),
]

CONF = cfg.CONF
CONF.import_opt('debug', 'sps.openstack.common.log')
CONF.import_opt('connection',