blob: eb018eb3cffad0894b03dba503eca5746d994d3b [file] [log] [blame]
Julie Pichond1017642013-07-24 16:37:23 +01001# All Rights Reserved.
2#
3# Licensed under the Apache License, Version 2.0 (the "License"); you may
4# not use this file except in compliance with the License. You may obtain
5# a copy of the License at
6#
7# http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12# License for the specific language governing permissions and limitations
13# under the License.
14
Matthew Treinish89128142015-04-23 10:44:30 -040015from six.moves import html_parser as HTMLParser
16from six.moves.urllib import parse
17from six.moves.urllib import request
Julie Pichond1017642013-07-24 16:37:23 +010018
Matthew Treinish6c072292014-01-29 19:15:52 +000019from tempest import config
Julie Pichond1017642013-07-24 16:37:23 +010020from tempest.scenario import manager
Masayuki Igawa4ded9f02014-02-17 15:05:59 +090021from tempest import test
Julie Pichond1017642013-07-24 16:37:23 +010022
Matthew Treinish6c072292014-01-29 19:15:52 +000023CONF = config.CONF
24
Julie Pichond1017642013-07-24 16:37:23 +010025
Sean Dague8fa6c032014-11-25 10:54:38 -050026class HorizonHTMLParser(HTMLParser.HTMLParser):
27 csrf_token = None
28 region = None
29
30 def _find_name(self, attrs, name):
31 for attrpair in attrs:
32 if attrpair[0] == 'name' and attrpair[1] == name:
33 return True
34 return False
35
36 def _find_value(self, attrs):
37 for attrpair in attrs:
38 if attrpair[0] == 'value':
39 return attrpair[1]
40 return None
41
42 def handle_starttag(self, tag, attrs):
43 if tag == 'input':
44 if self._find_name(attrs, 'csrfmiddlewaretoken'):
45 self.csrf_token = self._find_value(attrs)
46 if self._find_name(attrs, 'region'):
47 self.region = self._find_value(attrs)
48
49
Masayuki Igawa2675f8f2014-07-17 13:46:26 +020050class TestDashboardBasicOps(manager.ScenarioTest):
Julie Pichond1017642013-07-24 16:37:23 +010051
52 """
53 This is a basic scenario test:
54 * checks that the login page is available
55 * logs in as a regular user
56 * checks that the user home page loads without error
57 """
58
59 @classmethod
Emily Hugenbruch5e2d2a22015-02-25 21:35:45 +000060 def skip_checks(cls):
61 super(TestDashboardBasicOps, cls).skip_checks()
Matthew Treinish6c072292014-01-29 19:15:52 +000062 if not CONF.service_available.horizon:
Julie Pichond1017642013-07-24 16:37:23 +010063 raise cls.skipException("Horizon support is required")
Emily Hugenbruch5e2d2a22015-02-25 21:35:45 +000064
65 @classmethod
66 def setup_credentials(cls):
Masayuki Igawa60ea6c52014-10-15 17:32:14 +090067 cls.set_network_resources()
Emily Hugenbruch5e2d2a22015-02-25 21:35:45 +000068 super(TestDashboardBasicOps, cls).setup_credentials()
Julie Pichond1017642013-07-24 16:37:23 +010069
70 def check_login_page(self):
Matthew Treinish89128142015-04-23 10:44:30 -040071 response = request.urlopen(CONF.dashboard.dashboard_url)
Thomas Bechtold44587492015-02-09 10:04:03 +010072 self.assertIn("id_username", response.read())
Julie Pichond1017642013-07-24 16:37:23 +010073
Matthew Treinish643f4c62014-12-12 19:54:34 -050074 def user_login(self, username, password):
Matthew Treinish89128142015-04-23 10:44:30 -040075 self.opener = request.build_opener(request.HTTPCookieProcessor())
Matthew Treinish6c072292014-01-29 19:15:52 +000076 response = self.opener.open(CONF.dashboard.dashboard_url).read()
Julie Pichond1017642013-07-24 16:37:23 +010077
78 # Grab the CSRF token and default region
Sean Dague8fa6c032014-11-25 10:54:38 -050079 parser = HorizonHTMLParser()
80 parser.feed(response)
Julie Pichond1017642013-07-24 16:37:23 +010081
82 # Prepare login form request
Matthew Treinish89128142015-04-23 10:44:30 -040083 req = request.Request(CONF.dashboard.login_url)
Julie Pichond1017642013-07-24 16:37:23 +010084 req.add_header('Content-type', 'application/x-www-form-urlencoded')
Matthew Treinish6c072292014-01-29 19:15:52 +000085 req.add_header('Referer', CONF.dashboard.dashboard_url)
Matthew Treinish643f4c62014-12-12 19:54:34 -050086 params = {'username': username,
87 'password': password,
Sean Dague8fa6c032014-11-25 10:54:38 -050088 'region': parser.region,
89 'csrfmiddlewaretoken': parser.csrf_token}
Matthew Treinish89128142015-04-23 10:44:30 -040090 self.opener.open(req, parse.urlencode(params))
Julie Pichond1017642013-07-24 16:37:23 +010091
92 def check_home_page(self):
Matthew Treinish6c072292014-01-29 19:15:52 +000093 response = self.opener.open(CONF.dashboard.dashboard_url)
Julie Pichond1017642013-07-24 16:37:23 +010094 self.assertIn('Overview', response.read())
95
Chris Hoge7579c1a2015-02-26 14:12:15 -080096 @test.idempotent_id('4f8851b1-0e69-482b-b63b-84c6e76f6c80')
Masayuki Igawa4ded9f02014-02-17 15:05:59 +090097 @test.services('dashboard')
Julie Pichond1017642013-07-24 16:37:23 +010098 def test_basic_scenario(self):
Andrea Frittolib21de6c2015-02-06 20:12:38 +000099 creds = self.os.credentials
Julie Pichond1017642013-07-24 16:37:23 +0100100 self.check_login_page()
Matthew Treinish643f4c62014-12-12 19:54:34 -0500101 self.user_login(creds.username, creds.password)
Julie Pichond1017642013-07-24 16:37:23 +0100102 self.check_home_page()