From a94074b54fa61f593df4945a1ebf4e3edd8cb27d Mon Sep 17 00:00:00 2001 From: "Chris St. Pierre" Date: Tue, 7 Aug 2012 15:13:13 -0400 Subject: updated migrate_configs.py to handle reports config changes --- tools/upgrade/1.3/migrate_configs.py | 42 ++++++++++++++++++++++++++++++------ 1 file changed, 36 insertions(+), 6 deletions(-) (limited to 'tools/upgrade') diff --git a/tools/upgrade/1.3/migrate_configs.py b/tools/upgrade/1.3/migrate_configs.py index c6e6cd2c3..dd8e5708b 100755 --- a/tools/upgrade/1.3/migrate_configs.py +++ b/tools/upgrade/1.3/migrate_configs.py @@ -35,17 +35,47 @@ def main(): setup = Bcfg2.Options.OptionParser(opts) setup.parse(sys.argv[1:]) - copy_section(os.path.join(setup['repo'], 'Rules', 'rules.conf'), setup.cfp, - "rules") + # files that you should remove manually + remove = [] + + # move rules config out of rules.conf and into bcfg2.conf + rules_conf = os.path.join(setup['repo'], 'Rules', 'rules.conf') + if os.path.exists(rules_conf): + remove.append(rules_conf) + copy_section(rules_conf, setup.cfp, "rules") + + # move packages config out of packages.conf and into bcfg2.conf pkgs_conf = os.path.join(setup['repo'], 'Packages', 'packages.conf') - copy_section(pkgs_conf, setup.cfp, "global", newsection="packages") - for section in ["apt", "yum", "pulp"]: - copy_section(pkgs_conf, setup.cfp, section, - newsection="packages:" + section) + if os.path.exists(pkgs_conf): + remove.append(pkgs_conf) + copy_section(pkgs_conf, setup.cfp, "global", newsection="packages") + for section in ["apt", "yum", "pulp"]: + copy_section(pkgs_conf, setup.cfp, section, + newsection="packages:" + section) + + # move reports database config into [database] section + if setup.cfp.has_section("statistics"): + if not setup.cfp.has_section("database"): + setup.cfp.add_section("database") + for opt in setup.cfp.options("statistics"): + if opt.startswith("database_"): + newopt = opt[9:] + if setup.cfp.has_option("database", newopt): + print("%s in [database] already populated, skipping" % + newopt) + else: + setup.cfp.set("database", newopt, + setup.cfp.get("statistics", opt)) + setup.cfp.remove_option("statistics", opt) print("Writing %s" % setup['configfile']) try: setup.cfp.write(open(setup['configfile'], "w")) + if len(remove): + print("Settings were migrated, but you must remove these files " + "manually:") + for path in remove: + print(" %s" % path) except IOError: err = sys.exc_info()[1] print("Could not write %s: %s" % (setup['configfile'], err)) -- cgit v1.2.3-1-g7c22