How to use generate_stestr_conf method in tempest

Best Python code snippet using tempest_python

init.py

Source:init.py Github

copy

Full Screen

...66 parser.add_argument('--workspace-path', default=None,67 help="The path to the workspace file, the default "68 "is ~/.tempest/workspace.yaml")69 return parser70 def generate_stestr_conf(self, local_path):71 stestr_conf_path = os.path.join(local_path, '.stestr.conf')72 top_level_path = os.path.dirname(os.path.dirname(__file__))73 discover_path = os.path.join(top_level_path, 'test_discover')74 stestr_conf = STESTR_CONF % (discover_path, top_level_path)75 with open(stestr_conf_path, 'w+') as stestr_conf_file:76 stestr_conf_file.write(stestr_conf)77 def get_configparser(self, conf_path):78 config_parse = moves.configparser.ConfigParser()79 config_parse.optionxform = str80 # get any existing values if a config file already exists81 if os.path.isfile(conf_path):82 # use read() for Python 2 and 3 compatibility83 config_parse.read(conf_path)84 return config_parse85 def update_local_conf(self, conf_path, lock_dir, log_dir):86 config_parse = self.get_configparser(conf_path)87 # Set local lock_dir in tempest conf88 if not config_parse.has_section('oslo_concurrency'):89 config_parse.add_section('oslo_concurrency')90 config_parse.set('oslo_concurrency', 'lock_path', lock_dir)91 # Set local log_dir in tempest conf92 config_parse.set('DEFAULT', 'log_dir', log_dir)93 # Set default log filename to tempest.log94 config_parse.set('DEFAULT', 'log_file', 'tempest.log')95 # write out a new file with the updated configurations96 with open(conf_path, 'w+') as conf_file:97 config_parse.write(conf_file)98 def copy_config(self, etc_dir, config_dir):99 if os.path.isdir(config_dir):100 shutil.copytree(config_dir, etc_dir)101 else:102 LOG.warning("Global config dir %s can't be found", config_dir)103 def generate_sample_config(self, local_dir):104 conf_generator = os.path.join(os.path.dirname(__file__),105 'config-generator.tempest.conf')106 output_file = os.path.join(local_dir, 'etc/tempest.conf.sample')107 if os.path.isfile(conf_generator):108 generator.main(['--config-file', conf_generator, '--output-file',109 output_file])110 else:111 LOG.warning("Skipping sample config generation because global "112 "config file %s can't be found", conf_generator)113 def create_working_dir(self, local_dir, config_dir):114 # make sure we are working with abspath however tempest init is called115 local_dir = os.path.abspath(local_dir)116 # Create local dir if missing117 if not os.path.isdir(local_dir):118 LOG.debug('Creating local working dir: %s', local_dir)119 os.mkdir(local_dir)120 elif os.listdir(local_dir):121 raise OSError("Directory you are trying to initialize already "122 "exists and is not empty: %s" % local_dir)123 lock_dir = os.path.join(local_dir, 'tempest_lock')124 etc_dir = os.path.join(local_dir, 'etc')125 config_path = os.path.join(etc_dir, 'tempest.conf')126 log_dir = os.path.join(local_dir, 'logs')127 stestr_dir = os.path.join(local_dir, '.stestr')128 # Create lock dir129 if not os.path.isdir(lock_dir):130 LOG.debug('Creating lock dir: %s', lock_dir)131 os.mkdir(lock_dir)132 # Create log dir133 if not os.path.isdir(log_dir):134 LOG.debug('Creating log dir: %s', log_dir)135 os.mkdir(log_dir)136 # Create and copy local etc dir137 self.copy_config(etc_dir, config_dir)138 # Generate the sample config file139 self.generate_sample_config(local_dir)140 # Update local confs to reflect local paths141 self.update_local_conf(config_path, lock_dir, log_dir)142 # Generate a stestr conf file143 self.generate_stestr_conf(local_dir)144 # setup local stestr working dir145 if not os.path.isdir(stestr_dir):146 commands.init_command(repo_url=local_dir)147 def take_action(self, parsed_args):148 workspace_manager = workspace.WorkspaceManager(149 parsed_args.workspace_path)150 name = parsed_args.name or parsed_args.dir.split(os.path.sep)[-1]151 config_dir = parsed_args.config_dir or get_tempest_default_config_dir()152 if parsed_args.show_global_dir:153 print("Global config dir is located at: %s" % config_dir)154 sys.exit(0)155 self.create_working_dir(parsed_args.dir, config_dir)156 workspace_manager.register_new_workspace(157 name, parsed_args.dir, init=True)

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