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

make bootstrap.py EL5 compatible again #284

Merged
merged 2 commits into from
Jan 7, 2019
Merged
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
58 changes: 46 additions & 12 deletions bootstrap.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ def get_architecture():
'ENDC': '\033[0m',
}

SUBSCRIPTION_MANAGER_SERVER_TIMEOUT_VERSION = '1.18.2'


def filter_string(string):
"""Helper function to filter out passwords from strings"""
Expand Down Expand Up @@ -177,20 +179,39 @@ def check_migration_version():
"""
Verify that the command 'subscription-manager-migration' isn't too old.
"""
required_version = ('0', '1.14.2', '1')
err = "subscription-manager-migration not found"
required_version = '1.14.2'
_, err = check_package_version('subscription-manager-migration', required_version)

if err:
print_error(err)
sys.exit(1)


def check_subman_version(required_version):
"""
Verify that the command 'subscription-manager' isn't too old.
"""
status, _ = check_package_version('subscription-manager', required_version)

return status


def check_package_version(package_name, package_version):
"""
Verify that the version of a package
"""
required_version = ('0', package_version, '1')
err = "%s not found" % package_name

transaction_set = rpm.TransactionSet()
db_result = transaction_set.dbMatch('name', 'subscription-manager-migration')
db_result = transaction_set.dbMatch('name', package_name)
for package in db_result:
if rpm.labelCompare(('0', package['version'].decode('ascii'), '1'), required_version) < 0:
err = "%s %s is too old" % (package['name'], package['version'])
else:
err = None

if err:
print_error(err)
sys.exit(1)
return (err is None, err)


def setup_yum_repo(url, gpg_key):
Expand Down Expand Up @@ -382,7 +403,8 @@ 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)
if check_subman_version(SUBSCRIPTION_MANAGER_SERVER_TIMEOUT_VERSION):
exec_failok("/usr/sbin/subscription-manager config --server.server_timeout=%s" % options.timeout)
exec_command("/usr/sbin/rhn-migrate-classic-to-rhsm --org %s --activation-key '%s' %s" % (org_label, activationkey, options.rhsmargs), options.ignore_registration_failures)
exec_command("subscription-manager config --rhsm.baseurl=https://%s/pulp/repos" % options.foreman_fqdn, options.ignore_registration_failures)
if options.release:
Expand Down Expand Up @@ -411,7 +433,8 @@ 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)
if check_subman_version(SUBSCRIPTION_MANAGER_SERVER_TIMEOUT_VERSION):
exec_failok("/usr/sbin/subscription-manager config --server.server_timeout=%s" % options.timeout)
exec_command("/usr/sbin/subscription-manager register --org '%s' --name '%s' --activationkey '%s' %s" % (org_label, FQDN, activationkey, options.smargs), options.ignore_registration_failures)
enable_rhsmcertd()

Expand Down Expand Up @@ -586,7 +609,10 @@ def install_foreman_ssh_key(remote_url):
print_error("Foreman's SSH key not installed. File where authorized_keys must be located is not found: %s" % options.remote_exec_authpath)
return
try:
foreman_ssh_key = urllib2.urlopen(remote_url, timeout=options.timeout).read()
if sys.version_info >= (2, 6):
foreman_ssh_key = urllib2.urlopen(remote_url, timeout=options.timeout).read()
else:
foreman_ssh_key = urllib2.urlopen(remote_url).read()
except urllib2.HTTPError, exception:
print_generic("The server was unable to fulfill the request. Error: %s - %s" % (exception.code, exception.reason))
print_generic("Please ensure the Remote Execution feature is configured properly")
Expand Down Expand Up @@ -644,7 +670,10 @@ 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, timeout=options.timeout)
if sys.version_info >= (2, 6):
result = urllib2.urlopen(request, timeout=options.timeout)
else:
result = urllib2.urlopen(request)
jsonresult = json.load(result)
if options.verbose:
print 'result: %s' % json.dumps(jsonresult, sort_keys=False, indent=2)
Expand Down Expand Up @@ -1042,6 +1071,11 @@ def exec_service(service, command, failonerror=True):
RELEASE = platform.linux_distribution()[1]
except AttributeError:
RELEASE = platform.dist()[1]
IS_EL5 = int(RELEASE[0]) == 5
if not IS_EL5:
DEFAULT_DOWNLOAD_METHOD = 'https'
else:
DEFAULT_DOWNLOAD_METHOD = 'http'

SKIP_STEPS = ['foreman', 'puppet', 'migration', 'prereq-update', 'katello-agent', 'remove-obsolete-packages', 'puppet-enable']

Expand Down Expand Up @@ -1079,7 +1113,7 @@ def exec_service(service, command, failonerror=True):
parser.add_option("--remove", dest="remove", action="store_true", help="Instead of registering the machine to Foreman remove it")
parser.add_option("-r", "--release", dest="release", help="Specify release version")
parser.add_option("-R", "--remove-obsolete-packages", dest="removepkgs", action="store_true", help="Remove old Red Hat Network and RHUI Packages (default)", default=True)
parser.add_option("--download-method", dest="download_method", default="https", help="Method to download katello-ca-consumer package (e.g. http or https)", metavar="DOWNLOADMETHOD", choices=['http', 'https'])
parser.add_option("--download-method", dest="download_method", default=DEFAULT_DOWNLOAD_METHOD, help="Method to download katello-ca-consumer package (e.g. http or https)", metavar="DOWNLOADMETHOD", choices=['http', 'https'])
parser.add_option("--no-remove-obsolete-packages", dest="removepkgs", action="store_false", help="Don't remove old Red Hat Network and RHUI Packages")
parser.add_option("--unmanaged", dest="unmanaged", action="store_true", help="Add the server as unmanaged. Useful to skip provisioning dependencies.")
parser.add_option("--rex", dest="remote_exec", action="store_true", help="Install Foreman's SSH key for remote execution.", default=False)
Expand Down Expand Up @@ -1246,7 +1280,7 @@ def exec_service(service, command, failonerror=True):
clean_environment()

# > IF RHEL 5, not removing, and not moving to new capsule prepare the migration.
if not options.remove and int(RELEASE[0]) == 5 and not options.new_capsule:
if not options.remove and IS_EL5 and not options.new_capsule:
prepare_rhel5_migration()

if options.remove:
Expand Down