aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNeil Williams <neil.williams@linaro.org>2018-05-22 18:32:22 +0100
committerSenthil Kumaran S <senthil.kumaran@linaro.org>2018-05-23 08:33:19 +0530
commit4a4bde2a18651806fd2be816ae7f403fc007dd4d (patch)
tree912d9dbe232e3b55c0b79adfe071c1bc4db3015f
parent6f50e11453ffc4a25fa93381cb2d9f38dbe6d055 (diff)
LAVA-999 Export master and logger config
Export details of the lava-master and lava-logs config to support auto-configuration. Change-Id: I9d539edd5ceaa169c79685110a9f601083c95a2e
-rw-r--r--lava_server/__init__.py26
-rw-r--r--lava_server/api.py75
-rw-r--r--lava_server/management/commands/lava-logs.py7
-rw-r--r--lava_server/management/commands/lava-master.py5
4 files changed, 85 insertions, 28 deletions
diff --git a/lava_server/__init__.py b/lava_server/__init__.py
index 7127fb400..e69de29bb 100644
--- a/lava_server/__init__.py
+++ b/lava_server/__init__.py
@@ -1,26 +0,0 @@
-# Copyright (C) 2010, 2011 Linaro Limited
-#
-# Author: Zygmunt Krynicki <zygmunt.krynicki@linaro.org>
-#
-# This file is part of LAVA Server.
-#
-# LAVA Server is free software: you can redistribute it and/or modify
-# it under the terms of the GNU Affero General Public License version 3
-# as published by the Free Software Foundation
-#
-# LAVA Server is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU Affero General Public License
-# along with LAVA Server. If not, see <http://www.gnu.org/licenses/>.
-
-"""
-lava_server
-===========
-
-The LAVA server package. Contains only the version declaration.
-"""
-
-__version__ = (0, 22, 0, "final", 0)
diff --git a/lava_server/api.py b/lava_server/api.py
index b783a13ee..b67f1f184 100644
--- a/lava_server/api.py
+++ b/lava_server/api.py
@@ -23,7 +23,7 @@ import xmlrpc.client
import yaml
from django.http import Http404
-
+from django.conf import settings
from django.core.exceptions import PermissionDenied
from lava_scheduler_app.views import get_restricted_job
from lava_scheduler_app.models import Device, DeviceType
@@ -121,6 +121,79 @@ class LavaSystemAPI(SystemAPI):
"""
return 2
+ def master_config(self):
+ """
+ Name
+ ----
+ `master_config` ()
+
+ Description
+ -----------
+ Return a dictionary containing the master and logger ZMQ
+ socket addresses for this instance.
+
+ Arguments
+ ---------
+ None
+
+ Return value
+ ------------
+ Returns a dictionary containing the following keys:
+ {
+ "MASTER_URL": "tcp://<lava-master-dns>:5556",
+ "LOGGING_URL": "tcp://<lava-master-dns>:5555",
+ "ENCRYPT": False,
+ "IPv6": False,
+ "EVENT_SOCKET": "tcp://*:5500",
+ "EVENT_TOPIC": "org.linaro.validation",
+ "EVENT_NOTIFICATION": True,
+ "LOG_SIZE_LIMIT": 10,
+ }
+
+ If ENCRYPT is True, clients MUST already have a usable
+ client certificate installed on the master AND the current
+ master certificate installed on the client, before a
+ connection can be made.
+ """
+ data = {
+ "master_socket": "tcp://<lava-master-dns>:5556",
+ "socket": "tcp://<lava-master-dns>:5555",
+ "encrypt": False,
+ "ipv6": False,
+ }
+
+ master = {"ERROR": "invalid master config"}
+ filename = os.path.join(settings.MEDIA_ROOT, 'lava-master-config.yaml')
+ if os.path.exists(filename):
+ try:
+ with open(filename, 'r') as output:
+ master = yaml.load(output)
+ except yaml.YAMLError as exc:
+ return master
+ if master:
+ data.update(master)
+
+ log_config = {"ERROR": "invalid logging config"}
+ filename = os.path.join(settings.MEDIA_ROOT, 'lava-logs-config.yaml')
+ if os.path.exists(filename):
+ try:
+ with open(filename, 'r') as output:
+ log_config = yaml.load(output)
+ except yaml.YAMLError as exc:
+ return log_config
+ if log_config:
+ data.update(log_config)
+ return {
+ "MASTER_URL": data['master_socket'],
+ "LOGGING_URL": data['socket'],
+ "IPv6": data['ipv6'],
+ "ENCRYPT": data.get('encrypt', False),
+ "EVENT_TOPIC": settings.EVENT_TOPIC,
+ "EVENT_SOCKET": settings.EVENT_SOCKET,
+ "EVENT_NOTIFICATION": settings.EVENT_NOTIFICATION,
+ "LOG_SIZE_LIMIT": settings.LOG_SIZE_LIMIT,
+ }
+
def user_can_view_jobs(self, job_list, username=None):
"""
Name
diff --git a/lava_server/management/commands/lava-logs.py b/lava_server/management/commands/lava-logs.py
index 065c087b1..ce291bf69 100644
--- a/lava_server/management/commands/lava-logs.py
+++ b/lava_server/management/commands/lava-logs.py
@@ -28,7 +28,7 @@ import zmq
import zmq.auth
from zmq.utils.strtypes import u
from zmq.auth.thread import ThreadAuthenticator
-
+from django.conf import settings
from django.db import connection, transaction
from django.db.utils import OperationalError, InterfaceError
@@ -115,6 +115,11 @@ class Command(LAVADaemonCommand):
self.logger.error("[INIT] Unable to drop privileges")
return
+ filename = os.path.join(settings.MEDIA_ROOT, 'lava-logs-config.yaml')
+ self.logger.debug("[INIT] Dumping config to %s", filename)
+ with open(filename, 'w') as output:
+ yaml.dump(options, output)
+
# Create the sockets
context = zmq.Context()
self.log_socket = context.socket(zmq.PULL)
diff --git a/lava_server/management/commands/lava-master.py b/lava_server/management/commands/lava-master.py
index 7c798f4fe..20ebfa97e 100644
--- a/lava_server/management/commands/lava-master.py
+++ b/lava_server/management/commands/lava-master.py
@@ -536,6 +536,11 @@ class Command(LAVADaemonCommand):
self.logger.error("[INIT] Unable to drop privileges")
return
+ filename = os.path.join(settings.MEDIA_ROOT, 'lava-master-config.yaml')
+ self.logger.debug("[INIT] Dumping config to %s", filename)
+ with open(filename, 'w') as output:
+ yaml.dump(options, output)
+
self.logger.info("[INIT] Marking all workers as offline")
with transaction.atomic():
for worker in Worker.objects.select_for_update().all():