Best Python code snippet using tempest_python
rollback_setup.py
Source:rollback_setup.py
...152 pass153 #remove all of the endpoints except keystone154 logger.sys_info('Deleting the OpenStack API endpoints.')155 try:156 endpoint.delete_endpoint('nova')157 endpoint.delete_endpoint('cinder')158 endpoint.delete_endpoint('cinder_v2')159 endpoint.delete_endpoint('glance')160 endpoint.delete_endpoint('neutron')161 endpoint.delete_endpoint('ceilometer')162 endpoint.delete_endpoint('heat')163 endpoint.delete_endpoint('ec2')164 endpoint.delete_endpoint('s3')165 except:166 logger.sys_error('Could not delete endpoints')167 pass168 #stop all of the openstack services169 logger.sys_info('Stopping the OpenStack services.')170 try:171 nova_stop = service.nova('stop')172 cinder_stop = service.cinder('stop')173 glance_stop = service.glance('stop')174 heat_stop = service.heat('stop')175 ceilometer_stop = service.ceilometer('stop')176 neutron_stop = service.neutron('stop')177 except:178 logger.sys_error('Could not stop services')179 pass180 #set nova,glance,cinder,neutron config files to defaults181 logger.sys_info('Removing the OpenStack configs.')182 try:183 os.system('sudo rm -rf /etc/nova')184 os.system('sudo rm -rf /etc/cinder')185 os.system('sudo rm -rf /etc/glance')186 os.system('sudo rm -rf /etc/heat')187 os.system('sudo rm -rf /etc/ceilometer')188 os.system('sudo rm -rf /etc/neutron')189 for f in os.listdir('/etc'):190 if fnmatch(f, 'os_configs*'):191 os.system('sudo tar -xvf /etc/%s -C /etc' %f)192 os.system('sudo chown -R nova:nova /etc/nova')193 os.system('sudo chown -R cinder:cinder /etc/cinder')194 os.system('sudo chown -R glance:glance /etc/glance')195 os.system('sudo chown -R heat:heat /etc/heat')196 os.system('sudo chown -R ceilometer:ceilometer /etc/ceilometer')197 os.system('sudo chown -R neutron:neutron /etc/neutron')198 os.system('sudo chmod -R 770 /etc/nova /etc/neutron /etc/glance /etc/cinder /etc/ceilometer /etc/heat')199 except:200 logger.sys_error('Could not remove configs')201 pass202 #remove the node entry203 logger.sys_info('Removing the node from the Transcirrus DB.')204 try:205 del_node = node_db.delete_node(config.NODE_ID)206 logger.sys_info("delnode: %s" %(str(del_node)))207 except:208 logger.sys_error('Could not remove node entry')209 pass210 #copy all of the factory defaults to trans_system_settings211 logger.sys_info("\n --- config.NODE_NAME: %s ---\n" %(str(config.NODE_NAME)))212 rollback_array = []213 for key,value in factory_defaults.items():214 dictionary = {"system_name":config.NODE_NAME,"parameter":key,"param_value":value}215 rollback_array.append(dictionary)216 logger.sys_info("\n --- rollback_array: %s ---\n" %(str(rollback_array)))217 logger.sys_info('Resetting the factory system defaults.')218 try:219 up = util.update_system_variables(rollback_array)220 util.update_cloud_controller_name({"old_name":config.NODE_NAME,"new_name":factory_defaults['node_name']})221 except:222 logger.sys_error('Could not reset factory defaults')223 pass224 try:225 logger.sys_info('Resetting OpenStack Keystone.')226 #move the default config file back in place227 del_keystone = endpoint.delete_endpoint('keystone')228 if(del_keystone == 'OK'):229 input_dict = {'cloud_name':'TransCirrusCloud','service_name':'keystone'}230 create_keystone = endpoint.create_endpoint(input_dict)231 if(create_keystone['endpoint_id']):232 logger.sys_info("Keystone endpoint set up complete.")233 else:234 return "Keystone error."235 except:236 logger.sys_error('Could not reset keystone')237 pass238 #may have to hack endpoint not deleted for some reason, however the default endpoint is created ???????239 try:240 logger.sys_info('Resetting OpenStack Swift.')241 #move the default config file back in place242 del_swift = endpoint.delete_endpoint('swift')243 if(del_swift == 'OK'):244 input_dict = {'cloud_name':'TransCirrusCloud','service_name':'swift'}245 create_swift = endpoint.create_endpoint(input_dict)246 if(create_swift['endpoint_id']):247 logger.sys_info("Swift endpoint set up complete.")248 else:249 return "Swift error."250 except:251 logger.sys_error('Could not reset swift')252 pass253 #reset the config file254 sys_vars = None255 os.system('sudo mv /usr/local/lib/python2.7/transcirrus/common/config.py /usr/local/lib/python2.7/transcirrus/common/config.orig')256 try:...
test_imports_and_delete.py
Source:test_imports_and_delete.py
1import requests2def test_import_and_delete_one_item(imports_endpoint, delete_endpoint):3 response = requests.post(4 imports_endpoint,5 json={6 "items": [7 {8 "type": "OFFER",9 "name": "Teapot",10 "id": "4b31f4d1-ba85-4908-9a92-a98dec759016",11 "price": 1999,12 "parentId": None13 }14 ],15 "updateDate": "2022-02-10T12:00:00.000Z"16 }17 )18 assert response.status_code == 20019 response = requests.delete(20 delete_endpoint + "4b31f4d1-ba85-4908-9a92-a98dec759016"21 )22 assert response.status_code == 20023 response = requests.delete(24 delete_endpoint + "4b31f4d1-ba85-4908-9a92-a98dec759016"25 )26 assert response.status_code == 40427 assert response.json() == {28 "code": 404,29 "message": "Item not found"30 }31def test_import_and_delete_items(imports_endpoint, delete_endpoint):32 response = requests.post(33 imports_endpoint,34 json={35 "items": [36 {37 "type": "OFFER",38 "name": "Teapot Blue",39 "id": "9a293f76-75d7-4258-b244-d6477f28d010",40 "price": 3999,41 },42 {43 "type": "CATEGORY",44 "name": "Books",45 "id": "da96d714-9fe8-4e75-a74f-3ba54c583853",46 },47 {48 "type": "CATEGORY",49 "name": "Computer Books",50 "id": "45798ab3-7404-4f98-85bd-9640d0e7719a",51 "parentId": "da96d714-9fe8-4e75-a74f-3ba54c583853"52 }53 ],54 "updateDate": "2022-02-21T12:00:00.000Z"55 }56 )57 assert response.status_code == 20058 response = requests.delete(59 delete_endpoint + "9a293f76-75d7-4258-b244-d6477f28d010"60 )61 assert response.status_code == 20062 response = requests.delete(63 delete_endpoint + "45798ab3-7404-4f98-85bd-9640d0e7719a"64 )65 assert response.status_code == 20066 response = requests.delete(67 delete_endpoint + "da96d714-9fe8-4e75-a74f-3ba54c583853"68 )69 assert response.status_code == 20070 # after deletion71 response = requests.delete(72 delete_endpoint + "9a293f76-75d7-4258-b244-d6477f28d010"73 )74 assert response.status_code == 40475 assert response.json() == {76 "code": 404,77 "message": "Item not found"78 }79 response = requests.delete(80 delete_endpoint + "45798ab3-7404-4f98-85bd-9640d0e7719a"81 )82 assert response.status_code == 40483 assert response.json() == {84 "code": 404,85 "message": "Item not found"86 }87 response = requests.delete(88 delete_endpoint + "da96d714-9fe8-4e75-a74f-3ba54c583853"89 )90 assert response.status_code == 40491 assert response.json() == {92 "code": 404,93 "message": "Item not found"94 }95def test_import_and_delete_category_with_items(imports_endpoint, delete_endpoint):96 response = requests.post(97 imports_endpoint,98 json={99 "items": [100 {101 "type": "CATEGORY",102 "name": "Video Cards",103 "id": "80ea8f97-fd4a-4098-bd81-8728929dd925",104 },105 {106 "type": "CATEGORY",107 "name": "NVIDIA",108 "id": "0911b3fa-07bb-46a6-89fa-c4996a548939",109 "parentId": "80ea8f97-fd4a-4098-bd81-8728929dd925",110 },111 {112 "type": "CATEGORY",113 "name": "AMD",114 "id": "1502b962-4c34-4f1b-a1e9-5656e19d6065",115 "parentId": "80ea8f97-fd4a-4098-bd81-8728929dd925",116 },117 {118 "type": "OFFER",119 "name": "gtx 3090",120 "id": "37d9e437-15b8-4027-9d82-ecfe6fd2525d",121 "parentId": "0911b3fa-07bb-46a6-89fa-c4996a548939",122 "price": 108000123 },124 {125 "type": "OFFER",126 "name": "gtx 2080",127 "id": "430a63d5-8401-4f2c-af24-e3b72db8d843",128 "parentId": "0911b3fa-07bb-46a6-89fa-c4996a548939",129 "price": 108000130 },131 {132 "type": "OFFER",133 "name": "rx 6600",134 "id": "cc99524b-a8e9-4bf3-a4a9-ff3d4656c379",135 "parentId": "1502b962-4c34-4f1b-a1e9-5656e19d6065",136 "price": 90000137 }138 ],139 "updateDate": "2022-12-31T03:06:22+00:00"140 }141 )142 assert response.status_code == 200143 # Video Cards144 response = requests.delete(145 delete_endpoint + "80ea8f97-fd4a-4098-bd81-8728929dd925"146 )147 assert response.status_code == 200148 # rx 6600149 response = requests.delete(150 delete_endpoint + "cc99524b-a8e9-4bf3-a4a9-ff3d4656c379"151 )152 assert response.status_code == 404153 assert response.json() == {154 "code": 404,155 "message": "Item not found"156 }157 # gtx 2080158 response = requests.delete(159 delete_endpoint + "430a63d5-8401-4f2c-af24-e3b72db8d843"160 )161 assert response.status_code == 404162 assert response.json() == {163 "code": 404,164 "message": "Item not found"165 }166 # gtx 3090167 response = requests.delete(168 delete_endpoint + "37d9e437-15b8-4027-9d82-ecfe6fd2525d"169 )170 assert response.status_code == 404171 assert response.json() == {172 "code": 404,173 "message": "Item not found"174 }175 # AMD176 response = requests.delete(177 delete_endpoint + "1502b962-4c34-4f1b-a1e9-5656e19d6065"178 )179 assert response.status_code == 404180 assert response.json() == {181 "code": 404,182 "message": "Item not found"183 }184 # NVIDIA185 response = requests.delete(186 delete_endpoint + "0911b3fa-07bb-46a6-89fa-c4996a548939"187 )188 assert response.status_code == 404189 assert response.json() == {190 "code": 404,191 "message": "Item not found"...
test_delete_endpoint.py
Source:test_delete_endpoint.py
1#!/usr/bin/env python32from helpers.database_actioner import DatabaseActioner3from helpers.delete_endpoint import DeleteEndpoint4H2_JAR = "/home/mdreisinger/src/testAutomation/target/h2-1.4.200.jar"5UNIQUE_GUY_0 = (0,'Mike0','D','0000000000')6UNIQUE_GUY_1 = (1,'Mike1','Dre','1111111111')7UNIQUE_GUY_2 = (2,'Mike2','Dr. Dre','2222222222')8def setup():9 # Delete everything from the database and then add one unique guy10 dba = DatabaseActioner(H2_JAR)11 dba.execute("delete from PERSON")12 dba.execute("select * from PERSON")13 pretest_data = dba.fetchall()14 assert pretest_data == [], "Failed to clear database before running test."15 dba.execute(f"insert into PERSON values {UNIQUE_GUY_0}")16 dba.execute(f"insert into PERSON values {UNIQUE_GUY_1}")17 dba.execute(f"insert into PERSON values {UNIQUE_GUY_2}")18 dba.execute("select * from PERSON")19 pretest_data = dba.fetchall()20 assert pretest_data == [UNIQUE_GUY_0, UNIQUE_GUY_1, UNIQUE_GUY_2], "Failed to insert unique people into database before running test."21 dba.close()22def test_deleteEndpointShouldReturn200GivenValidIdAndCredentials():23 # Arrange24 setup()25 delete_endpoint = DeleteEndpoint()26 27 # Act28 actual_response = delete_endpoint.delete(UNIQUE_GUY_0[0], write_access=True)29 30 # Assert31 assert actual_response.status_code == 20032def test_deleteEndpointShouldReturn401GivenValidIdAndInvalidCredentials():33 # Arrange34 setup()35 delete_endpoint = DeleteEndpoint()36 delete_endpoint.write_credentials = ("not", "arealguy")37 38 # Act39 actual_response = delete_endpoint.delete(UNIQUE_GUY_0[0], write_access=True)40 41 # Assert42 assert actual_response.status_code == 40143def test_deleteEndpointShouldReturn403GivenValidIdAndReadOnlyCredentials():44 # Arrange45 setup()46 delete_endpoint = DeleteEndpoint()47 48 # Act49 actual_response = delete_endpoint.delete(UNIQUE_GUY_0[0], write_access=False)50 51 # Assert52 assert actual_response.status_code == 40353def test_deleteEndpointShouldDeleteTheCorrectPersonGivenValidIdAndCredentials_0():54 # Arrange55 setup()56 delete_endpoint = DeleteEndpoint()57 58 # Act59 actual_response = delete_endpoint.delete(UNIQUE_GUY_0[0], write_access=True)60 61 # Assert62 assert actual_response.status_code == 20063 dba = DatabaseActioner(H2_JAR)64 dba.execute("select * from PERSON")65 data = dba.fetchall()66 assert data == [UNIQUE_GUY_1, UNIQUE_GUY_2]67 dba.close()68def test_deleteEndpointShouldDeleteTheCorrectPersonGivenValidIdAndCredentials_1():69 # Arrange70 setup()71 delete_endpoint = DeleteEndpoint()72 73 # Act74 actual_response = delete_endpoint.delete(UNIQUE_GUY_1[0], write_access=True)75 76 # Assert77 assert actual_response.status_code == 20078 dba = DatabaseActioner(H2_JAR)79 dba.execute("select * from PERSON")80 data = dba.fetchall()81 assert data == [UNIQUE_GUY_0, UNIQUE_GUY_2]82 dba.close()83def test_deleteEndpointShouldDeleteTheCorrectPersonGivenValidIdAndCredentials_2():84 # Arrange85 setup()86 delete_endpoint = DeleteEndpoint()87 88 # Act89 actual_response = delete_endpoint.delete(UNIQUE_GUY_2[0], write_access=True)90 91 # Assert92 assert actual_response.status_code == 20093 dba = DatabaseActioner(H2_JAR)94 dba.execute("select * from PERSON")95 data = dba.fetchall()96 assert data == [UNIQUE_GUY_0, UNIQUE_GUY_1]...
lambda_function.py
Source:lambda_function.py
...19 print("Action is to invoke endpoint.")20 invoke_endpoint(config)21 elif event['action'] == 'delete_endpoint':22 print("Action is to delete endpoint.")23 delete_endpoint(config)24 else:25 print("Action not supported.")26# if __name__ == '__main__':27# event = {28# "action": "create_endpoint" | "invoke_endpoint" | "delete_endpoint",29# "metric": "dollarsales" | "transcount" | "itemcount",30# "location_num": "all"31# }...
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!!