Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allow configuring timeout for API calls and subscription-manager #237

Merged
merged 1 commit into from
Jan 19, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,24 @@ For some users who do not have a configuration management or automation solution

~~~

### Changing the API/Subscription Manager timeouts

On busy servers, it is sometimes useful to increase the amount of time that the system waits before timing out during registration and subscription tasks.
`bootstrap.py` defaults to an timeout of **900** seconds for APIs. Additionally, the `server_timeout` parameter for `subscription-manager`
is configured with this value. If desired, this value can be overridden using the `--timeout` option.

~~~
./bootstrap.py -l admin \
-s foreman.example.com \
-o "Red Hat" \
-L RDU \
-g "RHEL7/Crash" \
-a ak-Reg_To_Crash \
--timeout 1800

~~~


# Help / Available options:

~~~
Expand Down Expand Up @@ -478,6 +496,9 @@ Options:
--install-packages=installpackages
List of packages to be additionally installed - comma
separated
-t timeout, --timeout=timeout
Timeout (in seconds) for API calls and subscription-
manager registration. Defaults to 900
~~~

# Ansible integration
Expand Down
8 changes: 6 additions & 2 deletions bootstrap.py
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,7 @@ def migrate_systems(org_name, activationkey):
options.rhsmargs += " --legacy-user '%s' --legacy-password '%s'" % (options.legacy_login, options.legacy_password)
else:
options.rhsmargs += " --keep"
exec_failok("/usr/sbin/subscription-manager config --server.server_timeout=%s" % options.timeout)
exec_failexit("/usr/sbin/rhn-migrate-classic-to-rhsm --org %s --activation-key '%s' %s" % (org_label, activationkey, options.rhsmargs))
exec_failexit("subscription-manager config --rhsm.baseurl=https://%s/pulp/repos" % options.foreman_fqdn)
if options.release:
Expand Down Expand Up @@ -351,6 +352,7 @@ def register_systems(org_name, activationkey):
options.smargs += " --force"
if options.release:
options.smargs += " --release %s" % options.release
exec_failok("/usr/sbin/subscription-manager config --server.server_timeout=%s" % options.timeout)
exec_failexit("/usr/sbin/subscription-manager register --org '%s' --name '%s' --activationkey '%s' %s" % (org_label, FQDN, activationkey, options.smargs))
enable_rhsmcertd()

Expand Down Expand Up @@ -486,7 +488,7 @@ def install_foreman_ssh_key():
os.mkdir(foreman_ssh_dir, 0700)
os.chown(foreman_ssh_dir, userpw.pw_uid, userpw.pw_gid)
try:
foreman_ssh_key = urllib2.urlopen("https://%s:9090/ssh/pubkey" % options.foreman_fqdn).read()
foreman_ssh_key = urllib2.urlopen(("https://%s:9090/ssh/pubkey" % options.foreman_fqdn).read(), timeout=options.timeout)
except urllib2.HTTPError, e:
print_generic("The server was unable to fulfill the request. Error: %s - %s" % (e.code, e.reason))
print_generic("Please ensure the Remote Execution feature is configured properly")
Expand Down Expand Up @@ -539,7 +541,7 @@ def call_api(url, data=None, method='GET'):
if data:
request.add_data(json.dumps(data))
request.get_method = lambda: method
result = urllib2.urlopen(request)
result = urllib2.urlopen(request, timeout=options.timeout)
jsonresult = json.load(result)
if options.verbose:
print 'result: %s' % json.dumps(jsonresult, sort_keys=False, indent=2)
Expand Down Expand Up @@ -934,6 +936,7 @@ def exec_service(service, command, failonerror=True):
parser.add_option("--deps-repository-url", dest="deps_repository_url", help="URL to a repository that contains the subscription-manager RPMs")
parser.add_option("--deps-repository-gpg-key", dest="deps_repository_gpg_key", help="GPG Key to the repository that contains the subscription-manager RPMs", default="file:///etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release")
parser.add_option("--install-packages", dest="install_packages", help="List of packages to be additionally installed - comma separated", metavar="installpackages")
parser.add_option("-t", "--timeout", dest="timeout", type="int", help="Timeout (in seconds) for API calls and subscription-manager registration. Defaults to %default", metavar="timeout", default=900)
(options, args) = parser.parse_args()

if options.no_foreman:
Expand Down Expand Up @@ -1036,6 +1039,7 @@ def exec_service(service, command, failonerror=True):
print "LEGACY PASSWORD - %s" % options.legacy_password
print "DOWNLOAD METHOD - %s" % options.download_method
print "SKIP - %s" % options.skip
print "TIMEOUT - %s" % options.timeout

# > Exit if the user isn't root.
# Done here to allow an unprivileged user to run the script to see
Expand Down