diff options
| author | Matthew Treinish <treinish@linux.vnet.ibm.com> | 2013-02-27 15:30:07 -0500 |
|---|---|---|
| committer | Matthew Treinish <treinish@linux.vnet.ibm.com> | 2013-02-28 17:18:15 -0500 |
| commit | 0ce8d40cc47580d202c8b5fd25d263bff78f7e8d (patch) | |
| tree | 79ce561cc91503864a082b057eca423f7a91d1c5 /nova/api | |
| parent | 7be9e64fe20e4c45966bae63165ced4413af2605 (diff) | |
| download | nova-0ce8d40cc47580d202c8b5fd25d263bff78f7e8d.tar.gz nova-0ce8d40cc47580d202c8b5fd25d263bff78f7e8d.tar.xz nova-0ce8d40cc47580d202c8b5fd25d263bff78f7e8d.zip | |
Fallback coverage backdoor telnet connection to lo
This commit adds a fallback condition for the telnet connection.
If trying to establish a connection to the backdoor fails with
ECONNREFUSED the extension will then try to connect to the same
port on the lo device. Eventlet backdoors currently open on the
lo interface and this is to cover the common (and CI) use case
where the hostname doesn't resolve to 127.0.0.1.
Using the fallback was done to avoid adding a new config option
to specify that the hostname that is in the DB for the service
doesn't resolve to the lo device, and that the extension should
use just use localhost.
Change-Id: I0321db68cbccf0cddf13d91a77dfb744bb456d87
Diffstat (limited to 'nova/api')
| -rw-r--r-- | nova/api/openstack/compute/contrib/coverage_ext.py | 23 |
1 files changed, 20 insertions, 3 deletions
diff --git a/nova/api/openstack/compute/contrib/coverage_ext.py b/nova/api/openstack/compute/contrib/coverage_ext.py index 6eeb363f2..9e7ed1fe3 100644 --- a/nova/api/openstack/compute/contrib/coverage_ext.py +++ b/nova/api/openstack/compute/contrib/coverage_ext.py @@ -19,10 +19,12 @@ import os import re +import socket import sys import telnetlib import tempfile +from oslo.config import cfg from webob import exc from nova.api.openstack import extensions @@ -39,6 +41,7 @@ from nova.scheduler import rpcapi as scheduler_api LOG = logging.getLogger(__name__) authorize = extensions.extension_authorizer('compute', 'coverage_ext') +CONF = cfg.CONF class CoverageController(object): @@ -55,6 +58,7 @@ class CoverageController(object): self.services = [] self.combine = False self._cover_inst = None + self.host = CONF.host super(CoverageController, self).__init__() @property @@ -71,7 +75,7 @@ class CoverageController(object): def _find_services(self, req): """Returns a list of services.""" context = req.environ['nova.context'] - services = db.service_get_all(context, False) + services = db.service_get_all(context) hosts = [] for serv in services: hosts.append({"service": serv["topic"], "host": serv["host"]}) @@ -140,8 +144,21 @@ class CoverageController(object): ports = self._find_ports(req, hosts) self.services = [] for service in ports: - service['telnet'] = telnetlib.Telnet(service['host'], - service['port']) + try: + service['telnet'] = telnetlib.Telnet(service['host'], + service['port']) + # NOTE(mtreinish): Fallback to try connecting to lo if + # ECONNREFUSED is raised. If using the hostname that is returned + # for the service from the service_get_all() DB query raises + # ECONNREFUSED it most likely means that the hostname in the DB + # doesn't resolve to 127.0.0.1. Currently backdoors only open on + # loopback so this is for covering the common single host use case + except socket.error as e: + if 'ECONNREFUSED' in e and service['host'] == self.host: + service['telnet'] = telnetlib.Telnet('127.0.0.1', + service['port']) + else: + raise e self.services.append(service) self._start_coverage_telnet(service['telnet'], service['service']) |
