Example #1
0
    def test_run_server_global_conf_callback(self):
        calls = defaultdict(lambda: 0)

        def _initrp(conf_file, app_section, *args, **kwargs):
            return (
                {'__file__': 'test', 'workers': 0},
                'logger',
                'log_name')

        def _global_conf_callback(preloaded_app_conf, global_conf):
            calls['_global_conf_callback'] += 1
            self.assertEqual(
                preloaded_app_conf, {'__file__': 'test', 'workers': 0})
            self.assertEqual(global_conf, {'log_name': 'log_name'})
            global_conf['test1'] = 'one'

        def _loadapp(uri, name=None, **kwargs):
            calls['_loadapp'] += 1
            self.assertTrue('global_conf' in kwargs)
            self.assertEqual(kwargs['global_conf'],
                             {'log_name': 'log_name', 'test1': 'one'})

        with nested(
                mock.patch.object(wsgi, '_initrp', _initrp),
                mock.patch.object(wsgi, 'get_socket'),
                mock.patch.object(wsgi, 'drop_privileges'),
                mock.patch.object(wsgi, 'loadapp', _loadapp),
                mock.patch.object(wsgi, 'capture_stdio'),
                mock.patch.object(wsgi, 'run_server')):
            wsgi.run_wsgi('conf_file', 'app_section',
                          global_conf_callback=_global_conf_callback)
        self.assertEqual(calls['_global_conf_callback'], 1)
        self.assertEqual(calls['_loadapp'], 1)
Example #2
0
    def test_run_server_global_conf_callback(self):
        calls = defaultdict(lambda: 0)

        def _initrp(conf_file, app_section, *args, **kwargs):
            return ({"__file__": "test", "workers": 0}, "logger", "log_name")

        def _global_conf_callback(preloaded_app_conf, global_conf):
            calls["_global_conf_callback"] += 1
            self.assertEqual(preloaded_app_conf, {"__file__": "test", "workers": 0})
            self.assertEqual(global_conf, {"log_name": "log_name"})
            global_conf["test1"] = "one"

        def _loadapp(uri, name=None, **kwargs):
            calls["_loadapp"] += 1
            self.assertTrue("global_conf" in kwargs)
            self.assertEqual(kwargs["global_conf"], {"log_name": "log_name", "test1": "one"})

        with nested(
            mock.patch.object(wsgi, "_initrp", _initrp),
            mock.patch.object(wsgi, "get_socket"),
            mock.patch.object(wsgi, "drop_privileges"),
            mock.patch.object(wsgi, "loadapp", _loadapp),
            mock.patch.object(wsgi, "capture_stdio"),
            mock.patch.object(wsgi, "run_server"),
        ):
            wsgi.run_wsgi("conf_file", "app_section", global_conf_callback=_global_conf_callback)
        self.assertEqual(calls["_global_conf_callback"], 1)
        self.assertEqual(calls["_loadapp"], 1)
Example #3
0
def main():
    """
    cloud-connector daemon entry point.

    Loads main config file from a S3 endpoint per environment configuration and
    then starts the wsgi server.
    """

    # We need to monkeypatch out the hash validation stuff
    monkeypatch_hash_validation()

    # We need to monkeypatch swift3 request class determination so we can
    # override some behavior in multipart uploads
    monkeypatch_swift3_requests()

    env_options = get_env_options()

    get_and_write_conf_file_from_s3(env_options['CONF_NAME'],
                                    CLOUD_CONNECTOR_CONF_PATH, env_options)
    sys.argv.insert(1, CLOUD_CONNECTOR_CONF_PATH)

    conf_file, options = utils.parse_options()
    # Calling this "proxy-server" in the pipeline is a little white lie to keep
    # the swift3 pipeline check from blowing up.
    sys.exit(wsgi.run_wsgi(conf_file, 'proxy-server', **options))
Example #4
0
    def test_run_server_failure1(self):
        calls = defaultdict(lambda: 0)

        def _initrp(conf_file, app_section, *args, **kwargs):
            calls['_initrp'] += 1
            raise wsgi.ConfigFileError('test exception')

        def _loadapp(uri, name=None, **kwargs):
            calls['_loadapp'] += 1

        with nested(mock.patch.object(wsgi, '_initrp', _initrp),
                    mock.patch.object(wsgi, 'get_socket'),
                    mock.patch.object(wsgi, 'drop_privileges'),
                    mock.patch.object(wsgi, 'loadapp', _loadapp),
                    mock.patch.object(wsgi, 'capture_stdio'),
                    mock.patch.object(wsgi, 'run_server')):
            rc = wsgi.run_wsgi('conf_file', 'app_section')
        self.assertEqual(calls['_initrp'], 1)
        self.assertEqual(calls['_loadapp'], 0)
        self.assertEqual(rc, 1)
Example #5
0
    def test_run_server_success(self):
        calls = defaultdict(lambda: 0)

        def _initrp(conf_file, app_section, *args, **kwargs):
            calls['_initrp'] += 1
            return ({'__file__': 'test', 'workers': 0}, 'logger', 'log_name')

        def _loadapp(uri, name=None, **kwargs):
            calls['_loadapp'] += 1

        with nested(mock.patch.object(wsgi, '_initrp', _initrp),
                    mock.patch.object(wsgi, 'get_socket'),
                    mock.patch.object(wsgi, 'drop_privileges'),
                    mock.patch.object(wsgi, 'loadapp', _loadapp),
                    mock.patch.object(wsgi, 'capture_stdio'),
                    mock.patch.object(wsgi, 'run_server')):
            rc = wsgi.run_wsgi('conf_file', 'app_section')
        self.assertEqual(calls['_initrp'], 1)
        self.assertEqual(calls['_loadapp'], 1)
        self.assertEqual(rc, 0)
Example #6
0
    def test_run_server_failure1(self):
        calls = defaultdict(lambda: 0)

        def _initrp(conf_file, app_section, *args, **kwargs):
            calls['_initrp'] += 1
            raise wsgi.ConfigFileError('test exception')

        def _loadapp(uri, name=None, **kwargs):
            calls['_loadapp'] += 1

        with nested(
                mock.patch.object(wsgi, '_initrp', _initrp),
                mock.patch.object(wsgi, 'get_socket'),
                mock.patch.object(wsgi, 'drop_privileges'),
                mock.patch.object(wsgi, 'loadapp', _loadapp),
                mock.patch.object(wsgi, 'capture_stdio'),
                mock.patch.object(wsgi, 'run_server')):
            rc = wsgi.run_wsgi('conf_file', 'app_section')
        self.assertEqual(calls['_initrp'], 1)
        self.assertEqual(calls['_loadapp'], 0)
        self.assertEqual(rc, 1)
Example #7
0
    def test_run_server_failure1(self):
        calls = defaultdict(lambda: 0)

        def _initrp(conf_file, app_section, *args, **kwargs):
            calls["_initrp"] += 1
            raise wsgi.ConfigFileError("test exception")

        def _loadapp(uri, name=None, **kwargs):
            calls["_loadapp"] += 1

        with nested(
            mock.patch.object(wsgi, "_initrp", _initrp),
            mock.patch.object(wsgi, "get_socket"),
            mock.patch.object(wsgi, "drop_privileges"),
            mock.patch.object(wsgi, "loadapp", _loadapp),
            mock.patch.object(wsgi, "capture_stdio"),
            mock.patch.object(wsgi, "run_server"),
        ):
            rc = wsgi.run_wsgi("conf_file", "app_section")
        self.assertEqual(calls["_initrp"], 1)
        self.assertEqual(calls["_loadapp"], 0)
        self.assertEqual(rc, 1)
Example #8
0
    def test_run_server_success(self):
        calls = defaultdict(lambda: 0)

        def _initrp(conf_file, app_section, *args, **kwargs):
            calls["_initrp"] += 1
            return ({"__file__": "test", "workers": 0}, "logger", "log_name")

        def _loadapp(uri, name=None, **kwargs):
            calls["_loadapp"] += 1

        with nested(
            mock.patch.object(wsgi, "_initrp", _initrp),
            mock.patch.object(wsgi, "get_socket"),
            mock.patch.object(wsgi, "drop_privileges"),
            mock.patch.object(wsgi, "loadapp", _loadapp),
            mock.patch.object(wsgi, "capture_stdio"),
            mock.patch.object(wsgi, "run_server"),
        ):
            rc = wsgi.run_wsgi("conf_file", "app_section")
        self.assertEqual(calls["_initrp"], 1)
        self.assertEqual(calls["_loadapp"], 1)
        self.assertEqual(rc, 0)
Example #9
0
    def test_run_server_success(self):
        calls = defaultdict(lambda: 0)

        def _initrp(conf_file, app_section, *args, **kwargs):
            calls['_initrp'] += 1
            return (
                {'__file__': 'test', 'workers': 0},
                'logger',
                'log_name')

        def _loadapp(uri, name=None, **kwargs):
            calls['_loadapp'] += 1

        with nested(
                mock.patch.object(wsgi, '_initrp', _initrp),
                mock.patch.object(wsgi, 'get_socket'),
                mock.patch.object(wsgi, 'drop_privileges'),
                mock.patch.object(wsgi, 'loadapp', _loadapp),
                mock.patch.object(wsgi, 'capture_stdio'),
                mock.patch.object(wsgi, 'run_server')):
            rc = wsgi.run_wsgi('conf_file', 'app_section')
        self.assertEqual(calls['_initrp'], 1)
        self.assertEqual(calls['_loadapp'], 1)
        self.assertEqual(rc, 0)
Example #10
0
from os.path import isfile

import sys
from swift.common.utils import parse_options
from swift.common.wsgi import run_wsgi

pass  # (clac) print 'Number of arguments:', len(sys.argv), 'arguments.'
pass  # (clac) print 'Argument List:', str(sys.argv)

if __name__ == '__main__':
    conf_file, options = parse_options()
    conf = 'proxy-server.conf'
    if len(sys.argv) >= 2 and isfile(sys.argv[1]):
        conf = sys.argv[1]
    run_wsgi(conf, 'proxy-server')
Example #11
0
import sys
from swift.common.utils import parse_options
from swift.common.wsgi import run_wsgi

if __name__ == '__main__':
    conf_file, options = parse_options()
    sys.exit(run_wsgi(conf_file, 'proxy-server', **options))
Example #12
0
def start_daemon(conf_file='/etc/swift/proxy-server.conf', options={}):
    run_wsgi(conf_file, 'proxy-server', **options)
Example #13
0
#!/usr/bin/python
# Copyright (c) 2010-2011 OpenStack, LLC.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#    http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT 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 swift.common.utils import parse_options
from swift.common.wsgi import run_wsgi

if __name__ == '__main__':
    conf_file, options = parse_options()
    run_wsgi(conf_file, 'proxy-server', default_port=8080, **options)
Example #14
0
def start_daemon(conf_file='/etc/swift/proxy-server.conf', options={}):
    run_wsgi(conf_file, 'proxy-server', **options)
Example #15
0

def run_objgraph(types):
    import objgraph
    import os
    import random
    objgraph.show_most_common_types(limit=50, shortnames=False)
    for type_ in types:
        count = objgraph.count(type_)
        print '%s objects: %d' % (type_, count)
        if count:
            objgraph.show_backrefs(
                random.choice(objgraph.by_type(type_)), max_depth=20,
                filename='/tmp/backrefs_%s_%d.dot' % (type_, os.getpid()))


if __name__ == '__main__':
    parser = OptionParser(usage="%prog CONFIG [options]")
    parser.add_option('--objgraph', action='store_true',
                      help=('Run objgraph, show most common '
                            'types before exiting'))
    parser.add_option('--show-backrefs', action='append', default=list(),
                      help=('Draw backreference graph for one randomly '
                            'chosen object of that type. Can be used '
                            'multiple times.'))
    conf_file, options = parse_options(parser)
    res = run_wsgi(conf_file, 'proxy-server', **options)
    if options.get('objgraph'):
        run_objgraph(options.get('show_backrefs', list()))
    sys.exit(res)
#!/usr/bin/env python
# Copyright (c) 2014 OpenStack Foundation
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#    http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
# implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import sys
from swift.common.utils import parse_options
from swift.common import utils

utils.SWIFT_CONF_FILE = 'conf/swift.conf'

from swift.common.wsgi import run_wsgi

if __name__ == '__main__':
    server = sys.argv.pop(1)
    port = sys.argv.pop(1)
    conf_file, options = parse_options()
    sys.exit(run_wsgi(conf_file, server + '-server', default_port=port,
                      **options))
Example #17
0
#!/usr/bin/env python
# Copyright (c) 2014 OpenStack Foundation
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#    http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
# implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import sys
from swift.common.utils import parse_options
from swift.common import utils

utils.SWIFT_CONF_FILE = 'conf/swift.conf'

from swift.common.wsgi import run_wsgi

if __name__ == '__main__':
    server = sys.argv.pop(1)
    port = sys.argv.pop(1)
    conf_file, options = parse_options()
    sys.exit(
        run_wsgi(conf_file, server + '-server', default_port=port, **options))