Best Python code snippet using tempest_python
test_volumes_extend.py
Source:test_volumes_extend.py
...69 server_id)['instanceActions']70 for action in actions:71 if action['action'] == 'extend_volume':72 return action73 def _find_extend_volume_instance_action_finish_event(self, action):74 # This has to be called by an admin client otherwise75 # the events don't show up.76 action = self.os_admin.servers_client.show_instance_action(77 action['instance_uuid'], action['request_id'])['instanceAction']78 for event in action['events']:79 if (event['event'] == 'compute_extend_volume' and80 event['finish_time']):81 return event82 @decorators.idempotent_id('301f5a30-1c6f-4ea0-be1a-91fd28d44354')83 @testtools.skipUnless(CONF.volume_feature_enabled.extend_attached_volume,84 "Attached volume extend is disabled.")85 @utils.services('compute')86 def test_extend_attached_volume(self):87 """This is a happy path test which does the following:88 * Create a volume at the configured volume_size.89 * Create a server instance.90 * Attach the volume to the server.91 * Wait for the volume status to be "in-use".92 * Extend the size of the volume and wait for the volume status to go93 back to "in-use".94 * Assert the volume size change is reflected in the volume API.95 * Wait for the "compute_extend_volume" instance action event to show96 up in the compute API with the success or failure status. We fail97 if we timeout waiting for the instance action event to show up, or98 if the action on the server fails.99 """100 # Create a test volume. Will be automatically cleaned up on teardown.101 volume = self.create_volume()102 # Create a test server. Will be automatically cleaned up on teardown.103 server = self.create_server()104 # Attach the volume to the server and wait for the volume status to be105 # "in-use".106 self.attach_volume(server['id'], volume['id'])107 # Extend the size of the volume. If this is successful, the volume API108 # will change the status on the volume to "extending" before doing an109 # RPC cast to the volume manager on the backend. Note that we multiply110 # the size of the volume since certain Cinder backends, e.g. ScaleIO,111 # require multiples of 8GB.112 extend_size = volume['size'] * 2113 self.volumes_client.extend_volume(volume['id'], new_size=extend_size)114 # The volume status should go back to in-use since it is still attached115 # to the server instance.116 waiters.wait_for_volume_resource_status(self.volumes_client,117 volume['id'], 'in-use')118 # Assert that the volume size has changed in the volume API.119 volume = self.volumes_client.show_volume(volume['id'])['volume']120 self.assertEqual(extend_size, volume['size'])121 # Now we wait for the "compute_extend_volume" instance action event122 # to show up for the server instance. This is our indication that the123 # asynchronous operation is complete on the compute side.124 start_time = int(time.time())125 timeout = self.servers_client.build_timeout126 action = self._find_extend_volume_instance_action(server['id'])127 while action is None and int(time.time()) - start_time < timeout:128 time.sleep(self.servers_client.build_interval)129 action = self._find_extend_volume_instance_action(server['id'])130 if action is None:131 msg = ("Timed out waiting to get 'extend_volume' instance action "132 "record for server %(server)s after %(timeout)s seconds." %133 {'server': server['id'], 'timeout': timeout})134 raise lib_exc.TimeoutException(msg)135 # Now that we found the extend_volume instance action, we can wait for136 # the compute_extend_volume instance action event to show up to137 # indicate the operation is complete.138 start_time = int(time.time())139 event = self._find_extend_volume_instance_action_finish_event(action)140 while event is None and int(time.time()) - start_time < timeout:141 time.sleep(self.servers_client.build_interval)142 event = self._find_extend_volume_instance_action_finish_event(143 action)144 if event is None:145 msg = ("Timed out waiting to get 'compute_extend_volume' instance "146 "action event record for server %(server)s and request "147 "%(request_id)s after %(timeout)s seconds." %148 {'server': server['id'],149 'request_id': action['request_id'],150 'timeout': timeout})151 raise lib_exc.TimeoutException(msg)152 # Finally, assert that the action completed successfully.153 self.assertTrue(154 event['result'].lower() == 'success',155 "Unexpected compute_extend_volume result '%(result)s' for request "156 "%(request_id)s." %...
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!!