Fix portage mod usage of jobs and load-average opt

In short, it enables portage module to emit emerge
command with --jobs and --load-average options
with and without argument.

To emit emerge with such CLI argument without
a value, the user must set the corresponding
module option to 0.

By default, if these arguments are missing from
playbook they are omitted.

Misc changes:

* Use to_native to ensure crosspython compat

* Adjust jobs and LA options to accept 0 as reset

* Add docstring to emerge_packages

* Explicitly note in doc that False will work as 0

PR  #36355 by @webknjaz
pull/36432/head
Sviatoslav Sydorenko 7 years ago committed by GitHub
parent 78e900cd7f
commit 2ce1009c04
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -156,6 +156,8 @@ options:
jobs:
description:
- Specifies the number of packages to build simultaneously.
- "Since version 2.6: Value of 0 or False resets any previously added"
- --jobs setting values
required: false
default: None
version_added: 2.3
@ -164,6 +166,8 @@ options:
description:
- Specifies that no new builds should be started if there are
- other builds running and the load average is at least LOAD
- "Since version 2.6: Value of 0 or False resets any previously added"
- --load-average setting values
required: false
default: None
version_added: 2.3
@ -224,6 +228,7 @@ import os
import re
from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils._text import to_native
def query_package(module, package, action):
@ -287,6 +292,7 @@ def sync_repositories(module, webrsync=False):
def emerge_packages(module, packages):
"""Run emerge command against given list of atoms."""
p = module.params
if not (p['update'] or p['noreplace'] or p['state'] == 'latest'):
@ -326,13 +332,24 @@ def emerge_packages(module, packages):
module.fail_json(msg='Use only one of usepkg, usepkgonly')
emerge_flags = {
'jobs': '--jobs=',
'loadavg': '--load-average ',
'jobs': '--jobs',
'loadavg': '--load-average',
}
for flag, arg in emerge_flags.items():
if p[flag] is not None:
args.append(arg + str(p[flag]))
flag_val = p[flag]
if flag_val is None:
"""Fallback to default: don't use this argument at all."""
continue
if not flag_val:
"""If the value is 0 or 0.0: add the flag, but not the value."""
args.append(arg)
continue
"""Add the --flag=value pair."""
args.extend((arg, to_native(flag_val)))
cmd, (rc, out, err) = run_emerge(module, packages, *args)
if rc != 0:

Loading…
Cancel
Save