1 # Copyright (c) 2017 Cable Television Laboratories, Inc. ("CableLabs")
2 # and others. All rights reserved.
4 # Licensed under the Apache License, Version 2.0 (the "License");
5 # you may not use this file except in compliance with the License.
6 # You may obtain a copy of the License at:
8 # http://www.apache.org/licenses/LICENSE-2.0
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
17 from snaps.openstack.create_project import ProjectSettings
18 from snaps.openstack.create_user import UserSettings
19 from snaps.openstack.tests.os_source_file_test import OSComponentTestCase
20 from snaps.openstack.utils import keystone_utils
22 __author__ = 'spisarski'
25 class KeystoneSmokeTests(OSComponentTestCase):
27 Tests to ensure that the neutron client can communicate with the cloud
30 def test_keystone_connect_success(self):
32 Tests to ensure that the proper credentials can connect.
34 keystone = keystone_utils.keystone_client(self.os_creds)
36 users = keystone.users.list()
37 self.assertIsNotNone(users)
39 def test_keystone_connect_fail(self):
41 Tests to ensure that the improper credentials cannot connect.
43 from snaps.openstack.os_credentials import OSCreds
45 with self.assertRaises(Exception):
46 keystone = keystone_utils.keystone_client(OSCreds('user', 'pass', 'url', 'project'))
49 def test_get_endpoint_success(self):
51 Tests to ensure that proper credentials and proper service type can succeed.
53 endpoint = keystone_utils.get_endpoint(self.os_creds,
54 service_type="identity")
55 self.assertIsNotNone(endpoint)
57 def test_get_endpoint_fail_without_proper_service(self):
59 Tests to ensure that proper credentials and improper service type cannot succeed.
61 with self.assertRaises(Exception):
62 keystone_utils.get_endpoint(self.os_creds, service_type="glance")
64 def test_get_endpoint_fail_without_proper_credentials(self):
66 Tests to ensure that improper credentials and proper service type cannot succeed.
68 from snaps.openstack.os_credentials import OSCreds
70 with self.assertRaises(Exception):
71 keystone_utils.get_endpoint(
72 OSCreds('user', 'pass', 'url', 'project'),
76 class KeystoneUtilsTests(OSComponentTestCase):
78 Test for the CreateImage class defined in create_image.py
83 Instantiates the CreateImage object that is responsible for downloading and creating an OS image file
87 self.username = self.__class__.__name__ + '-' + str(guid)
90 self.project_name = self.__class__.__name__ + '-' + str(guid)
92 self.keystone = keystone_utils.keystone_client(self.os_creds)
96 Cleans the remote OpenStack objects
99 keystone_utils.delete_project(self.keystone, self.project)
102 keystone_utils.delete_user(self.keystone, self.user)
104 def test_create_user_minimal(self):
106 Tests the keystone_utils.create_user() function
108 user_settings = UserSettings(name=self.username, password='test123')
109 self.user = keystone_utils.create_user(self.keystone, user_settings)
110 self.assertEqual(self.username, self.user.name)
112 user = keystone_utils.get_user(self.keystone, self.username)
113 self.assertIsNotNone(user)
114 self.assertEqual(self.user, user)
116 def test_create_project_minimal(self):
118 Tests the keyston_utils.create_project() funtion
120 project_settings = ProjectSettings(name=self.project_name)
121 self.project = keystone_utils.create_project(self.keystone, project_settings)
122 self.assertEqual(self.project_name, self.project.name)
124 project = keystone_utils.get_project(keystone=self.keystone, project_name=project_settings.name)
125 self.assertIsNotNone(project)
126 self.assertEqual(self.project_name, self.project.name)