Best Python code snippet using autotest_python
042_unique_index_on_hqe_job_and_host.py
Source:042_unique_index_on_hqe_job_and_host.py
...6DOWN_SQL = """7CREATE INDEX host_queue_entries_job_id ON host_queue_entries (job_id);8DROP INDEX host_queue_entries_job_id_and_host_id ON host_queue_entries;9"""10def null_out_duplicate_hqes(manager, hqe_ids):11 if not hqe_ids:12 return13 ids_to_null_string = ','.join(str(hqe_id) for hqe_id in hqe_ids)14 # check if any of the HQEs we're going to null out are active. if so, it's15 # too dangerous to proceed.16 rows = manager.execute('SELECT id FROM host_queue_entries '17 'WHERE active AND id IN (%s)' % ids_to_null_string)18 if rows:19 raise Exception('Active duplicate HQEs exist, cannot proceed. Please '20 'manually abort these HQE IDs: %s' % ids_to_null_string)21 # go ahead and null them out22 print 'Nulling out duplicate HQE IDs: %s' % ids_to_null_string23 manager.execute('UPDATE host_queue_entries '24 'SET host_id = NULL, active = FALSE, complete = TRUE, '25 'aborted = TRUE, status = "Aborted" '26 'WHERE id IN (%s)' % ids_to_null_string)27def migrate_up(manager):28 # cleanup duplicate host_queue_entries. rather than deleting them (and29 # dealing with foreign key references), we'll just null out their host_ids30 # and set them to aborted.31 rows = manager.execute('SELECT GROUP_CONCAT(id), COUNT(1) AS count '32 'FROM host_queue_entries '33 'WHERE host_id IS NOT NULL '34 'GROUP BY job_id, host_id HAVING count > 1')35 # gather all the HQE IDs we want to null out36 ids_to_null = []37 for ids_string, _ in rows:38 id_list = ids_string.split(',')39 # null out all but the first one. this isn't terribly important, but40 # the first one is the most likely to have actually executed, so might41 # as well keep that one.42 ids_to_null.extend(id_list[1:])43 null_out_duplicate_hqes(manager, ids_to_null)...
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!!