From 7197aba51d24ab2cf6cde77efa853903d7ddd5ba Mon Sep 17 00:00:00 2001 From: Devan Goodwin Date: Wed, 28 Oct 2015 12:12:39 -0300 Subject: Block upgrade if targetting enterprise deployment type. enterprise is being phased out in favor of openshift-enterprise, you need to specify where you wish to go. --- playbooks/adhoc/upgrades/upgrade.yml | 8 ++++++++ utils/src/ooinstall/cli_installer.py | 21 +++++++++++++++++++++ utils/src/ooinstall/install_transactions.py | 12 ++++++++++++ 3 files changed, 41 insertions(+) diff --git a/playbooks/adhoc/upgrades/upgrade.yml b/playbooks/adhoc/upgrades/upgrade.yml index 56a1df860..e8d6a335d 100644 --- a/playbooks/adhoc/upgrades/upgrade.yml +++ b/playbooks/adhoc/upgrades/upgrade.yml @@ -1,4 +1,12 @@ --- +- name: Verify deployment type + hosts: masters + tasks: + # Checking the global deployment type rather than host facts, this is about + # what the user is requesting. + - fail: msg="Deployment type enterprise not supported for upgrade" + when: deployment_type == "enterprise" + - name: Re-Run cluster configuration to apply latest configuration changes include: ../../common/openshift-cluster/config.yml vars: diff --git a/utils/src/ooinstall/cli_installer.py b/utils/src/ooinstall/cli_installer.py index 03f86a166..e22217fdb 100644 --- a/utils/src/ooinstall/cli_installer.py +++ b/utils/src/ooinstall/cli_installer.py @@ -459,6 +459,26 @@ def uninstall(ctx): install_transactions.run_uninstall_playbook() +@click.command() +@click.pass_context +def upgrade(ctx): + oo_cfg = ctx.obj['oo_cfg'] + + if len(oo_cfg.hosts) == 0: + click.echo("No hosts defined in: %s" % oo_cfg['configuration']) + sys.exit(1) + + click.echo("OpenShift will be upgraded on the following hosts:\n") + if not ctx.obj['unattended']: + # Prompt interactively to confirm: + for host in oo_cfg.hosts: + click.echo(" * %s" % host.name) + proceed = click.confirm("\nDo you wish to proceed?") + if not proceed: + click.echo("Upgrade cancelled.") + sys.exit(0) + install_transactions.run_upgrade_playbook() + @click.command() @click.option('--force', '-f', is_flag=True, default=False) @@ -523,6 +543,7 @@ http://docs.openshift.com/enterprise/latest/admin_guide/overview.html click.pause() cli.add_command(install) +cli.add_command(upgrade) cli.add_command(uninstall) if __name__ == '__main__': diff --git a/utils/src/ooinstall/install_transactions.py b/utils/src/ooinstall/install_transactions.py index 3306271c8..60b0f3d9f 100644 --- a/utils/src/ooinstall/install_transactions.py +++ b/utils/src/ooinstall/install_transactions.py @@ -143,3 +143,15 @@ def run_uninstall_playbook(): if 'ansible_config' in CFG.settings: facts_env['ANSIBLE_CONFIG'] = CFG.settings['ansible_config'] return run_ansible(playbook, inventory_file, facts_env) + +def run_upgrade_playbook(): + playbook = os.path.join(CFG.settings['ansible_playbook_directory'], + 'playbooks/adhoc/upgrades/upgrade.yml') + # TODO: Upgrade inventory for upgrade? + inventory_file = generate_inventory(CFG.hosts) + facts_env = os.environ.copy() + if 'ansible_log_path' in CFG.settings: + facts_env['ANSIBLE_LOG_PATH'] = CFG.settings['ansible_log_path'] + if 'ansible_config' in CFG.settings: + facts_env['ANSIBLE_CONFIG'] = CFG.settings['ansible_config'] + return run_ansible(playbook, inventory_file, facts_env) -- cgit v1.2.3 From 3d7c5c6fd545112d87fa09e4a8c3f3cbc1cda1ee Mon Sep 17 00:00:00 2001 From: Devan Goodwin Date: Wed, 28 Oct 2015 15:29:52 -0300 Subject: First cut at checking available disk space for etcd backup. --- playbooks/adhoc/upgrades/upgrade.yml | 27 ++++++++++++++++++++++++++- utils/src/ooinstall/cli_installer.py | 15 ++++++++++++++- utils/src/ooinstall/install_transactions.py | 1 - utils/src/ooinstall/variants.py | 5 ++++- 4 files changed, 44 insertions(+), 4 deletions(-) diff --git a/playbooks/adhoc/upgrades/upgrade.yml b/playbooks/adhoc/upgrades/upgrade.yml index e8d6a335d..c2c1d57e8 100644 --- a/playbooks/adhoc/upgrades/upgrade.yml +++ b/playbooks/adhoc/upgrades/upgrade.yml @@ -1,5 +1,5 @@ --- -- name: Verify deployment type +- name: Verify upgrade can proceed hosts: masters tasks: # Checking the global deployment type rather than host facts, this is about @@ -7,6 +7,31 @@ - fail: msg="Deployment type enterprise not supported for upgrade" when: deployment_type == "enterprise" +- name: Backup etcd + hosts: masters + vars: + embedded_etcd: "{{ openshift.master.embedded_etcd }}" + roles: + - openshift_facts + tasks: + - name: display all variables set for the current host + debug: + var: hostvars[inventory_hostname] + - debug: var=embedded_etcd + - name: Check available data dir disk space + shell: > + df --output=avail -k {{ openshift.common.data_dir }} | tail -n 1 + register: avail_disk + when: embedded_etcd | bool + - debug: var=avail_disk.stdout + - name: Check current etcd disk usage + shell: > + df --output=avail -k /var/lib/openshift/openshift.local.etcd/ | tail -n 1 + register: etc_disk_usage + when: embedded_etcd | bool + - debug: var=etc_disk_usage.stdout + - fail: msg="All done for now." + - name: Re-Run cluster configuration to apply latest configuration changes include: ../../common/openshift-cluster/config.yml vars: diff --git a/utils/src/ooinstall/cli_installer.py b/utils/src/ooinstall/cli_installer.py index e22217fdb..daac5e388 100644 --- a/utils/src/ooinstall/cli_installer.py +++ b/utils/src/ooinstall/cli_installer.py @@ -191,7 +191,7 @@ Notes: facts_confirmed = click.confirm("Do the above facts look correct?") if not facts_confirmed: message = """ -Edit %s with the desired values and rerun oo-install with --unattended . +Edit %s with the desired values and re-run with --unattended . """ % oo_cfg.config_path click.echo(message) # Make sure we actually write out the config file. @@ -477,6 +477,19 @@ def upgrade(ctx): if not proceed: click.echo("Upgrade cancelled.") sys.exit(0) + + # Update config to reflect the version we're targetting, we'll write + # to disk once ansible completes successfully, not before. + old_variant = oo_cfg.settings['variant'] + old_version = oo_cfg.settings['variant_version'] + if oo_cfg.settings['variant'] == 'enterprise': + oo_cfg.settings['variant'] = 'openshift-enterprise' + variant, version = find_variant(oo_cfg.settings['variant']) + oo_cfg.settings['variant_version'] = version.name + click.echo("Upgrading from %s %s to %s %s" % ( + old_variant, old_version, oo_cfg.settings['variant'], + oo_cfg.settings['variant_version'])) + install_transactions.run_upgrade_playbook() diff --git a/utils/src/ooinstall/install_transactions.py b/utils/src/ooinstall/install_transactions.py index 60b0f3d9f..1d1dbe340 100644 --- a/utils/src/ooinstall/install_transactions.py +++ b/utils/src/ooinstall/install_transactions.py @@ -14,7 +14,6 @@ def set_config(cfg): CFG = cfg def generate_inventory(hosts): - print hosts global CFG base_inventory_path = CFG.settings['ansible_inventory_path'] base_inventory = open(base_inventory_path, 'w') diff --git a/utils/src/ooinstall/variants.py b/utils/src/ooinstall/variants.py index ed98429fc..219af6cd2 100644 --- a/utils/src/ooinstall/variants.py +++ b/utils/src/ooinstall/variants.py @@ -29,6 +29,9 @@ class Variant(object): self.versions = versions + def latest_version(self): + return self.versions[-1] + # WARNING: Keep the versions ordered, most recent last: OSE = Variant('openshift-enterprise', 'OpenShift Enterprise', @@ -58,7 +61,7 @@ def find_variant(name, version=None): for prod in SUPPORTED_VARIANTS: if prod.name == name: if version is None: - return (prod, prod.versions[-1]) + return (prod, prod.latest_version()) for v in prod.versions: if v.name == version: return (prod, v) -- cgit v1.2.3 From 18df191a381ced63613dea302c5bf2e172d3c803 Mon Sep 17 00:00:00 2001 From: Devan Goodwin Date: Thu, 29 Oct 2015 15:07:42 -0300 Subject: Functional disk space checking for etcd backup. --- playbooks/adhoc/upgrades/upgrade.yml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/playbooks/adhoc/upgrades/upgrade.yml b/playbooks/adhoc/upgrades/upgrade.yml index c2c1d57e8..ec0eca66c 100644 --- a/playbooks/adhoc/upgrades/upgrade.yml +++ b/playbooks/adhoc/upgrades/upgrade.yml @@ -26,10 +26,13 @@ - debug: var=avail_disk.stdout - name: Check current etcd disk usage shell: > - df --output=avail -k /var/lib/openshift/openshift.local.etcd/ | tail -n 1 + du -k {{ openshift.common.data_dir }}/openshift.local.etcd | tail -n 1 | cut -f1 register: etc_disk_usage when: embedded_etcd | bool - debug: var=etc_disk_usage.stdout + - name: Abort if insufficient disk space for etcd backup + fail: msg="{{ etc_disk_usage.stdout }} Kb disk space required for etcd backup, {{ avail_disk.stdout }} Kb available." + when: (embedded_etcd | bool) and (etc_disk_usage.stdout|int > avail_disk.stdout|int) - fail: msg="All done for now." - name: Re-Run cluster configuration to apply latest configuration changes -- cgit v1.2.3 From ef2e4fc1fa247ba51394766f9cf9279f0beaf0b0 Mon Sep 17 00:00:00 2001 From: Devan Goodwin Date: Fri, 30 Oct 2015 09:02:26 -0300 Subject: Add etcd_data_dir fact. --- playbooks/adhoc/upgrades/upgrade.yml | 27 ++++++++++++------------ roles/openshift_facts/library/openshift_facts.py | 6 ++++++ 2 files changed, 20 insertions(+), 13 deletions(-) diff --git a/playbooks/adhoc/upgrades/upgrade.yml b/playbooks/adhoc/upgrades/upgrade.yml index ec0eca66c..948a320a2 100644 --- a/playbooks/adhoc/upgrades/upgrade.yml +++ b/playbooks/adhoc/upgrades/upgrade.yml @@ -14,25 +14,26 @@ roles: - openshift_facts tasks: - - name: display all variables set for the current host - debug: - var: hostvars[inventory_hostname] - - debug: var=embedded_etcd - - name: Check available data dir disk space + - debug: var=etcd_data_dir + - name: Check available disk space for etcd backup + # We assume to be using the data dir for all backups. shell: > df --output=avail -k {{ openshift.common.data_dir }} | tail -n 1 register: avail_disk - when: embedded_etcd | bool - - debug: var=avail_disk.stdout - - name: Check current etcd disk usage + + - name: Check current embedded etcd disk usage shell: > - du -k {{ openshift.common.data_dir }}/openshift.local.etcd | tail -n 1 | cut -f1 - register: etc_disk_usage + du -k {{ openshift.master.etcd_data_dir }} | tail -n 1 | cut -f1 + register: etcd_disk_usage when: embedded_etcd | bool - - debug: var=etc_disk_usage.stdout + - name: Abort if insufficient disk space for etcd backup - fail: msg="{{ etc_disk_usage.stdout }} Kb disk space required for etcd backup, {{ avail_disk.stdout }} Kb available." - when: (embedded_etcd | bool) and (etc_disk_usage.stdout|int > avail_disk.stdout|int) + fail: msg="{{ etcd_disk_usage.stdout }} Kb disk space required for etcd backup, {{ avail_disk.stdout }} Kb available." + when: (embedded_etcd | bool) and (etcd_disk_usage.stdout|int > avail_disk.stdout|int) + - name: Install etcd (for etcdctl) + yum: pkg=etcd state=latest + - name: Generate etcd backup + command: etcdctl backup - fail: msg="All done for now." - name: Re-Run cluster configuration to apply latest configuration changes diff --git a/roles/openshift_facts/library/openshift_facts.py b/roles/openshift_facts/library/openshift_facts.py index 3570de693..44f8cbb31 100755 --- a/roles/openshift_facts/library/openshift_facts.py +++ b/roles/openshift_facts/library/openshift_facts.py @@ -465,6 +465,12 @@ def set_aggregate_facts(facts): if 'cluster_public_hostname' in facts['master']: all_hostnames.add(facts['master']['cluster_public_hostname']) + if facts['master']['embedded_etcd']: + facts['master']['etcd_data_dir'] = os.path.join( + facts['common']['data_dir'], 'openshift.local.etcd') + else: + facts['master']['etcd_data_dir'] = '/var/lib/etcd' + facts['common']['all_hostnames'] = list(all_hostnames) return facts -- cgit v1.2.3 From 561c347d54c3a124f64b54eedbf6d2d56fb07c34 Mon Sep 17 00:00:00 2001 From: Devan Goodwin Date: Fri, 30 Oct 2015 09:41:12 -0300 Subject: Generate timestamped etcd backups. --- playbooks/adhoc/upgrades/upgrade.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/playbooks/adhoc/upgrades/upgrade.yml b/playbooks/adhoc/upgrades/upgrade.yml index 948a320a2..11d89a3da 100644 --- a/playbooks/adhoc/upgrades/upgrade.yml +++ b/playbooks/adhoc/upgrades/upgrade.yml @@ -11,10 +11,10 @@ hosts: masters vars: embedded_etcd: "{{ openshift.master.embedded_etcd }}" + timestamp: "{{ lookup('pipe', 'date +%Y%m%d%H%M%S') }}" roles: - openshift_facts tasks: - - debug: var=etcd_data_dir - name: Check available disk space for etcd backup # We assume to be using the data dir for all backups. shell: > @@ -33,7 +33,7 @@ - name: Install etcd (for etcdctl) yum: pkg=etcd state=latest - name: Generate etcd backup - command: etcdctl backup + command: etcdctl backup --data-dir={{ openshift.master.etcd_data_dir }} --backup-dir={{ openshift.common.data_dir }}/etcd-backup-{{ timestamp }} - fail: msg="All done for now." - name: Re-Run cluster configuration to apply latest configuration changes -- cgit v1.2.3 From 1976af21fed73240eb9b1f38daabc0af4d1dd388 Mon Sep 17 00:00:00 2001 From: Devan Goodwin Date: Fri, 30 Oct 2015 10:51:40 -0300 Subject: Add utils subpackage missing dep on openshift-ansible-roles. --- openshift-ansible.spec | 1 + 1 file changed, 1 insertion(+) diff --git a/openshift-ansible.spec b/openshift-ansible.spec index 3b69da825..d3be338a7 100644 --- a/openshift-ansible.spec +++ b/openshift-ansible.spec @@ -209,6 +209,7 @@ BuildArch: noarch Summary: Atomic OpenShift Utilities BuildRequires: python-setuptools Requires: openshift-ansible-playbooks +Requires: openshift-ansible-roles Requires: ansible Requires: python-click Requires: python-setuptools -- cgit v1.2.3 From 83e20a43c7b7e6876a7828d02b7fc96b8c8bbf38 Mon Sep 17 00:00:00 2001 From: Devan Goodwin Date: Fri, 30 Oct 2015 11:20:44 -0300 Subject: Remove devel fail and let upgrade proceed. --- playbooks/adhoc/upgrades/upgrade.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/playbooks/adhoc/upgrades/upgrade.yml b/playbooks/adhoc/upgrades/upgrade.yml index 11d89a3da..30896dc8e 100644 --- a/playbooks/adhoc/upgrades/upgrade.yml +++ b/playbooks/adhoc/upgrades/upgrade.yml @@ -34,7 +34,6 @@ yum: pkg=etcd state=latest - name: Generate etcd backup command: etcdctl backup --data-dir={{ openshift.master.etcd_data_dir }} --backup-dir={{ openshift.common.data_dir }}/etcd-backup-{{ timestamp }} - - fail: msg="All done for now." - name: Re-Run cluster configuration to apply latest configuration changes include: ../../common/openshift-cluster/config.yml @@ -50,6 +49,8 @@ vars: openshift_version: "{{ openshift_pkg_version | default('') }}" tasks: + - name: Upgrade to latest available kernel + yum: pkg=kernel state=latest - name: Upgrade master packages yum: pkg={{ openshift.common.service_type }}-master{{ openshift_version }} state=latest - name: Restart master services -- cgit v1.2.3 From 7063a66354faebe143124ff275cbe04a56c03237 Mon Sep 17 00:00:00 2001 From: Devan Goodwin Date: Mon, 2 Nov 2015 09:27:06 -0400 Subject: Automatically upgrade legacy config files. --- utils/src/ooinstall/oo_config.py | 41 ++++++++++++++++++++------- utils/test/oo_config_tests.py | 61 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 92 insertions(+), 10 deletions(-) diff --git a/utils/src/ooinstall/oo_config.py b/utils/src/ooinstall/oo_config.py index a2f53cf78..aa63180b5 100644 --- a/utils/src/ooinstall/oo_config.py +++ b/utils/src/ooinstall/oo_config.py @@ -73,7 +73,6 @@ class Host(object): class OOConfig(object): - new_config = True default_dir = os.path.normpath( os.environ.get('XDG_CONFIG_HOME', os.environ['HOME'] + '/.config/') + '/openshift/') @@ -86,19 +85,22 @@ class OOConfig(object): self.config_path = os.path.normpath(self.default_dir + self.default_file) self.settings = {} - self.read_config() - self.set_defaults() + self._read_config() + self._set_defaults() - def read_config(self, is_new=False): + def _read_config(self): self.hosts = [] try: - new_settings = None if os.path.exists(self.config_path): cfgfile = open(self.config_path, 'r') - new_settings = yaml.safe_load(cfgfile.read()) + self.settings = yaml.safe_load(cfgfile.read()) cfgfile.close() - if new_settings: - self.settings = new_settings + + # Use the presence of a Description as an indicator this is + # a legacy config file: + if 'Description' in self.settings: + self._upgrade_legacy_config() + # Parse the hosts into DTO objects: if 'hosts' in self.settings: for host in self.settings['hosts']: @@ -114,9 +116,28 @@ class OOConfig(object): ferr.strerror)) except yaml.scanner.ScannerError: raise OOConfigFileError('Config file "{}" is not a valid YAML document'.format(self.config_path)) - self.new_config = is_new - def set_defaults(self): + def _upgrade_legacy_config(self): + new_hosts = [] + if 'validated_facts' in self.settings: + for key, value in self.settings['validated_facts'].iteritems(): + if 'masters' in self.settings and key in self.settings['masters']: + value['master'] = True + if 'nodes' in self.settings and key in self.settings['nodes']: + value['node'] = True + new_hosts.append(value) + self.settings['hosts'] = new_hosts + + remove_settings = ['validated_facts', 'Description', 'Name', + 'Subscription', 'Vendor', 'Version', 'masters', 'nodes'] + for s in remove_settings: + del self.settings[s] + + # A legacy config implies openshift-enterprise 3.0: + self.settings['variant'] = 'openshift-enterprise' + self.settings['variant_version'] = '3.0' + + def _set_defaults(self): if 'ansible_inventory_directory' not in self.settings: self.settings['ansible_inventory_directory'] = \ diff --git a/utils/test/oo_config_tests.py b/utils/test/oo_config_tests.py index 01af33fd9..b88218459 100644 --- a/utils/test/oo_config_tests.py +++ b/utils/test/oo_config_tests.py @@ -32,6 +32,26 @@ hosts: node: true """ +# Used to test automatic upgrading of config: +LEGACY_CONFIG = """ +Description: This is the configuration file for the OpenShift Ansible-Based Installer. +Name: OpenShift Ansible-Based Installer Configuration +Subscription: {type: none} +Vendor: OpenShift Community +Version: 0.0.1 +ansible_config: /home/dgoodwin/.python-eggs/ooinstall-3.0.0-py2.7.egg-tmp/ooinstall/ansible.cfg +ansible_inventory_directory: /home/dgoodwin/.config/openshift/.ansible +ansible_log_path: /tmp/ansible.log +ansible_plugins_directory: /home/dgoodwin/.python-eggs/ooinstall-3.0.0-py2.7.egg-tmp/ooinstall/ansible_plugins +masters: [10.0.0.1] +nodes: [10.0.0.2, 10.0.0.3] +validated_facts: + 10.0.0.1: {hostname: master-private.example.com, ip: 10.0.0.1, public_hostname: master.example.com, public_ip: 24.222.0.1} + 10.0.0.2: {hostname: node1-private.example.com, ip: 10.0.0.2, public_hostname: node1.example.com, public_ip: 24.222.0.2} + 10.0.0.3: {hostname: node2-private.example.com, ip: 10.0.0.3, public_hostname: node2.example.com, public_ip: 24.222.0.3} +""" + + CONFIG_INCOMPLETE_FACTS = """ hosts: - ip: 10.0.0.1 @@ -74,6 +94,47 @@ class OOInstallFixture(unittest.TestCase): return path +class LegacyOOConfigTests(OOInstallFixture): + + def setUp(self): + OOInstallFixture.setUp(self) + self.cfg_path = self.write_config(os.path.join(self.work_dir, + 'ooinstall.conf'), LEGACY_CONFIG) + self.cfg = OOConfig(self.cfg_path) + + def test_load_config_memory(self): + self.assertEquals('openshift-enterprise', self.cfg.settings['variant']) + self.assertEquals('3.0', self.cfg.settings['variant_version']) + + self.assertEquals(3, len(self.cfg.hosts)) + h1 = self.cfg.get_host('10.0.0.1') + self.assertEquals('10.0.0.1', h1.ip) + self.assertEquals('24.222.0.1', h1.public_ip) + self.assertEquals('master-private.example.com', h1.hostname) + self.assertEquals('master.example.com', h1.public_hostname) + + h2 = self.cfg.get_host('10.0.0.2') + self.assertEquals('10.0.0.2', h2.ip) + self.assertEquals('24.222.0.2', h2.public_ip) + self.assertEquals('node1-private.example.com', h2.hostname) + self.assertEquals('node1.example.com', h2.public_hostname) + + h3 = self.cfg.get_host('10.0.0.3') + self.assertEquals('10.0.0.3', h3.ip) + self.assertEquals('24.222.0.3', h3.public_ip) + self.assertEquals('node2-private.example.com', h3.hostname) + self.assertEquals('node2.example.com', h3.public_hostname) + + self.assertFalse('masters' in self.cfg.settings) + self.assertFalse('nodes' in self.cfg.settings) + self.assertFalse('Description' in self.cfg.settings) + self.assertFalse('Name' in self.cfg.settings) + self.assertFalse('Subscription' in self.cfg.settings) + self.assertFalse('Vendor' in self.cfg.settings) + self.assertFalse('Version' in self.cfg.settings) + self.assertFalse('validates_facts' in self.cfg.settings) + + class OOConfigTests(OOInstallFixture): def test_load_config(self): -- cgit v1.2.3 From 1ddfdd136f4b22368c87ad7656faa0cccdfa4a25 Mon Sep 17 00:00:00 2001 From: Devan Goodwin Date: Mon, 2 Nov 2015 10:10:46 -0400 Subject: Print info after upgrade completes. --- utils/src/ooinstall/cli_installer.py | 7 ++++++- utils/src/ooinstall/install_transactions.py | 2 ++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/utils/src/ooinstall/cli_installer.py b/utils/src/ooinstall/cli_installer.py index daac5e388..978259f79 100644 --- a/utils/src/ooinstall/cli_installer.py +++ b/utils/src/ooinstall/cli_installer.py @@ -490,7 +490,12 @@ def upgrade(ctx): old_variant, old_version, oo_cfg.settings['variant'], oo_cfg.settings['variant_version'])) - install_transactions.run_upgrade_playbook() + retcode = install_transactions.run_upgrade_playbook() + if retcode > 0: + click.echo("Errors encountered during upgrade, please check %s." % + oo_cfg.settings['ansible_log_path']) + else: + click.echo("Upgrade completed! Rebooting all hosts is recommended.") @click.command() diff --git a/utils/src/ooinstall/install_transactions.py b/utils/src/ooinstall/install_transactions.py index 1d1dbe340..0754b8ab6 100644 --- a/utils/src/ooinstall/install_transactions.py +++ b/utils/src/ooinstall/install_transactions.py @@ -143,6 +143,7 @@ def run_uninstall_playbook(): facts_env['ANSIBLE_CONFIG'] = CFG.settings['ansible_config'] return run_ansible(playbook, inventory_file, facts_env) + def run_upgrade_playbook(): playbook = os.path.join(CFG.settings['ansible_playbook_directory'], 'playbooks/adhoc/upgrades/upgrade.yml') @@ -154,3 +155,4 @@ def run_upgrade_playbook(): if 'ansible_config' in CFG.settings: facts_env['ANSIBLE_CONFIG'] = CFG.settings['ansible_config'] return run_ansible(playbook, inventory_file, facts_env) + -- cgit v1.2.3 From 866dcbe962464a571f24e1e4ae5a9e928f7bbc47 Mon Sep 17 00:00:00 2001 From: Devan Goodwin Date: Mon, 2 Nov 2015 13:14:26 -0400 Subject: Fix etcd backup bug with not-yet-created /var/lib/origin symlink --- playbooks/adhoc/upgrades/upgrade.yml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/playbooks/adhoc/upgrades/upgrade.yml b/playbooks/adhoc/upgrades/upgrade.yml index 30896dc8e..c543a4416 100644 --- a/playbooks/adhoc/upgrades/upgrade.yml +++ b/playbooks/adhoc/upgrades/upgrade.yml @@ -15,6 +15,11 @@ roles: - openshift_facts tasks: + - stat: path=/var/lib/openshift + register: var_lib_openshift + - name: Create origin symlink if necessary + file: src=/var/lib/openshift/ dest=/var/lib/origin state=link + when: var_lib_openshift.stat.exists == True - name: Check available disk space for etcd backup # We assume to be using the data dir for all backups. shell: > -- cgit v1.2.3 From ef6b36d14a00757754aaf001a8acad8354cf62ff Mon Sep 17 00:00:00 2001 From: Devan Goodwin Date: Mon, 2 Nov 2015 15:17:47 -0400 Subject: Better info prior to initiating upgrade. --- utils/src/ooinstall/cli_installer.py | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/utils/src/ooinstall/cli_installer.py b/utils/src/ooinstall/cli_installer.py index 978259f79..c39eb5cac 100644 --- a/utils/src/ooinstall/cli_installer.py +++ b/utils/src/ooinstall/cli_installer.py @@ -468,16 +468,6 @@ def upgrade(ctx): click.echo("No hosts defined in: %s" % oo_cfg['configuration']) sys.exit(1) - click.echo("OpenShift will be upgraded on the following hosts:\n") - if not ctx.obj['unattended']: - # Prompt interactively to confirm: - for host in oo_cfg.hosts: - click.echo(" * %s" % host.name) - proceed = click.confirm("\nDo you wish to proceed?") - if not proceed: - click.echo("Upgrade cancelled.") - sys.exit(0) - # Update config to reflect the version we're targetting, we'll write # to disk once ansible completes successfully, not before. old_variant = oo_cfg.settings['variant'] @@ -486,9 +476,18 @@ def upgrade(ctx): oo_cfg.settings['variant'] = 'openshift-enterprise' variant, version = find_variant(oo_cfg.settings['variant']) oo_cfg.settings['variant_version'] = version.name - click.echo("Upgrading from %s %s to %s %s" % ( + click.echo("Openshift will be upgraded from %s %s to %s %s on the following hosts:\n" % ( old_variant, old_version, oo_cfg.settings['variant'], oo_cfg.settings['variant_version'])) + for host in oo_cfg.hosts: + click.echo(" * %s" % host.name) + + if not ctx.obj['unattended']: + # Prompt interactively to confirm: + proceed = click.confirm("\nDo you wish to proceed?") + if not proceed: + click.echo("Upgrade cancelled.") + sys.exit(0) retcode = install_transactions.run_upgrade_playbook() if retcode > 0: -- cgit v1.2.3 From 078a44715b1190f4a7e0b098b0dc87446d88ac8c Mon Sep 17 00:00:00 2001 From: Jason DeTiberus Date: Mon, 2 Nov 2015 17:09:54 -0500 Subject: initial module framework --- .../upgrades/library/openshift_upgrade_config.py | 62 ++++++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100755 playbooks/adhoc/upgrades/library/openshift_upgrade_config.py diff --git a/playbooks/adhoc/upgrades/library/openshift_upgrade_config.py b/playbooks/adhoc/upgrades/library/openshift_upgrade_config.py new file mode 100755 index 000000000..157fbc5c2 --- /dev/null +++ b/playbooks/adhoc/upgrades/library/openshift_upgrade_config.py @@ -0,0 +1,62 @@ +#!/usr/bin/python +# -*- coding: utf-8 -*- +# vim: expandtab:tabstop=4:shiftwidth=4 + +"""Ansible module for modifying OpenShift configs during an upgrade""" + +DOCUMENTATION = ''' +--- +module: openshift_upgrade_config +short_description: OpenShift Upgrade Config +author: Jason DeTiberus +requirements: [ ] +''' +EXAMPLES = ''' +''' + +def upgrade_master_3_0_to_3_1(backup): + pass + + +def upgrade_master(from_version, to_version, backup): + if from_version == '3.0': + if to_version == '3.1': + upgrade_master_3_0_to_3_1(backup) + + +def main(): + """ main """ + # disabling pylint errors for global-variable-undefined and invalid-name + # for 'global module' usage, since it is required to use ansible_facts + # pylint: disable=global-variable-undefined, invalid-name + global module + + module = AnsibleModule( + argument_spec=dict( + from_version=dict(required=True, choices=['3.0']), + to_version=dict(required=True, choices=['3.1']), + role=dict(required=True, choices=['master']), + backup=dict(required=False, default=True, type='bool') + ), + supports_check_mode=True, + ) + + changed = False + + from_version = module.params['from_version'] + to_version = module.params['to_version'] + role = module.params['role'] + backup = module.params['backup'] + + if role == 'master': + upgrade_master(from_version, to_version, backup) + + return module.exit_json(changed=changed) + +# ignore pylint errors related to the module_utils import +# pylint: disable=redefined-builtin, unused-wildcard-import, wildcard-import +# import module snippets +from ansible.module_utils.basic import * + +if __name__ == '__main__': + main() -- cgit v1.2.3 From 39250a47afca63ef0b5a73158a2c9b15443a4235 Mon Sep 17 00:00:00 2001 From: Devan Goodwin Date: Tue, 3 Nov 2015 08:27:26 -0400 Subject: Pylint fix. --- utils/src/ooinstall/cli_installer.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/utils/src/ooinstall/cli_installer.py b/utils/src/ooinstall/cli_installer.py index c39eb5cac..21e50de6d 100644 --- a/utils/src/ooinstall/cli_installer.py +++ b/utils/src/ooinstall/cli_installer.py @@ -474,7 +474,7 @@ def upgrade(ctx): old_version = oo_cfg.settings['variant_version'] if oo_cfg.settings['variant'] == 'enterprise': oo_cfg.settings['variant'] = 'openshift-enterprise' - variant, version = find_variant(oo_cfg.settings['variant']) + version = find_variant(oo_cfg.settings['variant'])[0] oo_cfg.settings['variant_version'] = version.name click.echo("Openshift will be upgraded from %s %s to %s %s on the following hosts:\n" % ( old_variant, old_version, oo_cfg.settings['variant'], -- cgit v1.2.3 From f91c0cac0b6e671d5ad70543054a17178c5f0a46 Mon Sep 17 00:00:00 2001 From: Devan Goodwin Date: Tue, 3 Nov 2015 08:37:31 -0400 Subject: Add a simple version for the installer config file. --- utils/src/ooinstall/oo_config.py | 3 +++ utils/test/oo_config_tests.py | 3 +++ 2 files changed, 6 insertions(+) diff --git a/utils/src/ooinstall/oo_config.py b/utils/src/ooinstall/oo_config.py index aa63180b5..4281947f1 100644 --- a/utils/src/ooinstall/oo_config.py +++ b/utils/src/ooinstall/oo_config.py @@ -12,6 +12,7 @@ PERSIST_SETTINGS = [ 'ansible_log_path', 'variant', 'variant_version', + 'version', ] REQUIRED_FACTS = ['ip', 'public_ip', 'hostname', 'public_hostname'] @@ -146,6 +147,8 @@ class OOConfig(object): os.makedirs(self.settings['ansible_inventory_directory']) if 'ansible_plugins_directory' not in self.settings: self.settings['ansible_plugins_directory'] = resource_filename(__name__, 'ansible_plugins') + if 'version' not in self.settings: + self.settings['version'] = 'v1' if 'ansible_callback_facts_yaml' not in self.settings: self.settings['ansible_callback_facts_yaml'] = '%s/callback_facts.yaml' % \ diff --git a/utils/test/oo_config_tests.py b/utils/test/oo_config_tests.py index b88218459..480560542 100644 --- a/utils/test/oo_config_tests.py +++ b/utils/test/oo_config_tests.py @@ -105,6 +105,7 @@ class LegacyOOConfigTests(OOInstallFixture): def test_load_config_memory(self): self.assertEquals('openshift-enterprise', self.cfg.settings['variant']) self.assertEquals('3.0', self.cfg.settings['variant_version']) + self.assertEquals('v1', self.cfg.settings['version']) self.assertEquals(3, len(self.cfg.hosts)) h1 = self.cfg.get_host('10.0.0.1') @@ -152,6 +153,7 @@ class OOConfigTests(OOInstallFixture): [host['ip'] for host in ooconfig.settings['hosts']]) self.assertEquals('openshift-enterprise', ooconfig.settings['variant']) + self.assertEquals('v1', ooconfig.settings['version']) def test_load_complete_facts(self): cfg_path = self.write_config(os.path.join(self.work_dir, @@ -189,6 +191,7 @@ class OOConfigTests(OOInstallFixture): self.assertTrue('ansible_ssh_user' in written_config) self.assertTrue('variant' in written_config) + self.assertEquals('v1', written_config['version']) # Some advanced settings should not get written out if they # were not specified by the user: -- cgit v1.2.3 From 3f28361fdf56c9e7395fcbfe5c2698569f8a5684 Mon Sep 17 00:00:00 2001 From: Devan Goodwin Date: Tue, 3 Nov 2015 08:57:57 -0400 Subject: Remove my username from some test data. --- utils/test/oo_config_tests.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/utils/test/oo_config_tests.py b/utils/test/oo_config_tests.py index 480560542..6dc335a0e 100644 --- a/utils/test/oo_config_tests.py +++ b/utils/test/oo_config_tests.py @@ -39,10 +39,10 @@ Name: OpenShift Ansible-Based Installer Configuration Subscription: {type: none} Vendor: OpenShift Community Version: 0.0.1 -ansible_config: /home/dgoodwin/.python-eggs/ooinstall-3.0.0-py2.7.egg-tmp/ooinstall/ansible.cfg -ansible_inventory_directory: /home/dgoodwin/.config/openshift/.ansible +ansible_config: /tmp/notreal/ansible.cfg +ansible_inventory_directory: /tmp/notreal/.config/openshift/.ansible ansible_log_path: /tmp/ansible.log -ansible_plugins_directory: /home/dgoodwin/.python-eggs/ooinstall-3.0.0-py2.7.egg-tmp/ooinstall/ansible_plugins +ansible_plugins_directory: /tmp/notreal/.python-eggs/ooinstall-3.0.0-py2.7.egg-tmp/ooinstall/ansible_plugins masters: [10.0.0.1] nodes: [10.0.0.2, 10.0.0.3] validated_facts: -- cgit v1.2.3 From ec31736606fc280de641e8909f03416c6b74e004 Mon Sep 17 00:00:00 2001 From: Devan Goodwin Date: Tue, 3 Nov 2015 09:20:04 -0400 Subject: Document the new version field for installer config. --- utils/docs/config.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/utils/docs/config.md b/utils/docs/config.md index 9399409dd..ee4b157c9 100644 --- a/utils/docs/config.md +++ b/utils/docs/config.md @@ -7,6 +7,7 @@ The default location this config file will be written to ~/.config/openshift/ins ## Example ``` +version: v1 variant: openshift-enterprise variant_version: 3.0 ansible_ssh_user: root @@ -32,6 +33,10 @@ hosts: ## Primary Settings +### version + +Indicates the version of configuration this file was written with. Current implementation is v1. + ### variant The OpenShift variant to install. Currently valid options are: -- cgit v1.2.3 From ab83e16dbed3eb5cf1dff96992509439d2739550 Mon Sep 17 00:00:00 2001 From: Devan Goodwin Date: Tue, 3 Nov 2015 09:51:10 -0400 Subject: Fix installer upgrade bug following pylint fix. --- utils/src/ooinstall/cli_installer.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/utils/src/ooinstall/cli_installer.py b/utils/src/ooinstall/cli_installer.py index 21e50de6d..2fc7a872f 100644 --- a/utils/src/ooinstall/cli_installer.py +++ b/utils/src/ooinstall/cli_installer.py @@ -474,7 +474,7 @@ def upgrade(ctx): old_version = oo_cfg.settings['variant_version'] if oo_cfg.settings['variant'] == 'enterprise': oo_cfg.settings['variant'] = 'openshift-enterprise' - version = find_variant(oo_cfg.settings['variant'])[0] + version = find_variant(oo_cfg.settings['variant'])[1] oo_cfg.settings['variant_version'] = version.name click.echo("Openshift will be upgraded from %s %s to %s %s on the following hosts:\n" % ( old_variant, old_version, oo_cfg.settings['variant'], -- cgit v1.2.3 From cbf98f53b0975a829a5720c33149c7014d5bd7cd Mon Sep 17 00:00:00 2001 From: Devan Goodwin Date: Tue, 3 Nov 2015 09:27:13 -0400 Subject: Implement master-config.yaml upgrade for v1beta3 apiLevel removal. --- .../upgrades/library/openshift_upgrade_config.py | 53 ++++++++++++++++++++-- playbooks/adhoc/upgrades/upgrade.yml | 25 ++++++---- utils/src/ooinstall/install_transactions.py | 2 +- 3 files changed, 67 insertions(+), 13 deletions(-) diff --git a/playbooks/adhoc/upgrades/library/openshift_upgrade_config.py b/playbooks/adhoc/upgrades/library/openshift_upgrade_config.py index 157fbc5c2..f41c6fb59 100755 --- a/playbooks/adhoc/upgrades/library/openshift_upgrade_config.py +++ b/playbooks/adhoc/upgrades/library/openshift_upgrade_config.py @@ -2,6 +2,12 @@ # -*- coding: utf-8 -*- # vim: expandtab:tabstop=4:shiftwidth=4 +import os +import shutil +import yaml + +from datetime import datetime + """Ansible module for modifying OpenShift configs during an upgrade""" DOCUMENTATION = ''' @@ -14,14 +20,53 @@ requirements: [ ] EXAMPLES = ''' ''' +def get_cfg_dir(): + cfg_path = '/etc/origin/' + if not os.path.exists(cfg_path): + cfg_path = '/etc/openshift/' + return cfg_path + def upgrade_master_3_0_to_3_1(backup): - pass + changed = False + + # Facts do not get transferred to the hosts where custom modules run, + # need to make some assumptions here. + master_config = os.path.join(get_cfg_dir(), 'master/master-config.yaml') + + f = open(master_config, 'r') + config = yaml.safe_load(f.read()) + f.close() + + # Remove v1beta3 from apiLevels: + if 'apiLevels' in config and \ + 'v1beta3' in config['apiLevels']: + config['apiLevels'].remove('v1beta3') + changed = True + if 'kubernetesMasterConfig' in config and \ + 'apiLevels' in config['kubernetesMasterConfig'] and \ + 'v1beta3' in config['kubernetesMasterConfig']['apiLevels']: + config['kubernetesMasterConfig']['apiLevels'].remove('v1beta3') + changed = True + + if changed: + if backup: + timestamp = datetime.now().strftime('%Y%m%d%H%M%S') + basedir = os.path.split(master_config)[0] + backup_file = os.path.join(basedir, 'master-config.yaml.bak-%s' + % timestamp) + shutil.copyfile(master_config, backup_file) + # Write the modified config: + out_file = open(master_config, 'w') + out_file.write(yaml.safe_dump(config, default_flow_style=False)) + out_file.close() + + return changed def upgrade_master(from_version, to_version, backup): if from_version == '3.0': if to_version == '3.1': - upgrade_master_3_0_to_3_1(backup) + return upgrade_master_3_0_to_3_1(backup) def main(): @@ -41,15 +86,15 @@ def main(): supports_check_mode=True, ) - changed = False from_version = module.params['from_version'] to_version = module.params['to_version'] role = module.params['role'] backup = module.params['backup'] + changed = False if role == 'master': - upgrade_master(from_version, to_version, backup) + changed = upgrade_master(from_version, to_version, backup) return module.exit_json(changed=changed) diff --git a/playbooks/adhoc/upgrades/upgrade.yml b/playbooks/adhoc/upgrades/upgrade.yml index e55f1536f..6cb6803a9 100644 --- a/playbooks/adhoc/upgrades/upgrade.yml +++ b/playbooks/adhoc/upgrades/upgrade.yml @@ -40,6 +40,15 @@ - name: Generate etcd backup command: etcdctl backup --data-dir={{ openshift.master.etcd_data_dir }} --backup-dir={{ openshift.common.data_dir }}/etcd-backup-{{ timestamp }} +- name: Update 3.0 configuration to 3.1 + hosts: masters + tasks: + tasks: + - debug: var=openshift_master_config_dir + - name: Upgrade configuration. + openshift_upgrade_config: from_version=3.0 to_version=3.1 role=master + - fail: All done for now. + - name: Upgrade base package on masters hosts: masters roles: @@ -50,14 +59,14 @@ - name: Upgrade base package yum: pkg={{ openshift.common.service_type }}{{ openshift_version }} state=latest -- name: Re-Run cluster configuration to apply latest configuration changes - include: ../../common/openshift-cluster/config.yml - vars: - g_etcd_group: "{{ 'etcd' }}" - g_masters_group: "{{ 'masters' }}" - g_nodes_group: "{{ 'nodes' }}" - openshift_cluster_id: "{{ cluster_id | default('default') }}" - openshift_deployment_type: "{{ deployment_type }}" + #- name: Re-Run cluster configuration to apply latest configuration changes + # include: ../../common/openshift-cluster/config.yml + # vars: + # g_etcd_group: "{{ 'etcd' }}" + # g_masters_group: "{{ 'masters' }}" + # g_nodes_group: "{{ 'nodes' }}" + # openshift_cluster_id: "{{ cluster_id | default('default') }}" + # openshift_deployment_type: "{{ deployment_type }}" - name: Upgrade masters hosts: masters diff --git a/utils/src/ooinstall/install_transactions.py b/utils/src/ooinstall/install_transactions.py index 0754b8ab6..e71bc183b 100644 --- a/utils/src/ooinstall/install_transactions.py +++ b/utils/src/ooinstall/install_transactions.py @@ -127,7 +127,7 @@ def run_main_playbook(hosts, hosts_to_run_on): def run_ansible(playbook, inventory, env_vars): - return subprocess.call(['ansible-playbook', + return subprocess.call(['ansible-playbook', '-v', '--inventory-file={}'.format(inventory), playbook], env=env_vars) -- cgit v1.2.3 From 6b03fcb185c7f37e258dd34ca8b70d5c124cabba Mon Sep 17 00:00:00 2001 From: Devan Goodwin Date: Tue, 3 Nov 2015 11:48:27 -0400 Subject: Add in proxyClientInfo if missing during config upgrade. --- playbooks/adhoc/upgrades/library/openshift_upgrade_config.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/playbooks/adhoc/upgrades/library/openshift_upgrade_config.py b/playbooks/adhoc/upgrades/library/openshift_upgrade_config.py index f41c6fb59..95c7b1664 100755 --- a/playbooks/adhoc/upgrades/library/openshift_upgrade_config.py +++ b/playbooks/adhoc/upgrades/library/openshift_upgrade_config.py @@ -26,6 +26,7 @@ def get_cfg_dir(): cfg_path = '/etc/openshift/' return cfg_path + def upgrade_master_3_0_to_3_1(backup): changed = False @@ -42,12 +43,18 @@ def upgrade_master_3_0_to_3_1(backup): 'v1beta3' in config['apiLevels']: config['apiLevels'].remove('v1beta3') changed = True - if 'kubernetesMasterConfig' in config and \ - 'apiLevels' in config['kubernetesMasterConfig'] and \ + if 'apiLevels' in config['kubernetesMasterConfig'] and \ 'v1beta3' in config['kubernetesMasterConfig']['apiLevels']: config['kubernetesMasterConfig']['apiLevels'].remove('v1beta3') changed = True + # Add the new master proxy client certs: + if 'proxyClientInfo' not in config['kubernetesMasterConfig']: + config['kubernetesMasterConfig']['proxyClientInfo'] = { + 'certFile': 'master.proxy-client.crt', + 'keyFile': 'master.proxy-client.key' + } + if changed: if backup: timestamp = datetime.now().strftime('%Y%m%d%H%M%S') @@ -86,7 +93,6 @@ def main(): supports_check_mode=True, ) - from_version = module.params['from_version'] to_version = module.params['to_version'] role = module.params['role'] -- cgit v1.2.3 From 74420660b1b12a00392a6d88a257e0cfe1b0a08e Mon Sep 17 00:00:00 2001 From: Devan Goodwin Date: Tue, 3 Nov 2015 12:34:05 -0400 Subject: Move config upgrade to correct place, fix node facts. --- playbooks/adhoc/upgrades/upgrade.yml | 29 ++++++++++++++++++--------- playbooks/common/openshift-cluster/config.yml | 6 +++--- utils/src/ooinstall/install_transactions.py | 2 +- 3 files changed, 24 insertions(+), 13 deletions(-) diff --git a/playbooks/adhoc/upgrades/upgrade.yml b/playbooks/adhoc/upgrades/upgrade.yml index 6cb6803a9..6e7292da1 100644 --- a/playbooks/adhoc/upgrades/upgrade.yml +++ b/playbooks/adhoc/upgrades/upgrade.yml @@ -40,15 +40,6 @@ - name: Generate etcd backup command: etcdctl backup --data-dir={{ openshift.master.etcd_data_dir }} --backup-dir={{ openshift.common.data_dir }}/etcd-backup-{{ timestamp }} -- name: Update 3.0 configuration to 3.1 - hosts: masters - tasks: - tasks: - - debug: var=openshift_master_config_dir - - name: Upgrade configuration. - openshift_upgrade_config: from_version=3.0 to_version=3.1 role=master - - fail: All done for now. - - name: Upgrade base package on masters hosts: masters roles: @@ -77,6 +68,8 @@ yum: pkg=kernel state=latest - name: Upgrade master packages yum: pkg={{ openshift.common.service_type }}-master{{ openshift_version }} state=latest + - name: Upgrade master configuration. + openshift_upgrade_config: from_version=3.0 to_version=3.1 role=master - name: Restart master services service: name="{{ openshift.common.service_type}}-master" state=restarted @@ -84,12 +77,30 @@ hosts: nodes vars: openshift_version: "{{ openshift_pkg_version | default('') }}" + roles: + - openshift_facts tasks: - name: Upgrade node packages yum: pkg={{ openshift.common.service_type }}-node{{ openshift_version }} state=latest - name: Restart node services service: name="{{ openshift.common.service_type }}-node" state=restarted +- name: Evaluate oo_first_master + hosts: localhost + vars: + g_masters_group: "{{ 'masters' }}" + tasks: + - name: display all variables set for the current host + debug: + var: hostvars[inventory_hostname] + - name: Evaluate oo_first_master + add_host: + name: "{{ groups[g_masters_group][0] }}" + groups: oo_first_master + ansible_ssh_user: "{{ g_ssh_user | default(omit) }}" + ansible_sudo: "{{ g_sudo | default(omit) }}" + when: g_masters_group in groups and (groups[g_masters_group] | length) > 0 + - name: Determine new master version hosts: oo_first_master tasks: diff --git a/playbooks/common/openshift-cluster/config.yml b/playbooks/common/openshift-cluster/config.yml index 4c74f96db..e6bf41ae4 100644 --- a/playbooks/common/openshift-cluster/config.yml +++ b/playbooks/common/openshift-cluster/config.yml @@ -4,15 +4,15 @@ gather_facts: no tasks: - fail: - msg: This playbook rquires g_etcd_group to be set + msg: This playbook requires g_etcd_group to be set when: g_etcd_group is not defined - fail: - msg: This playbook rquires g_masters_group to be set + msg: This playbook requires g_masters_group to be set when: g_masters_group is not defined - fail: - msg: This playbook rquires g_nodes_group to be set + msg: This playbook requires g_nodes_group to be set when: g_nodes_group is not defined - name: Evaluate oo_etcd_to_config diff --git a/utils/src/ooinstall/install_transactions.py b/utils/src/ooinstall/install_transactions.py index e71bc183b..0754b8ab6 100644 --- a/utils/src/ooinstall/install_transactions.py +++ b/utils/src/ooinstall/install_transactions.py @@ -127,7 +127,7 @@ def run_main_playbook(hosts, hosts_to_run_on): def run_ansible(playbook, inventory, env_vars): - return subprocess.call(['ansible-playbook', '-v', + return subprocess.call(['ansible-playbook', '--inventory-file={}'.format(inventory), playbook], env=env_vars) -- cgit v1.2.3 From 867a372321270311946375d71f7d08aab2b56d67 Mon Sep 17 00:00:00 2001 From: Devan Goodwin Date: Tue, 3 Nov 2015 14:57:06 -0400 Subject: Add debug output for location of etcd backup. --- playbooks/adhoc/upgrades/upgrade.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/playbooks/adhoc/upgrades/upgrade.yml b/playbooks/adhoc/upgrades/upgrade.yml index e55f1536f..539710469 100644 --- a/playbooks/adhoc/upgrades/upgrade.yml +++ b/playbooks/adhoc/upgrades/upgrade.yml @@ -39,6 +39,9 @@ yum: pkg=etcd state=latest - name: Generate etcd backup command: etcdctl backup --data-dir={{ openshift.master.etcd_data_dir }} --backup-dir={{ openshift.common.data_dir }}/etcd-backup-{{ timestamp }} + - name: Display location of etcd backup + debug: msg="Etcd backup created in {{ openshift.common.data_dir }}/etcd-backup-{{ timestamp }}" + - name: Upgrade base package on masters hosts: masters -- cgit v1.2.3 From 4a4ecb7e4517dddf989441f0e7d99617917f942d Mon Sep 17 00:00:00 2001 From: Devan Goodwin Date: Wed, 4 Nov 2015 08:14:46 -0400 Subject: Skip fail if enterprise deployment type depending on version. --- playbooks/adhoc/upgrades/upgrade.yml | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/playbooks/adhoc/upgrades/upgrade.yml b/playbooks/adhoc/upgrades/upgrade.yml index 539710469..ffcd2757b 100644 --- a/playbooks/adhoc/upgrades/upgrade.yml +++ b/playbooks/adhoc/upgrades/upgrade.yml @@ -98,6 +98,14 @@ fail: This playbook requires Origin 1.0.6 or Atomic OpenShift 3.0.2 or later when: _new_version.stdout | version_compare('1.0.6','<') or ( _new_version.stdout | version_compare('3.0','>=' and _new_version.stdout | version_compare('3.0.2','<') ) +- name: Verify upgrade can proceed + hosts: masters + tasks: + # Checking the global deployment type rather than host facts, this is about + # what the user is requesting. + - fail: msg="Deployment type 'enterprise' must be updated to 'openshift-enterprise' for upgrade to proceed" + when: deployment_type == "enterprise" and (_new_version.stdout | version_compare('1.0.7', '>=') or _new_version.stdout | version_compare('3.1', '>=')) + - name: Update cluster policy hosts: oo_first_master tasks: -- cgit v1.2.3 From 8ca4308854c44649d2dcfd94f441790c2e5c5d2b Mon Sep 17 00:00:00 2001 From: Devan Goodwin Date: Wed, 4 Nov 2015 08:27:21 -0400 Subject: Use the base package upgrade version so we can check things earlier. --- playbooks/adhoc/upgrades/upgrade.yml | 64 +++++++++++++++++++++++------------- 1 file changed, 41 insertions(+), 23 deletions(-) diff --git a/playbooks/adhoc/upgrades/upgrade.yml b/playbooks/adhoc/upgrades/upgrade.yml index ffcd2757b..a959aa881 100644 --- a/playbooks/adhoc/upgrades/upgrade.yml +++ b/playbooks/adhoc/upgrades/upgrade.yml @@ -42,7 +42,6 @@ - name: Display location of etcd backup debug: msg="Etcd backup created in {{ openshift.common.data_dir }}/etcd-backup-{{ timestamp }}" - - name: Upgrade base package on masters hosts: masters roles: @@ -53,6 +52,47 @@ - name: Upgrade base package yum: pkg={{ openshift.common.service_type }}{{ openshift_version }} state=latest +- name: Evaluate oo_first_master + hosts: localhost + vars: + g_masters_group: "{{ 'masters' }}" + tasks: + - name: display all variables set for the current host + debug: + var: hostvars[inventory_hostname] + - name: Evaluate oo_first_master + add_host: + name: "{{ groups[g_masters_group][0] }}" + groups: oo_first_master + ansible_ssh_user: "{{ g_ssh_user | default(omit) }}" + ansible_sudo: "{{ g_sudo | default(omit) }}" + when: g_masters_group in groups and (groups[g_masters_group] | length) > 0 + +# TODO: ideally we would check the new version, without installing it. (some +# kind of yum repoquery? would need to handle openshift -> atomic-openshift +# package rename) +- name: Perform upgrade version checking + hosts: oo_first_master + tasks: + - name: Determine new version + command: > + rpm -q --queryformat '%{version}' {{ openshift.common.service_type }} + register: _new_version + +- name: Ensure AOS 3.0.2 or Origin 1.0.6 + hosts: oo_first_master + tasks: + fail: This playbook requires Origin 1.0.6 or Atomic OpenShift 3.0.2 or later + when: _new_version.stdout | version_compare('1.0.6','<') or ( _new_version.stdout | version_compare('3.0','>=' and _new_version.stdout | version_compare('3.0.2','<') ) + +- name: Verify upgrade can proceed + hosts: oo_first_master + tasks: + # Checking the global deployment type rather than host facts, this is about + # what the user is requesting. + - fail: msg="Deployment type 'enterprise' must be updated to 'openshift-enterprise' for upgrade to proceed" + when: deployment_type == "enterprise" and (_new_version.stdout | version_compare('1.0.7', '>=') or _new_version.stdout | version_compare('3.1', '>=')) + - name: Re-Run cluster configuration to apply latest configuration changes include: ../../common/openshift-cluster/config.yml vars: @@ -84,28 +124,6 @@ - name: Restart node services service: name="{{ openshift.common.service_type }}-node" state=restarted -- name: Determine new master version - hosts: oo_first_master - tasks: - - name: Determine new version - command: > - rpm -q --queryformat '%{version}' {{ openshift.common.service_type }}-master - register: _new_version - -- name: Ensure AOS 3.0.2 or Origin 1.0.6 - hosts: oo_first_master - tasks: - fail: This playbook requires Origin 1.0.6 or Atomic OpenShift 3.0.2 or later - when: _new_version.stdout | version_compare('1.0.6','<') or ( _new_version.stdout | version_compare('3.0','>=' and _new_version.stdout | version_compare('3.0.2','<') ) - -- name: Verify upgrade can proceed - hosts: masters - tasks: - # Checking the global deployment type rather than host facts, this is about - # what the user is requesting. - - fail: msg="Deployment type 'enterprise' must be updated to 'openshift-enterprise' for upgrade to proceed" - when: deployment_type == "enterprise" and (_new_version.stdout | version_compare('1.0.7', '>=') or _new_version.stdout | version_compare('3.1', '>=')) - - name: Update cluster policy hosts: oo_first_master tasks: -- cgit v1.2.3 From 21f793b8aefcd680041150d0740eeed05d272c31 Mon Sep 17 00:00:00 2001 From: Devan Goodwin Date: Wed, 4 Nov 2015 09:13:39 -0400 Subject: Fix bug with default ansible playbook dir. --- utils/src/ooinstall/cli_installer.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/utils/src/ooinstall/cli_installer.py b/utils/src/ooinstall/cli_installer.py index 25705ec7a..455f56a66 100644 --- a/utils/src/ooinstall/cli_installer.py +++ b/utils/src/ooinstall/cli_installer.py @@ -385,7 +385,7 @@ def get_hosts_to_run_on(oo_cfg, callback_facts, unattended, force): dir_okay=True, readable=True), # callback=validate_ansible_dir, - default='/usr/share/openshift-ansible/', + default=DEFAULT_PLAYBOOK_DIR, envvar='OO_ANSIBLE_PLAYBOOK_DIRECTORY') @click.option('--ansible-config', type=click.Path(file_okay=True, -- cgit v1.2.3 From 6b2644268ed1bbb1ff3f2fd85427aefef0e51e0f Mon Sep 17 00:00:00 2001 From: Devan Goodwin Date: Wed, 4 Nov 2015 09:54:55 -0400 Subject: Fix bug from module rename. --- utils/src/ooinstall/cli_installer.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/utils/src/ooinstall/cli_installer.py b/utils/src/ooinstall/cli_installer.py index 455f56a66..e4fda2813 100644 --- a/utils/src/ooinstall/cli_installer.py +++ b/utils/src/ooinstall/cli_installer.py @@ -489,7 +489,7 @@ def upgrade(ctx): click.echo("Upgrade cancelled.") sys.exit(0) - retcode = install_transactions.run_upgrade_playbook() + retcode = openshift_ansible.run_upgrade_playbook() if retcode > 0: click.echo("Errors encountered during upgrade, please check %s." % oo_cfg.settings['ansible_log_path']) -- cgit v1.2.3 From 215a7aacc2fc3df19a64a2a57910516533665423 Mon Sep 17 00:00:00 2001 From: Devan Goodwin Date: Wed, 4 Nov 2015 10:41:39 -0400 Subject: Fix bug with not upgrading openshift-master to atomic-openshift-master. Removing the full call to config resulted in rpms not getting upgraded. Config was doing a yum update of everything, which picks up the atomic-openshift-master obsoleting openshift-master. The actual yum call changed here would not. Instead we switch to a direct call to yum which correctly picks up the obsoletes and updates to atomic-openshift packages. --- playbooks/adhoc/upgrades/upgrade.yml | 19 +++++-------------- utils/src/ooinstall/openshift_ansible.py | 1 + 2 files changed, 6 insertions(+), 14 deletions(-) diff --git a/playbooks/adhoc/upgrades/upgrade.yml b/playbooks/adhoc/upgrades/upgrade.yml index 8c1138797..0f505bf7d 100644 --- a/playbooks/adhoc/upgrades/upgrade.yml +++ b/playbooks/adhoc/upgrades/upgrade.yml @@ -57,9 +57,6 @@ vars: g_masters_group: "{{ 'masters' }}" tasks: - - name: display all variables set for the current host - debug: - var: hostvars[inventory_hostname] - name: Evaluate oo_first_master add_host: name: "{{ groups[g_masters_group][0] }}" @@ -93,15 +90,6 @@ - fail: msg="Deployment type 'enterprise' must be updated to 'openshift-enterprise' for upgrade to proceed" when: deployment_type == "enterprise" and (_new_version.stdout | version_compare('1.0.7', '>=') or _new_version.stdout | version_compare('3.1', '>=')) - #- name: Re-Run cluster configuration to apply latest configuration changes - # include: ../../common/openshift-cluster/config.yml - # vars: - # g_etcd_group: "{{ 'etcd' }}" - # g_masters_group: "{{ 'masters' }}" - # g_nodes_group: "{{ 'nodes' }}" - # openshift_cluster_id: "{{ cluster_id | default('default') }}" - # openshift_deployment_type: "{{ deployment_type }}" - - name: Upgrade masters hosts: masters vars: @@ -109,8 +97,11 @@ tasks: - name: Upgrade to latest available kernel yum: pkg=kernel state=latest + - name: display just the deployment_type variable for the current host + debug: + var: hostvars[inventory_hostname] - name: Upgrade master packages - yum: pkg={{ openshift.common.service_type }}-master{{ openshift_version }} state=latest + command: yum update -y {{ openshift.common.service_type }}-master{{ openshift_version }} - name: Upgrade master configuration. openshift_upgrade_config: from_version=3.0 to_version=3.1 role=master - name: Restart master services @@ -124,7 +115,7 @@ - openshift_facts tasks: - name: Upgrade node packages - yum: pkg={{ openshift.common.service_type }}-node{{ openshift_version }} state=latest + command: yum update -y {{ openshift.common.service_type }}-node{{ openshift_version }} - name: Restart node services service: name="{{ openshift.common.service_type }}-node" state=restarted diff --git a/utils/src/ooinstall/openshift_ansible.py b/utils/src/ooinstall/openshift_ansible.py index 9d801cabe..e33330102 100644 --- a/utils/src/ooinstall/openshift_ansible.py +++ b/utils/src/ooinstall/openshift_ansible.py @@ -144,6 +144,7 @@ def run_ansible(playbook, inventory, env_vars): playbook], env=env_vars) + def run_uninstall_playbook(): playbook = os.path.join(CFG.settings['ansible_playbook_directory'], 'playbooks/adhoc/uninstall.yml') -- cgit v1.2.3 From abab19316ff270d090e27a1fb576b78889e5563c Mon Sep 17 00:00:00 2001 From: Devan Goodwin Date: Wed, 4 Nov 2015 15:49:57 -0400 Subject: Disable proxy cert config upgrade until certs being generated. --- playbooks/adhoc/upgrades/library/openshift_upgrade_config.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/playbooks/adhoc/upgrades/library/openshift_upgrade_config.py b/playbooks/adhoc/upgrades/library/openshift_upgrade_config.py index 95c7b1664..357f244e0 100755 --- a/playbooks/adhoc/upgrades/library/openshift_upgrade_config.py +++ b/playbooks/adhoc/upgrades/library/openshift_upgrade_config.py @@ -49,11 +49,12 @@ def upgrade_master_3_0_to_3_1(backup): changed = True # Add the new master proxy client certs: - if 'proxyClientInfo' not in config['kubernetesMasterConfig']: - config['kubernetesMasterConfig']['proxyClientInfo'] = { - 'certFile': 'master.proxy-client.crt', - 'keyFile': 'master.proxy-client.key' - } + # TODO: re-enable this once these certs are generated during upgrade: +# if 'proxyClientInfo' not in config['kubernetesMasterConfig']: +# config['kubernetesMasterConfig']['proxyClientInfo'] = { +# 'certFile': 'master.proxy-client.crt', +# 'keyFile': 'master.proxy-client.key' +# } if changed: if backup: -- cgit v1.2.3 From 922cc828e959eb9bc0438890a876e7830cd73717 Mon Sep 17 00:00:00 2001 From: Devan Goodwin Date: Wed, 4 Nov 2015 16:07:58 -0400 Subject: Pylint fixes for config upgrade module. --- .../upgrades/library/openshift_upgrade_config.py | 23 ++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/playbooks/adhoc/upgrades/library/openshift_upgrade_config.py b/playbooks/adhoc/upgrades/library/openshift_upgrade_config.py index 357f244e0..60f4fd8b8 100755 --- a/playbooks/adhoc/upgrades/library/openshift_upgrade_config.py +++ b/playbooks/adhoc/upgrades/library/openshift_upgrade_config.py @@ -2,14 +2,14 @@ # -*- coding: utf-8 -*- # vim: expandtab:tabstop=4:shiftwidth=4 +"""Ansible module for modifying OpenShift configs during an upgrade""" + import os import shutil import yaml from datetime import datetime -"""Ansible module for modifying OpenShift configs during an upgrade""" - DOCUMENTATION = ''' --- module: openshift_upgrade_config @@ -21,6 +21,7 @@ EXAMPLES = ''' ''' def get_cfg_dir(): + """Return the correct config directory to use.""" cfg_path = '/etc/origin/' if not os.path.exists(cfg_path): cfg_path = '/etc/openshift/' @@ -28,25 +29,26 @@ def get_cfg_dir(): def upgrade_master_3_0_to_3_1(backup): + """Main upgrade method for 3.0 to 3.1.""" changed = False # Facts do not get transferred to the hosts where custom modules run, # need to make some assumptions here. master_config = os.path.join(get_cfg_dir(), 'master/master-config.yaml') - f = open(master_config, 'r') - config = yaml.safe_load(f.read()) - f.close() + master_cfg_file = open(master_config, 'r') + config = yaml.safe_load(master_cfg_file.read()) + master_cfg_file.close() # Remove v1beta3 from apiLevels: if 'apiLevels' in config and \ 'v1beta3' in config['apiLevels']: - config['apiLevels'].remove('v1beta3') - changed = True + config['apiLevels'].remove('v1beta3') + changed = True if 'apiLevels' in config['kubernetesMasterConfig'] and \ 'v1beta3' in config['kubernetesMasterConfig']['apiLevels']: - config['kubernetesMasterConfig']['apiLevels'].remove('v1beta3') - changed = True + config['kubernetesMasterConfig']['apiLevels'].remove('v1beta3') + changed = True # Add the new master proxy client certs: # TODO: re-enable this once these certs are generated during upgrade: @@ -61,7 +63,7 @@ def upgrade_master_3_0_to_3_1(backup): timestamp = datetime.now().strftime('%Y%m%d%H%M%S') basedir = os.path.split(master_config)[0] backup_file = os.path.join(basedir, 'master-config.yaml.bak-%s' - % timestamp) + % timestamp) shutil.copyfile(master_config, backup_file) # Write the modified config: out_file = open(master_config, 'w') @@ -72,6 +74,7 @@ def upgrade_master_3_0_to_3_1(backup): def upgrade_master(from_version, to_version, backup): + """Upgrade entry point.""" if from_version == '3.0': if to_version == '3.1': return upgrade_master_3_0_to_3_1(backup) -- cgit v1.2.3 From 75d357c9bba120221a5f996660aa4fdbb87f1fa8 Mon Sep 17 00:00:00 2001 From: Devan Goodwin Date: Wed, 4 Nov 2015 16:10:07 -0400 Subject: Override hosts deployment_type fact for version we're upgrading to. --- playbooks/adhoc/upgrades/upgrade.yml | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/playbooks/adhoc/upgrades/upgrade.yml b/playbooks/adhoc/upgrades/upgrade.yml index 0f505bf7d..09f991b1d 100644 --- a/playbooks/adhoc/upgrades/upgrade.yml +++ b/playbooks/adhoc/upgrades/upgrade.yml @@ -1,4 +1,14 @@ --- +- name: Update deployment type + hosts: OSEv3 + roles: + - openshift_facts + post_tasks: # technically tasks are run after roles, but post_tasks is a bit more explicit. + - openshift_facts: + role: common + local_facts: + deployment_type: "{{ deployment_type }}" + - name: Verify upgrade can proceed hosts: masters tasks: -- cgit v1.2.3