Best Python code snippet using tempest_python
test_volumes_manage_rbac.py
Source:test_volumes_manage_rbac.py
...58 volume_id = self.create_volume()['id']59 volume = self.volumes_client.show_volume(volume_id)['volume']60 # By default, the volume is managed after creation. We need to61 # unmanage the volume first before testing manage volume.62 self.volumes_client.unmanage_volume(volume['id'])63 self.volumes_client.wait_for_resource_deletion(volume['id'])64 new_volume_name = data_utils.rand_name(65 self.__class__.__name__ + '-volume')66 new_volume_ref = {67 'name': new_volume_name,68 'host': volume['os-vol-host-attr:host'],69 'ref': {CONF.volume.manage_volume_ref[0]:70 CONF.volume.manage_volume_ref[1] % volume['id']},71 'volume_type': volume['volume_type'],72 'availability_zone': volume['availability_zone']}73 with self.override_role():74 try:75 new_volume_id = self.volume_manage_client.manage_volume(76 **new_volume_ref)['volume']['id']77 except exceptions.Forbidden as e:78 # Since the test role under test does not have permission to79 # manage the volume, Forbidden exception is thrown and the80 # manageable list will not be cleaned up. Therefore, we need to81 # re-manage the volume at the end of the test case for proper82 # resource clean up.83 self.addCleanup(self._manage_volume, volume)84 raise exceptions.Forbidden(e)85 waiters.wait_for_volume_resource_status(self.volumes_client,86 new_volume_id, 'available')87 self.addCleanup(88 self.delete_volume, self.volumes_client, new_volume_id)89 @rbac_rule_validation.action(90 service="cinder",91 rules=["volume_extension:volume_unmanage"])92 @decorators.idempotent_id('d5d72abe-60bc-45ac-a8f2-c21b24f0b5d6')93 def test_volume_unmanage(self):94 volume_id = self.create_volume()['id']95 volume = self.volumes_client.show_volume(volume_id)['volume']96 with self.override_role():97 self.volumes_client.unmanage_volume(volume['id'])98 self.volumes_client.wait_for_resource_deletion(volume['id'])99 # In order to clean up the manageable list, we need to re-manage the100 # volume after the test. The _manage_volume method will set up the101 # proper resource cleanup...
message_field.py
Source:message_field.py
1# Licensed under the Apache License, Version 2.0 (the "License"); you may2# not use this file except in compliance with the License. You may obtain3# a copy of the License at4#5# http://www.apache.org/licenses/LICENSE-2.06#7# Unless required by applicable law or agreed to in writing, software8# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT9# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the10# License for the specific language governing permissions and limitations11# under the License.12"""Message Resource, Action, Detail and user visible message.13Use Resource, Action and Detail's combination to indicate the Event14in the format of:15EVENT: VOLUME_RESOURCE_ACTION_DETAIL16Also, use exception-to-detail mapping to decrease the workload of17classifying event in cinder's task code.18"""19from cinder.i18n import _20class Resource(object):21 VOLUME = 'VOLUME'22class Action(object):23 SCHEDULE_ALLOCATE_VOLUME = ('001', _('schedule allocate volume'))24 ATTACH_VOLUME = ('002', _('attach volume'))25 COPY_VOLUME_TO_IMAGE = ('003', _('copy volume to image'))26 UPDATE_ATTACHMENT = ('004', _('update attachment'))27 COPY_IMAGE_TO_VOLUME = ('005', _('copy image to volume'))28 UNMANAGE_VOLUME = ('006', _('unmanage volume'))29 ALL = (SCHEDULE_ALLOCATE_VOLUME,30 ATTACH_VOLUME,31 COPY_VOLUME_TO_IMAGE,32 UPDATE_ATTACHMENT,33 COPY_IMAGE_TO_VOLUME,34 UNMANAGE_VOLUME35 )36class Detail(object):37 UNKNOWN_ERROR = ('001', _('An unknown error occurred.'))38 DRIVER_NOT_INITIALIZED = ('002',39 _('Driver is not initialized at present.'))40 NO_BACKEND_AVAILABLE = ('003',41 _('Could not find any available '42 'weighted backend.'))43 FAILED_TO_UPLOAD_VOLUME = ('004',44 _("Failed to upload volume to image "45 "at backend."))46 VOLUME_ATTACH_MODE_INVALID = ('005',47 _("Volume's attach mode is invalid."))48 QUOTA_EXCEED = ('006',49 _("Not enough quota resource for operation."))50 NOT_ENOUGH_SPACE_FOR_IMAGE = ('007',51 _("Image used for creating volume exceeds "52 "available space."))53 UNMANAGE_ENC_NOT_SUPPORTED = (54 '008',55 _("Unmanaging encrypted volumes is not supported."))56 ALL = (UNKNOWN_ERROR,57 DRIVER_NOT_INITIALIZED,58 NO_BACKEND_AVAILABLE,59 FAILED_TO_UPLOAD_VOLUME,60 VOLUME_ATTACH_MODE_INVALID,61 QUOTA_EXCEED,62 NOT_ENOUGH_SPACE_FOR_IMAGE,63 UNMANAGE_ENC_NOT_SUPPORTED,64 )65 # Exception and detail mappings66 EXCEPTION_DETAIL_MAPPINGS = {67 DRIVER_NOT_INITIALIZED: ['DriverNotInitialized'],68 NO_BACKEND_AVAILABLE: ['NoValidBackend'],69 VOLUME_ATTACH_MODE_INVALID: ['InvalidVolumeAttachMode'],70 QUOTA_EXCEED: ['ImageLimitExceeded',71 'BackupLimitExceeded',72 'SnapshotLimitExceeded'],73 NOT_ENOUGH_SPACE_FOR_IMAGE: ['ImageTooBig'],74 UNMANAGE_ENC_NOT_SUPPORTED: ['UnmanageEncVolNotSupported'],75 }76def translate_action(action_id):77 action_message = next((action[1] for action in Action.ALL78 if action[0] == action_id), None)79 return action_message or 'unknown action'80def translate_detail(detail_id):81 detail_message = next((action[1] for action in Detail.ALL82 if action[0] == detail_id), None)83 return detail_message or Detail.UNKNOWN_ERROR[1]84def translate_detail_id(exception, detail):85 if exception is not None and isinstance(exception, Exception):86 for key, value in Detail.EXCEPTION_DETAIL_MAPPINGS.items():87 if exception.__class__.__name__ in value:88 return key[0]89 if detail in Detail.ALL:90 return detail[0]...
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!!