Add verification if proxy works

In case if controller is online, but connectivity
on it is broken we receive false positive
message like "Can not set proxy". To fix this:
* Import of keystoneclient was added into config.py
* find_proxy method was added
* set proxy changed

Change-Id: I77d3c0ec12bc071a7e490ddb3ea24cd2f7fea543
Closes-Bug: #1355897
This commit is contained in:
Tatyana Leontovich 2015-01-05 17:32:58 +02:00
parent 1a0b2c6618
commit 0b75defeb2
2 changed files with 46 additions and 11 deletions

View File

@ -22,6 +22,7 @@ import sys
import traceback
import unittest2
import keystoneclient
from oslo.config import cfg
import requests
@ -185,6 +186,7 @@ def register_compute_opts(conf):
for opt in ComputeGroup:
conf.register_opt(opt, group='compute')
image_group = cfg.OptGroup(name='image',
title="Image Service Options")
@ -197,8 +199,8 @@ ImageGroup = [
help='Catalog type of the Image service.'),
cfg.StrOpt('http_image',
default='http://download.cirros-cloud.net/0.3.1/'
'cirros-0.3.1-x86_64-uec.tar.gz',
help='http accessible image')
'cirros-0.3.1-x86_64-uec.tar.gz',
help='http accessable image')
]
@ -239,6 +241,7 @@ def register_network_opts(conf):
for opt in NetworkGroup:
conf.register_opt(opt, group='network')
volume_group = cfg.OptGroup(name='volume',
title='Block Storage Options')
@ -300,6 +303,7 @@ def register_object_storage_opts(conf):
for opt in ObjectStoreConfig:
conf.register_opt(opt, group='object-storage')
sahara = cfg.OptGroup(name='sahara',
title='Sahara Service Options')
@ -431,9 +435,8 @@ class FileConfig(object):
path = os.path.join(conf_dir, conf_file)
if not (os.path.isfile(path) or
'FUEL_CONFIG_DIR' in os.environ or
'FUEL_CONFIG' in os.environ):
if not (os.path.isfile(path) or 'FUEL_CONFIG_DIR'
in os.environ or 'FUEL_CONFIG' in os.environ):
path = failsafe_path
LOG.info("Using fuel config file %s" % path)
@ -536,7 +539,7 @@ class NailgunConfig(object):
self._parse_cluster_generated_data()
LOG.info('parse generated successful')
except exceptions.SetProxy as exc:
raise exc
raise exc
except Exception:
LOG.warning('Something wrong with endpoints')
LOG.debug(traceback.format_exc())
@ -677,17 +680,43 @@ class NailgunConfig(object):
self.identity.url = data['horizon_url'] + 'dashboard'
self.identity.uri = data['keystone_url'] + 'v2.0/'
def find_proxy(self, ip):
endpoint = self.network.raw_data.get(
'public_vip', None) or ip
auth_url = 'http://{0}:{1}/{2}/'.format(endpoint, 5000, 'v2.0')
try:
os.environ['http_proxy'] = 'http://{0}:{1}'.format(ip, 8888)
LOG.warning('Try to check proxy on {0}'.format(ip))
keystoneclient.v2_0.client.Client(
username=self.identity.admin_username,
password=self.identity.admin_password,
tenant_name=self.identity.admin_tenant_name,
auth_url=auth_url,
insecure=False)
return ip
except Exception:
LOG.warning('Can not pass authorization '
'with proxy on {0}'.format(ip))
LOG.debug(traceback.format_exc())
def set_proxy(self):
"""Sets environment property for http_proxy:
To behave properly - method must be called after all nailgun params
is processed
"""
if self.compute.online_controllers:
os.environ['http_proxy'] = 'http://{0}:{1}'.format(
self.compute.online_controllers[0], 8888)
else:
if not self.compute.online_controllers:
raise exceptions.OfflineControllers()
proxies = [self.find_proxy(ip) for ip in
self.compute.online_controllers]
if not proxies:
raise exceptions.SetProxy()
os.environ['http_proxy'] = 'http://{0}:{1}'.format(proxies[0], 8888)
def set_endpoints(self):
public_vip = self.network.raw_data.get('public_vip', None)
# workaround for api without public_vip for ha mode

View File

@ -53,7 +53,13 @@ class InvalidConfiguration(FuelException):
class SetProxy(InvalidConfiguration):
message = ("Can not set proxy for Health Check."
"Make sure that controllers are online")
"Make sure that network configuration "
"for controllers is correct")
class OfflineControllers(InvalidConfiguration):
message = ('Can not check health of cluster.'
' All controllers are offline')
class RestClientException(FuelException,