Merge "Return an exit code for configuration errors"
This commit is contained in:
commit
4dfe31e69e
@ -14,9 +14,11 @@
|
|||||||
# See the License for the specific language governing permissions and
|
# See the License for the specific language governing permissions and
|
||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
|
|
||||||
|
import sys
|
||||||
from swift.common.utils import parse_options
|
from swift.common.utils import parse_options
|
||||||
from swift.common.wsgi import run_wsgi
|
from swift.common.wsgi import run_wsgi
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
conf_file, options = parse_options()
|
conf_file, options = parse_options()
|
||||||
run_wsgi(conf_file, 'account-server', default_port=6002, **options)
|
sys.exit(run_wsgi(conf_file,
|
||||||
|
'account-server', default_port=6002, **options))
|
||||||
|
@ -14,9 +14,11 @@
|
|||||||
# See the License for the specific language governing permissions and
|
# See the License for the specific language governing permissions and
|
||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
|
|
||||||
|
import sys
|
||||||
from swift.common.utils import parse_options
|
from swift.common.utils import parse_options
|
||||||
from swift.common.wsgi import run_wsgi
|
from swift.common.wsgi import run_wsgi
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
conf_file, options = parse_options()
|
conf_file, options = parse_options()
|
||||||
run_wsgi(conf_file, 'container-server', default_port=6001, **options)
|
sys.exit(run_wsgi(conf_file,
|
||||||
|
'container-server', default_port=6001, **options))
|
||||||
|
@ -14,6 +14,7 @@
|
|||||||
# See the License for the specific language governing permissions and
|
# See the License for the specific language governing permissions and
|
||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
|
|
||||||
|
import sys
|
||||||
from swift.common.utils import parse_options
|
from swift.common.utils import parse_options
|
||||||
from swift.common.wsgi import run_wsgi
|
from swift.common.wsgi import run_wsgi
|
||||||
from swift.obj import server
|
from swift.obj import server
|
||||||
@ -21,5 +22,6 @@ from swift.obj import server
|
|||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
conf_file, options = parse_options()
|
conf_file, options = parse_options()
|
||||||
run_wsgi(conf_file, 'object-server', default_port=6000,
|
sys.exit(run_wsgi(conf_file, 'object-server', default_port=6000,
|
||||||
global_conf_callback=server.global_conf_callback, **options)
|
global_conf_callback=server.global_conf_callback,
|
||||||
|
**options))
|
||||||
|
@ -14,9 +14,10 @@
|
|||||||
# See the License for the specific language governing permissions and
|
# See the License for the specific language governing permissions and
|
||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
|
|
||||||
|
import sys
|
||||||
from swift.common.utils import parse_options
|
from swift.common.utils import parse_options
|
||||||
from swift.common.wsgi import run_wsgi
|
from swift.common.wsgi import run_wsgi
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
conf_file, options = parse_options()
|
conf_file, options = parse_options()
|
||||||
run_wsgi(conf_file, 'proxy-server', default_port=8080, **options)
|
sys.exit(run_wsgi(conf_file, 'proxy-server', default_port=8080, **options))
|
||||||
|
@ -241,6 +241,7 @@ def run_wsgi(conf_path, app_section, *args, **kwargs):
|
|||||||
|
|
||||||
:param conf_path: Path to paste.deploy style configuration file/directory
|
:param conf_path: Path to paste.deploy style configuration file/directory
|
||||||
:param app_section: App name from conf file to load config from
|
:param app_section: App name from conf file to load config from
|
||||||
|
:returns: 0 if successful, nonzero otherwise
|
||||||
"""
|
"""
|
||||||
# Load configuration, Set logger and Load request processor
|
# Load configuration, Set logger and Load request processor
|
||||||
try:
|
try:
|
||||||
@ -248,7 +249,7 @@ def run_wsgi(conf_path, app_section, *args, **kwargs):
|
|||||||
_initrp(conf_path, app_section, *args, **kwargs)
|
_initrp(conf_path, app_section, *args, **kwargs)
|
||||||
except ConfigFileError as e:
|
except ConfigFileError as e:
|
||||||
print e
|
print e
|
||||||
return
|
return 1
|
||||||
|
|
||||||
# bind to address and port
|
# bind to address and port
|
||||||
sock = get_socket(conf, default_port=kwargs.get('default_port', 8080))
|
sock = get_socket(conf, default_port=kwargs.get('default_port', 8080))
|
||||||
@ -273,7 +274,7 @@ def run_wsgi(conf_path, app_section, *args, **kwargs):
|
|||||||
# Useful for profiling [no forks].
|
# Useful for profiling [no forks].
|
||||||
if worker_count == 0:
|
if worker_count == 0:
|
||||||
run_server(conf, logger, sock, global_conf=global_conf)
|
run_server(conf, logger, sock, global_conf=global_conf)
|
||||||
return
|
return 0
|
||||||
|
|
||||||
def kill_children(*args):
|
def kill_children(*args):
|
||||||
"""Kills the entire process group."""
|
"""Kills the entire process group."""
|
||||||
@ -300,7 +301,7 @@ def run_wsgi(conf_path, app_section, *args, **kwargs):
|
|||||||
signal.signal(signal.SIGTERM, signal.SIG_DFL)
|
signal.signal(signal.SIGTERM, signal.SIG_DFL)
|
||||||
run_server(conf, logger, sock)
|
run_server(conf, logger, sock)
|
||||||
logger.notice('Child %d exiting normally' % os.getpid())
|
logger.notice('Child %d exiting normally' % os.getpid())
|
||||||
return
|
return 0
|
||||||
else:
|
else:
|
||||||
logger.notice('Started child %s' % pid)
|
logger.notice('Started child %s' % pid)
|
||||||
children.append(pid)
|
children.append(pid)
|
||||||
@ -318,6 +319,7 @@ def run_wsgi(conf_path, app_section, *args, **kwargs):
|
|||||||
greenio.shutdown_safe(sock)
|
greenio.shutdown_safe(sock)
|
||||||
sock.close()
|
sock.close()
|
||||||
logger.notice('Exited')
|
logger.notice('Exited')
|
||||||
|
return 0
|
||||||
|
|
||||||
|
|
||||||
class ConfigFileError(Exception):
|
class ConfigFileError(Exception):
|
||||||
|
@ -538,6 +538,53 @@ class TestWSGI(unittest.TestCase):
|
|||||||
self.assertEqual(calls['_global_conf_callback'], 1)
|
self.assertEqual(calls['_global_conf_callback'], 1)
|
||||||
self.assertEqual(calls['_loadapp'], 1)
|
self.assertEqual(calls['_loadapp'], 1)
|
||||||
|
|
||||||
|
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)
|
||||||
|
|
||||||
|
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)
|
||||||
|
|
||||||
def test_pre_auth_req_with_empty_env_no_path(self):
|
def test_pre_auth_req_with_empty_env_no_path(self):
|
||||||
r = wsgi.make_pre_authed_request(
|
r = wsgi.make_pre_authed_request(
|
||||||
{}, 'GET')
|
{}, 'GET')
|
||||||
|
Loading…
Reference in New Issue
Block a user