summaryrefslogtreecommitdiffstats
path: root/tools/upgrade
diff options
context:
space:
mode:
Diffstat (limited to 'tools/upgrade')
-rw-r--r--tools/upgrade/1.3/README5
-rwxr-xr-xtools/upgrade/1.3/migrate_dbstats.py19
-rwxr-xr-xtools/upgrade/1.3/migrate_info.py6
-rwxr-xr-xtools/upgrade/1.3/migrate_probe_groups_to_db.py68
4 files changed, 87 insertions, 11 deletions
diff --git a/tools/upgrade/1.3/README b/tools/upgrade/1.3/README
index 2831d8f00..1a919f869 100644
--- a/tools/upgrade/1.3/README
+++ b/tools/upgrade/1.3/README
@@ -19,3 +19,8 @@ migrate_dbstats.py
migrate_perms_to_mode.py
- Convert perms attribute to mode (note that if you have info/:info
files, you should run migrate_info.py first)
+
+migrate_probe_groups_to_db.py
+ - Migrate Probe host and group data from XML to DB backend for Metadata
+ and Probe plugins. Does not migrate individual probe return data. Assumes
+ migration to BOTH Metadata and Probe to database backends.
diff --git a/tools/upgrade/1.3/migrate_dbstats.py b/tools/upgrade/1.3/migrate_dbstats.py
index cbd2a6099..07def2ac8 100755
--- a/tools/upgrade/1.3/migrate_dbstats.py
+++ b/tools/upgrade/1.3/migrate_dbstats.py
@@ -21,6 +21,7 @@ logger = logging.getLogger(__name__)
_our_backend = None
+
def _quote(value):
"""
Quote a string to use as a table name or column
@@ -44,12 +45,12 @@ def _migrate_perms():
fperms = {}
logger.info("Creating FilePerms objects")
- for data in ( ('owner', 'group', 'perms'),
+ for data in (('owner', 'group', 'perms'),
('current_owner', 'current_group', 'current_perms')):
for grp in legacy_models.Reason.objects.values_list(*data).distinct():
if grp in fperms:
continue
- fp = new_models.FilePerms(owner=grp[0], group=grp[1], mode=grp[2])
+ fp = new_models.FilePerms(owner=grp[0], group=grp[1], mode=grp[2])
fp.save()
fperms[grp] = fp
@@ -60,7 +61,7 @@ def _migrate_perms():
def _migrate_transaction(inter, entries, fperms):
"""helper"""
- logger.debug("Migrating interaction %s for %s" %
+ logger.debug("Migrating interaction %s for %s" %
(inter.id, inter.client.name))
newint = new_models.Interaction(id=inter.id,
@@ -107,7 +108,7 @@ def _migrate_transaction(inter, entries, fperms):
elif ent.kind == 'Package':
act_dict['target_version'] = ei.reason.version
act_dict['current_version'] = ei.reason.current_version
- logger.debug("Adding package %s %s" %
+ logger.debug("Adding package %s %s" %
(name, act_dict['target_version']))
updates['packages'].append(new_models.PackageEntry.entry_get_or_create(act_dict))
elif ent.kind == 'Path':
@@ -116,7 +117,7 @@ def _migrate_transaction(inter, entries, fperms):
act_dict['target_perms'] = fperms[(
ei.reason.owner,
- ei.reason.group,
+ ei.reason.group,
ei.reason.perms
)]
@@ -141,7 +142,6 @@ def _migrate_transaction(inter, entries, fperms):
act_dict['detail_type'] = new_models.PathEntry.DETAIL_PRUNED
act_dict['details'] = ei.reason.unpruned
-
if ei.reason.is_sensitive:
act_dict['detail_type'] = new_models.PathEntry.DETAIL_SENSITIVE
elif ei.reason.is_binary:
@@ -164,7 +164,7 @@ def _migrate_transaction(inter, entries, fperms):
for entry_type in updates.keys():
i = 0
while(i < len(updates[entry_type])):
- getattr(newint, entry_type).add(*updates[entry_type][i:i+100])
+ getattr(newint, entry_type).add(*updates[entry_type][i:i + 100])
i += 100
for perf in inter.performance_items.all():
@@ -220,8 +220,8 @@ def _restructure():
# run any migrations from the previous schema
try:
- from Bcfg2.Server.Reports.updatefix import update_database
- update_database()
+ from Bcfg2.Server.Reports.updatefix import update_database
+ update_database()
except:
logger.error("Failed to run legacy schema updates", exc_info=1)
return False
@@ -295,4 +295,3 @@ if __name__ == '__main__':
Reports(setup).__call__(['update'])
_restructure()
-
diff --git a/tools/upgrade/1.3/migrate_info.py b/tools/upgrade/1.3/migrate_info.py
index e72599daf..3ccbf0285 100755
--- a/tools/upgrade/1.3/migrate_info.py
+++ b/tools/upgrade/1.3/migrate_info.py
@@ -1,12 +1,16 @@
#!/usr/bin/env python
import os
+import re
import sys
import lxml.etree
import Bcfg2.Options
from Bcfg2.Server.Plugin import INFO_REGEX
+PERMS_REGEX = re.compile(r'perms:\s*(?P<perms>\w+)')
+
+
def convert(info_file):
info_xml = os.path.join(os.path.dirname(info_file), "info.xml")
if os.path.exists(info_xml):
@@ -16,7 +20,7 @@ def convert(info_file):
fileinfo = lxml.etree.Element("FileInfo")
info = lxml.etree.SubElement(fileinfo, "Info")
for line in open(info_file).readlines():
- match = INFO_REGEX.match(line)
+ match = INFO_REGEX.match(line) or PERMS_REGEX.match(line)
if match:
mgd = match.groupdict()
for key, value in list(mgd.items()):
diff --git a/tools/upgrade/1.3/migrate_probe_groups_to_db.py b/tools/upgrade/1.3/migrate_probe_groups_to_db.py
new file mode 100755
index 000000000..73339e787
--- /dev/null
+++ b/tools/upgrade/1.3/migrate_probe_groups_to_db.py
@@ -0,0 +1,68 @@
+#!/bin/env python
+""" Migrate Probe host and group data from XML to DB backend for Metadata
+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 Bcfg2.Options
+
+from Bcfg2.Server.Plugins.Metadata import MetadataClientModel
+from Bcfg2.Server.Plugins.Probes import ProbesGroupsModel
+
+def migrate(xclient):
+ """ Helper to do the migration given a <Client/> XML element """
+ client_name = xclient.get('name')
+ try:
+ try:
+ client = MetadataClientModel.objects.get(hostname=client_name)
+ except MetadataClientModel.DoesNotExist:
+ client = MetadataClientModel(hostname=client_name)
+ client.save()
+ except:
+ print("Failed to migrate client %s" % (client))
+ return False
+
+ try:
+ cgroups = []
+ for xgroup in xclient.findall('Group'):
+ group_name = xgroup.get('name')
+ cgroups.append(group_name)
+ try:
+ group = ProbesGroupsModel.objects.get(hostname=client_name, group=group_name)
+ except ProbesGroupsModel.DoesNotExist:
+ group = ProbesGroupsModel(hostname=client_name, group=group_name)
+ group.save()
+
+ ProbesGroupsModel.objects.filter(
+ hostname=client.hostname).exclude(
+ group__in=cgroups).delete()
+
+ except:
+ print("Failed to migrate groups")
+ return False
+ return True
+
+def main():
+ """ Main """
+ opts = dict(repo=Bcfg2.Options.SERVER_REPOSITORY)
+ setup = Bcfg2.Options.OptionParser(opts)
+ setup.parse(sys.argv[1:])
+
+ probefile = os.path.join(setup['repo'], 'Probes', "probed.xml")
+
+ try:
+ xdata = lxml.etree.parse(probefile)
+ except lxml.etree.XMLSyntaxError:
+ err = sys.exc_info()[1]
+ print("Could not parse %s, skipping: %s" % (probefile, err))
+
+ for xclient in xdata.findall('Client'):
+ print "Migrating Metadata and Probe groups for %s" % xclient.get('name')
+ migrate(xclient)
+
+if __name__ == '__main__':
+ sys.exit(main())