diff options
Diffstat (limited to 'tools/upgrade/1.3')
-rwxr-xr-x | tools/upgrade/1.3/migrate_configs.py | 50 | ||||
-rwxr-xr-x | tools/upgrade/1.3/migrate_dbstats.py | 21 | ||||
-rwxr-xr-x | tools/upgrade/1.3/migrate_info.py | 26 | ||||
-rwxr-xr-x | tools/upgrade/1.3/migrate_perms_to_mode.py | 34 | ||||
-rwxr-xr-x | tools/upgrade/1.3/migrate_probe_groups_to_db.py | 27 | ||||
-rwxr-xr-x | tools/upgrade/1.3/service_modes.py | 12 |
6 files changed, 93 insertions, 77 deletions
diff --git a/tools/upgrade/1.3/migrate_configs.py b/tools/upgrade/1.3/migrate_configs.py index 76b2392e7..547ce61e4 100755 --- a/tools/upgrade/1.3/migrate_configs.py +++ b/tools/upgrade/1.3/migrate_configs.py @@ -5,6 +5,7 @@ import sys from Bcfg2.Compat import ConfigParser import Bcfg2.Options + def copy_section(src_file, tgt_cfg, section, newsection=None): if newsection is None: newsection = section @@ -16,13 +17,13 @@ def copy_section(src_file, tgt_cfg, section, newsection=None): tgt_cfg.add_section(newsection) except ConfigParser.DuplicateSectionError: print("[%s] section already exists in %s, adding options" % - (newsection, setup['configfile'])) + (newsection, Bcfg2.Options.setup.config)) for opt in cfg.options(section): val = cfg.get(section, opt) if tgt_cfg.has_option(newsection, opt): print("%s in [%s] already populated in %s, skipping" % - (opt, newsection, setup['configfile'])) - print(" %s: %s" % (setup['configfile'], + (opt, newsection, Bcfg2.Options.setup.config)) + print(" %s: %s" % (Bcfg2.Options.setup.config, tgt_cfg.get(newsection, opt))) print(" %s: %s" % (src_file, val)) else: @@ -30,47 +31,50 @@ def copy_section(src_file, tgt_cfg, section, newsection=None): tgt_cfg.set(newsection, opt, val) def main(): - opts = dict(repo=Bcfg2.Options.SERVER_REPOSITORY, - configfile=Bcfg2.Options.CFILE) - setup = Bcfg2.Options.OptionParser(opts) - setup.parse(sys.argv[1:]) + parser = Bcfg2.Options.get_parser( + description="Migrate from Bcfg2 1.2 per-plugin config files to 1.3 " + "unified config file") + parser.add_options([Bcfg2.Options.Common.repository]) + parser.parse() + repo = Bcfg2.Options.setup.repository + cfp = ConfigParser.ConfigParser() + cfp.read(Bcfg2.Options.setup.config) # 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') + rules_conf = os.path.join(repo, 'Rules', 'rules.conf') if os.path.exists(rules_conf): remove.append(rules_conf) - copy_section(rules_conf, setup.cfp, "rules") + copy_section(rules_conf, cfp, "rules") # move packages config out of packages.conf and into bcfg2.conf - pkgs_conf = os.path.join(setup['repo'], 'Packages', 'packages.conf') + pkgs_conf = os.path.join(repo, 'Packages', 'packages.conf') if os.path.exists(pkgs_conf): remove.append(pkgs_conf) - copy_section(pkgs_conf, setup.cfp, "global", newsection="packages") + copy_section(pkgs_conf, cfp, "global", newsection="packages") for section in ["apt", "yum", "pulp"]: - copy_section(pkgs_conf, setup.cfp, section, + copy_section(pkgs_conf, 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 cfp.has_section("statistics"): + if not cfp.has_section("database"): + cfp.add_section("database") + for opt in cfp.options("statistics"): if opt.startswith("database_"): newopt = opt[9:] - if setup.cfp.has_option("database", newopt): + if 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) + cfp.set("database", newopt, cfp.get("statistics", opt)) + cfp.remove_option("statistics", opt) - print("Writing %s" % setup['configfile']) + print("Writing %s" % Bcfg2.Options.setup.config) try: - setup.cfp.write(open(setup['configfile'], "w")) + cfp.write(open(Bcfg2.Options.setup.config, "w")) if len(remove): print("Settings were migrated, but you must remove these files " "manually:") @@ -78,7 +82,7 @@ def main(): print(" %s" % path) except IOError: err = sys.exc_info()[1] - print("Could not write %s: %s" % (setup['configfile'], err)) + print("Could not write %s: %s" % (Bcfg2.Options.setup.config, err)) if __name__ == '__main__': sys.exit(main()) diff --git a/tools/upgrade/1.3/migrate_dbstats.py b/tools/upgrade/1.3/migrate_dbstats.py index 07def2ac8..ed514289a 100755 --- a/tools/upgrade/1.3/migrate_dbstats.py +++ b/tools/upgrade/1.3/migrate_dbstats.py @@ -2,17 +2,15 @@ import os os.environ['BCFG2_LEGACY_MODELS'] = '1' -os.environ['DJANGO_SETTINGS_MODULE'] = 'Bcfg2.settings' import sys import logging import time import Bcfg2.Logger import Bcfg2.Options -from django.core.cache import cache from django.db import connection, transaction, backend -from Bcfg2.Server.Admin.Reports import Reports +from Bcfg2.Server.Admin import UpdateReports from Bcfg2.Reporting import models as new_models from Bcfg2.Reporting.utils import BatchFetch from Bcfg2.Server.Reports.reports import models as legacy_models @@ -281,17 +279,10 @@ def _restructure(): if __name__ == '__main__': - Bcfg2.Logger.setup_logging('bcfg2-report-collector', - to_console=logging.INFO, - level=logging.INFO) - - optinfo = dict() - optinfo.update(Bcfg2.Options.CLI_COMMON_OPTIONS) - optinfo.update(Bcfg2.Options.SERVER_COMMON_OPTIONS) - setup = Bcfg2.Options.OptionParser(optinfo) - setup.parse(sys.argv[1:]) - - #sync! - Reports(setup).__call__(['update']) + parser = Bcfg2.Options.get_parser( + description="Migrate from Bcfg2 1.2 DBStats plugin to 1.3 Reporting " + "subsystem", + components=[UpdateReports]) + UpdateReports().run(Bcfg2.Options.setup) _restructure() diff --git a/tools/upgrade/1.3/migrate_info.py b/tools/upgrade/1.3/migrate_info.py index 3ccbf0285..7f3bb9a29 100755 --- a/tools/upgrade/1.3/migrate_info.py +++ b/tools/upgrade/1.3/migrate_info.py @@ -5,7 +5,16 @@ import re import sys import lxml.etree import Bcfg2.Options -from Bcfg2.Server.Plugin import INFO_REGEX + +INFO_REGEX = re.compile(r'owner:\s*(?P<owner>\S+)|' + + r'group:\s*(?P<group>\S+)|' + + r'mode:\s*(?P<mode>\w+)|' + + r'secontext:\s*(?P<secontext>\S+)|' + + r'paranoid:\s*(?P<paranoid>\S+)|' + + r'sensitive:\s*(?P<sensitive>\S+)|' + + r'encoding:\s*(?P<encoding>\S+)|' + + r'important:\s*(?P<important>\S+)|' + + r'mtime:\s*(?P<mtime>\w+)') PERMS_REGEX = re.compile(r'perms:\s*(?P<perms>\w+)') @@ -32,16 +41,17 @@ def convert(info_file): def main(): - opts = dict(repo=Bcfg2.Options.SERVER_REPOSITORY, - configfile=Bcfg2.Options.CFILE, - plugins=Bcfg2.Options.SERVER_PLUGINS) - setup = Bcfg2.Options.OptionParser(opts) - setup.parse(sys.argv[1:]) + parser = Bcfg2.Options.get_parser( + description="Migrate from Bcfg2 1.2 info/:info files to 1.3 info.xml") + parser.add_options([Bcfg2.Options.Common.repository, + Bcfg2.Options.Common.plugins]) + parser.parse() - for plugin in setup['plugins']: + for plugin in Bcfg2.Options.setup.plugins: if plugin not in ['SSLCA', 'Cfg', 'TGenshi', 'TCheetah', 'SSHbase']: continue - for root, dirs, files in os.walk(os.path.join(setup['repo'], plugin)): + datastore = os.path.join(Bcfg2.Options.setup.repository, plugin) + for root, dirs, files in os.walk(datastore): for fname in files: if fname in [":info", "info"]: convert(os.path.join(root, fname)) diff --git a/tools/upgrade/1.3/migrate_perms_to_mode.py b/tools/upgrade/1.3/migrate_perms_to_mode.py index ee440bc8e..2dfb70388 100755 --- a/tools/upgrade/1.3/migrate_perms_to_mode.py +++ b/tools/upgrade/1.3/migrate_perms_to_mode.py @@ -4,13 +4,14 @@ import lxml.etree import os import sys from fnmatch import fnmatch -from Bcfg2.Compat import any +from Bcfg2.Compat import any # pylint: disable=W0622 +from Bcfg2.Server.FileMonitor import FileMonitor import Bcfg2.Options def setmodeattr(elem): """Set the mode attribute for a given element.""" - if elem.attrib.has_key('perms'): + if 'perms' in elem.attrib: elem.set('mode', elem.get('perms')) del elem.attrib['perms'] return True @@ -54,33 +55,34 @@ def convertstructure(structfile): writefile(structfile, xdata) -def skip_path(path, setup): +def skip_path(path): return any(fnmatch(path, p) or fnmatch(os.path.basename(path), p) - for p in setup['ignore']) + for p in Bcfg2.Options.setup.ignore_files) def main(): - opts = dict(repo=Bcfg2.Options.SERVER_REPOSITORY, - configfile=Bcfg2.Options.CFILE, - ignore=Bcfg2.Options.SERVER_FAM_IGNORE, - plugins=Bcfg2.Options.SERVER_PLUGINS) - setup = Bcfg2.Options.OptionParser(opts) - setup.parse(sys.argv[1:]) - repo = setup['repo'] + parser = Bcfg2.Options.get_parser( + description="Migrate from Bcfg2 1.2 'perms' attribute to 1.3 'mode' " + "attribute", + components=FileMonitor) + parser.add_options([Bcfg2.Options.Common.repository, + Bcfg2.Options.Common.plugins]) + parser.parse() + repo = Bcfg2.Options.setup.repository - for plugin in setup['plugins']: + for plugin in Bcfg2.Options.setup.plugins: if plugin in ['Base', 'Bundler', 'Rules']: - for root, dirs, files in os.walk(os.path.join(repo, plugin)): - if skip_path(root, setup): + for root, _, files in os.walk(os.path.join(repo, plugin)): + if skip_path(root): continue for fname in files: - if skip_path(fname, setup): + if skip_path(fname): continue convertstructure(os.path.join(root, fname)) if plugin not in ['Cfg', 'TGenshi', 'TCheetah', 'SSHbase', 'SSLCA']: continue for root, dirs, files in os.walk(os.path.join(repo, plugin)): - if skip_path(root, setup): + if skip_path(root): continue for fname in files: if fname == 'info.xml': diff --git a/tools/upgrade/1.3/migrate_probe_groups_to_db.py b/tools/upgrade/1.3/migrate_probe_groups_to_db.py index 73339e787..f9abbf982 100755 --- a/tools/upgrade/1.3/migrate_probe_groups_to_db.py +++ b/tools/upgrade/1.3/migrate_probe_groups_to_db.py @@ -4,16 +4,13 @@ and Probe plugins. Does not migrate individual probe return data. Assumes migration to BOTH Metadata and Probe to database backends. """ import os -os.environ['DJANGO_SETTINGS_MODULE'] = 'Bcfg2.settings' - -import lxml.etree import sys +import lxml.etree import Bcfg2.Options +import Bcfg2.DBSettings -from Bcfg2.Server.Plugins.Metadata import MetadataClientModel -from Bcfg2.Server.Plugins.Probes import ProbesGroupsModel -def migrate(xclient): +def migrate(xclient, MetadataClientModel, ProbesGroupsModel): """ Helper to do the migration given a <Client/> XML element """ client_name = xclient.get('name') try: @@ -32,9 +29,11 @@ def migrate(xclient): group_name = xgroup.get('name') cgroups.append(group_name) try: - group = ProbesGroupsModel.objects.get(hostname=client_name, group=group_name) + group = ProbesGroupsModel.objects.get(hostname=client_name, + group=group_name) except ProbesGroupsModel.DoesNotExist: - group = ProbesGroupsModel(hostname=client_name, group=group_name) + group = ProbesGroupsModel(hostname=client_name, + group=group_name) group.save() ProbesGroupsModel.objects.filter( @@ -46,6 +45,7 @@ def migrate(xclient): return False return True + def main(): """ Main """ opts = dict(repo=Bcfg2.Options.SERVER_REPOSITORY) @@ -59,10 +59,15 @@ def main(): except lxml.etree.XMLSyntaxError: err = sys.exc_info()[1] print("Could not parse %s, skipping: %s" % (probefile, err)) - + + # these must be loaded after option parsing is complete + from Bcfg2.Server.Plugins.Metadata import MetadataClientModel + from Bcfg2.Server.Plugins.Probes import ProbesGroupsModel + for xclient in xdata.findall('Client'): - print "Migrating Metadata and Probe groups for %s" % xclient.get('name') - migrate(xclient) + print("Migrating Metadata and Probe groups for %s" % + xclient.get('name')) + migrate(xclient, MetadataClientModel, ProbesGroupsModel) if __name__ == '__main__': sys.exit(main()) diff --git a/tools/upgrade/1.3/service_modes.py b/tools/upgrade/1.3/service_modes.py index 0c458c3a9..d8e3c9e6f 100755 --- a/tools/upgrade/1.3/service_modes.py +++ b/tools/upgrade/1.3/service_modes.py @@ -6,14 +6,18 @@ import glob import lxml.etree import Bcfg2.Options + def main(): - opts = dict(repo=Bcfg2.Options.SERVER_REPOSITORY) - setup = Bcfg2.Options.OptionParser(opts) - setup.parse(sys.argv[1:]) + parser = Bcfg2.Options.get_parser( + description="Migrate from Bcfg2 1.2 Service modes to 1.3-style " + "granular Service specification") + parser.add_options([Bcfg2.Options.Common.repository]) + parser.parse() files = [] for plugin in ['Bundler', 'Rules', 'Default']: - files.extend(glob.glob(os.path.join(setup['repo'], plugin, "*"))) + files.extend(glob.glob(os.path.join(Bcfg2.Options.setup.repository, + plugin, "*"))) for bfile in files: bdata = lxml.etree.parse(bfile) |