Best Python code snippet using tempest_python
validation_resources.py
Source:validation_resources.py
...15from tempest_lib.common.utils import data_utils16from tempest_lib import exceptions as lib_exc17CONF = config.CONF18LOG = logging.getLogger(__name__)19def create_ssh_security_group(os, add_rule=False):20 security_group_client = os.security_groups_client21 sg_name = data_utils.rand_name('securitygroup-')22 sg_description = data_utils.rand_name('description-')23 security_group = \24 security_group_client.create_security_group(sg_name, sg_description)25 if add_rule:26 security_group_client.create_security_group_rule(security_group['id'],27 'tcp', 22, 22)28 security_group_client.create_security_group_rule(security_group['id'],29 'icmp', -1, -1)30 LOG.debug("SSH Validation resource security group with tcp and icmp "31 "rules %s created"32 % sg_name)33 return security_group34def create_validation_resources(os, validation_resources=None):35 # Create and Return the validation resources required to validate a VM36 validation_data = {}37 if validation_resources:38 if validation_resources['keypair']:39 keypair_name = data_utils.rand_name('keypair')40 validation_data['keypair'] = \41 os.keypairs_client.create_keypair(keypair_name)42 LOG.debug("Validation resource key %s created" % keypair_name)43 add_rule = False44 if validation_resources['security_group']:45 if validation_resources['security_group_rules']:46 add_rule = True47 validation_data['security_group'] = \48 create_ssh_security_group(os, add_rule)49 if validation_resources['floating_ip']:50 floating_client = os.floating_ips_client51 validation_data['floating_ip'] = \52 floating_client.create_floating_ip()53 return validation_data54def clear_validation_resources(os, validation_data=None):55 # Cleanup the vm validation resources56 has_exception = None57 if validation_data:58 if 'keypair' in validation_data:59 keypair_client = os.keypairs_client60 keypair_name = validation_data['keypair']['name']61 try:62 keypair_client.delete_keypair(keypair_name)...
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!!