Commit ad31af17 authored by Daniele Venzano's avatar Daniele Venzano

Add some configuration sanity checking at startup

parent 1578fbfb
......@@ -34,6 +34,13 @@ log = logging.getLogger("zoe_api")
LOG_FORMAT = '%(asctime)-15s %(levelname)s %(threadName)s->%(name)s: %(message)s'
def _check_configuration_sanity():
if config.get_conf().auth_type == 'ldap' and not zoe_api.auth.ldap.LDAP_AVAILABLE:
log.error("LDAP authentication requested, but 'pyldap' module not installed.")
return 1
return 0
def zoe_web_main() -> int:
"""
This is the entry point for the Zoe Web script.
......@@ -46,9 +53,9 @@ def zoe_web_main() -> int:
else:
logging.basicConfig(level=logging.INFO, format=LOG_FORMAT)
if config.get_conf().auth_type == 'ldap' and not zoe_api.auth.ldap.LDAP_AVAILABLE:
log.error("LDAP authentication requested, but 'pyldap' module not installed.")
return 1
ret = _check_configuration_sanity()
if ret != 0:
return ret
zoe_api.db_init.init()
......
......@@ -48,7 +48,7 @@ def gen_environment(service: Service, execution: Execution):
def _create_logs_directories(exec_id, service_name):
path = get_conf().logs_base_path + '/' + get_conf().deployment_name + str(exec_id) + '/' + service_name
path = get_conf().logs_base_path + '/' + get_conf().deployment_name + '/' + str(exec_id) + '/' + service_name
try:
os.makedirs(path)
except OSError as e:
......
......@@ -23,8 +23,10 @@ from zoe_lib.state import Execution, Service
from zoe_master.backends.base import BaseBackend
from zoe_master.backends.old_swarm.backend import OldSwarmBackend
import zoe_master.backends.old_swarm.api_client
from zoe_master.backends.old_swarm_new_api.backend import OldSwarmNewAPIBackend
from zoe_master.exceptions import ZoeStartExecutionFatalException, ZoeStartExecutionRetryException
import zoe_master.backends.old_swarm_new_api.api_client
from zoe_master.exceptions import ZoeStartExecutionFatalException, ZoeStartExecutionRetryException, ZoeException
log = logging.getLogger(__name__)
......@@ -33,8 +35,12 @@ def _get_backend() -> BaseBackend:
"""Return the right backend instance by reading the global configuration."""
backend_name = get_conf().backend
if backend_name == 'OldSwarm':
if not zoe_master.backends.old_swarm.api_client.AVAILABLE:
raise ZoeException('The OldSwarm backend requires docker-py version <= 1.10.2')
return OldSwarmBackend(get_conf())
elif backend_name == 'OldSwarmNewAPI':
if not zoe_master.backends.old_swarm_new_api.api_client.AVAILABLE:
raise ZoeException('The OldSwarmNewAPI backend requires docker python version >= 2.0.2')
return OldSwarmNewAPIBackend(get_conf())
else:
log.error('Unknown backend selected')
......
......@@ -32,12 +32,17 @@ try:
except ImportError:
KazooClient = None
AVAILABLE = True
try:
import docker
import docker.errors
import docker.utils
except ImportError:
pass
AVAILABLE = False
try:
docker.Client()
except:
AVAILABLE = False
import requests.packages
......@@ -148,9 +153,13 @@ class SwarmClient:
self.opts = opts
url = opts.swarm
if 'zk://' in url:
if KazooClient is None:
raise ZoeLibException('ZooKeeper URL for Swarm, but the kazoo package is not installed')
url = url[len('zk://'):]
manager = zookeeper_swarm(url, opts.backend_swarm_zk_path)
elif 'consul://' in url:
if Consul is None:
raise ZoeLibException('Consul URL for Swarm, but the consul package is not installed')
url = url[len('consul://'):]
manager = consul_swarm(url)
elif 'http://' or 'https://' in url:
......
......@@ -32,12 +32,18 @@ try:
except ImportError:
KazooClient = None
AVAILABLE = True
try:
import docker
import docker.errors
import docker.utils
except ImportError:
pass
AVAILABLE = False
else:
try:
docker.DockerClient()
except:
AVAILABLE = False
import requests.packages
......@@ -290,6 +296,9 @@ class SwarmClient:
elif container.status == 'OOMKilled' or container.status == 'exited':
info["state"] = "killed"
info["running"] = False
elif container.status == 'created':
info["state"] = 'created'
info["running"] = False
else:
log.error('Unknown container status: {}'.format(container.status))
info["state"] = "unknown"
......
......@@ -20,11 +20,11 @@ import logging
from zoe_lib.config import get_conf
from zoe_lib.exceptions import ZoeLibException, ZoeNotEnoughResourcesException
from zoe_lib.state import Execution, Service
from zoe_master.backends.old_swarm.api_client import DockerContainerOptions, SwarmClient
from zoe_master.backends.old_swarm_new_api.api_client import DockerContainerOptions, SwarmClient
from zoe_master.exceptions import ZoeStartExecutionRetryException, ZoeStartExecutionFatalException, ZoeException
import zoe_master.backends.common
import zoe_master.backends.base
from zoe_master.backends.old_swarm.threads import SwarmMonitor, SwarmStateSynchronizer
from zoe_master.backends.old_swarm_new_api.threads import SwarmMonitor, SwarmStateSynchronizer
from zoe_master.stats import NodeStats, ClusterStats # pylint: disable=unused-import
log = logging.getLogger(__name__)
......
......@@ -21,7 +21,7 @@ import time
from zoe_lib.config import get_conf
from zoe_lib.state import SQLManager, Service
from zoe_master.backends.old_swarm.api_client import SwarmClient
from zoe_master.backends.old_swarm_new_api.api_client import SwarmClient
log = logging.getLogger(__name__)
......
......@@ -18,6 +18,7 @@
"""Zoe Master main entrypoint."""
import logging
import os
import zoe_lib.config as config
from zoe_lib.metrics.influxdb import InfluxDBMetricSender
......@@ -28,11 +29,19 @@ import zoe_master.scheduler
import zoe_master.backends.interface
from zoe_master.preprocessing import restart_resubmit_scheduler
from zoe_master.master_api import APIManager
from zoe_master.exceptions import ZoeException
log = logging.getLogger("main")
LOG_FORMAT = '%(asctime)-15s %(levelname)s %(threadName)s->%(name)s: %(message)s'
def _check_configuration_sanity():
if not os.access(config.get_conf().logs_base_path, os.W_OK):
log.error('Logs directory {} is not writable'.format(config.get_conf().logs_base_path))
return 1
return 0
def main():
"""
The entrypoint for the zoe-master script.
......@@ -42,10 +51,13 @@ def main():
args = config.get_conf()
if args.debug:
logging.basicConfig(level=logging.DEBUG, format=LOG_FORMAT)
else:
logging.basicConfig(level=logging.INFO, format=LOG_FORMAT)
ret = _check_configuration_sanity()
if ret != 0:
return ret
if config.get_conf().influxdb_enable:
metrics = InfluxDBMetricSender(config.get_conf().deployment_name, config.get_conf().influxdb_url, config.get_conf().influxdb_dbname)
else:
......@@ -57,7 +69,11 @@ def main():
log.info("Initializing scheduler")
scheduler = getattr(zoe_master.scheduler, config.get_conf().scheduler_class)(state, config.get_conf().scheduler_policy)
zoe_master.backends.interface.initialize_backend(state)
try:
zoe_master.backends.interface.initialize_backend(state)
except ZoeException as e:
log.error('Cannot initialize backend: {}'.format(e.message))
return 1
restart_resubmit_scheduler(state, scheduler)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment