From 46d0ed8e8f4f6cb33decdd435b965a5088474fec Mon Sep 17 00:00:00 2001 From: Tobias Henkel Date: Wed, 12 Jun 2019 10:36:44 +0200 Subject: [PATCH] Move fingergw config to fingergw We currently read the config in the fingergw app and put the config into the fingergw object. This gets ugly when adding more config options so move evaluation of the config file into the FingerGateway class. This is a preparation for adding ssl support to the FingerGateway which will need more config options. Depends-On: https://review.opendev.org/663413 Change-Id: I83f3863586b85f8befd84eb8f6079fa35ee3a8cb --- tests/unit/test_component_registry.py | 10 ++++++--- tests/unit/test_streaming.py | 10 ++++++--- zuul/cmd/fingergw.py | 12 ----------- zuul/lib/fingergw.py | 31 ++++++++++++++++++--------- 4 files changed, 35 insertions(+), 28 deletions(-) diff --git a/tests/unit/test_component_registry.py b/tests/unit/test_component_registry.py index 4f3c936521..2af412c8e0 100644 --- a/tests/unit/test_component_registry.py +++ b/tests/unit/test_component_registry.py @@ -25,6 +25,7 @@ class TestComponentRegistry(ZuulTestCase): def setUp(self): super().setUp() + self.host = '::' self.zk_client = ZooKeeperClient( self.zk_chroot_fixture.zk_hosts, tls_cert=self.zk_chroot_fixture.zookeeper_cert, @@ -98,11 +99,14 @@ class TestComponentRegistry(ZuulTestCase): self.assertComponentStopped("merger") def test_fingergw_component(self): + self.config.read_dict({ + 'fingergw': { + 'listen_address': self.host, + 'port': '0', + } + }) gateway = FingerGateway( self.config, - ("127.0.0.1", self.gearman_server.port, None, None, None), - ("127.0.0.1", 0), - user=None, command_socket=None, pid_file=None ) diff --git a/tests/unit/test_streaming.py b/tests/unit/test_streaming.py index a3e31cc558..71f9d09d69 100644 --- a/tests/unit/test_streaming.py +++ b/tests/unit/test_streaming.py @@ -522,11 +522,15 @@ class TestStreaming(tests.base.AnsibleZuulTestCase): self.addCleanup(logfile.close) # Start the finger gateway daemon + self.config.read_dict({ + 'fingergw': { + 'listen_address': self.host, + 'port': '0', + } + }) + gateway = FingerGateway( self.config, - ('127.0.0.1', self.gearman_server.port, None, None, None), - (self.host, 0), - user=None, command_socket=None, pid_file=None ) diff --git a/zuul/cmd/fingergw.py b/zuul/cmd/fingergw.py index 3d09ac57e9..9497d7e859 100644 --- a/zuul/cmd/fingergw.py +++ b/zuul/cmd/fingergw.py @@ -59,24 +59,12 @@ class FingerGatewayApp(zuul.cmd.ZuulDaemonApp): self.setup_logging('fingergw', 'log_config') self.log = logging.getLogger('zuul.fingergw') - # Get values from configuration file - host = get_default(self.config, 'fingergw', 'listen_address', '::') - port = int(get_default(self.config, 'fingergw', 'port', 79)) - user = get_default(self.config, 'fingergw', 'user', None) cmdsock = get_default( self.config, 'fingergw', 'command_socket', '/var/lib/zuul/%s.socket' % self.app_name) - gear_server = get_default(self.config, 'gearman', 'server') - gear_port = get_default(self.config, 'gearman', 'port', 4730) - ssl_key = get_default(self.config, 'gearman', 'ssl_key') - ssl_cert = get_default(self.config, 'gearman', 'ssl_cert') - ssl_ca = get_default(self.config, 'gearman', 'ssl_ca') self.gateway = FingerGateway( self.config, - (gear_server, gear_port, ssl_key, ssl_cert, ssl_ca), - (host, port), - user, cmdsock, self.getPidFile(), ) diff --git a/zuul/lib/fingergw.py b/zuul/lib/fingergw.py index a3d25c8534..022c6c6f36 100644 --- a/zuul/lib/fingergw.py +++ b/zuul/lib/fingergw.py @@ -17,14 +17,16 @@ import logging import socket import threading from configparser import ConfigParser -from typing import Optional, Tuple +from typing import Optional import zuul.rpcclient from zuul.lib import streamer_utils from zuul.lib.commandsocket import CommandSocket +from zuul.lib.config import get_default from zuul.zk import ZooKeeperClient from zuul.zk.components import FingerGatewayComponent + COMMANDS = ['stop'] @@ -106,9 +108,6 @@ class FingerGateway(object): def __init__( self, config: ConfigParser, - gearman: Tuple, - address: Tuple, - user: Optional[str], command_socket: Optional[str], pid_file: Optional[str], ): @@ -124,12 +123,24 @@ class FingerGateway(object): :param str command_socket: Path to the daemon command socket. :param str pid_file: Path to the daemon PID file. ''' - self.gear_server = gearman[0] - self.gear_port = gearman[1] - self.gear_ssl_key = gearman[2] - self.gear_ssl_cert = gearman[3] - self.gear_ssl_ca = gearman[4] - self.address = address + + gear_server = get_default(config, 'gearman', 'server') + gear_port = get_default(config, 'gearman', 'port', 4730) + gear_ssl_key = get_default(config, 'gearman', 'ssl_key') + gear_ssl_cert = get_default(config, 'gearman', 'ssl_cert') + gear_ssl_ca = get_default(config, 'gearman', 'ssl_ca') + + self.gear_server = gear_server + self.gear_port = gear_port + self.gear_ssl_key = gear_ssl_key + self.gear_ssl_cert = gear_ssl_cert + self.gear_ssl_ca = gear_ssl_ca + + host = get_default(config, 'fingergw', 'listen_address', '::') + port = int(get_default(config, 'fingergw', 'port', 79)) + user = get_default(config, 'fingergw', 'user', None) + + self.address = (host, port) self.user = user self.pid_file = pid_file