From bddca37807e09fb2e7a42b710e1ecbde37391916 Mon Sep 17 00:00:00 2001 From: Ilya Etingof Date: Thu, 5 Mar 2020 18:29:23 +0100 Subject: [PATCH] Remove `vbmc` feature of starting up `vbmcd` Removes the backward compatibility feature of `vbmc` to automatically start up `vbmcd` daemon process if it is not running. From now on, `vbmcd` should be started by systemd or some other mechanism. Change-Id: I931751d7cdd591cae6f9a1bca8d72a4b3935a45f --- ...move-vbmcd-autostart-d1f567803526a4c1.yaml | 6 +++ virtualbmc/cmd/vbmc.py | 52 ++++--------------- virtualbmc/tests/unit/cmd/test_vbmc.py | 4 +- 3 files changed, 19 insertions(+), 43 deletions(-) create mode 100644 releasenotes/notes/remove-vbmcd-autostart-d1f567803526a4c1.yaml diff --git a/releasenotes/notes/remove-vbmcd-autostart-d1f567803526a4c1.yaml b/releasenotes/notes/remove-vbmcd-autostart-d1f567803526a4c1.yaml new file mode 100644 index 0000000..f70ea28 --- /dev/null +++ b/releasenotes/notes/remove-vbmcd-autostart-d1f567803526a4c1.yaml @@ -0,0 +1,6 @@ +--- +upgrade: + - | + Removes the backward compatibility feature of ``vbmc`` to automatically + start up ``vbmcd`` daemon process if it is not running. From now on, + ``vbmcd`` should be started by systemd or some other mechanism. diff --git a/virtualbmc/cmd/vbmc.py b/virtualbmc/cmd/vbmc.py index 6eb7cb8..5584d7f 100644 --- a/virtualbmc/cmd/vbmc.py +++ b/virtualbmc/cmd/vbmc.py @@ -13,7 +13,6 @@ import json import logging import sys -import time from cliff.app import App from cliff.command import Command @@ -23,11 +22,9 @@ from cliff.lister import Lister import zmq import virtualbmc -from virtualbmc.cmd import vbmcd from virtualbmc import config as vbmc_config from virtualbmc.exception import VirtualBMCError from virtualbmc import log -from virtualbmc import utils CONF = vbmc_config.get_config() @@ -78,49 +75,22 @@ class ZmqClient(object): poller = zmq.Poller() poller.register(socket, zmq.POLLIN) - while True: - try: - if data_out: - socket.send(data_out.encode('utf-8')) + try: + socket.send(data_out.encode('utf-8')) - socks = dict(poller.poll(timeout=self.SERVER_TIMEOUT)) - if socket in socks and socks[socket] == zmq.POLLIN: - data_in = socket.recv() - break + socks = dict(poller.poll(timeout=self.SERVER_TIMEOUT)) + if socket in socks and socks[socket] == zmq.POLLIN: + data_in = socket.recv() + else: raise zmq.ZMQError( zmq.RCVTIMEO, msg='Server response timed out') - except zmq.ZMQError as ex: - LOG.debug('Server at %(port)s connection error: ' - '%(error)s', {'port': server_port, 'error': ex}) - - if no_daemon: - msg = ('Server at %(port)s may be dead, will not ' - 'try to revive it' % {'port': server_port}) - LOG.error(msg) - raise VirtualBMCError(msg) - - no_daemon = True - - LOG.debug("Attempting to start `vbmcd` behind the " - "scenes. Consider configuring your system to " - "manage `vbmcd` via systemd. Automatic " - "`vbmcd` start up will be removed in the " - "future releases!") - - # attempt to start and daemonize the server - with utils.detach_process() as pid: - if pid == 0: - # NOTE(etingof): this child will never return - vbmcd.main(['--foreground']) - - # TODO(etingof): perform some more retries - time.sleep(CONF['default']['server_spawn_wait'] / 1000.) - - # MQ will deliver the original message to the daemon - # we've started - data_out = {} + except zmq.ZMQError as ex: + msg = ('Server at %(port)s connection error: ' + '%(error)s' % {'port': server_port, 'error': ex}) + LOG.error(msg) + raise VirtualBMCError(msg) finally: if socket: diff --git a/virtualbmc/tests/unit/cmd/test_vbmc.py b/virtualbmc/tests/unit/cmd/test_vbmc.py index e59ec3a..eec5dfe 100644 --- a/virtualbmc/tests/unit/cmd/test_vbmc.py +++ b/virtualbmc/tests/unit/cmd/test_vbmc.py @@ -36,8 +36,8 @@ class VBMCTestCase(base.TestCase): @mock.patch.object(zmq, 'Poller') def test_server_timeout(self, mock_zmq_poller, mock_zmq_context): expected_rc = 1 - expected_output = ('Server at 50891 may be dead, ' - 'will not try to revive it\n') + expected_output = ( + 'Server at 50891 connection error: Server response timed out\n') mock_zmq_poller = mock_zmq_poller.return_value mock_zmq_poller.poll.return_value = {}