metal/bsp-files/platform_comps.py
Don Penney 4792d66618 Enhance filtering of software groups for install
Software groups are generated using the platform_comps.py
utility to declare what software is installed on the
various node types, generating a comps.xml for the base
software repo in the ISO (and on the controller) with
package groups for each node type. The "filter_out_from_X"
files provide a list of packages to exclude from the
corresponding software group.

This update enhances the filtering by using the package
list from the image.inc files, rather than the full set of
packages included in the ISO. The latter, which is the existing
implementation, would include all packages pulled in to meet
dependency requirements in addition to those specified in
image.inc files. As a result, we would also need to include
these dependencies in the filter files to ensure they are not
installed on a given node.

By using just the package list from the image.inc files, the
software groups will only include the requested packages. Adding
a package to the filter file would then effectively also filter
its dependencies.

For example, if package A is in an image.inc file and requires
package B, and we include A in the filter_out_from_storage list,
the existing implementation would still include B in the storage
software group and B would be installed on the node. With this
updated implementation, B would not be included in the software
groups at all, and only installed on nodes that also install A.

Additionally, this update also cleans up filter references from
centos-ks-gen.pl which were obsolete and should have been removed
previously.

This update also adds starlingx-dashboard to the filter lists for
storage and worker nodes.

As an example, this update has the net effect of reducing the
number of packages installed on a worker node from the current
total of 1060 to 932 packages, by trimming the unneeded packages
pulled in from dependencies of filtered packages.

Change-Id: I1c1c3fabf53c4a1dd085f135c7443e09f96e5906
Story: 2004764
Task: 33602
Signed-off-by: Don Penney <don.penney@windriver.com>
2019-06-07 10:01:41 -04:00

150 lines
4.5 KiB
Python

#!/usr/bin/env python
"""
Copyright (c) 2018-2019 Wind River Systems, Inc.
SPDX-License-Identifier: Apache-2.0
"""
from __future__ import print_function
import getopt
import os
import subprocess
import sys
import xml.etree.ElementTree as ElementTree
def usage():
print("Usage: %s --groups <groups.xml> --pkglist <pkglist>"
% os.path.basename(sys.argv[0]))
exit(1)
def add_text_tag_to_xml(parent,
name,
text):
"""
Utility function for adding a text tag to an XML object
:param parent: Parent element
:param name: Element name
:param text: Text value
:return:The created element
"""
tag = ElementTree.SubElement(parent, name)
tag.text = text
tag.tail = '\n '
return tag
def add_group(comps, personality, rpmlist=None, filter_dir=None, filter=None):
"""
Add a software group to the comps.xml
:param comps: comps element
:param personality: Personality of node for group
:param rpmlist: List of all rpms in the base load
:param filter_dir: Path to filter files
:param filter: Name of filter file to use
"""
if rpmlist is not None:
# Define a base platform group
groupname = "platform-%s" % personality
desc = "Platform packages for %s" % personality
else:
# Define an empty patch group
groupname = "updates-%s" % personality
desc = "Patches for %s" % personality
group = ElementTree.SubElement(comps, 'group')
group.tail = '\n'
add_text_tag_to_xml(group, 'id', groupname)
add_text_tag_to_xml(group, 'default', "false")
add_text_tag_to_xml(group, 'uservisible', "true")
add_text_tag_to_xml(group, 'display_order', "1024")
add_text_tag_to_xml(group, 'name', groupname)
add_text_tag_to_xml(group, 'description', desc)
package_element = ElementTree.SubElement(group,
'packagelist')
package_element.tail = '\n '
if rpmlist is not None:
# Read the filter file
f = open(os.path.join(filter_dir, filter), 'r')
filtered = f.read().split()
f.close()
for pkg in sorted(rpmlist):
if pkg not in filtered:
tag = ElementTree.SubElement(package_element,
'packagereq',
type="mandatory")
tag.text = pkg
tag.tail = '\n '
def main():
try:
opts, remainder = getopt.getopt(sys.argv[1:],
'',
['pkgdir=', # Deprecated
'groups=',
'pkglist='])
except getopt.GetoptError:
usage()
groups_file = None
pkglist = []
# Filters are colocated with this script
filter_dir = os.path.dirname(sys.argv[0])
for opt, arg in opts:
if opt == "--groups":
groups_file = arg
elif opt == "--pkglist":
pkglist.append(arg)
if groups_file is None:
usage()
if len(pkglist) == 0:
# Use default files
pkglist.append(os.path.join(os.environ['MY_REPO'],
'build-tools/build_iso/minimal_rpm_list.txt'))
pkglist.append(os.path.join(os.environ['MY_WORKSPACE'],
'std/image.inc'))
# Get the pkglist
cmd = "sed 's/#.*//' %s" % ' '.join(pkglist)
rpmlist = subprocess.check_output(cmd, shell=True).split()
tree = ElementTree.parse(groups_file)
comps = tree.getroot()
comps.tail = '\n'
add_group(comps, 'controller', rpmlist,
filter_dir, 'filter_out_from_controller')
add_group(comps, 'controller-worker', rpmlist,
filter_dir, 'filter_out_from_smallsystem')
add_group(comps, 'controller-worker-lowlatency', rpmlist,
filter_dir, 'filter_out_from_smallsystem_lowlatency')
add_group(comps, 'worker', rpmlist, filter_dir, 'filter_out_from_worker')
add_group(comps, 'worker-lowlatency', rpmlist,
filter_dir, 'filter_out_from_worker_lowlatency')
add_group(comps, 'storage', rpmlist, filter_dir, 'filter_out_from_storage')
add_group(comps, 'controller')
add_group(comps, 'controller-worker')
add_group(comps, 'controller-worker-lowlatency')
add_group(comps, 'worker')
add_group(comps, 'worker-lowlatency')
add_group(comps, 'storage')
tree.write(groups_file, encoding="UTF-8")
if __name__ == "__main__":
main()