Best Python code snippet using molecule_python
_playbook.py
Source: _playbook.py
...67 @property68 def playbook_dirname(self) -> str:69 return tobiko.check_valid_type(self._playbook_dirname, str)70 @property71 def roles_path(self) -> typing.List[str]:72 roles_path = self._roles_path73 if roles_path is None:74 if roles_path is None:75 roles_path = []76 else:77 roles_path = list(roles_path)78 playbook_dirname = self._playbook_dirname79 if playbook_dirname is not None:80 playbook_roles_dir = os.path.join(playbook_dirname, 'roles')81 roles_path = ([playbook_roles_dir] +82 roles_path +83 [playbook_dirname])84 self._roles_path = roles_path85 return list(roles_path)...
runner.py
Source: runner.py
1#!/usr/bin/env python32import pathlib3import yaml4import docutils.parsers.rst5import docutils.core6from sphinx.errors import ExtensionError7from sphinx.util import logging8import ansible_runner9logger = logging.getLogger(__name__)10def write_play(play_content, tmp_dir):11 tmp_dir = pathlib.Path(tmp_dir)12 tmp_dir.mkdir(exist_ok=True)13 temp_file = tmp_dir / "temp_file.yaml"14 temp_file.write_text(play_content)15 return temp_file16def run_playbook(play_file, roles_path=None):17 logger.info("[ansible_runner] Running: {}".format(play_file))18 r = ansible_runner.run(19 private_data_dir=str(play_file.parent),20 playbook=play_file.name,21 roles_path=roles_path,22 )23 return r24def get_outputs(play_file, roles_path=None):25 r = run_playbook(play_file, roles_path=roles_path)26 if r.rc:27 raise ExtensionError("ansible execution has failed")28 outputs = {}29 for each_host_event in r.events:30 if each_host_event["event"] == "runner_on_ok":31 event_data = each_host_event["event_data"]32 task = each_host_event["event_data"].get("task")33 res = each_host_event["event_data"].get("res")34 if not (task and res):35 continue36 if task == "Gathering Facts":37 continue38 print(f"{task}> {res}")39 outputs[task] = res40 return outputs41def evaluate_playbook(play_content, roles_path=None, tmp_dir=None):42 play_file = write_play(play_content, tmp_dir=tmp_dir)43 outputs = get_outputs(play_file, roles_path=roles_path)44 return outputs45def evaluate_tasks(tasks, roles_path=None, tmp_dir=None):46 playbook_content = "- hosts: localhost\n tasks:\n"47 for block in tasks:48 task_str = yaml.dump([block["task"]])49 new_lines = [" " + l for l in task_str.split("\n")]50 playbook_content += "\n".join(new_lines) + "\n"...
Check out the latest blogs from LambdaTest on this topic:
People love to watch, read and interact with quality content — especially video content. Whether it is sports, news, TV shows, or videos captured on smartphones, people crave digital content. The emergence of OTT platforms has already shaped the way people consume content. Viewers can now enjoy their favorite shows whenever they want rather than at pre-set times. Thus, the OTT platform’s concept of viewing anything, anytime, anywhere has hit the right chord.
When working on web automation with Selenium, I encountered scenarios where I needed to refresh pages from time to time. When does this happen? One scenario is that I needed to refresh the page to check that the data I expected to see was still available even after refreshing. Another possibility is to clear form data without going through each input individually.
Most test automation tools just do test execution automation. Without test design involved in the whole test automation process, the test cases remain ad hoc and detect only simple bugs. This solution is just automation without real testing. In addition, test execution automation is very inefficient.
I was once asked at a testing summit, “How do you manage a QA team using scrum?” After some consideration, I realized it would make a good article, so here I am. Understand that the idea behind developing software in a scrum environment is for development teams to self-organize.
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!!