How to use delete_server method in tempest

Best Python code snippet using tempest_python

unittest_wireguard_server.py

Source:unittest_wireguard_server.py Github

copy

Full Screen

...5 6 def test_create_server_expected(self):7 wireguard_state = Wireguard_database()8 result = wireguard_state.create_server("wireguard01", "192.168.2.0", 24, "gjXnuVSwfiqiZkf/rcEV8KczlTF4BseS4zY6dnKjCXc=", "192.168.2.55", 5128, 20, "192.168.2.0/32")9 wireguard_state.delete_server("wireguard01")10 self.assertEqual(201, result)11 12 def test_create_server_bad_net_addr(self):13 wireguard_state = Wireguard_database()14 result = wireguard_state.create_server("wireguard01", "192.168.2", 24, "gjXnuVSwfiqiZkf/rcEV8KczlTF4BseS4zY6dnKjCXc=", "192.168.2.55", 5128, 20, "192.168.2.0/32")15 wireguard_state.delete_server("wireguard01")16 self.assertEqual(400, result)1718 def test_create_server_bad_net_mask(self):19 wireguard_state = Wireguard_database()20 result = wireguard_state.create_server("wireguard01", "192.168.2.0", 33, "gjXnuVSwfiqiZkf/rcEV8KczlTF4BseS4zY6dnKjCXc=", "192.168.2.55", 5128, 20, "192.168.2.0/32")21 wireguard_state.delete_server("wireguard01")22 self.assertEqual(400, result)23 24 def test_create_server_bad_key(self):25 wireguard_state = Wireguard_database()26 result = wireguard_state.create_server("wireguard01", "192.168.2.0", 33, "sdfser", "192.168.2.55", 5128, 20, "192.168.2.0/32")27 wireguard_state.delete_server("wireguard01")28 self.assertEqual(400, result)29 30 def test_create_server_bad_port(self):31 wireguard_state = Wireguard_database()32 result = wireguard_state.create_server("wireguard01", "192.168.2.0", 33, "gjXnuVSwfiqiZkf/rcEV8KczlTF4BseS4zY6dnKjCXc=", "192.168.2.55", 512800, 20, "192.168.2.0/32")33 wireguard_state.delete_server("wireguard01")34 self.assertEqual(400, result)35 36 def test_delete_server_expected(self):37 wireguard_state = Wireguard_database()38 wireguard_state.create_server("wireguard01", "192.168.2.0", 33, "gjXnuVSwfiqiZkf/rcEV8KczlTF4BseS4zY6dnKjCXc=", "192.168.2.55", 5128, 20, "192.168.2.0/32")39 result = wireguard_state.delete_server("wireguard01")40 self.assertEqual(200, result)4142 def test_delete_server_nonexistent(self):43 wireguard_state = Wireguard_database()44 result = wireguard_state.delete_server("wireguard01")45 self.assertEqual(200, result)46 47 def test_delete_server_bad_connection(self):48 wireguard_state = Wireguard_database()49 wireguard_state.cursor = None50 result = wireguard_state.delete_server("wireguard01")51 self.assertEqual(500, result)52 53 def test_server_config_expected(self):54 expected_result = { 55 "peers": [56 { 57 "ip_address": "192.168.2.21",58 "public_key": "gjXsuVSwfiqiZkf/rcEV8KszlTF4BseS4zY6dnKjCXc="59 }60 ]61 }6263 wireguard_state = Wireguard_database()64 wireguard_state.create_server("wireguard01", "192.168.2.0", 24, "gjXnuVSwfiqiZkf/rcEV8KczlTF4BseS4zY6dnKjCXc=", "192.168.2.55", 5128, 20, "192.168.2.0/32")65 wireguard_state.create_client("testclient1", "wireguard01", "gjXsuVSwfiqiZkf/rcEV8KszlTF4BseS4zY6dnKjCXc=")66 result = wireguard_state.get_server_config("wireguard01")67 wireguard_state.delete_server("wireguard01")68 self.assertEqual(expected_result, result)6970 def test_server_config_expected_multi(self):71 expected_result = { 72 "peers": [73 { 74 "ip_address": "192.168.2.21",75 "public_key": "gjXsuVSwfiqiZkf/rcEV8KszlTF4BseS4zY6dnKjCXc="76 },77 { 78 "ip_address": "192.168.2.22",79 "public_key": "xjXsuVSwfiqiZkf/rcEV8KszlTF4BseS4zY6dnKjCXc="80 },81 { 82 "ip_address": "192.168.2.23",83 "public_key": "zjXsuVSwfiqiZkf/rcEV8KszlTF4BseS4zY6dnKjCXc="84 }85 ]86 }8788 wireguard_state = Wireguard_database()89 wireguard_state.create_server("wireguard01", "192.168.2.0", 24, "gjXnuVSwfiqiZkf/rcEV8KczlTF4BseS4zY6dnKjCXc=", "192.168.2.55", 5128, 20, "192.168.2.0/32")90 wireguard_state.create_client("testclient1", "wireguard01", "gjXsuVSwfiqiZkf/rcEV8KszlTF4BseS4zY6dnKjCXc=")91 wireguard_state.create_client("testclient2", "wireguard01", "xjXsuVSwfiqiZkf/rcEV8KszlTF4BseS4zY6dnKjCXc=")92 wireguard_state.create_client("testclient3", "wireguard01", "zjXsuVSwfiqiZkf/rcEV8KszlTF4BseS4zY6dnKjCXc=")93 result = wireguard_state.get_server_config("wireguard01")94 wireguard_state.delete_server("wireguard01")95 self.assertEqual(expected_result, result)9697 def test_server_config_no_peers(self):98 wireguard_state = Wireguard_database()99 wireguard_state.create_server("wireguard01", "192.168.2.0", 24, "gjXnuVSwfiqiZkf/rcEV8KczlTF4BseS4zY6dnKjCXc=", "192.168.2.55", 5128, 20, "192.168.2.0/32")100 result = wireguard_state.get_server_config("wireguard01")101 wireguard_state.delete_server("wireguard01")102 self.assertEqual({"peers": []}, result)103104 def test_server_config_nonexistent(self):105 wireguard_state = Wireguard_database()106 result = wireguard_state.get_server_config("wireguard01")107 self.assertEqual(None, result)108109 def test_server_exists_absent(self):110 wireguard_state = Wireguard_database()111 result = wireguard_state.check_server_exists("wireguard01")112 wireguard_state.delete_server("wireguard01")113 self.assertEqual(False, result)114115 def test_server_exists_present(self):116 wireguard_state = Wireguard_database()117 wireguard_state.create_server("wireguard01", "192.168.2.0", 24, "gjXnuVSwfiqiZkf/rcEV8KczlTF4BseS4zY6dnKjCXc=", "192.168.2.55", 5128, 20, "192.168.2.0/32")118 result = wireguard_state.check_server_exists("wireguard01")119 wireguard_state.delete_server("wireguard01")120 self.assertEqual(True, result)121 122 def test_server_wg_ip_present(self):123 wireguard_state = Wireguard_database()124 wireguard_state.create_server("wireguard01", "192.168.2.0", 24, "gjXnuVSwfiqiZkf/rcEV8KczlTF4BseS4zY6dnKjCXc=", "192.168.2.55", 5128, 20, "192.168.2.0/32")125 result = wireguard_state.get_server_wireguard_ip("wireguard01")126 wireguard_state.delete_server("wireguard01")127 self.assertEqual({'server_wg_ip': '192.168.2.1'}, result)128 129 def test_server_wg_ip_absent(self):130 wireguard_state = Wireguard_database()131 result = wireguard_state.get_server_wireguard_ip("wireguard01")132 wireguard_state.delete_server("wireguard01")133 self.assertEqual({}, result)134 135 def test_client_create_expected(self):136 wireguard_state = Wireguard_database()137 wireguard_state.create_server("wireguard01", "192.168.2.0", 24, "gjXnuVSwfiqiZkf/rcEV8KczlTF4BseS4zY6dnKjCXc=", "192.168.2.55", 5128, 20, "192.168.2.0/32")138 result = wireguard_state.create_client("testclient01", "wireguard01", "XxXnuVSwfiqiZkf/rcEV8KczlTF4BseS4zY6dnKjCXc=")139 wireguard_state.delete_server("wireguard01")140 self.assertEqual(201, result)141 142 def test_client_create_bad_key(self):143 wireguard_state = Wireguard_database()144 wireguard_state.create_server("wireguard01", "192.168.2.0", 24, "gjXnuVSwfiqiZkf/rcEV8KczlTF4BseS4zY6dnKjCXc=", "192.168.2.55", 5128, 20, "192.168.2.0/32")145 result = wireguard_state.create_client("testclient01", "wireguard01", "xXnuVSwfiqiZkf/rcEV8KczlTF4BseS4zY6dnKjCXc=")146 wireguard_state.delete_server("wireguard01")147 self.assertEqual(400, result)148 149 def test_client_create_bad_server(self):150 wireguard_state = Wireguard_database()151 wireguard_state.create_server("wireguard01", "192.168.2.0", 24, "gjXnuVSwfiqiZkf/rcEV8KczlTF4BseS4zY6dnKjCXc=", "192.168.2.55", 5128, 20, "192.168.2.0/32")152 result = wireguard_state.create_client("testclient01", "wireguard02", "XxXnuVSwfiqiZkf/rcEV8KczlTF4BseS4zY6dnKjCXc=")153 wireguard_state.delete_server("wireguard01")154 self.assertEqual(404, result)155 156 def test_client_create_no_lease(self):157 wireguard_state = Wireguard_database()158 wireguard_state.create_server("wireguard01", "192.168.2.0", 24, "gjXnuVSwfiqiZkf/rcEV8KczlTF4BseS4zY6dnKjCXc=", "192.168.2.55", 5128, 254, "192.168.2.0/32")159 result = wireguard_state.create_client("testclient01", "wireguard01", "XxXnuVSwfiqiZkf/rcEV8KczlTF4BseS4zY6dnKjCXc=")160 wireguard_state.delete_server("wireguard01")161 self.assertEqual(500, result)162163 def test_client_config_expected(self):164 expected = {165 'server': 166 {167 'public_key': 'gjXnuVSwfiqiZkf/rcEV8KczlTF4BseS4zY6dnKjCXc=', 168 'endpoint_address': '192.168.2.55', 169 'endpoint_port': 5128170 },171 'subnet': 172 {173 'allowed_ips': '192.168.2.0/32',174 'lease': '192.168.2.21'175 }176 }177 wireguard_state = Wireguard_database()178 wireguard_state.create_server("wireguard01", "192.168.2.0", 24, "gjXnuVSwfiqiZkf/rcEV8KczlTF4BseS4zY6dnKjCXc=", "192.168.2.55", 5128, 20, "192.168.2.0/32")179 wireguard_state.create_client("testclient01", "wireguard01", "XxXnuVSwfiqiZkf/rcEV8KczlTF4BseS4zY6dnKjCXc=")180 result = wireguard_state.get_client_config("testclient01", "wireguard01")181 print(wireguard_state.get_client_config("testclient01", "wireguard01"))182 wireguard_state.delete_server("wireguard01")183 self.assertEqual(expected, result)184185 def test_client_config_absent(self):186 wireguard_state = Wireguard_database()187 wireguard_state.create_server("wireguard01", "192.168.2.0", 24, "gjXnuVSwfiqiZkf/rcEV8KczlTF4BseS4zY6dnKjCXc=", "192.168.2.55", 5128, 20, "192.168.2.0/32")188 result = wireguard_state.get_client_config("testclient01", "wireguard01")189 wireguard_state.delete_server("wireguard01")190 self.assertEqual(None, result)191192 def test_client_exists_absent(self):193 wireguard_state = Wireguard_database()194 wireguard_state.create_server("wireguard01", "192.168.2.0", 24, "gjXnuVSwfiqiZkf/rcEV8KczlTF4BseS4zY6dnKjCXc=", "192.168.2.55", 5128, 20, "192.168.2.0/32")195 result = wireguard_state.check_client_exists("testclient01", "wireguard01")196 wireguard_state.delete_server("wireguard01")197 self.assertEqual(False, result)198199 def test_client_exists_present(self):200 wireguard_state = Wireguard_database()201 wireguard_state.create_server("wireguard01", "192.168.2.0", 24, "gjXnuVSwfiqiZkf/rcEV8KczlTF4BseS4zY6dnKjCXc=", "192.168.2.55", 5128, 20, "192.168.2.0/32")202 wireguard_state.create_client("testclient01", "wireguard01", "XxXnuVSwfiqiZkf/rcEV8KczlTF4BseS4zY6dnKjCXc=")203 result = wireguard_state.check_client_exists("testclient01", "wireguard01")204 wireguard_state.delete_server("wireguard01")205 self.assertEqual(True, result)206207if __name__ == '__main__': ...

Full Screen

Full Screen

cleanup_initialization_duplicates.py

Source:cleanup_initialization_duplicates.py Github

copy

Full Screen

...90 for delete_server in delete_list:91 print('{} --- {} --- {} --- {}'.format(delete_server.id, delete_server.hostname, \92 delete_server.cve_announcements_count, delete_server.created_at))93 if delete is True:94 API.delete_server(str(delete_server.id))95def launch_script(parsed_args):96 '''Launch script'''97 connect_api()98 servers = API.servers()99 if parsed_args.duplicates_only:100 duplicates = find_duplicates(servers)101 display_and_delete(duplicates, 'duplicates', parsed_args.duplicates_only)102 elif parsed_args.agents_only:103 agents = find_agents(servers, parsed_args.agents_time)104 display_and_delete(agents, 'agents', parsed_args.agents_only)105 elif parsed_args.agentless_only:106 agentless = find_agentless(servers, parsed_args.agentless_time)107 display_and_delete(agentless, 'agentless connections', parsed_args.agentless_only)108 else:...

Full Screen

Full Screen

tasks.py

Source:tasks.py Github

copy

Full Screen

...39 finally:40 db.session.close()41 return42@app.task43def delete_server(uuid):44 """45 Celery task to delete server. If server was extended, re-apply task for updated expiration.46 @param uuid:47 @return:48 """49 try:50 print("Running delete_server task: %s" % uuid)51 s = Server.query.filter_by(uuid=uuid).first_or_404()52 if not s:53 print("Server not found: %s" % uuid)54 return55 if s.status != "expired" and datetime.utcnow() < s.expiration: # Is not expired?56 # Re-set task with new expiration57 print("Extend task for server: %s" % uuid)58 delete_server.apply_async([uuid], eta=s.expiration)59 elif s.status != "expired":60 # Delete mumble server and expire server61 print("Deleting server: %s" % uuid)62 s.status = 'expired'63 resp = murmur.delete_server(s.mumble_host, s.mumble_instance)64 if resp:65 db.session.commit()66 print("Deleted server: %s host: %s, id: %d" % (uuid, s.mumble_host, s.mumble_instance))67 else:68 print("ERROR deleting server: %s host: %s id: %d" % (uuid, s.mumble_host, s.mumble_instance))69 else:70 print("Server instance %s already expired." % uuid)71 except:72 import traceback73 print("ERROR deleting server: %s" % uuid)74 db.session.rollback()75 traceback.print_exc()76 finally:77 db.session.close()...

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