How to use generate_sample_config method in tempest

Best Python code snippet using tempest_python

conf_cli.py

Source:conf_cli.py Github

copy

Full Screen

1import argparse2# While the config is yaml, using json to dump the examples of it gives a3# cleaner output4import json5import os6import sys7from cosmo_tester.framework.config import load_config8from cosmo_tester.framework.logger import get_logger9def show_schema(schema,10 generate_sample_config=False,11 include_defaults=False,12 indent='',13 raw_config=None):14 raw_config = raw_config or {}15 output = []16 sorted_config_entries = schema.keys()17 sorted_config_entries = [18 entry for entry in sorted_config_entries19 if isinstance(schema[entry], dict)20 ]21 sorted_config_entries.sort()22 namespaces = [23 entry for entry in sorted_config_entries24 if schema[entry].get('.is_namespace', False)25 ]26 root_config_entries = [27 entry for entry in sorted_config_entries28 if entry not in namespaces29 ]30 for config_entry in root_config_entries:31 details = schema[config_entry]32 template = '{indent}{entry}: {value} # {description}'33 if generate_sample_config:34 if config_entry in raw_config:35 output.append(template.format(36 indent=indent,37 entry=config_entry,38 value=raw_config[config_entry],39 description=details['description'],40 ))41 elif 'default' in details.keys():42 if include_defaults:43 output.append(template.format(44 indent=indent,45 entry=config_entry,46 value=json.dumps(details['default']),47 description=details['description'],48 ))49 else:50 output.append(template.format(51 indent=indent,52 entry=config_entry,53 value='',54 description=details['description'],55 ))56 else:57 line = '{entry}: {description}'58 if 'default' in schema[config_entry].keys():59 line = line + ' (Default: {default})'60 line = line.format(61 entry=config_entry,62 description=details['description'],63 default=json.dumps(details.get('default')),64 )65 output.append(indent + line)66 for namespace in namespaces:67 namespace_output = show_schema(68 schema[namespace],69 generate_sample_config,70 include_defaults,71 indent + ' ',72 raw_config=raw_config.get(namespace, {}),73 )74 if namespace_output:75 output.append(indent + namespace + ':')76 output.append(namespace_output)77 return '\n'.join(output)78def apply_platform_config(logger, config, platform):79 config.raw_config['target_platform'] = platform80 if platform == 'openstack':81 config.raw_config['openstack'] = {}82 target = config.raw_config['openstack']83 target['username'] = os.environ["OS_USERNAME"]84 target['password'] = os.environ["OS_PASSWORD"]85 target['tenant'] = (86 os.environ.get("OS_TENANT_NAME")87 or os.environ['OS_PROJECT_NAME']88 )89 target['url'] = os.environ["OS_AUTH_URL"].replace('v2.0', 'v3')90 target['region'] = os.environ.get("OS_REGION_NAME", "RegionOne")91def main():92 parser = argparse.ArgumentParser(93 description=(94 'Tool for working with test configs.'95 ),96 )97 subparsers = parser.add_subparsers(help='Action',98 dest='action')99 validate_args = subparsers.add_parser('validate',100 help='Validate the config.')101 validate_args.add_argument(102 '-c', '--config-location',103 help='The config file to validate.',104 default='test_config.yaml',105 )106 subparsers.add_parser('schema',107 help='Print the schema.')108 generate_args = subparsers.add_parser('generate',109 help='Generate sample config.')110 generate_args.add_argument(111 '-i', '--include-defaults',112 help=(113 'Include entries with default values. '114 'This will result in a much longer config, most of which will '115 'not be required, but will allow for easy modification of any '116 'settings.'117 ),118 action='store_true',119 default=False120 )121 generate_args.add_argument(122 '-p', '--platform',123 help=(124 'Generate the initial config including values for the specified '125 'target platform. For platform configuration to be properly '126 "generated, you should have that platform's default way of "127 'authenticating prepared, e.g. ". openstackrc".'128 ),129 )130 args = parser.parse_args()131 logger = get_logger('conf_cli')132 if args.action == 'validate':133 # We validate on loading, so simply attempting to load the config with134 # the config supplied by the user will validate it135 load_config(logger, args.config_location)136 elif args.action == 'schema':137 config = load_config(logger, validate=False)138 print(show_schema(config.schema, False))139 elif args.action == 'generate':140 if args.platform:141 raw_config = {'target_platform': args.platform}142 else:143 raw_config = {}144 config = load_config(logger, raw_config=raw_config, validate=False)145 if args.platform:146 apply_platform_config(logger, config, args.platform)147 if not config.check_config_is_valid(fail_on_missing=False):148 sys.exit(1)149 print(show_schema(config.schema,150 generate_sample_config=True,151 include_defaults=args.include_defaults,152 raw_config=config.raw_config))153if __name__ == '__main__':...

Full Screen

Full Screen

test_config.py

Source:test_config.py Github

copy

Full Screen

1import os2import shutil3from hydrand.config import generate_sample_config, load_config, CONFIG_BASE_DIR4def test_save_load():5 x = generate_sample_config(17, write_to_disk=True)6 y = load_config(17)7 for a, b in zip(x, y):8 assert a.id == b.id9 assert a.address == b.address10 assert a.port == b.port11 assert a.keypair == b.keypair12 assert a.public_key == b.public_key13 assert a.initial_secret == b.initial_secret14 assert a.initial_shares == b.initial_shares15 assert a.initial_proof == b.initial_proof16 assert a.initial_merkle_root == b.initial_merkle_root...

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