From 795499f5d42abb9879f2bdb12a8266f9c1849f33 Mon Sep 17 00:00:00 2001 From: Lukas Pramuk Date: Wed, 6 May 2015 12:31:18 +0200 Subject: [PATCH] satellite5 installation task refactoring --- automation_tools/__init__.py | 79 ------------------ automation_tools/satellite5.py | 148 +++++++++++++++++++++++++++++++++ fabfile.py | 4 + 3 files changed, 152 insertions(+), 79 deletions(-) create mode 100644 automation_tools/satellite5.py diff --git a/automation_tools/__init__.py b/automation_tools/__init__.py index dbfb54eb8..42d67aa7d 100644 --- a/automation_tools/__init__.py +++ b/automation_tools/__init__.py @@ -821,84 +821,6 @@ def iso_install( return installer_options -def satellite5_iso_install( - admin_password=None, check_sigs=False, run_katello_installer=True): - """Installs Satellite 5 from an ISO image. - - The following environment variables affect this command: - - """ - if isinstance(check_sigs, str): - check_sigs = (check_sigs.lower() == 'true') - - if admin_password is None: - admin_password = os.environ.get('ADMIN_PASSWORD', 'changeme') - - iso_url = os.environ.get('ISO_URL') or os.environ.get('BASE_URL') - if iso_url is None: - print('Please provide a valid URL for the ISO image.') - sys.exit(1) - - # Download the ISO - print('Downloading ISO...') - iso_download(iso_url) - # Create a 'check-out' folder, mount ISO to it... - run('mkdir -p ISO') - run('mount *.iso ISO -t iso9660 -o loop') - - # prepare the answer file - opts = { - 'admin-email': os.environ.get('ADMIN_EMAIL', ''), - 'rhn-username': os.environ.get('RHN_USERNAME', ''), - 'rhn-password': os.environ.get('RHN_PASSWORD', ''), - 'rhn-profile-name': os.environ.get('RHN_PROFILE', ''), - 'rhn-http-proxy': os.environ.get('RHN_HTTP_PROXY', ''), - 'rhn-http-proxy-username': - os.environ.get('RHN_HTTP_PROXY_USERNAME', ''), - 'rhn-http-proxy-password': - os.environ.get('RHN_HTTP_PROXY_PASSWORD', ''), - 'ssl-set-org': os.environ.get('SSL_SET_ORG', ''), - 'ssl-set-org-unit': os.environ.get('SSL_SET_ORG_UNIT', ''), - 'ssl-set-city': os.environ.get('SSL_SET_CITY', ''), - 'ssl-set-state': os.environ.get('SSL_SET_STATE', ''), - 'ssl-set-country': os.environ.get('SSL_SET_COUNTRY', ''), - 'ssl-password': os.environ.get('SSL_PASSWORD', ''), - 'satellite-cert-file': os.environ.get('SATELLITE_CERT_FILE', '') - } - run( - 'cat < /answers.txt\n' - 'admin-email={admin-email}\n' - 'rhn-username={rhn-username}\n' - 'rhn-password={rhn-password}\n' - 'rhn-profile-name={rhn-profile-name}\n' - 'rhn-http-proxy={rhn-http-proxy}\n' - 'rhn-http-proxy-username={rhn-http-proxy-username}\n' - 'rhn-http-proxy-password={rhn-http-proxy-password}\n' - 'ssl-config-sslvhost=y\n' - 'ssl-set-org={ssl-set-org}\n' - 'ssl-set-org-unit={ssl-set-org-unit}\n' - 'ssl-set-city={ssl-set-city}\n' - 'ssl-set-state={ssl-set-state}\n' - 'ssl-set-country={ssl-set-country}\n' - 'ssl-set-email={admin-email}\n' - 'ssl-password={ssl-password}\n' - 'satellite-cert-file=/root/satellite-engineering-qa-5.7.cert\n' - 'enable-tftp=yes\n' - 'EOF\n'.format(**opts) - ) - - # download a certificate - print('Downloading Certificate...') - run('wget {satellite-cert-file}'.format(**opts)) - # ...and run the installer script. - with cd('/root/ISO'): - run('./install.pl --answer-file=/answers.txt --non-interactive ' - '--re-register --run-updater=yes --enable-tftp=yes') - run('yum -y update') - - return {} - - def sam_upstream_install(admin_password=None): """Task to install SAM nightly using katello-deploy script""" upstream_install(admin_password, sam=True) @@ -934,7 +856,6 @@ def product_install(distribution, create_vm=False, certificate_url=None, 'satellite6-cdn': cdn_install, 'satellite6-downstream': downstream_install, 'satellite6-iso': iso_install, - 'satellite5-iso': satellite5_iso_install, 'satellite6-upstream': upstream_install, } distribution = distribution.lower() diff --git a/automation_tools/satellite5.py b/automation_tools/satellite5.py new file mode 100644 index 000000000..9cbff34e9 --- /dev/null +++ b/automation_tools/satellite5.py @@ -0,0 +1,148 @@ +"""A set of tasks for automating installation of Satellite5 servers. + +Many commands are affected by environment variables. Unless stated otherwise, +all environment variables are required. + +""" +from __future__ import print_function +import os +import sys + +from automation_tools import ( + install_prerequisites, + iso_download, + setenforce, + setup_ddns, + subscribe, + vm_create, + vm_destroy, +) +from automation_tools.repository import enable_satellite_repos +from automation_tools.utils import update_packages +from fabric.api import cd, env, execute, run + + +def satellite5_product_install(create_vm=False, selinux_mode=None): + """Task which installs only satellite5 product. + + If ``create_vm`` is True then ``vm_destroy`` and ``vm_create`` tasks will + be run. Make sure to set the required environment variables for those + tasks. Also, if one of the ``setup_ddns`` required environment variables + is set then that task will run. + + :param bool create_vm: creates a virtual machine and then install the + product on it. + :param str selinux_mode: switches to specified selinux mode. + + """ + # Command-line arguments are passed in as strings. + if isinstance(create_vm, str): + create_vm = (create_vm.lower() == 'true') + + if selinux_mode is None: + selinux_mode = os.environ.get('SELINUX_MODE', 'enforcing') + + if create_vm: + target_image = os.environ.get('TARGET_IMAGE') + if target_image is None: + print('The TARGET_IMAGE environment variable should be defined') + sys.exit(1) + + execute(vm_destroy, target_image, delete_image=True) + execute(vm_create) + + if 'DDNS_HASH' in os.environ or 'DDNS_PACKAGE_URL' in os.environ: + execute( + setup_ddns, env['vm_domain'], env['vm_ip'], host=env['vm_ip']) + + # When creating a vm the vm_ip will be set, otherwise use the fabric host + host = env.get('vm_ip', env['host']) + + # Register and subscribe machine to Red Hat + execute(subscribe, host=host) + + execute(install_prerequisites, host=host) + execute(setenforce, selinux_mode, host=host) + execute(enable_satellite_repos, host=host) + execute(update_packages, warn_only=True) + execute(satellite5_installer, host=host) + + +def satellite5_installer(): + """Installs Satellite 5 from an ISO image. + + The following environment variables affect this command: + + RHN_USERNAME + Red Hat Network username. + RHN_PASSWORD + Red Hat Network password. + ISO_URL + The URL where the ISO will be downloaded. + SATELLITE_CERT_URL + The URL where the activation certificate will be downloaded. + + """ + iso_url = os.environ.get('ISO_URL') + if iso_url is None: + print('Please provide a valid URL for the ISO image.') + sys.exit(1) + + # Download and mount the ISO + print('Downloading ISO...') + iso_download(iso_url) + run('umount ISO', warn_only=True) + run('mkdir -p ISO') + run('mount -t iso9660 -o loop *.iso ISO') + + # prepare the answer file + opts = { + 'admin-email': os.environ.get('ADMIN_EMAIL', 'root@localhost'), + 'rhn-username': os.environ.get('RHN_USERNAME', ''), + 'rhn-password': os.environ.get('RHN_PASSWORD', ''), + 'rhn-profile-name': os.environ.get('RHN_PROFILE', ''), + 'rhn-http-proxy': os.environ.get('RHN_HTTP_PROXY', ''), + 'rhn-http-proxy-username': + os.environ.get('RHN_HTTP_PROXY_USERNAME', ''), + 'rhn-http-proxy-password': + os.environ.get('RHN_HTTP_PROXY_PASSWORD', ''), + 'ssl-set-org': os.environ.get('SSL_SET_ORG', 'Red Hat'), + 'ssl-set-org-unit': os.environ.get('SSL_SET_ORG_UNIT', 'Satellite QE'), + 'ssl-set-city': os.environ.get('SSL_SET_CITY', 'Brno'), + 'ssl-set-state': os.environ.get('SSL_SET_STATE', 'BRQ'), + 'ssl-set-country': os.environ.get('SSL_SET_COUNTRY', 'CZ'), + 'ssl-password': os.environ.get('SSL_PASSWORD', 'reset'), + 'satellite-cert-url': os.environ.get('SATELLITE_CERT_URL', '') + } + run( + 'cat < /tmp/answers.txt\n' + 'admin-email={admin-email}\n' + 'rhn-username={rhn-username}\n' + 'rhn-password={rhn-password}\n' + 'rhn-profile-name={rhn-profile-name}\n' + 'rhn-http-proxy={rhn-http-proxy}\n' + 'rhn-http-proxy-username={rhn-http-proxy-username}\n' + 'rhn-http-proxy-password={rhn-http-proxy-password}\n' + 'ssl-config-sslvhost=y\n' + 'ssl-set-org={ssl-set-org}\n' + 'ssl-set-org-unit={ssl-set-org-unit}\n' + 'ssl-set-city={ssl-set-city}\n' + 'ssl-set-state={ssl-set-state}\n' + 'ssl-set-country={ssl-set-country}\n' + 'ssl-set-email={admin-email}\n' + 'ssl-password={ssl-password}\n' + 'satellite-cert-file=/tmp/SATCERT\n' + 'enable-tftp=yes\n' + 'EOF\n'.format(**opts) + ) + + # download a certificate + print('Downloading Certificate...') + run('wget -nv -O /tmp/SATCERT {satellite-cert-url}'.format(**opts)) + # ...and run the installer script. + with cd('ISO'): + run('./install.pl --answer-file=/tmp/answers.txt --non-interactive ' + '--re-register --run-updater=yes --enable-tftp=yes') + run('yum -y update') + run('spacewalk-schema-upgrade -y') + run('rhn-satellite restart') diff --git a/fabfile.py b/fabfile.py index 07d8a6640..94c115c03 100644 --- a/fabfile.py +++ b/fabfile.py @@ -46,6 +46,10 @@ enable_satellite_repos, manage_custom_repos, ) +from automation_tools.satellite5 import ( + satellite5_installer, + satellite5_product_install, +) from automation_tools.utils import ( distro_info, update_packages