Richard W.M. Jones
2016-May-04 13:12 UTC
[Libguestfs] [PATCH 1/2] inspection: Set package manager to "unknown" if parsing major version failed (RHBZ#1332025).
In cases where parsing the release file failed and so we have an obviously incorrect major version number, don't try to infer the package manager from the major version number. In the bug report, parsing the /etc/redhat-release file of a CentOS 7.1 guest failed, so major version was set to 0, and the package manager was inferred as "up2date". virt-customize then failed with a peculiar error: virt-customize: sorry, don't know how to use --install with the 'up2date' package manager Instead this sets it to "unknown" which will cause virt-customize to fail with: virt-customize: --install is not supported for this guest operating system which is (only very slightly) better. Problem reported by novegin on IRC. --- src/inspect-fs.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/inspect-fs.c b/src/inspect-fs.c index 0714ae1..7f7d5d1 100644 --- a/src/inspect-fs.c +++ b/src/inspect-fs.c @@ -531,8 +531,11 @@ guestfs_int_check_package_management (guestfs_h *g, struct inspect_fs *fs) guestfs_is_file_opts (g, "/usr/bin/dnf", GUESTFS_IS_FILE_OPTS_FOLLOWSYMLINKS, 1, -1) > 0) fs->package_management = OS_PACKAGE_MANAGEMENT_DNF; - else + else if (fs->major_version >= 1) fs->package_management = OS_PACKAGE_MANAGEMENT_YUM; + else + /* Probably parsing the release file failed, see RHBZ#1332025. */ + fs->package_management = OS_PACKAGE_MANAGEMENT_UNKNOWN; break; case OS_DISTRO_REDHAT_BASED: @@ -542,8 +545,11 @@ guestfs_int_check_package_management (guestfs_h *g, struct inspect_fs *fs) case OS_DISTRO_ORACLE_LINUX: if (fs->major_version >= 5) fs->package_management = OS_PACKAGE_MANAGEMENT_YUM; - else + else if (fs->major_version >= 2) fs->package_management = OS_PACKAGE_MANAGEMENT_UP2DATE; + else + /* Probably parsing the release file failed, see RHBZ#1332025. */ + fs->package_management = OS_PACKAGE_MANAGEMENT_UNKNOWN; break; case OS_DISTRO_DEBIAN: -- 2.7.4
Richard W.M. Jones
2016-May-04 13:12 UTC
[Libguestfs] [PATCH 2/2] customize: Improve the error messages when package manager is unknown or unsupported.
For Windows, we now print: $ virt-customize -a ./test-data/phony-guests/windows.img --install MSSQL [ 0.0] Examining the guest ... [ 14.2] Setting a random seed virt-customize: warning: random seed could not be set for this type of guest [ 14.2] Installing packages: MSSQL virt-customize: error: '--install' failed because inspection could not determine the package manager for this guest OS. If this guest OS is a common one with ordinary package management then this may have been caused by a failure of libguestfs inspection. For OSes such as Windows that lack package management, this is not possible. Try using one of the '--firstboot*' flags instead (described in the manual). --- customize/customize_run.ml | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/customize/customize_run.ml b/customize/customize_run.ml index 83e70a6..c0e1e44 100644 --- a/customize/customize_run.ml +++ b/customize/customize_run.ml @@ -94,7 +94,7 @@ exec >>%s 2>&1 in (* http://distrowatch.com/dwres.php?resource=package-management *) - let guest_install_command packages + let rec guest_install_command packages let quoted_args = String.concat " " (List.map quote packages) in match g#inspect_get_package_management root with | "apk" -> @@ -116,10 +116,11 @@ exec >>%s 2>&1 | "urpmi" -> sprintf "urpmi %s" quoted_args | "yum" -> sprintf "yum -y install %s" quoted_args | "zypper" -> sprintf "zypper -n in -l %s" quoted_args + | "unknown" -> - error (f_"--install is not supported for this guest operating system") + error_unknown_package_manager (s_"--install") | pm -> - error (f_"sorry, don't know how to use --install with the '%s' package manager") pm + error_unimplemented_package_manager (s_"--install") pm and guest_update_command () match g#inspect_get_package_management root with @@ -142,10 +143,18 @@ exec >>%s 2>&1 | "urpmi" -> "urpmi --auto-select" | "yum" -> "yum -y update" | "zypper" -> "zypper -n update -l" + | "unknown" -> - error (f_"--update is not supported for this guest operating system") + error_unknown_package_manager (s_"--update") | pm -> - error (f_"sorry, don't know how to use --update with the '%s' package manager") pm + error_unimplemented_package_manager (s_"--update") pm + + (* Windows has package_management == "unknown". *) + and error_unknown_package_manager flag + error (f_"'%s' failed because inspection could not determine the package manager for this guest OS.\n\nIf this guest OS is a common one with ordinary package management then this may have been caused by a failure of libguestfs inspection.\n\nFor OSes such as Windows that lack package management, this is not possible. Try using one of the '--firstboot*' flags instead (described in the manual).") flag + + and error_unimplemented_package_manager flag pm + error (f_"sorry, '%s' with the '%s' package manager has not been implemented.\n\nIf this guest OS has ordinary package management then you will need to add support to virt-customize.\n\nFor OSes lack package management, this is not possible.\n\nYou can work around this by using one of the '--run*' or '--firstboot*' options instead (described in the manual).") flag pm in (* Set the random seed. *) -- 2.7.4
Pino Toscano
2016-May-04 14:09 UTC
Re: [Libguestfs] [PATCH 2/2] customize: Improve the error messages when package manager is unknown or unsupported.
On Wednesday 04 May 2016 14:12:30 Richard W.M. Jones wrote:> For Windows, we now print: > > $ virt-customize -a ./test-data/phony-guests/windows.img --install MSSQL > [ 0.0] Examining the guest ... > [ 14.2] Setting a random seed > virt-customize: warning: random seed could not be set for this type of > guest > [ 14.2] Installing packages: MSSQL > virt-customize: error: '--install' failed because inspection could not > determine the package manager for this guest OS. > > If this guest OS is a common one with ordinary package management then this > may have been caused by a failure of libguestfs inspection. > > For OSes such as Windows that lack package management, this is not > possible. Try using one of the '--firstboot*' flags instead (described in > the manual). > --- > customize/customize_run.ml | 19 ++++++++++++++----- > 1 file changed, 14 insertions(+), 5 deletions(-) > > diff --git a/customize/customize_run.ml b/customize/customize_run.ml > index 83e70a6..c0e1e44 100644 > --- a/customize/customize_run.ml > +++ b/customize/customize_run.ml > @@ -94,7 +94,7 @@ exec >>%s 2>&1 > in > > (* http://distrowatch.com/dwres.php?resource=package-management *) > - let guest_install_command packages > + let rec guest_install_command packages > let quoted_args = String.concat " " (List.map quote packages) in > match g#inspect_get_package_management root with > | "apk" -> > @@ -116,10 +116,11 @@ exec >>%s 2>&1 > | "urpmi" -> sprintf "urpmi %s" quoted_args > | "yum" -> sprintf "yum -y install %s" quoted_args > | "zypper" -> sprintf "zypper -n in -l %s" quoted_args > + > | "unknown" -> > - error (f_"--install is not supported for this guest operating system") > + error_unknown_package_manager (s_"--install") > | pm -> > - error (f_"sorry, don't know how to use --install with the '%s' package manager") pm > + error_unimplemented_package_manager (s_"--install") pm > > and guest_update_command () > match g#inspect_get_package_management root with > @@ -142,10 +143,18 @@ exec >>%s 2>&1 > | "urpmi" -> "urpmi --auto-select" > | "yum" -> "yum -y update" > | "zypper" -> "zypper -n update -l" > + > | "unknown" -> > - error (f_"--update is not supported for this guest operating system") > + error_unknown_package_manager (s_"--update") > | pm -> > - error (f_"sorry, don't know how to use --update with the '%s' package manager") pm > + error_unimplemented_package_manager (s_"--update") pm > + > + (* Windows has package_management == "unknown". *) > + and error_unknown_package_manager flag > + error (f_"'%s' failed because inspection could not determine the package manager for this guest OS.\n\nIf this guest OS is a common one with ordinary package management then this may have been caused by a failure of libguestfs inspection.\n\nFor OSes such as Windows that lack package management, this is not possible. Try using one of the '--firstboot*' flags instead (described in the manual).") flagwhat about "cannot run '%s' because no package management has been detected for this guest OS.\n etc"> + > + and error_unimplemented_package_manager flag pm > + error (f_"sorry, '%s' with the '%s' package manager has not been implemented.\n\nIf this guest OS has ordinary package management then you will need to add support to virt-customize.\n\nFor OSes lack package management, this is not possible.\n\nYou can work around this by using one of the '--run*' or '--firstboot*' options instead (described in the manual).") flag pmI'd shorten this message: "sorry, '%s' with the '%s' package manager has not been implemented yet.\n\nYou can work around this by using one of the '--run*' or '--firstboot*' options instead (described in the manual)." rationale behind that: - telling users to add support for that is not exactly useful, and what will happen in such cases is that we get reports with that - if the OS lacks package management, then the result will be "unknown" and thus the other message will be shown - this would be shown in virt-builder, other than virt-customize (but that's just a minor point) -- Pino Toscano
Pino Toscano
2016-May-04 14:09 UTC
Re: [Libguestfs] [PATCH 1/2] inspection: Set package manager to "unknown" if parsing major version failed (RHBZ#1332025).
On Wednesday 04 May 2016 14:12:29 Richard W.M. Jones wrote:> In cases where parsing the release file failed and so we have an > obviously incorrect major version number, don't try to infer the > package manager from the major version number. > > In the bug report, parsing the /etc/redhat-release file of a CentOS > 7.1 guest failed, so major version was set to 0, and the package > manager was inferred as "up2date". virt-customize then failed with a > peculiar error: > > virt-customize: sorry, don't know how to use --install with the 'up2date' package manager > > Instead this sets it to "unknown" which will cause virt-customize to > fail with: > > virt-customize: --install is not supported for this guest operating system > > which is (only very slightly) better. > > Problem reported by novegin on IRC. > ---LGTM. Thanks, -- Pino Toscano
Apparently Analagous Threads
- [PATCH] customize: Add --uninstall operation.
- [PATCH 2/2] customize: Improve the error messages when package manager is unknown or unsupported.
- [PATCH 1/2] inspection: Set package manager to "unknown" if parsing major version failed (RHBZ#1332025).
- [PATCH] customize: use --noconfirm when installing Arch Linux packages
- [PATCH] Fix error with --uninstall option on SUSE