How to use _attach_volume_to_servers method in tempest

Best Python code snippet using tempest_python

test_attach_volume.py

Source:test_attach_volume.py Github

copy

Full Screen

...251 def skip_checks(cls):252 super(AttachVolumeMultiAttachTest, cls).skip_checks()253 if not CONF.compute_feature_enabled.volume_multiattach:254 raise cls.skipException('Volume multi-attach is not available.')255 def _attach_volume_to_servers(self, volume, servers):256 """Attaches the given volume to the list of servers.257 :param volume: The multiattach volume to use.258 :param servers: list of server instances on which the volume will be259 attached260 :returns: dict of server ID to volumeAttachment dict entries261 """262 attachments = {}263 for server in servers:264 # map the server id to the volume attachment265 attachments[server['id']] = self.attach_volume(server, volume)266 # NOTE(mriedem): In the case of multi-attach, after the first267 # attach the volume will be in-use. On the second attach, nova will268 # 'reserve' the volume which puts it back into 'attaching' status269 # and then the volume shouldn't go back to in-use until the compute270 # actually attaches the server to the volume.271 return attachments272 def _detach_multiattach_volume(self, volume_id, server_id):273 """Detaches a multiattach volume from the given server.274 Depending on the number of attachments the volume has, this method275 will wait for the volume to go to back to 'in-use' status if there are276 more attachments or 'available' state if there are no more attachments.277 """278 # Count the number of attachments before starting the detach.279 volume = self.volumes_client.show_volume(volume_id)['volume']280 attachments = volume['attachments']281 wait_status = 'in-use' if len(attachments) > 1 else 'available'282 # Now detach the volume from the given server.283 self.servers_client.detach_volume(server_id, volume_id)284 # Now wait for the volume status to change.285 waiters.wait_for_volume_resource_status(286 self.volumes_client, volume_id, wait_status)287 def _create_multiattach_volume(self, bootable=False):288 kwargs = {}289 if bootable:290 kwargs['image_ref'] = CONF.compute.image_ref291 return self.create_volume(multiattach=True, **kwargs)292 def _create_and_multiattach(self):293 """Creates two server instances and a volume and attaches to both.294 :returns: A three-item tuple of the list of created servers,295 the created volume, and dict of server ID to volumeAttachment296 dict entries297 """298 servers = []299 for x in range(2):300 name = 'multiattach-server-%i' % x301 servers.append(self.create_test_server(name=name))302 # Now wait for the servers to be ACTIVE.303 for server in servers:304 waiters.wait_for_server_status(self.servers_client, server['id'],305 'ACTIVE')306 volume = self._create_multiattach_volume()307 # Attach the volume to the servers308 attachments = self._attach_volume_to_servers(volume, servers)309 return servers, volume, attachments310 @decorators.idempotent_id('8d5853f7-56e7-4988-9b0c-48cea3c7049a')311 def test_list_get_volume_attachments_multiattach(self):312 # Attach a single volume to two servers.313 servers, volume, attachments = self._create_and_multiattach()314 # List attachments from the volume and make sure the server uuids315 # are in that list.316 vol_attachments = self.volumes_client.show_volume(317 volume['id'])['volume']['attachments']318 attached_server_ids = [attachment['server_id']319 for attachment in vol_attachments]320 self.assertEqual(2, len(attached_server_ids))321 # List Volume attachment of the servers322 for server in servers:...

Full Screen

Full Screen

Automation Testing Tutorials

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.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run tempest automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful