Best Python code snippet using tempest_python
keypairs.py
Source:keypairs.py
...26def keypair_steps(nova_client):27 """Fixture to get keypair steps."""28 return KeypairSteps(nova_client.keypairs)29@pytest.yield_fixture30def create_keypair(keypair_steps):31 """Fixture to create keypair with options.32 Can be called several times during test.33 """34 keypairs = []35 def _create_keypair(keypair_name):36 keypair = keypair_steps.create_keypair(keypair_name)37 keypairs.append(keypair)38 return keypair39 yield _create_keypair40 for keypair in keypairs:41 keypair_steps.delete_keypair(keypair)42@pytest.fixture43def keypair(create_keypair):44 """Fixture to create keypair with default options before test."""45 keypair_name = next(generate_ids('keypair'))...
create_keypair.py
Source:create_keypair.py
1# Copyright 2010-2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.2#3# This file is licensed under the Apache License, Version 2.0 (the "License").4# You may not use this file except in compliance with the License. A copy of the5# License is located at6#7# http://aws.amazon.com/apache2.0/8#9# This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS10# OF ANY KIND, either express or implied. See the License for the specific11# language governing permissions and limitations under the License. 12# snippet-start:[ec2.python.create_keypair.complete]131415import boto31617ec2 = boto3.client('ec2')18response = ec2.create_key_pair(KeyName='KEY_PAIR_NAME')19print(response)20 21 22# snippet-end:[ec2.python.create_keypair.complete]23# snippet-comment:[These are tags for the AWS doc team's sample catalog. Do not remove.]24# snippet-sourcedescription:[create_keypair.py demonstrates how to create a 2048-bit RSA Amazon EC2 key pair.]25# snippet-keyword:[Python]26# snippet-keyword:[AWS SDK for Python (Boto3)]27# snippet-keyword:[Code Sample]28# snippet-keyword:[Amazon EC2]29# snippet-service:[ec2]30# snippet-sourcetype:[full-example]31# snippet-sourcedate:[2018-12-26]32# snippet-sourceauthor:[jschwarzwalder (AWS)]
...
createKeyPair.py
Source:createKeyPair.py
...7username="admin",8password="manoj",9user_domain_id="default",10project_domain_id="default")11def create_keypair(conn): 12 keypair_name = "packtpub-keypair" # The name of the keypair to be created13 private_key_file = "private.key" # The name of the file that stores the private key14 keypair = conn.compute.find_keypair(keypair_name)15 if not keypair:16 keypair = conn.compute.create_keypair(name=keypair_name) # Create a keypair17 with open(private_key_file, 'w') as filehandle: 18 filehandle.write("%s" % keypair.private_key) # Write the private key to a file 19 os.chmod(private_key_file, 0o400) # Change the permission of the key file20 return keypair...
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!!