Best Python code snippet using avocado_python
rpm.py
Source: rpm.py
...46 if rc == 0:47 return True48 else:49 module.fail_json(msg='Error from rpm: %s: %s' % (cmd, err))50def rpm_erase(module, name):51 cmd = [ 'rpm', '-e', '--quiet', name ]52 rc, out, err = module.run_command(cmd)53 if rc == 0:54 return True55 else:56 module.fail_json(msg='Error from rpm: %s: %s' % (cmd, err))57def rpm_exists(module, name):58 cmd = [ 'rpm', '-q', '--quiet', '--nosignature', name ]59 rc, out, err = module.run_command(cmd)60 return rc == 061def query_pkgid_for_pkg(module, name):62 cmd = [ 'rpm', '-q', '--qf', '%{PKGID}', '--nosignature',63 name ]64 rc, out, err = module.run_command(cmd)65 if rc == 0:66 return out.strip()67 else:68 return None69def query_rpm_value_for_file(module, filename, format):70 file = os.path.expanduser(filename)71 if not os.path.exists(file):72 module.fail_json(msg='No package file: %s' % (filename))73 cmd = [ 'rpm', '-q', '--qf', format, '--nosignature', '-p', file ]74 rc, out, err = module.run_command(cmd)75 if rc == 0:76 return out77 else:78 module.fail_json(msg='Error from rpm: %s: %s' % (cmd, err))79def query_pkgid_for_file(module, filename):80 return query_rpm_value_for_file(module, filename, '%{PKGID}').strip()81def query_rpm_name_for_file(module, filename):82 return query_rpm_value_for_file(module, filename, '%{NAME}').strip()83def ensure_installed(module, params):84 if params['file']:85 file_pkgid = query_pkgid_for_file(module, params['file'])86 rpm_pkgid = query_pkgid_for_pkg(module, params['name'])87 if file_pkgid == rpm_pkgid:88 return module.exit_json(changed=False)89 if rpm_install(module, params['file']):90 return module.exit_json(changed=True, name=params['name'],91 pkgid=file_pkgid)92 else:93 pkgid = query_pkgid_for_pkg(module, params['name'])94 if pkgid:95 return module.exit_json(changed=False)96 module.fail_json(msg='could not install package %s' % (params['name']))97def ensure_removed(module, params):98 pkgid = query_pkgid_for_pkg(module, params['name'])99 if not pkgid:100 return module.exit_json(changed=False, name=params['name'], pkgid=pkgid)101 if rpm_erase(module, params['name']):102 return module.exit_json(changed=True, name=params['name'], pkgid=pkgid)103def main():104 module = AnsibleModule(105 argument_spec = dict(106 name=dict(),107 state=dict(default='installed', choices=[ 'present', 'absent', 'installed', 'removed' ]),108 file=dict(),109 ),110 required_one_of = [ ['name', 'file'] ]111 )112 params = module.params113 if params['file'] and not params['name']:114 params['name'] = query_rpm_name_for_file(module, params['file'])115 if params['state'] in ['installed', 'present']:...
Check out the latest blogs from LambdaTest on this topic:
Hola Testers! Hope you all had a great Thanksgiving weekend! To make this time more memorable, we at LambdaTest have something to offer you as a token of appreciation.
In addition to the four values, the Agile Manifesto contains twelve principles that are used as guides for all methodologies included under the Agile movement, such as XP, Scrum, and Kanban.
JavaScript is one of the most widely used programming languages. This popularity invites a lot of JavaScript development and testing frameworks to ease the process of working with it. As a result, numerous JavaScript testing frameworks can be used to perform unit testing.
When I started writing tests with Cypress, I was always going to use the user interface to interact and change the application’s state when running tests.
The rapid shift in the use of technology has impacted testing and quality assurance significantly, especially around the cloud adoption of agile development methodologies. With this, the increasing importance of quality and automation testing has risen enough to deliver quality work.
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!!