Best Python code snippet using tempest_python
cinder_db.py
Source:cinder_db.py
...56 self.mysql.execute(sql, **parameters)57 def update_volume(self, old_id, **kwargs):58 sql = 'UPDATE volumes SET {} WHERE id = :old_id'59 self._update_table(sql, old_id, kwargs)60 def update_volume_metadata(self, old_id, **kwargs):61 sql = 'UPDATE volume_metadata SET {} WHERE volume_id = :old_id'62 self._update_table(sql, old_id, kwargs)63 def update_volume_id(self, old_id, new_id):64 with self.mysql.transaction():65 # It is impossible to update the primary key if any tables have66 # dependent records.67 # Making a copy of the fake volume with ID from source cloud.68 row = self.mysql.execute("SELECT * FROM volumes "69 "WHERE id = :old_id",70 old_id=old_id).fetchone()71 parameters = {'id': new_id}72 parameters.update({k: v for k, v in row.items() if k != 'id'})73 insert = "INSERT INTO volumes ({}) VALUES ({})".format(74 ', '.join(parameters.keys()),75 ', '.join(':{}'.format(k) for k in parameters.keys())76 )77 self.mysql.execute(insert, **parameters)78 # Update all dependent tables79 self.update_volume_metadata(old_id, volume_id=new_id)80 # Update an ID of fake volume to raise an exception if it still has81 # not updated dependent records in other tables82 fake_id = str(uuid_lib.uuid4())83 self.update_volume(old_id, id=fake_id)84 # Delete fake volume85 self.mysql.execute('DELETE FROM volumes WHERE id = :old_id',86 old_id=fake_id)87 def inc_quota_usages(self, project_id, resource, value):88 self.mysql.execute("UPDATE quota_usages "89 "SET in_use = in_use + :value "90 "WHERE project_id = :project_id "91 "AND resource = :resource",92 project_id=project_id,93 resource=resource,...
test_volume_metadata_rbac.py
Source:test_volume_metadata_rbac.py
...26 def setUp(self):27 super(VolumeMetadataRbacTest, self).setUp()28 self._add_metadata(self.volume)29 def tearDown(self):30 self.volumes_client.update_volume_metadata(self.volume['id'], {})31 super(VolumeMetadataRbacTest, self).tearDown()32 def _add_metadata(self, volume):33 # Create metadata for the volume34 metadata = {"key1": "value1"}35 self.volumes_client.create_volume_metadata(36 self.volume['id'], metadata)['metadata']37 @rbac_rule_validation.action(service="cinder",38 rule="volume:create_volume_metadata")39 @decorators.idempotent_id('232bbb8b-4c29-44dc-9077-b1398c20b738')40 def test_create_volume_metadata(self):41 self.rbac_utils.switch_role(self, toggle_rbac_role=True)42 self._add_metadata(self.volume)43 @rbac_rule_validation.action(service="cinder",44 rule="volume:get_volume_metadata")45 @decorators.idempotent_id('87ea37d9-23ab-47b2-a59c-16fc4d2c6dfa')46 def test_show_volume_metadata(self):47 self.rbac_utils.switch_role(self, toggle_rbac_role=True)48 self.volumes_client.show_volume_metadata(self.volume['id'])['metadata']49 @rbac_rule_validation.action(service="cinder",50 rule="volume:delete_volume_metadata")51 @decorators.idempotent_id('7498dfc1-9db2-4423-ad20-e6dcb25d1beb')52 def test_delete_volume_metadata_item(self):53 self.rbac_utils.switch_role(self, toggle_rbac_role=True)54 self.volumes_client.delete_volume_metadata_item(self.volume['id'],55 "key1")56 @decorators.idempotent_id('a41c8eed-2051-4a25-b401-df036faacbdc')57 @rbac_rule_validation.action(58 service="cinder",59 rule="volume:delete_volume_metadata")60 def test_delete_volume_image_metadata(self):61 self.volumes_client.update_volume_image_metadata(62 self.volume['id'], image_id=self.image_id)63 self.rbac_utils.switch_role(self, toggle_rbac_role=True)64 self.volumes_client.delete_volume_image_metadata(self.volume['id'],65 'image_id')66 @rbac_rule_validation.action(service="cinder",67 rule="volume:update_volume_metadata")68 @decorators.idempotent_id('8ce2ff80-99ba-49ae-9bb1-7e96729ee5af')69 def test_update_volume_metadata_item(self):70 updated_metadata_item = {"key1": "value1_update"}71 self.rbac_utils.switch_role(self, toggle_rbac_role=True)72 self.volumes_client.update_volume_metadata_item(73 self.volume['id'], "key1", updated_metadata_item)['meta']74 @decorators.idempotent_id('a231b445-97a5-4657-b05f-245895e88da9')75 @rbac_rule_validation.action(service="cinder",76 rule="volume:update_volume_metadata")77 def test_update_volume_metadata(self):78 updated_metadata = {"key1": "value1"}79 self.rbac_utils.switch_role(self, toggle_rbac_role=True)80 self.volumes_client.update_volume_metadata(self.volume['id'],81 updated_metadata)82 @decorators.idempotent_id('a9d9e825-5ea3-42e6-96f3-7ac4e97b2ed0')83 @rbac_rule_validation.action(84 service="cinder",85 rule="volume:update_volume_metadata")86 def test_update_volume_image_metadata(self):87 self.rbac_utils.switch_role(self, toggle_rbac_role=True)88 self.volumes_client.update_volume_image_metadata(...
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!!