Best Python code snippet using tempest_python
backups_client.py
Source:backups_client.py
...47 """Delete a backup of volume."""48 resp, body = self.delete('backups/%s' % (str(backup_id)))49 self.expected_success(202, resp.status)50 return service_client.ResponseBody(resp, body)51 def show_backup(self, backup_id):52 """Returns the details of a single backup."""53 url = "backups/%s" % str(backup_id)54 resp, body = self.get(url)55 body = json.loads(body)56 self.expected_success(200, resp.status)57 return service_client.ResponseBody(resp, body['backup'])58 def list_backups(self, detail=False):59 """Information for all the tenant's backups."""60 url = "backups"61 if detail:62 url += "/detail"63 resp, body = self.get(url)64 body = json.loads(body)65 self.expected_success(200, resp.status)66 return service_client.ResponseBodyList(resp, body['backups'])67 def export_backup(self, backup_id):68 """Export backup metadata record."""69 url = "backups/%s/export_record" % backup_id70 resp, body = self.get(url)71 body = json.loads(body)72 self.expected_success(200, resp.status)73 return service_client.ResponseBody(resp, body['backup-record'])74 def import_backup(self, backup_service, backup_url):75 """Import backup metadata record."""76 post_body = {'backup_service': backup_service,77 'backup_url': backup_url}78 post_body = json.dumps({'backup-record': post_body})79 resp, body = self.post("backups/import_record", post_body)80 body = json.loads(body)81 self.expected_success(201, resp.status)82 return service_client.ResponseBody(resp, body['backup'])83 def wait_for_backup_status(self, backup_id, status):84 """Waits for a Backup to reach a given status."""85 body = self.show_backup(backup_id)86 backup_status = body['status']87 start = int(time.time())88 while backup_status != status:89 time.sleep(self.build_interval)90 body = self.show_backup(backup_id)91 backup_status = body['status']92 if backup_status == 'error':93 raise exceptions.VolumeBackupException(backup_id=backup_id)94 if int(time.time()) - start >= self.build_timeout:95 message = ('Volume backup %s failed to reach %s status '96 '(current %s) within the required time (%s s).' %97 (backup_id, status, backup_status,98 self.build_timeout))99 raise exceptions.TimeoutException(message)100 def wait_for_backup_deletion(self, backup_id):101 """Waits for backup deletion"""102 start_time = int(time.time())103 while True:104 try:105 self.show_backup(backup_id)106 except exceptions.NotFound:107 return108 if int(time.time()) - start_time >= self.build_timeout:109 raise exceptions.TimeoutException110 time.sleep(self.build_interval)111class BackupsClient(BaseBackupsClient):...
test_volume_backup.py
Source:test_volume_backup.py
...59 volume_id=volume['id'], backup_client=self.admin_backups_client)60 # create backup as user61 backup_usr = self.create_backup(volume_id=volume['id'])62 # refresh admin backup and assert no child backups63 backup_adm = self.admin_backups_client.show_backup(64 backup_adm['id'])['backup']65 self.assertFalse(backup_adm['has_dependent_backups'])66 # create incremental backup as admin67 self.create_backup(volume_id=volume['id'], incremental=True,68 backup_client=self.admin_backups_client)69 # refresh user backup and assert no child backups70 backup_usr = self.backups_client.show_backup(71 backup_usr['id'])['backup']72 self.assertFalse(backup_usr['has_dependent_backups'])73 # refresh admin backup and assert it has childs74 backup_adm = self.admin_backups_client.show_backup(75 backup_adm['id'])['backup']76 self.assertTrue(backup_adm['has_dependent_backups'])77 # create incremental backup as user78 self.create_backup(volume_id=volume['id'],79 incremental=True)80 # refresh user backup and assert it has childs81 backup_usr = self.backups_client.show_backup(82 backup_usr['id'])['backup']...
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!!