提交 8128fa82 编写于 作者: C Cleber Rosa

Distro plugin: implement distro definition file creation

As a subcommand (option, really) of the plugin command. The generated
distro file is supposed to be portable and be named canonically based
on the name, version, release and arch.

Changes from v0:
 * Return proper exit status when required command line arguments are
   missing
Signed-off-by: NCleber Rosa <crosa@redhat.com>
上级 30b18b30
......@@ -14,9 +14,11 @@
import os
import bz2
import sys
import json
from avocado.core import output
from avocado.core import exit_codes
from avocado.plugins import plugin
from avocado.utils import process
from avocado.linux import distro as distro_utils
......@@ -299,14 +301,81 @@ class DistroOptions(plugin.Plugin):
self.parser = parser.subcommands.add_parser(
'distro',
help='Shows detected Linux distribution')
self.parser.add_argument('--distro-def-create',
action='store_true', default=False,
help=('Creates a distro definition file '
'based on the path given'))
self.parser.add_argument('--distro-def-name',
help='Distribution short name')
self.parser.add_argument('--distro-def-version',
help='Distribution major version number')
self.parser.add_argument('---distro-def-release', default='',
help='Distribution release version number')
self.parser.add_argument('--distro-def-arch',
help=('Primary architecture that the distro '
'targets'))
self.parser.add_argument('--distro-def-path',
help=('Top level directory of the distro '
'installation files'))
type_choices = DISTRO_PKG_INFO_LOADERS.keys()
type_choices_hlp = ', '.join(type_choices)
type_help_msg = 'Distro type (one of: %s)' % type_choices_hlp
self.parser.add_argument('--distro-def-type', choices=type_choices,
help=type_help_msg)
super(DistroOptions, self).configure(self.parser)
def get_output_file_name(self, args):
'''
Adapt the output file name based on given args
It's not uncommon for some distros to not have a release number, so
adapt the output file name to that
'''
if args.distro_def_release:
return '%s-%s.%s-%s.distro' % (args.distro_def_name,
args.distro_def_version,
args.distro_def_release,
args.distro_def_arch)
else:
return '%s-%s-%s.distro' % (args.distro_def_name,
args.distro_def_version,
args.distro_def_arch)
def run(self, args):
view = output.View()
detected = distro_utils.detect()
msg = 'Detected distribution: %s (%s) version %s release %s' % (
detected.name,
detected.arch,
detected.version,
detected.release)
view.notify(event="message", msg=msg)
if args.distro_def_create:
if not (args.distro_def_name and args.distro_def_version and
args.distro_def_arch and args.distro_def_type and
args.distro_def_path):
error_msg = ('Required arguments: name, version, arch, type '
'and path')
view.notify(event="error", msg=error_msg)
sys.exit(exit_codes.AVOCADO_CRASH)
output_file_name = self.get_output_file_name(args)
if os.path.exists(output_file_name):
error_msg = ('Output file "%s" already exists, will not '
'overwrite it' % output_file_name)
view.notify(event="error", msg=error_msg)
else:
view.notify(event="message",
msg=("Loading distro information from tree... "
"Please wait..."))
distro = load_from_tree(args.distro_def_name,
args.distro_def_version,
args.distro_def_release,
args.distro_def_arch,
args.distro_def_type,
args.distro_def_path)
save_distro(distro, output_file_name)
view.notify(event="message",
msg=('Distro information saved '
'to "%s"' % output_file_name))
else:
detected = distro_utils.detect()
msg = 'Detected distribution: %s (%s) version %s release %s' % (
detected.name,
detected.arch,
detected.version,
detected.release)
view.notify(event="message", msg=msg)
......@@ -488,6 +488,27 @@ The most basic command prints the detected Linux Distribution::
$ avocado distro
Detected distribution: fedora (x86_64) version 21 release 0
Other features are available with the same command when command line options are given, as shown by the
`--help` option.
For instance, it possible to create a so-called "Linux Distribution Definition" file, by inspecting an installation
tree. The installation tree could be the contents of the official installation ISO or a local network mirror.
These files let Avocado pinpoint if a given installed package is part of the original Linux Distribution or
something else that was installed from an external repository or even manually. This, in turn, can help
detecting regressions in base system pacakges that affected a given test result.
To generate a definition file run::
$ avocado distro --distro-def-create --distro-def-name avocadix \
--distro-def-version 1 --distro-def-arch x86_64 \
--distro-def-type rpm --distro-def-path /mnt/dvd
And the output will be something like::
Loading distro information from tree... Please wait...
Distro information saved to "avocadix-1-x86_64.distro"
FILES
=====
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册