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 (limited to 'playbooks/adhoc/upgrades/library') 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 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 ++++++++++++++++++++-- 1 file changed, 49 insertions(+), 4 deletions(-) (limited to 'playbooks/adhoc/upgrades/library') 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) -- 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(-) (limited to 'playbooks/adhoc/upgrades/library') 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 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(-) (limited to 'playbooks/adhoc/upgrades/library') 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(-) (limited to 'playbooks/adhoc/upgrades/library') 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