Skip to content

Commit

Permalink
allow configuring timeout for API calls and subscription-manager (#237)
Browse files Browse the repository at this point in the history
  • Loading branch information
sideangleside authored and evgeni committed Jan 19, 2018
1 parent 3f3d316 commit 43c3982
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
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
~~~

# Additional Notes
Expand Down
8 changes: 6 additions & 2 deletions bootstrap.py
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,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 @@ -360,6 +361,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 @@ -498,7 +500,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 @@ -551,7 +553,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 @@ -946,6 +948,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 @@ -1048,6 +1051,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

0 comments on commit 43c3982

Please sign in to comment.