Best Python code snippet using tempest_python
test_verify_tempest_config.py
Source:test_verify_tempest_config.py
1# Copyright 2014 IBM Corp.2#3# Licensed under the Apache License, Version 2.0 (the "License"); you may4# not use this file except in compliance with the License. You may obtain5# a copy of the License at6#7# http://www.apache.org/licenses/LICENSE-2.08#9# Unless required by applicable law or agreed to in writing, software10# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT11# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the12# License for the specific language governing permissions and limitations13# under the License.14import json15import mock16from oslo.config import cfg17from tempest.cmd import verify_tempest_config18from tempest import config19from tempest.openstack.common.fixture import mockpatch20from tempest.tests import base21from tempest.tests import fake_config22class TestGetAPIVersions(base.TestCase):23 def test_url_grab_versioned_nova_nossl(self):24 base_url = 'http://127.0.0.1:8774/v2/'25 endpoint = verify_tempest_config._get_unversioned_endpoint(base_url)26 self.assertEqual('http://127.0.0.1:8774', endpoint)27 def test_url_grab_versioned_nova_ssl(self):28 base_url = 'https://127.0.0.1:8774/v3/'29 endpoint = verify_tempest_config._get_unversioned_endpoint(base_url)30 self.assertEqual('https://127.0.0.1:8774', endpoint)31class TestDiscovery(base.TestCase):32 def setUp(self):33 super(TestDiscovery, self).setUp()34 self.useFixture(fake_config.ConfigFixture())35 self.stubs.Set(config, 'TempestConfigPrivate', fake_config.FakePrivate)36 def test_get_keystone_api_versions(self):37 self.useFixture(mockpatch.PatchObject(38 verify_tempest_config, '_get_unversioned_endpoint',39 return_value='http://fake_endpoint:5000'))40 fake_resp = {'versions': {'values': [{'id': 'v2.0'}, {'id': 'v3.0'}]}}41 fake_resp = json.dumps(fake_resp)42 self.useFixture(mockpatch.PatchObject(43 verify_tempest_config.RAW_HTTP, 'request',44 return_value=(None, fake_resp)))45 fake_os = mock.MagicMock()46 versions = verify_tempest_config._get_api_versions(fake_os, 'keystone')47 self.assertIn('v2.0', versions)48 self.assertIn('v3.0', versions)49 def test_get_cinder_api_versions(self):50 self.useFixture(mockpatch.PatchObject(51 verify_tempest_config, '_get_unversioned_endpoint',52 return_value='http://fake_endpoint:5000'))53 fake_resp = {'versions': [{'id': 'v1.0'}, {'id': 'v2.0'}]}54 fake_resp = json.dumps(fake_resp)55 self.useFixture(mockpatch.PatchObject(56 verify_tempest_config.RAW_HTTP, 'request',57 return_value=(None, fake_resp)))58 fake_os = mock.MagicMock()59 versions = verify_tempest_config._get_api_versions(fake_os, 'cinder')60 self.assertIn('v1.0', versions)61 self.assertIn('v2.0', versions)62 def test_get_nova_versions(self):63 self.useFixture(mockpatch.PatchObject(64 verify_tempest_config, '_get_unversioned_endpoint',65 return_value='http://fake_endpoint:5000'))66 fake_resp = {'versions': [{'id': 'v2.0'}, {'id': 'v3.0'}]}67 fake_resp = json.dumps(fake_resp)68 self.useFixture(mockpatch.PatchObject(69 verify_tempest_config.RAW_HTTP, 'request',70 return_value=(None, fake_resp)))71 fake_os = mock.MagicMock()72 versions = verify_tempest_config._get_api_versions(fake_os, 'nova')73 self.assertIn('v2.0', versions)74 self.assertIn('v3.0', versions)75 def test_verify_api_versions(self):76 api_services = ['cinder', 'glance', 'keystone', 'nova']77 fake_os = mock.MagicMock()78 for svc in api_services:79 m = 'verify_%s_api_versions' % svc80 with mock.patch.object(verify_tempest_config, m) as verify_mock:81 verify_tempest_config.verify_api_versions(fake_os, svc, True)82 verify_mock.assert_called_once_with(fake_os, True)83 def test_verify_api_versions_not_implemented(self):84 api_services = ['cinder', 'glance', 'keystone', 'nova']85 fake_os = mock.MagicMock()86 for svc in api_services:87 m = 'verify_%s_api_versions' % svc88 with mock.patch.object(verify_tempest_config, m) as verify_mock:89 verify_tempest_config.verify_api_versions(fake_os, 'foo', True)90 self.assertFalse(verify_mock.called)91 def test_verify_keystone_api_versions_no_v3(self):92 self.useFixture(mockpatch.PatchObject(93 verify_tempest_config, '_get_unversioned_endpoint',94 return_value='http://fake_endpoint:5000'))95 fake_resp = {'versions': {'values': [{'id': 'v2.0'}]}}96 fake_resp = json.dumps(fake_resp)97 self.useFixture(mockpatch.PatchObject(98 verify_tempest_config.RAW_HTTP, 'request',99 return_value=(None, fake_resp)))100 fake_os = mock.MagicMock()101 with mock.patch.object(verify_tempest_config,102 'print_and_or_update') as print_mock:103 verify_tempest_config.verify_keystone_api_versions(fake_os, True)104 print_mock.assert_called_once_with('api_v3',105 'identity_feature_enabled',106 False, True)107 def test_verify_keystone_api_versions_no_v2(self):108 self.useFixture(mockpatch.PatchObject(109 verify_tempest_config, '_get_unversioned_endpoint',110 return_value='http://fake_endpoint:5000'))111 fake_resp = {'versions': {'values': [{'id': 'v3.0'}]}}112 fake_resp = json.dumps(fake_resp)113 self.useFixture(mockpatch.PatchObject(114 verify_tempest_config.RAW_HTTP, 'request',115 return_value=(None, fake_resp)))116 fake_os = mock.MagicMock()117 with mock.patch.object(verify_tempest_config,118 'print_and_or_update') as print_mock:119 verify_tempest_config.verify_keystone_api_versions(fake_os, True)120 print_mock.assert_called_once_with('api_v2',121 'identity_feature_enabled',122 False, True)123 def test_verify_cinder_api_versions_no_v2(self):124 self.useFixture(mockpatch.PatchObject(125 verify_tempest_config, '_get_unversioned_endpoint',126 return_value='http://fake_endpoint:5000'))127 fake_resp = {'versions': [{'id': 'v1.0'}]}128 fake_resp = json.dumps(fake_resp)129 self.useFixture(mockpatch.PatchObject(130 verify_tempest_config.RAW_HTTP, 'request',131 return_value=(None, fake_resp)))132 fake_os = mock.MagicMock()133 with mock.patch.object(verify_tempest_config,134 'print_and_or_update') as print_mock:135 verify_tempest_config.verify_cinder_api_versions(fake_os, True)136 print_mock.assert_called_once_with('api_v2', 'volume_feature_enabled',137 False, True)138 def test_verify_cinder_api_versions_no_v1(self):139 self.useFixture(mockpatch.PatchObject(140 verify_tempest_config, '_get_unversioned_endpoint',141 return_value='http://fake_endpoint:5000'))142 fake_resp = {'versions': [{'id': 'v2.0'}]}143 fake_resp = json.dumps(fake_resp)144 self.useFixture(mockpatch.PatchObject(145 verify_tempest_config.RAW_HTTP, 'request',146 return_value=(None, fake_resp)))147 fake_os = mock.MagicMock()148 with mock.patch.object(verify_tempest_config,149 'print_and_or_update') as print_mock:150 verify_tempest_config.verify_cinder_api_versions(fake_os, True)151 print_mock.assert_called_once_with('api_v1', 'volume_feature_enabled',152 False, True)153 def test_verify_nova_versions(self):154 cfg.CONF.set_default('api_v3', True, 'compute-feature-enabled')155 self.useFixture(mockpatch.PatchObject(156 verify_tempest_config, '_get_unversioned_endpoint',157 return_value='http://fake_endpoint:5000'))158 fake_resp = {'versions': [{'id': 'v2.0'}]}159 fake_resp = json.dumps(fake_resp)160 self.useFixture(mockpatch.PatchObject(161 verify_tempest_config.RAW_HTTP, 'request',162 return_value=(None, fake_resp)))163 fake_os = mock.MagicMock()164 with mock.patch.object(verify_tempest_config,165 'print_and_or_update') as print_mock:166 verify_tempest_config.verify_nova_api_versions(fake_os, True)167 print_mock.assert_called_once_with('api_v3', 'compute_feature_enabled',168 False, True)169 def test_verify_glance_version_no_v2_with_v1_1(self):170 def fake_get_versions():171 return (None, ['v1.1'])172 fake_os = mock.MagicMock()173 fake_os.image_client.get_versions = fake_get_versions174 with mock.patch.object(verify_tempest_config,175 'print_and_or_update') as print_mock:176 verify_tempest_config.verify_glance_api_versions(fake_os, True)177 print_mock.assert_called_once_with('api_v2', 'image_feature_enabled',178 False, True)179 def test_verify_glance_version_no_v2_with_v1_0(self):180 def fake_get_versions():181 return (None, ['v1.0'])182 fake_os = mock.MagicMock()183 fake_os.image_client.get_versions = fake_get_versions184 with mock.patch.object(verify_tempest_config,185 'print_and_or_update') as print_mock:186 verify_tempest_config.verify_glance_api_versions(fake_os, True)187 print_mock.assert_called_once_with('api_v2', 'image_feature_enabled',188 False, True)189 def test_verify_glance_version_no_v1(self):190 def fake_get_versions():191 return (None, ['v2.0'])192 fake_os = mock.MagicMock()193 fake_os.image_client.get_versions = fake_get_versions194 with mock.patch.object(verify_tempest_config,195 'print_and_or_update') as print_mock:196 verify_tempest_config.verify_glance_api_versions(fake_os, True)197 print_mock.assert_called_once_with('api_v1', 'image_feature_enabled',198 False, True)199 def test_verify_extensions_neutron(self):200 def fake_list_extensions():201 return (None, {'extensions': [{'alias': 'fake1'},202 {'alias': 'fake2'},203 {'alias': 'not_fake'}]})204 fake_os = mock.MagicMock()205 fake_os.network_client.list_extensions = fake_list_extensions206 self.useFixture(mockpatch.PatchObject(207 verify_tempest_config, 'get_enabled_extensions',208 return_value=(['fake1', 'fake2', 'fake3'])))209 results = verify_tempest_config.verify_extensions(fake_os,210 'neutron', {})211 self.assertIn('neutron', results)212 self.assertIn('fake1', results['neutron'])213 self.assertTrue(results['neutron']['fake1'])214 self.assertIn('fake2', results['neutron'])215 self.assertTrue(results['neutron']['fake2'])216 self.assertIn('fake3', results['neutron'])217 self.assertFalse(results['neutron']['fake3'])218 self.assertIn('not_fake', results['neutron'])219 self.assertFalse(results['neutron']['not_fake'])220 def test_verify_extensions_neutron_all(self):221 def fake_list_extensions():222 return (None, {'extensions': [{'alias': 'fake1'},223 {'alias': 'fake2'},224 {'alias': 'not_fake'}]})225 fake_os = mock.MagicMock()226 fake_os.network_client.list_extensions = fake_list_extensions227 self.useFixture(mockpatch.PatchObject(228 verify_tempest_config, 'get_enabled_extensions',229 return_value=(['all'])))230 results = verify_tempest_config.verify_extensions(fake_os,231 'neutron', {})232 self.assertIn('neutron', results)233 self.assertIn('extensions', results['neutron'])234 self.assertEqual(sorted(['fake1', 'fake2', 'not_fake']),235 sorted(results['neutron']['extensions']))236 def test_verify_extensions_cinder(self):237 def fake_list_extensions():238 return (None, {'extensions': [{'name': 'fake1'},239 {'name': 'fake2'},240 {'name': 'not_fake'}]})241 fake_os = mock.MagicMock()242 fake_os.volumes_extension_client.list_extensions = fake_list_extensions243 self.useFixture(mockpatch.PatchObject(244 verify_tempest_config, 'get_enabled_extensions',245 return_value=(['fake1', 'fake2', 'fake3'])))246 results = verify_tempest_config.verify_extensions(fake_os,247 'cinder', {})248 self.assertIn('cinder', results)249 self.assertIn('fake1', results['cinder'])250 self.assertTrue(results['cinder']['fake1'])251 self.assertIn('fake2', results['cinder'])252 self.assertTrue(results['cinder']['fake2'])253 self.assertIn('fake3', results['cinder'])254 self.assertFalse(results['cinder']['fake3'])255 self.assertIn('not_fake', results['cinder'])256 self.assertFalse(results['cinder']['not_fake'])257 def test_verify_extensions_cinder_all(self):258 def fake_list_extensions():259 return (None, {'extensions': [{'name': 'fake1'},260 {'name': 'fake2'},261 {'name': 'not_fake'}]})262 fake_os = mock.MagicMock()263 fake_os.volumes_extension_client.list_extensions = fake_list_extensions264 self.useFixture(mockpatch.PatchObject(265 verify_tempest_config, 'get_enabled_extensions',266 return_value=(['all'])))267 results = verify_tempest_config.verify_extensions(fake_os,268 'cinder', {})269 self.assertIn('cinder', results)270 self.assertIn('extensions', results['cinder'])271 self.assertEqual(sorted(['fake1', 'fake2', 'not_fake']),272 sorted(results['cinder']['extensions']))273 def test_verify_extensions_nova(self):274 def fake_list_extensions():275 return (None, {'extensions': [{'alias': 'fake1'},276 {'alias': 'fake2'},277 {'alias': 'not_fake'}]})278 fake_os = mock.MagicMock()279 fake_os.extensions_client.list_extensions = fake_list_extensions280 self.useFixture(mockpatch.PatchObject(281 verify_tempest_config, 'get_enabled_extensions',282 return_value=(['fake1', 'fake2', 'fake3'])))283 results = verify_tempest_config.verify_extensions(fake_os,284 'nova', {})285 self.assertIn('nova', results)286 self.assertIn('fake1', results['nova'])287 self.assertTrue(results['nova']['fake1'])288 self.assertIn('fake2', results['nova'])289 self.assertTrue(results['nova']['fake2'])290 self.assertIn('fake3', results['nova'])291 self.assertFalse(results['nova']['fake3'])292 self.assertIn('not_fake', results['nova'])293 self.assertFalse(results['nova']['not_fake'])294 def test_verify_extensions_nova_all(self):295 def fake_list_extensions():296 return (None, {'extensions': [{'alias': 'fake1'},297 {'alias': 'fake2'},298 {'alias': 'not_fake'}]})299 fake_os = mock.MagicMock()300 fake_os.extensions_client.list_extensions = fake_list_extensions301 self.useFixture(mockpatch.PatchObject(302 verify_tempest_config, 'get_enabled_extensions',303 return_value=(['all'])))304 results = verify_tempest_config.verify_extensions(fake_os,305 'nova', {})306 self.assertIn('nova', results)307 self.assertIn('extensions', results['nova'])308 self.assertEqual(sorted(['fake1', 'fake2', 'not_fake']),309 sorted(results['nova']['extensions']))310 def test_verify_extensions_nova_v3(self):311 def fake_list_extensions():312 return (None, {'extensions': [{'alias': 'fake1'},313 {'alias': 'fake2'},314 {'alias': 'not_fake'}]})315 fake_os = mock.MagicMock()316 fake_os.extensions_v3_client.list_extensions = fake_list_extensions317 self.useFixture(mockpatch.PatchObject(318 verify_tempest_config, 'get_enabled_extensions',319 return_value=(['fake1', 'fake2', 'fake3'])))320 results = verify_tempest_config.verify_extensions(fake_os,321 'nova_v3', {})322 self.assertIn('nova_v3', results)323 self.assertIn('fake1', results['nova_v3'])324 self.assertTrue(results['nova_v3']['fake1'])325 self.assertIn('fake2', results['nova_v3'])326 self.assertTrue(results['nova_v3']['fake2'])327 self.assertIn('fake3', results['nova_v3'])328 self.assertFalse(results['nova_v3']['fake3'])329 self.assertIn('not_fake', results['nova_v3'])330 self.assertFalse(results['nova_v3']['not_fake'])331 def test_verify_extensions_nova_v3_all(self):332 def fake_list_extensions():333 return (None, {'extensions': [{'alias': 'fake1'},334 {'alias': 'fake2'},335 {'alias': 'not_fake'}]})336 fake_os = mock.MagicMock()337 fake_os.extensions_v3_client.list_extensions = fake_list_extensions338 self.useFixture(mockpatch.PatchObject(339 verify_tempest_config, 'get_enabled_extensions',340 return_value=(['all'])))341 results = verify_tempest_config.verify_extensions(fake_os,342 'nova_v3', {})343 self.assertIn('nova_v3', results)344 self.assertIn('extensions', results['nova_v3'])345 self.assertEqual(sorted(['fake1', 'fake2', 'not_fake']),346 sorted(results['nova_v3']['extensions']))347 def test_verify_extensions_swift(self):348 def fake_list_extensions():349 return (None, {'fake1': 'metadata',350 'fake2': 'metadata',351 'not_fake': 'metadata',352 'swift': 'metadata'})353 fake_os = mock.MagicMock()354 fake_os.account_client.list_extensions = fake_list_extensions355 self.useFixture(mockpatch.PatchObject(356 verify_tempest_config, 'get_enabled_extensions',357 return_value=(['fake1', 'fake2', 'fake3'])))358 results = verify_tempest_config.verify_extensions(fake_os, 'swift', {})359 self.assertIn('swift', results)360 self.assertIn('fake1', results['swift'])361 self.assertTrue(results['swift']['fake1'])362 self.assertIn('fake2', results['swift'])363 self.assertTrue(results['swift']['fake2'])364 self.assertIn('fake3', results['swift'])365 self.assertFalse(results['swift']['fake3'])366 self.assertIn('not_fake', results['swift'])367 self.assertFalse(results['swift']['not_fake'])368 def test_verify_extensions_swift_all(self):369 def fake_list_extensions():370 return (None, {'fake1': 'metadata',371 'fake2': 'metadata',372 'not_fake': 'metadata',373 'swift': 'metadata'})374 fake_os = mock.MagicMock()375 fake_os.account_client.list_extensions = fake_list_extensions376 self.useFixture(mockpatch.PatchObject(377 verify_tempest_config, 'get_enabled_extensions',378 return_value=(['all'])))379 results = verify_tempest_config.verify_extensions(fake_os,380 'swift', {})381 self.assertIn('swift', results)382 self.assertIn('extensions', results['swift'])383 self.assertEqual(sorted(['not_fake', 'fake1', 'fake2']),...
managers.py
Source:managers.py
...23 self.loader = loader24 async def reload_extensions(self):25 await self.load_extensions()26 async def do_extension_loading(self):27 enabled_extensions = self.get_enabled_extensions()28 for extension in enabled_extensions:29 await extension.on_installing()30 async def load_extensions(self):31 self.logger.info('start loading extensions')32 extension_names = get_extensions_paths(self.loader.paths)33 self.logger.debug('extension_names:{}'.format(extension_names))34 extension_infos = self.load_extension_infos(extension_names)35 extensions = self.load_extension_entries(extension_infos)36 await self.do_extension_loading()37 return extensions38 def load_extension_infos(self, extension_names):39 extension_infos = []40 info_loader = ExtensionInfoLoader(self.env, self.loader)41 for item in extension_names:42 try:43 info = info_loader.load(item)44 if info:45 extension_infos.append(info)46 self.logger.debug('[load_extension_info] found loader for [{}]'.format(item))47 except Exception as e:48 self.logger.exception('[load_extension_infos] load extension info [{}] error', item, e)49 raise e50 extension_infos = sort_extension_dependency(extension_infos)51 self.logger.info(52 '[load_extension_infos] sorted extension info dependency [{}]'.format([x.name for x in extension_infos]))53 return extension_infos54 def load_extension_entries(self, extension_infos):55 for item in extension_infos:56 if item.name:57 item.enabled = True58 try:59 if item.enabled:60 extension = self.loader.load(item, self.app)61 self.extensions[item.name] = extension62 self.logger.info('[load_extensions] extension [{}] loaded'.format(item.name))63 else:64 self.logger.info('[load_extensions] extension [{}] skiped [disabled]'.format(item.name))65 except Exception as e:66 self.logger.exception('[load_extensions] extension [{}] load error'.format(item.name))67 return self.extensions68 def get_enabled_extensions(self):69 enabled_extensions = [x for x in self.extensions.values() if x.info.enabled]70 return enabled_extensions71 def get_worked_features(self, event):72 enabled_extensions = self.get_enabled_extensions()73 fs = []74 for item in enabled_extensions:75 enabled_features = item.get_worked_features(event)76 fs.extend(enabled_features)...
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!