allow non '/' root for dashboard

Currently, there is a hard coded value for the login url for the
dashboard in the tempest config. The root for dashboard needs to
be configurable in tempest as well. This patch allows construction
of the login url from information on the page and the hard-coded
url for the dashboard in the tempest config.

The main goal of this patch is a bridge between current use of '/'
and '/dashboard' for the horizon root in devstack. If desired, post
switch we can update the hardcoded value. And revert this patch.

Related change: I6fbca5cea9e44df160afbccc71bd045437657320

Change-Id: I9a04f936ed6d8c14775a332dc28e903992806c42
This commit is contained in:
David Lyle
2015-08-12 19:27:18 -06:00
parent 5eee9908e6
commit f0b070c012

View File

@@ -26,6 +26,7 @@ CONF = config.CONF
class HorizonHTMLParser(HTMLParser.HTMLParser):
csrf_token = None
region = None
login = None
def _find_name(self, attrs, name):
for attrpair in attrs:
@@ -39,12 +40,20 @@ class HorizonHTMLParser(HTMLParser.HTMLParser):
return attrpair[1]
return None
def _find_attr_value(self, attrs, attr_name):
for attrpair in attrs:
if attrpair[0] == attr_name:
return attrpair[1]
return None
def handle_starttag(self, tag, attrs):
if tag == 'input':
if self._find_name(attrs, 'csrfmiddlewaretoken'):
self.csrf_token = self._find_value(attrs)
if self._find_name(attrs, 'region'):
self.region = self._find_value(attrs)
if tag == 'form':
self.login = self._find_attr_value(attrs, 'action')
class TestDashboardBasicOps(manager.ScenarioTest):
@@ -79,8 +88,12 @@ class TestDashboardBasicOps(manager.ScenarioTest):
parser = HorizonHTMLParser()
parser.feed(response)
# construct login url for dashboard, discovery accomodates non-/ web
# root for dashboard
login_url = CONF.dashboard.dashboard_url + parser.login[1:]
# Prepare login form request
req = request.Request(CONF.dashboard.login_url)
req = request.Request(login_url)
req.add_header('Content-type', 'application/x-www-form-urlencoded')
req.add_header('Referer', CONF.dashboard.dashboard_url)
params = {'username': username,