How to use delete_key_pair method in lisa

Best Python code snippet using lisa_python

test_key_pairs.py

Source:test_key_pairs.py Github

copy

Full Screen

...18from ec2api.tests.functional import config19CONF = config.CONF20class KeyPairTest(base.EC2TestCase):21 @decorators.idempotent_id('15cfd866-d6bb-473a-9b8a-6420900a5ca3')22 def test_create_delete_key_pair(self):23 keyName = 'Test key'24 data = self.client.create_key_pair(KeyName=keyName)25 res_clean = self.addResourceCleanUp(self.client.delete_key_pair,26 KeyName=keyName)27 self.assertEqual(keyName, data['KeyName'])28 self.assertIsNotNone(data.get('KeyFingerprint'))29 self.assertGreater(len(data['KeyFingerprint']), 0)30 self.assertGreater(len(data.get('KeyMaterial')), 0)31 data = self.client.delete_key_pair(KeyName=keyName)32 self.cancelResourceCleanUp(res_clean)33 @decorators.idempotent_id('05478a51-1505-42a8-8c7d-4fd7e32c467e')34 def test_create_duplicate_key_pair(self):35 keyName = 'Test key'36 self.client.create_key_pair(KeyName=keyName)37 res_clean = self.addResourceCleanUp(self.client.delete_key_pair,38 KeyName=keyName)39 self.assertRaises('InvalidKeyPair.Duplicate',40 self.client.create_key_pair,41 KeyName=keyName)42 self.client.delete_key_pair(KeyName=keyName)43 self.cancelResourceCleanUp(res_clean)44 @decorators.idempotent_id('43d87b6e-6667-4d19-8c0b-e73901105bb7')45 def test_describe_key_pairs(self):46 keyName = 'Test key'47 data = self.client.create_key_pair(KeyName=keyName)48 res_clean = self.addResourceCleanUp(self.client.delete_key_pair,49 KeyName=keyName)50 self.assertIsNotNone(data.get('KeyFingerprint'))51 self.assertGreater(len(data['KeyFingerprint']), 0)52 fingerprint = data.get('KeyFingerprint')53 data = self.client.describe_key_pairs(KeyNames=[keyName])54 self.assertEqual(1, len(data.get('KeyPairs')))55 data = data['KeyPairs'][0]56 self.assertEqual(keyName, data['KeyName'])57 self.assertIsNotNone(data.get('KeyFingerprint'))58 self.assertGreater(len(data['KeyFingerprint']), 0)59 self.assertIsNone(data.get('KeyMaterial'))60 data = self.client.describe_key_pairs(61 Filters=[{'Name': 'key-name', 'Values': [keyName]}])62 self.assertEqual(1, len(data.get('KeyPairs')))63 self.assertEqual(keyName, data['KeyPairs'][0]['KeyName'])64 data = self.client.describe_key_pairs(65 Filters=[{'Name': 'fingerprint', 'Values': [fingerprint]}])66 self.assertEqual(1, len(data.get('KeyPairs')))67 self.assertEqual(keyName, data['KeyPairs'][0]['KeyName'])68 self.assertRaises('InvalidKeyPair.NotFound',69 self.client.describe_key_pairs,70 KeyNames=['fake key'])71 data = self.client.delete_key_pair(KeyName=keyName)72 self.cancelResourceCleanUp(res_clean)73 self.assertRaises('InvalidKeyPair.NotFound',74 self.client.describe_key_pairs,75 KeyNames=[keyName])76 # NOTE(andrey-mp): Amazon allows to delete absent key and returns 20077 self.client.delete_key_pair(KeyName=keyName)78 @decorators.idempotent_id('0e51eec5-3f61-4d8a-89c9-8d098f381682')79 def test_import_empty_key_pair(self):80 keyName = 'Test key'81 publicKey = ''82 def _rollback(fn_data):83 self.client.delete_key_pair(KeyName=keyName)84 self.assertRaises('MissingParameter',85 self.client.import_key_pair,86 rollback_fn=_rollback,87 KeyName=keyName, PublicKeyMaterial=publicKey)88 @decorators.idempotent_id('478c17e6-b7ca-4115-bee2-be279bdd0f65')89 @testtools.skipUnless(CONF.aws.run_incompatible_tests,90 "Different error code")91 def test_import_invalid_key_pair(self):92 keyName = 'Test key'93 publicKey = 'ssh-rsa JUNK test@ubuntu'94 def _rollback():95 self.client.delete_key_pair(KeyName=keyName)96 self.assertRaises('InvalidKey.Format',97 self.client.import_key_pair,98 rollback_fn=_rollback,99 KeyName=keyName, PublicKeyMaterial=publicKey)100 @decorators.idempotent_id('eda525d6-144b-4840-b6ba-e18d93e3589f')101 def test_import_key_pair(self):102 keyName = 'Test key'103 publicKey = ("ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCs"104 "Ne3/1ILNCqFyfYWDeTKLD6jEXC2OQHLmietMWW+/vd"105 "aZq7KZEwO0jhglaFjU1mpqq4Gz5RX156sCTNM9vRbw"106 "KAxfsdF9laBYVsex3m3Wmui3uYrKyumsoJn2g9GNnG1P"107 "I1mrVjZ61i0GY3khna+wzlTpCCmy5HNlrmbj3XLqBUpip"108 "TOXmsnr4sChzC53KCd8LXuwc1i/CZPvF+3XipvAgFSE53pCt"109 "LOeB1kYMOBaiUPLQTWXR3JpckqFIQwhIH0zoHlJvZE8hh90"110 "XcPojYN56tI0OlrGqojbediJYD0rUsJu4weZpbn8vilb3JuDY+jws"111 "snSA8wzBx3A/8y9Pp1B test@ubuntu")112 data = self.client.import_key_pair(KeyName=keyName,113 PublicKeyMaterial=publicKey)114 res_clean = self.addResourceCleanUp(self.client.delete_key_pair,115 KeyName=keyName)116 self.assertEqual(keyName, data['KeyName'])117 self.assertIsNotNone(data.get('KeyFingerprint'))118 self.assertGreater(len(data['KeyFingerprint']), 0)119 self.assertIsNone(data.get('KeyMaterial'))120 self.client.delete_key_pair(KeyName=keyName)...

Full Screen

Full Screen

ec2_delete_key_pair.py

Source:ec2_delete_key_pair.py Github

copy

Full Screen

...12 keypair = entity.get('id')13 try:14 #Delete the keypair15 ec2_client = boto_session.client('ec2')16 result = ec2_client.delete_key_pair(KeyName=keypair)17 text_output = f"Keypair {keypair} was deleted successfully.\n"18 except ClientError as e:19 text_output = f"Client error: {e}.\n"...

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 lisa 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