How to use rpm_erase method in avocado

Best Python code snippet using avocado_python

rpm.py

Source:rpm.py Github

copy

Full Screen

...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']:...

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 avocado 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