|
|
58b090 |
From 75e92678bfb687d23594c3ecef299cddca657c3e Mon Sep 17 00:00:00 2001
|
|
|
58b090 |
From: Jan Kolarik <jkolarik@redhat.com>
|
|
|
58b090 |
Date: Thu, 22 Sep 2022 16:02:55 +0000
|
|
|
58b090 |
Subject: [PATCH 1/4] Move system-upgrade plugin to core (RhBug:2054235)
|
|
|
58b090 |
|
|
|
58b090 |
= changelog =
|
|
|
58b090 |
type: bugfix
|
|
|
58b090 |
resolves: https://bugzilla.redhat.com/show_bug.cgi?id=2054235
|
|
|
58b090 |
---
|
|
|
58b090 |
CMakeLists.txt | 15 +
|
|
|
58b090 |
dnf-plugins-core.spec | 38 +-
|
|
|
58b090 |
doc/CMakeLists.txt | 1 +
|
|
|
58b090 |
doc/conf.py | 1 +
|
|
|
58b090 |
doc/index.rst | 1 +
|
|
|
58b090 |
doc/system-upgrade.rst | 207 ++++++
|
|
|
58b090 |
etc/CMakeLists.txt | 1 +
|
|
|
58b090 |
etc/systemd/CMakeLists.txt | 1 +
|
|
|
58b090 |
.../dnf-system-upgrade-cleanup.service | 11 +
|
|
|
58b090 |
etc/systemd/dnf-system-upgrade.service | 20 +
|
|
|
58b090 |
plugins/CMakeLists.txt | 1 +
|
|
|
58b090 |
plugins/system_upgrade.py | 699 ++++++++++++++++++
|
|
|
58b090 |
tests/test_system_upgrade.py | 502 +++++++++++++
|
|
|
58b090 |
13 files changed, 1494 insertions(+), 4 deletions(-)
|
|
|
58b090 |
create mode 100644 doc/system-upgrade.rst
|
|
|
58b090 |
create mode 100644 etc/systemd/CMakeLists.txt
|
|
|
58b090 |
create mode 100644 etc/systemd/dnf-system-upgrade-cleanup.service
|
|
|
58b090 |
create mode 100644 etc/systemd/dnf-system-upgrade.service
|
|
|
58b090 |
create mode 100644 plugins/system_upgrade.py
|
|
|
58b090 |
create mode 100644 tests/test_system_upgrade.py
|
|
|
58b090 |
|
|
|
58b090 |
diff --git a/CMakeLists.txt b/CMakeLists.txt
|
|
|
58b090 |
index 59c4f2a..a1eea7b 100644
|
|
|
58b090 |
--- a/CMakeLists.txt
|
|
|
58b090 |
+++ b/CMakeLists.txt
|
|
|
58b090 |
@@ -23,6 +23,21 @@ MESSAGE(STATUS "Python install dir is ${PYTHON_INSTALL_DIR}")
|
|
|
58b090 |
|
|
|
58b090 |
SET (SYSCONFDIR /etc)
|
|
|
58b090 |
|
|
|
58b090 |
+find_package (PkgConfig)
|
|
|
58b090 |
+
|
|
|
58b090 |
+if (PKG_CONFIG_FOUND)
|
|
|
58b090 |
+ pkg_search_module (SYSTEMD systemd)
|
|
|
58b090 |
+ if (SYSTEMD_FOUND)
|
|
|
58b090 |
+ execute_process (COMMAND ${PKG_CONFIG_EXECUTABLE} --variable=systemdsystemunitdir systemd
|
|
|
58b090 |
+ OUTPUT_VARIABLE SYSTEMD_DIR
|
|
|
58b090 |
+ OUTPUT_STRIP_TRAILING_WHITESPACE)
|
|
|
58b090 |
+ endif ()
|
|
|
58b090 |
+endif()
|
|
|
58b090 |
+
|
|
|
58b090 |
+if (NOT SYSTEMD_DIR)
|
|
|
58b090 |
+ set (SYSTEMD_DIR /usr/lib/systemd/system)
|
|
|
58b090 |
+endif ()
|
|
|
58b090 |
+
|
|
|
58b090 |
ADD_SUBDIRECTORY (libexec)
|
|
|
58b090 |
ADD_SUBDIRECTORY (doc)
|
|
|
58b090 |
ADD_SUBDIRECTORY (etc)
|
|
|
58b090 |
diff --git a/dnf-plugins-core.spec b/dnf-plugins-core.spec
|
|
|
58b090 |
index c37dda8..4df6e44 100644
|
|
|
58b090 |
--- a/dnf-plugins-core.spec
|
|
|
58b090 |
+++ b/dnf-plugins-core.spec
|
|
|
58b090 |
@@ -64,6 +64,9 @@ Provides: dnf-command(repograph)
|
|
|
58b090 |
Provides: dnf-command(repomanage)
|
|
|
58b090 |
Provides: dnf-command(reposync)
|
|
|
58b090 |
Provides: dnf-command(repodiff)
|
|
|
58b090 |
+Provides: dnf-command(system-upgrade)
|
|
|
58b090 |
+Provides: dnf-command(offline-upgrade)
|
|
|
58b090 |
+Provides: dnf-command(offline-distrosync)
|
|
|
58b090 |
Provides: dnf-plugins-extras-debug = %{version}-%{release}
|
|
|
58b090 |
Provides: dnf-plugins-extras-repoclosure = %{version}-%{release}
|
|
|
58b090 |
Provides: dnf-plugins-extras-repograph = %{version}-%{release}
|
|
|
58b090 |
@@ -80,6 +83,7 @@ Provides: dnf-plugin-repodiff = %{version}-%{release}
|
|
|
58b090 |
Provides: dnf-plugin-repograph = %{version}-%{release}
|
|
|
58b090 |
Provides: dnf-plugin-repomanage = %{version}-%{release}
|
|
|
58b090 |
Provides: dnf-plugin-reposync = %{version}-%{release}
|
|
|
58b090 |
+Provides: dnf-plugin-system-upgrade = %{version}-%{release}
|
|
|
58b090 |
%if %{with yumcompatibility}
|
|
|
58b090 |
Provides: yum-plugin-copr = %{version}-%{release}
|
|
|
58b090 |
Provides: yum-plugin-changelog = %{version}-%{release}
|
|
|
58b090 |
@@ -133,8 +137,8 @@ Conflicts: python-%{name} < %{version}-%{release}
|
|
|
58b090 |
%description -n python2-%{name}
|
|
|
58b090 |
Core Plugins for DNF, Python 2 interface. This package enhances DNF with builddep,
|
|
|
58b090 |
config-manager, copr, degug, debuginfo-install, download, needs-restarting,
|
|
|
58b090 |
-groups-manager, repoclosure, repograph, repomanage, reposync, changelog
|
|
|
58b090 |
-and repodiff commands.
|
|
|
58b090 |
+groups-manager, repoclosure, repograph, repomanage, reposync, changelog,
|
|
|
58b090 |
+repodiff, system-upgrade, offline-upgrade and offline-distrosync commands.
|
|
|
58b090 |
Additionally provides generate_completion_cache passive plugin.
|
|
|
58b090 |
%endif
|
|
|
58b090 |
|
|
|
58b090 |
@@ -145,6 +149,10 @@ Summary: Core Plugins for DNF
|
|
|
58b090 |
BuildRequires: python3-dbus
|
|
|
58b090 |
BuildRequires: python3-devel
|
|
|
58b090 |
BuildRequires: python3-dnf >= %{dnf_lowest_compatible}
|
|
|
58b090 |
+BuildRequires: python3-systemd
|
|
|
58b090 |
+BuildRequires: pkgconfig(systemd)
|
|
|
58b090 |
+BuildRequires: systemd
|
|
|
58b090 |
+%{?systemd_ordering}
|
|
|
58b090 |
%if 0%{?fedora}
|
|
|
58b090 |
Requires: python3-distro
|
|
|
58b090 |
%endif
|
|
|
58b090 |
@@ -152,14 +160,17 @@ Requires: python3-dbus
|
|
|
58b090 |
Requires: python3-dnf >= %{dnf_lowest_compatible}
|
|
|
58b090 |
Requires: python3-hawkey >= %{hawkey_version}
|
|
|
58b090 |
Requires: python3-dateutil
|
|
|
58b090 |
+Requires: python3-systemd
|
|
|
58b090 |
Provides: python3-dnf-plugins-extras-debug = %{version}-%{release}
|
|
|
58b090 |
Provides: python3-dnf-plugins-extras-repoclosure = %{version}-%{release}
|
|
|
58b090 |
Provides: python3-dnf-plugins-extras-repograph = %{version}-%{release}
|
|
|
58b090 |
Provides: python3-dnf-plugins-extras-repomanage = %{version}-%{release}
|
|
|
58b090 |
+Provides: python3-dnf-plugin-system-upgrade = %{version}-%{release}
|
|
|
58b090 |
Obsoletes: python3-dnf-plugins-extras-debug < %{dnf_plugins_extra}
|
|
|
58b090 |
Obsoletes: python3-dnf-plugins-extras-repoclosure < %{dnf_plugins_extra}
|
|
|
58b090 |
Obsoletes: python3-dnf-plugins-extras-repograph < %{dnf_plugins_extra}
|
|
|
58b090 |
Obsoletes: python3-dnf-plugins-extras-repomanage < %{dnf_plugins_extra}
|
|
|
58b090 |
+Obsoletes: python3-dnf-plugin-system-upgrade < %{version}-%{release}
|
|
|
58b090 |
|
|
|
58b090 |
Conflicts: %{name} <= 0.1.5
|
|
|
58b090 |
# let the both python plugin versions be updated simultaneously
|
|
|
58b090 |
@@ -169,8 +180,8 @@ Conflicts: python-%{name} < %{version}-%{release}
|
|
|
58b090 |
%description -n python3-%{name}
|
|
|
58b090 |
Core Plugins for DNF, Python 3 interface. This package enhances DNF with builddep,
|
|
|
58b090 |
config-manager, copr, debug, debuginfo-install, download, needs-restarting,
|
|
|
58b090 |
-groups-manager, repoclosure, repograph, repomanage, reposync, changelog
|
|
|
58b090 |
-and repodiff commands.
|
|
|
58b090 |
+groups-manager, repoclosure, repograph, repomanage, reposync, changelog,
|
|
|
58b090 |
+repodiff, system-upgrade, offline-upgrade and offline-distrosync commands.
|
|
|
58b090 |
Additionally provides generate_completion_cache passive plugin.
|
|
|
58b090 |
%endif
|
|
|
58b090 |
|
|
|
58b090 |
@@ -451,6 +462,17 @@ pushd build-py3
|
|
|
58b090 |
%make_install
|
|
|
58b090 |
popd
|
|
|
58b090 |
%endif
|
|
|
58b090 |
+
|
|
|
58b090 |
+%if %{with python3}
|
|
|
58b090 |
+mkdir -p %{buildroot}%{_unitdir}/system-update.target.wants/
|
|
|
58b090 |
+pushd %{buildroot}%{_unitdir}/system-update.target.wants/
|
|
|
58b090 |
+ ln -sr ../dnf-system-upgrade.service
|
|
|
58b090 |
+popd
|
|
|
58b090 |
+
|
|
|
58b090 |
+ln -sf %{_mandir}/man8/dnf-system-upgrade.8.gz %{buildroot}%{_mandir}/man8/dnf-offline-upgrade.8.gz
|
|
|
58b090 |
+ln -sf %{_mandir}/man8/dnf-system-upgrade.8.gz %{buildroot}%{_mandir}/man8/dnf-offline-distrosync.8.gz
|
|
|
58b090 |
+%endif
|
|
|
58b090 |
+
|
|
|
58b090 |
%find_lang %{name}
|
|
|
58b090 |
%if %{with yumutils}
|
|
|
58b090 |
%if %{with python3}
|
|
|
58b090 |
@@ -515,6 +537,9 @@ ln -sf %{_mandir}/man1/%{yum_utils_subpackage_name}.1.gz %{buildroot}%{_mandir}/
|
|
|
58b090 |
%{_mandir}/man8/dnf-repograph.*
|
|
|
58b090 |
%{_mandir}/man8/dnf-repomanage.*
|
|
|
58b090 |
%{_mandir}/man8/dnf-reposync.*
|
|
|
58b090 |
+%{_mandir}/man8/dnf-system-upgrade.*
|
|
|
58b090 |
+%{_mandir}/man8/dnf-offline-upgrade.*
|
|
|
58b090 |
+%{_mandir}/man8/dnf-offline-distrosync.*
|
|
|
58b090 |
%if %{with yumcompatibility}
|
|
|
58b090 |
%{_mandir}/man1/yum-changelog.*
|
|
|
58b090 |
%{_mandir}/man8/yum-copr.*
|
|
|
58b090 |
@@ -572,6 +597,7 @@ ln -sf %{_mandir}/man1/%{yum_utils_subpackage_name}.1.gz %{buildroot}%{_mandir}/
|
|
|
58b090 |
%{python3_sitelib}/dnf-plugins/repograph.py
|
|
|
58b090 |
%{python3_sitelib}/dnf-plugins/repomanage.py
|
|
|
58b090 |
%{python3_sitelib}/dnf-plugins/reposync.py
|
|
|
58b090 |
+%{python3_sitelib}/dnf-plugins/system_upgrade.py
|
|
|
58b090 |
%{python3_sitelib}/dnf-plugins/__pycache__/builddep.*
|
|
|
58b090 |
%{python3_sitelib}/dnf-plugins/__pycache__/changelog.*
|
|
|
58b090 |
%{python3_sitelib}/dnf-plugins/__pycache__/config_manager.*
|
|
|
58b090 |
@@ -587,7 +613,11 @@ ln -sf %{_mandir}/man1/%{yum_utils_subpackage_name}.1.gz %{buildroot}%{_mandir}/
|
|
|
58b090 |
%{python3_sitelib}/dnf-plugins/__pycache__/repograph.*
|
|
|
58b090 |
%{python3_sitelib}/dnf-plugins/__pycache__/repomanage.*
|
|
|
58b090 |
%{python3_sitelib}/dnf-plugins/__pycache__/reposync.*
|
|
|
58b090 |
+%{python3_sitelib}/dnf-plugins/__pycache__/system_upgrade.*
|
|
|
58b090 |
%{python3_sitelib}/dnfpluginscore/
|
|
|
58b090 |
+%{_unitdir}/dnf-system-upgrade.service
|
|
|
58b090 |
+%{_unitdir}/dnf-system-upgrade-cleanup.service
|
|
|
58b090 |
+%{_unitdir}/system-update.target.wants/dnf-system-upgrade.service
|
|
|
58b090 |
%endif
|
|
|
58b090 |
|
|
|
58b090 |
%if %{with yumutils}
|
|
|
58b090 |
diff --git a/doc/CMakeLists.txt b/doc/CMakeLists.txt
|
|
|
58b090 |
index ff84cf8..79472a5 100644
|
|
|
58b090 |
--- a/doc/CMakeLists.txt
|
|
|
58b090 |
+++ b/doc/CMakeLists.txt
|
|
|
58b090 |
@@ -37,6 +37,7 @@ INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/dnf-builddep.8
|
|
|
58b090 |
${CMAKE_CURRENT_BINARY_DIR}/dnf-reposync.8
|
|
|
58b090 |
${CMAKE_CURRENT_BINARY_DIR}/dnf-post-transaction-actions.8
|
|
|
58b090 |
${CMAKE_CURRENT_BINARY_DIR}/dnf-show-leaves.8
|
|
|
58b090 |
+ ${CMAKE_CURRENT_BINARY_DIR}/dnf-system-upgrade.8
|
|
|
58b090 |
${CMAKE_CURRENT_BINARY_DIR}/dnf-versionlock.8
|
|
|
58b090 |
${CMAKE_CURRENT_BINARY_DIR}/yum-copr.8
|
|
|
58b090 |
${CMAKE_CURRENT_BINARY_DIR}/yum-versionlock.8
|
|
|
58b090 |
diff --git a/doc/conf.py b/doc/conf.py
|
|
|
58b090 |
index 41d6936..327ac07 100644
|
|
|
58b090 |
--- a/doc/conf.py
|
|
|
58b090 |
+++ b/doc/conf.py
|
|
|
58b090 |
@@ -264,6 +264,7 @@ man_pages = [
|
|
|
58b090 |
('post-transaction-actions', 'dnf-post-transaction-actions',
|
|
|
58b090 |
u'DNF post transaction actions Plugin', AUTHORS, 8),
|
|
|
58b090 |
('show-leaves', 'dnf-show-leaves', u'DNF show-leaves Plugin', AUTHORS, 8),
|
|
|
58b090 |
+ ('system-upgrade', 'dnf-system-upgrade', u'DNF system-upgrade Plugin', AUTHORS, 8),
|
|
|
58b090 |
('versionlock', 'dnf-versionlock', u'DNF versionlock Plugin', AUTHORS, 8),
|
|
|
58b090 |
|
|
|
58b090 |
# yum3 compatible layer for manpages
|
|
|
58b090 |
diff --git a/doc/index.rst b/doc/index.rst
|
|
|
58b090 |
index 07f6052..251a24e 100644
|
|
|
58b090 |
--- a/doc/index.rst
|
|
|
58b090 |
+++ b/doc/index.rst
|
|
|
58b090 |
@@ -46,6 +46,7 @@ This documents core plugins of DNF:
|
|
|
58b090 |
repomanage
|
|
|
58b090 |
reposync
|
|
|
58b090 |
show-leaves
|
|
|
58b090 |
+ system-upgrade
|
|
|
58b090 |
versionlock
|
|
|
58b090 |
|
|
|
58b090 |
|
|
|
58b090 |
diff --git a/doc/system-upgrade.rst b/doc/system-upgrade.rst
|
|
|
58b090 |
new file mode 100644
|
|
|
58b090 |
index 0000000..3110460
|
|
|
58b090 |
--- /dev/null
|
|
|
58b090 |
+++ b/doc/system-upgrade.rst
|
|
|
58b090 |
@@ -0,0 +1,207 @@
|
|
|
58b090 |
+..
|
|
|
58b090 |
+ Copyright (C) 2014-2016 Red Hat, Inc.
|
|
|
58b090 |
+
|
|
|
58b090 |
+ This copyrighted material is made available to anyone wishing to use,
|
|
|
58b090 |
+ modify, copy, or redistribute it subject to the terms and conditions of
|
|
|
58b090 |
+ the GNU General Public License v.2, or (at your option) any later version.
|
|
|
58b090 |
+ This program is distributed in the hope that it will be useful, but WITHOUT
|
|
|
58b090 |
+ ANY WARRANTY expressed or implied, including the implied warranties of
|
|
|
58b090 |
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
|
|
|
58b090 |
+ Public License for more details. You should have received a copy of the
|
|
|
58b090 |
+ GNU General Public License along with this program; if not, write to the
|
|
|
58b090 |
+ Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
|
|
58b090 |
+ 02110-1301, USA. Any Red Hat trademarks that are incorporated in the
|
|
|
58b090 |
+ source code or documentation are not subject to the GNU General Public
|
|
|
58b090 |
+ License and may only be used or replicated with the express permission of
|
|
|
58b090 |
+ Red Hat, Inc.
|
|
|
58b090 |
+
|
|
|
58b090 |
+=========================
|
|
|
58b090 |
+DNF system-upgrade Plugin
|
|
|
58b090 |
+=========================
|
|
|
58b090 |
+
|
|
|
58b090 |
+-----------
|
|
|
58b090 |
+Description
|
|
|
58b090 |
+-----------
|
|
|
58b090 |
+
|
|
|
58b090 |
+DNF system-upgrades plugin provides three commands: ``system-upgrade``, ``offline-upgrade``, and
|
|
|
58b090 |
+``offline-distrosync``. Only ``system-upgrade`` command requires increase of distribution major
|
|
|
58b090 |
+version (``--releasever``) compared to installed version.
|
|
|
58b090 |
+
|
|
|
58b090 |
+``dnf system-upgrade`` can be used to upgrade a Fedora system to a new major
|
|
|
58b090 |
+release. It replaces fedup (the old Fedora Upgrade tool). Before you proceed ensure that your system
|
|
|
58b090 |
+is fully upgraded (``dnf --refresh upgrade``).
|
|
|
58b090 |
+
|
|
|
58b090 |
+The ``system-upgrade`` command also performes additional actions necessary for the upgrade of the
|
|
|
58b090 |
+system, for example an upgrade of groups and environments.
|
|
|
58b090 |
+
|
|
|
58b090 |
+--------
|
|
|
58b090 |
+Synopsis
|
|
|
58b090 |
+--------
|
|
|
58b090 |
+
|
|
|
58b090 |
+``dnf system-upgrade download --releasever VERSION [OPTIONS]``
|
|
|
58b090 |
+
|
|
|
58b090 |
+``dnf system-upgrade reboot``
|
|
|
58b090 |
+
|
|
|
58b090 |
+``dnf system-upgrade clean``
|
|
|
58b090 |
+
|
|
|
58b090 |
+``dnf system-upgrade log``
|
|
|
58b090 |
+
|
|
|
58b090 |
+``dnf system-upgrade log --number=<number>``
|
|
|
58b090 |
+
|
|
|
58b090 |
+``dnf offline-upgrade download [OPTIONS]``
|
|
|
58b090 |
+
|
|
|
58b090 |
+``dnf offline-upgrade reboot``
|
|
|
58b090 |
+
|
|
|
58b090 |
+``dnf offline-upgrade clean``
|
|
|
58b090 |
+
|
|
|
58b090 |
+``dnf offline-upgrade log``
|
|
|
58b090 |
+
|
|
|
58b090 |
+``dnf offline-upgrade log --number=<number>``
|
|
|
58b090 |
+
|
|
|
58b090 |
+``dnf offline-distrosync download [OPTIONS]``
|
|
|
58b090 |
+
|
|
|
58b090 |
+``dnf offline-distrosync reboot``
|
|
|
58b090 |
+
|
|
|
58b090 |
+``dnf offline-distrosync clean``
|
|
|
58b090 |
+
|
|
|
58b090 |
+``dnf offline-distrosync log``
|
|
|
58b090 |
+
|
|
|
58b090 |
+``dnf offline-distrosync log --number=<number>``
|
|
|
58b090 |
+
|
|
|
58b090 |
+-----------
|
|
|
58b090 |
+Subcommands
|
|
|
58b090 |
+-----------
|
|
|
58b090 |
+
|
|
|
58b090 |
+``download``
|
|
|
58b090 |
+ Downloads everything needed to upgrade to a new major release.
|
|
|
58b090 |
+
|
|
|
58b090 |
+``reboot``
|
|
|
58b090 |
+ Prepares the system to perform the upgrade, and reboots to start the upgrade.
|
|
|
58b090 |
+ This can only be used after the ``download`` command completes successfully.
|
|
|
58b090 |
+
|
|
|
58b090 |
+``clean``
|
|
|
58b090 |
+ Remove previously-downloaded data. This happens automatically at the end of
|
|
|
58b090 |
+ a successful upgrade.
|
|
|
58b090 |
+
|
|
|
58b090 |
+``log``
|
|
|
58b090 |
+ Used to see a list of boots during which an upgrade was attempted, or show
|
|
|
58b090 |
+ the logs from an upgrade attempt. The logs for one of the boots can be shown
|
|
|
58b090 |
+ by specifying one of the numbers in the first column. Negative numbers can
|
|
|
58b090 |
+ be used to number the boots from last to first. For example, ``log --number=-1`` can
|
|
|
58b090 |
+ be used to see the logs for the last upgrade attempt.
|
|
|
58b090 |
+
|
|
|
58b090 |
+-------
|
|
|
58b090 |
+Options
|
|
|
58b090 |
+-------
|
|
|
58b090 |
+
|
|
|
58b090 |
+``--releasever=VERSION``
|
|
|
58b090 |
+ REQUIRED. The version to upgrade to. Sets ``$releasever`` in all enabled
|
|
|
58b090 |
+ repos. Usually a number, or ``rawhide``.
|
|
|
58b090 |
+
|
|
|
58b090 |
+``--downloaddir=<path>``
|
|
|
58b090 |
+ Redirect download of packages to provided ``<path>``. By default, packages
|
|
|
58b090 |
+ are downloaded into (per repository created) subdirectories of
|
|
|
58b090 |
+ /var/lib/dnf/system-upgrade.
|
|
|
58b090 |
+
|
|
|
58b090 |
+``--distro-sync``
|
|
|
58b090 |
+ Behave like ``dnf distro-sync``: always install packages from the new
|
|
|
58b090 |
+ release, even if they are older than the currently-installed version. This
|
|
|
58b090 |
+ is the default behavior.
|
|
|
58b090 |
+
|
|
|
58b090 |
+``--no-downgrade``
|
|
|
58b090 |
+ Behave like ``dnf update``: do not install packages from the new release
|
|
|
58b090 |
+ if they are older than what is currently installed. This is the opposite of
|
|
|
58b090 |
+ ``--distro-sync``. If both are specified, the last option will be used. The option cannot be
|
|
|
58b090 |
+ used with the ``offline-distrosync`` command.
|
|
|
58b090 |
+
|
|
|
58b090 |
+``--number``
|
|
|
58b090 |
+ Applied with ``log`` subcommand will show the log specified by the number.
|
|
|
58b090 |
+
|
|
|
58b090 |
+-----
|
|
|
58b090 |
+Notes
|
|
|
58b090 |
+-----
|
|
|
58b090 |
+
|
|
|
58b090 |
+``dnf system-upgrade reboot`` does not create a "System Upgrade" boot item. The
|
|
|
58b090 |
+upgrade will start regardless of which boot item is chosen.
|
|
|
58b090 |
+
|
|
|
58b090 |
+The ``DNF_SYSTEM_UPGRADE_NO_REBOOT`` environment variable can be set to a
|
|
|
58b090 |
+non-empty value to disable the actual reboot performed by ``system-upgrade``
|
|
|
58b090 |
+(e.g. for testing purposes).
|
|
|
58b090 |
+
|
|
|
58b090 |
+Since this is a DNF plugin, options accepted by ``dnf`` are also valid here,
|
|
|
58b090 |
+such as ``--allowerasing``.
|
|
|
58b090 |
+See :manpage:`dnf(8)` for more information.
|
|
|
58b090 |
+
|
|
|
58b090 |
+The ``fedup`` command is not provided, not even as an alias for
|
|
|
58b090 |
+``dnf system-upgrade``.
|
|
|
58b090 |
+
|
|
|
58b090 |
+----
|
|
|
58b090 |
+Bugs
|
|
|
58b090 |
+----
|
|
|
58b090 |
+
|
|
|
58b090 |
+Upgrading from install media (e.g. a DVD or .iso file) currently requires the
|
|
|
58b090 |
+user to manually set up a DNF repo and fstab entry for the media.
|
|
|
58b090 |
+
|
|
|
58b090 |
+--------
|
|
|
58b090 |
+Examples
|
|
|
58b090 |
+--------
|
|
|
58b090 |
+
|
|
|
58b090 |
+Typical upgrade usage
|
|
|
58b090 |
+---------------------
|
|
|
58b090 |
+
|
|
|
58b090 |
+``dnf --refresh upgrade``
|
|
|
58b090 |
+
|
|
|
58b090 |
+``dnf system-upgrade download --releasever 26``
|
|
|
58b090 |
+
|
|
|
58b090 |
+``dnf system-upgrade reboot``
|
|
|
58b090 |
+
|
|
|
58b090 |
+Show logs from last upgrade attempt
|
|
|
58b090 |
+-----------------------------------
|
|
|
58b090 |
+
|
|
|
58b090 |
+``dnf system-upgrade log --number=-1``
|
|
|
58b090 |
+
|
|
|
58b090 |
+--------------
|
|
|
58b090 |
+Reporting Bugs
|
|
|
58b090 |
+--------------
|
|
|
58b090 |
+
|
|
|
58b090 |
+Bugs should be filed here:
|
|
|
58b090 |
+
|
|
|
58b090 |
+ https://bugzilla.redhat.com/
|
|
|
58b090 |
+
|
|
|
58b090 |
+For more info on filing bugs, see the Fedora Project wiki:
|
|
|
58b090 |
+
|
|
|
58b090 |
+ https://fedoraproject.org/wiki/How_to_file_a_bug_report
|
|
|
58b090 |
+
|
|
|
58b090 |
+ https://fedoraproject.org/wiki/Bugs_and_feature_requests
|
|
|
58b090 |
+
|
|
|
58b090 |
+Please include ``/var/log/dnf.log`` and the output of
|
|
|
58b090 |
+``dnf system-upgrade log --number=-1`` (if applicable) in your bug reports.
|
|
|
58b090 |
+
|
|
|
58b090 |
+Problems with dependency solving during download are best reported to the
|
|
|
58b090 |
+maintainers of the package(s) with the dependency problems.
|
|
|
58b090 |
+
|
|
|
58b090 |
+Similarly, problems encountered on your system after the upgrade completes
|
|
|
58b090 |
+should be reported to the maintainers of the affected components. In other
|
|
|
58b090 |
+words: if (for example) KDE stops working, it's best if you report that to
|
|
|
58b090 |
+the KDE maintainers.
|
|
|
58b090 |
+
|
|
|
58b090 |
+--------
|
|
|
58b090 |
+See Also
|
|
|
58b090 |
+--------
|
|
|
58b090 |
+
|
|
|
58b090 |
+:manpage:`dnf(8)`,
|
|
|
58b090 |
+:manpage:`dnf.conf(5)`,
|
|
|
58b090 |
+:manpage:`journalctl(1)`.
|
|
|
58b090 |
+
|
|
|
58b090 |
+Project homepage
|
|
|
58b090 |
+----------------
|
|
|
58b090 |
+
|
|
|
58b090 |
+https://github.com/rpm-software-management/dnf-plugins-core
|
|
|
58b090 |
+
|
|
|
58b090 |
+-------
|
|
|
58b090 |
+Authors
|
|
|
58b090 |
+-------
|
|
|
58b090 |
+
|
|
|
58b090 |
+Will Woods <wwoods@redhat.com>
|
|
|
58b090 |
+
|
|
|
58b090 |
+Štěpán Smetana <ssmetana@redhat.com>
|
|
|
58b090 |
diff --git a/etc/CMakeLists.txt b/etc/CMakeLists.txt
|
|
|
58b090 |
index 2e9cccd..a892f8a 100644
|
|
|
58b090 |
--- a/etc/CMakeLists.txt
|
|
|
58b090 |
+++ b/etc/CMakeLists.txt
|
|
|
58b090 |
@@ -1 +1,2 @@
|
|
|
58b090 |
ADD_SUBDIRECTORY (dnf)
|
|
|
58b090 |
+ADD_SUBDIRECTORY (systemd)
|
|
|
58b090 |
diff --git a/etc/systemd/CMakeLists.txt b/etc/systemd/CMakeLists.txt
|
|
|
58b090 |
new file mode 100644
|
|
|
58b090 |
index 0000000..8a29403
|
|
|
58b090 |
--- /dev/null
|
|
|
58b090 |
+++ b/etc/systemd/CMakeLists.txt
|
|
|
58b090 |
@@ -0,0 +1 @@
|
|
|
58b090 |
+INSTALL (FILES "dnf-system-upgrade.service" "dnf-system-upgrade-cleanup.service" DESTINATION ${SYSTEMD_DIR})
|
|
|
58b090 |
diff --git a/etc/systemd/dnf-system-upgrade-cleanup.service b/etc/systemd/dnf-system-upgrade-cleanup.service
|
|
|
58b090 |
new file mode 100644
|
|
|
58b090 |
index 0000000..49f771c
|
|
|
58b090 |
--- /dev/null
|
|
|
58b090 |
+++ b/etc/systemd/dnf-system-upgrade-cleanup.service
|
|
|
58b090 |
@@ -0,0 +1,11 @@
|
|
|
58b090 |
+[Unit]
|
|
|
58b090 |
+Description=System Upgrade using DNF failed
|
|
|
58b090 |
+DefaultDependencies=no
|
|
|
58b090 |
+
|
|
|
58b090 |
+[Service]
|
|
|
58b090 |
+Type=oneshot
|
|
|
58b090 |
+# Remove the symlink if it's still there, to protect against reboot loops.
|
|
|
58b090 |
+ExecStart=/usr/bin/rm -fv /system-update
|
|
|
58b090 |
+# If anything goes wrong, reboot back to the normal system.
|
|
|
58b090 |
+ExecStart=/usr/bin/systemctl --no-block reboot
|
|
|
58b090 |
+
|
|
|
58b090 |
diff --git a/etc/systemd/dnf-system-upgrade.service b/etc/systemd/dnf-system-upgrade.service
|
|
|
58b090 |
new file mode 100644
|
|
|
58b090 |
index 0000000..2d23cfe
|
|
|
58b090 |
--- /dev/null
|
|
|
58b090 |
+++ b/etc/systemd/dnf-system-upgrade.service
|
|
|
58b090 |
@@ -0,0 +1,20 @@
|
|
|
58b090 |
+[Unit]
|
|
|
58b090 |
+Description=System Upgrade using DNF
|
|
|
58b090 |
+ConditionPathExists=/system-update
|
|
|
58b090 |
+Documentation=http://www.freedesktop.org/wiki/Software/systemd/SystemUpdates
|
|
|
58b090 |
+
|
|
|
58b090 |
+DefaultDependencies=no
|
|
|
58b090 |
+Requires=sysinit.target
|
|
|
58b090 |
+After=sysinit.target systemd-journald.socket system-update-pre.target
|
|
|
58b090 |
+Before=shutdown.target system-update.target
|
|
|
58b090 |
+OnFailure=dnf-system-upgrade-cleanup.service
|
|
|
58b090 |
+
|
|
|
58b090 |
+[Service]
|
|
|
58b090 |
+# We are done when the script exits, not before
|
|
|
58b090 |
+Type=oneshot
|
|
|
58b090 |
+# Upgrade output goes to journal and on-screen.
|
|
|
58b090 |
+StandardOutput=journal+console
|
|
|
58b090 |
+ExecStart=/usr/bin/dnf system-upgrade upgrade
|
|
|
58b090 |
+
|
|
|
58b090 |
+[Install]
|
|
|
58b090 |
+WantedBy=system-update.target
|
|
|
58b090 |
diff --git a/plugins/CMakeLists.txt b/plugins/CMakeLists.txt
|
|
|
58b090 |
index 59f148f..d004e5e 100644
|
|
|
58b090 |
--- a/plugins/CMakeLists.txt
|
|
|
58b090 |
+++ b/plugins/CMakeLists.txt
|
|
|
58b090 |
@@ -22,6 +22,7 @@ INSTALL (FILES repograph.py DESTINATION ${PYTHON_INSTALL_DIR}/dnf-plugins)
|
|
|
58b090 |
INSTALL (FILES repomanage.py DESTINATION ${PYTHON_INSTALL_DIR}/dnf-plugins)
|
|
|
58b090 |
INSTALL (FILES reposync.py DESTINATION ${PYTHON_INSTALL_DIR}/dnf-plugins)
|
|
|
58b090 |
INSTALL (FILES show_leaves.py DESTINATION ${PYTHON_INSTALL_DIR}/dnf-plugins)
|
|
|
58b090 |
+INSTALL (FILES system_upgrade.py DESTINATION ${PYTHON_INSTALL_DIR}/dnf-plugins)
|
|
|
58b090 |
INSTALL (FILES modulesync.py DESTINATION ${PYTHON_INSTALL_DIR}/dnf-plugins)
|
|
|
58b090 |
INSTALL (FILES versionlock.py DESTINATION ${PYTHON_INSTALL_DIR}/dnf-plugins)
|
|
|
58b090 |
|
|
|
58b090 |
diff --git a/plugins/system_upgrade.py b/plugins/system_upgrade.py
|
|
|
58b090 |
new file mode 100644
|
|
|
58b090 |
index 0000000..fee6762
|
|
|
58b090 |
--- /dev/null
|
|
|
58b090 |
+++ b/plugins/system_upgrade.py
|
|
|
58b090 |
@@ -0,0 +1,699 @@
|
|
|
58b090 |
+# -*- coding: utf-8 -*-
|
|
|
58b090 |
+#
|
|
|
58b090 |
+# Copyright (c) 2015-2020 Red Hat, Inc.
|
|
|
58b090 |
+#
|
|
|
58b090 |
+# This program is free software; you can redistribute it and/or modify
|
|
|
58b090 |
+# it under the terms of the GNU General Public License as published by
|
|
|
58b090 |
+# the Free Software Foundation; either version 2 of the License, or
|
|
|
58b090 |
+# (at your option) any later version.
|
|
|
58b090 |
+#
|
|
|
58b090 |
+# This program is distributed in the hope that it will be useful,
|
|
|
58b090 |
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
58b090 |
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
58b090 |
+# GNU General Public License for more details.
|
|
|
58b090 |
+#
|
|
|
58b090 |
+# You should have received a copy of the GNU General Public License along
|
|
|
58b090 |
+# with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
58b090 |
+#
|
|
|
58b090 |
+# Author(s): Will Woods <wwoods@redhat.com>
|
|
|
58b090 |
+
|
|
|
58b090 |
+"""system_upgrade.py - DNF plugin to handle major-version system upgrades."""
|
|
|
58b090 |
+
|
|
|
58b090 |
+from subprocess import call, Popen, check_output, CalledProcessError
|
|
|
58b090 |
+import json
|
|
|
58b090 |
+import os
|
|
|
58b090 |
+import os.path
|
|
|
58b090 |
+import re
|
|
|
58b090 |
+import sys
|
|
|
58b090 |
+import uuid
|
|
|
58b090 |
+
|
|
|
58b090 |
+from systemd import journal
|
|
|
58b090 |
+
|
|
|
58b090 |
+from dnfpluginscore import _, logger
|
|
|
58b090 |
+
|
|
|
58b090 |
+import dnf
|
|
|
58b090 |
+import dnf.cli
|
|
|
58b090 |
+from dnf.cli import CliError
|
|
|
58b090 |
+from dnf.i18n import ucd
|
|
|
58b090 |
+import dnf.transaction
|
|
|
58b090 |
+from dnf.transaction_sr import serialize_transaction, TransactionReplay
|
|
|
58b090 |
+
|
|
|
58b090 |
+import libdnf.conf
|
|
|
58b090 |
+
|
|
|
58b090 |
+
|
|
|
58b090 |
+# Translators: This string is only used in unit tests.
|
|
|
58b090 |
+_("the color of the sky")
|
|
|
58b090 |
+
|
|
|
58b090 |
+DOWNLOAD_FINISHED_ID = uuid.UUID('9348174c5cc74001a71ef26bd79d302e')
|
|
|
58b090 |
+REBOOT_REQUESTED_ID = uuid.UUID('fef1cc509d5047268b83a3a553f54b43')
|
|
|
58b090 |
+UPGRADE_STARTED_ID = uuid.UUID('3e0a5636d16b4ca4bbe5321d06c6aa62')
|
|
|
58b090 |
+UPGRADE_FINISHED_ID = uuid.UUID('8cec00a1566f4d3594f116450395f06c')
|
|
|
58b090 |
+
|
|
|
58b090 |
+ID_TO_IDENTIFY_BOOTS = UPGRADE_STARTED_ID
|
|
|
58b090 |
+
|
|
|
58b090 |
+PLYMOUTH = '/usr/bin/plymouth'
|
|
|
58b090 |
+
|
|
|
58b090 |
+RELEASEVER_MSG = _(
|
|
|
58b090 |
+ "Need a --releasever greater than the current system version.")
|
|
|
58b090 |
+DOWNLOAD_FINISHED_MSG = _( # Translators: do not change "reboot" here
|
|
|
58b090 |
+ "Download complete! Use 'dnf {command} reboot' to start the upgrade.\n"
|
|
|
58b090 |
+ "To remove cached metadata and transaction use 'dnf {command} clean'")
|
|
|
58b090 |
+CANT_RESET_RELEASEVER = _(
|
|
|
58b090 |
+ "Sorry, you need to use 'download --releasever' instead of '--network'")
|
|
|
58b090 |
+
|
|
|
58b090 |
+STATE_VERSION = 2
|
|
|
58b090 |
+
|
|
|
58b090 |
+# --- Miscellaneous helper functions ------------------------------------------
|
|
|
58b090 |
+
|
|
|
58b090 |
+
|
|
|
58b090 |
+def reboot():
|
|
|
58b090 |
+ if os.getenv("DNF_SYSTEM_UPGRADE_NO_REBOOT", default=False):
|
|
|
58b090 |
+ logger.info(_("Reboot turned off, not rebooting."))
|
|
|
58b090 |
+ else:
|
|
|
58b090 |
+ Popen(["systemctl", "reboot"])
|
|
|
58b090 |
+
|
|
|
58b090 |
+
|
|
|
58b090 |
+def get_url_from_os_release():
|
|
|
58b090 |
+ key = "UPGRADE_GUIDE_URL="
|
|
|
58b090 |
+ for path in ["/etc/os-release", "/usr/lib/os-release"]:
|
|
|
58b090 |
+ try:
|
|
|
58b090 |
+ with open(path) as release_file:
|
|
|
58b090 |
+ for line in release_file:
|
|
|
58b090 |
+ line = line.strip()
|
|
|
58b090 |
+ if line.startswith(key):
|
|
|
58b090 |
+ return line[len(key):].strip('"')
|
|
|
58b090 |
+ except IOError:
|
|
|
58b090 |
+ continue
|
|
|
58b090 |
+ return None
|
|
|
58b090 |
+
|
|
|
58b090 |
+
|
|
|
58b090 |
+# DNF-FIXME: dnf.util.clear_dir() doesn't delete regular files :/
|
|
|
58b090 |
+def clear_dir(path, ignore=[]):
|
|
|
58b090 |
+ if not os.path.isdir(path):
|
|
|
58b090 |
+ return
|
|
|
58b090 |
+
|
|
|
58b090 |
+ for entry in os.listdir(path):
|
|
|
58b090 |
+ fullpath = os.path.join(path, entry)
|
|
|
58b090 |
+ if fullpath in ignore:
|
|
|
58b090 |
+ continue
|
|
|
58b090 |
+ try:
|
|
|
58b090 |
+ if os.path.isdir(fullpath):
|
|
|
58b090 |
+ dnf.util.rm_rf(fullpath)
|
|
|
58b090 |
+ else:
|
|
|
58b090 |
+ os.unlink(fullpath)
|
|
|
58b090 |
+ except OSError:
|
|
|
58b090 |
+ pass
|
|
|
58b090 |
+
|
|
|
58b090 |
+
|
|
|
58b090 |
+def check_release_ver(conf, target=None):
|
|
|
58b090 |
+ if dnf.rpm.detect_releasever(conf.installroot) == conf.releasever:
|
|
|
58b090 |
+ raise CliError(RELEASEVER_MSG)
|
|
|
58b090 |
+ if target and target != conf.releasever:
|
|
|
58b090 |
+ # it's too late to set releasever here, so this can't work.
|
|
|
58b090 |
+ # (see https://bugzilla.redhat.com/show_bug.cgi?id=1212341)
|
|
|
58b090 |
+ raise CliError(CANT_RESET_RELEASEVER)
|
|
|
58b090 |
+
|
|
|
58b090 |
+
|
|
|
58b090 |
+def disable_blanking():
|
|
|
58b090 |
+ try:
|
|
|
58b090 |
+ tty = open('/dev/tty0', 'wb')
|
|
|
58b090 |
+ tty.write(b'\33[9;0]')
|
|
|
58b090 |
+ except Exception as e:
|
|
|
58b090 |
+ print(_("Screen blanking can't be disabled: %s") % e)
|
|
|
58b090 |
+
|
|
|
58b090 |
+# --- State object - for tracking upgrade state between runs ------------------
|
|
|
58b090 |
+
|
|
|
58b090 |
+
|
|
|
58b090 |
+# DNF-INTEGRATION-NOTE: basically the same thing as dnf.persistor.JSONDB
|
|
|
58b090 |
+class State(object):
|
|
|
58b090 |
+ def __init__(self, statefile):
|
|
|
58b090 |
+ self.statefile = statefile
|
|
|
58b090 |
+ self._data = {}
|
|
|
58b090 |
+ self._read()
|
|
|
58b090 |
+
|
|
|
58b090 |
+ def _read(self):
|
|
|
58b090 |
+ try:
|
|
|
58b090 |
+ with open(self.statefile) as fp:
|
|
|
58b090 |
+ self._data = json.load(fp)
|
|
|
58b090 |
+ except IOError:
|
|
|
58b090 |
+ self._data = {}
|
|
|
58b090 |
+ except ValueError:
|
|
|
58b090 |
+ self._data = {}
|
|
|
58b090 |
+ logger.warning(_("Failed loading state file: %s, continuing with "
|
|
|
58b090 |
+ "empty state."), self.statefile)
|
|
|
58b090 |
+
|
|
|
58b090 |
+ def write(self):
|
|
|
58b090 |
+ dnf.util.ensure_dir(os.path.dirname(self.statefile))
|
|
|
58b090 |
+ with open(self.statefile, 'w') as outf:
|
|
|
58b090 |
+ json.dump(self._data, outf, indent=4, sort_keys=True)
|
|
|
58b090 |
+
|
|
|
58b090 |
+ def clear(self):
|
|
|
58b090 |
+ if os.path.exists(self.statefile):
|
|
|
58b090 |
+ os.unlink(self.statefile)
|
|
|
58b090 |
+ self._read()
|
|
|
58b090 |
+
|
|
|
58b090 |
+ def __enter__(self):
|
|
|
58b090 |
+ return self
|
|
|
58b090 |
+
|
|
|
58b090 |
+ def __exit__(self, exc_type, exc_value, traceback):
|
|
|
58b090 |
+ if exc_type is None:
|
|
|
58b090 |
+ self.write()
|
|
|
58b090 |
+
|
|
|
58b090 |
+ # helper function for creating properties. pylint: disable=protected-access
|
|
|
58b090 |
+ def _prop(option): # pylint: disable=no-self-argument
|
|
|
58b090 |
+ def setprop(self, value):
|
|
|
58b090 |
+ self._data[option] = value
|
|
|
58b090 |
+
|
|
|
58b090 |
+ def getprop(self):
|
|
|
58b090 |
+ return self._data.get(option)
|
|
|
58b090 |
+ return property(getprop, setprop)
|
|
|
58b090 |
+
|
|
|
58b090 |
+ # !!! Increase STATE_VERSION for any changes in data structure like a new property or a new
|
|
|
58b090 |
+ # data structure !!!
|
|
|
58b090 |
+ state_version = _prop("state_version")
|
|
|
58b090 |
+ download_status = _prop("download_status")
|
|
|
58b090 |
+ destdir = _prop("destdir")
|
|
|
58b090 |
+ target_releasever = _prop("target_releasever")
|
|
|
58b090 |
+ system_releasever = _prop("system_releasever")
|
|
|
58b090 |
+ gpgcheck = _prop("gpgcheck")
|
|
|
58b090 |
+ # list of repos with gpgcheck=True
|
|
|
58b090 |
+ gpgcheck_repos = _prop("gpgcheck_repos")
|
|
|
58b090 |
+ # list of repos with repo_gpgcheck=True
|
|
|
58b090 |
+ repo_gpgcheck_repos = _prop("repo_gpgcheck_repos")
|
|
|
58b090 |
+ upgrade_status = _prop("upgrade_status")
|
|
|
58b090 |
+ upgrade_command = _prop("upgrade_command")
|
|
|
58b090 |
+ distro_sync = _prop("distro_sync")
|
|
|
58b090 |
+ enable_disable_repos = _prop("enable_disable_repos")
|
|
|
58b090 |
+ module_platform_id = _prop("module_platform_id")
|
|
|
58b090 |
+
|
|
|
58b090 |
+# --- Plymouth output helpers -------------------------------------------------
|
|
|
58b090 |
+
|
|
|
58b090 |
+
|
|
|
58b090 |
+class PlymouthOutput(object):
|
|
|
58b090 |
+ """A plymouth output helper class.
|
|
|
58b090 |
+
|
|
|
58b090 |
+ Filters duplicate calls, and stops calling the plymouth binary if we
|
|
|
58b090 |
+ fail to contact it.
|
|
|
58b090 |
+ """
|
|
|
58b090 |
+
|
|
|
58b090 |
+ def __init__(self):
|
|
|
58b090 |
+ self.alive = True
|
|
|
58b090 |
+ self._last_args = dict()
|
|
|
58b090 |
+ self._last_msg = None
|
|
|
58b090 |
+
|
|
|
58b090 |
+ def _plymouth(self, cmd, *args):
|
|
|
58b090 |
+ dupe_cmd = (args == self._last_args.get(cmd))
|
|
|
58b090 |
+ if (self.alive and not dupe_cmd) or cmd == '--ping':
|
|
|
58b090 |
+ try:
|
|
|
58b090 |
+ self.alive = (call((PLYMOUTH, cmd) + args) == 0)
|
|
|
58b090 |
+ except OSError:
|
|
|
58b090 |
+ self.alive = False
|
|
|
58b090 |
+ self._last_args[cmd] = args
|
|
|
58b090 |
+ return self.alive
|
|
|
58b090 |
+
|
|
|
58b090 |
+ def ping(self):
|
|
|
58b090 |
+ return self._plymouth("--ping")
|
|
|
58b090 |
+
|
|
|
58b090 |
+ def message(self, msg):
|
|
|
58b090 |
+ if self._last_msg and self._last_msg != msg:
|
|
|
58b090 |
+ self._plymouth("hide-message", "--text", self._last_msg)
|
|
|
58b090 |
+ self._last_msg = msg
|
|
|
58b090 |
+ return self._plymouth("display-message", "--text", msg)
|
|
|
58b090 |
+
|
|
|
58b090 |
+ def set_mode(self):
|
|
|
58b090 |
+ mode = 'updates'
|
|
|
58b090 |
+ try:
|
|
|
58b090 |
+ s = check_output([PLYMOUTH, '--help'])
|
|
|
58b090 |
+ if re.search('--system-upgrade', ucd(s)):
|
|
|
58b090 |
+ mode = 'system-upgrade'
|
|
|
58b090 |
+ except (CalledProcessError, OSError):
|
|
|
58b090 |
+ pass
|
|
|
58b090 |
+ return self._plymouth("change-mode", "--" + mode)
|
|
|
58b090 |
+
|
|
|
58b090 |
+ def progress(self, percent):
|
|
|
58b090 |
+ return self._plymouth("system-update", "--progress", str(percent))
|
|
|
58b090 |
+
|
|
|
58b090 |
+
|
|
|
58b090 |
+# A single PlymouthOutput instance for us to use within this module
|
|
|
58b090 |
+Plymouth = PlymouthOutput()
|
|
|
58b090 |
+
|
|
|
58b090 |
+
|
|
|
58b090 |
+# A TransactionProgress class that updates plymouth for us.
|
|
|
58b090 |
+class PlymouthTransactionProgress(dnf.callback.TransactionProgress):
|
|
|
58b090 |
+
|
|
|
58b090 |
+ # pylint: disable=too-many-arguments
|
|
|
58b090 |
+ def progress(self, package, action, ti_done, ti_total, ts_done, ts_total):
|
|
|
58b090 |
+ self._update_plymouth(package, action, ts_done, ts_total)
|
|
|
58b090 |
+
|
|
|
58b090 |
+ def _update_plymouth(self, package, action, current, total):
|
|
|
58b090 |
+ # Prevents quick jumps of progressbar when pretrans scriptlets
|
|
|
58b090 |
+ # and TRANS_PREPARATION are reported as 1/1
|
|
|
58b090 |
+ if total == 1:
|
|
|
58b090 |
+ return
|
|
|
58b090 |
+ # Verification goes through all the packages again,
|
|
|
58b090 |
+ # which resets the "current" param value, this prevents
|
|
|
58b090 |
+ # resetting of the progress bar as well. (Rhbug:1809096)
|
|
|
58b090 |
+ if action != dnf.callback.PKG_VERIFY:
|
|
|
58b090 |
+ Plymouth.progress(int(90.0 * current / total))
|
|
|
58b090 |
+ else:
|
|
|
58b090 |
+ Plymouth.progress(90 + int(10.0 * current / total))
|
|
|
58b090 |
+
|
|
|
58b090 |
+ Plymouth.message(self._fmt_event(package, action, current, total))
|
|
|
58b090 |
+
|
|
|
58b090 |
+ def _fmt_event(self, package, action, current, total):
|
|
|
58b090 |
+ action = dnf.transaction.ACTIONS.get(action, action)
|
|
|
58b090 |
+ return "[%d/%d] %s %s..." % (current, total, action, package)
|
|
|
58b090 |
+
|
|
|
58b090 |
+# --- journal helpers -------------------------------------------------
|
|
|
58b090 |
+
|
|
|
58b090 |
+
|
|
|
58b090 |
+def find_boots(message_id):
|
|
|
58b090 |
+ """Find all boots with this message id.
|
|
|
58b090 |
+
|
|
|
58b090 |
+ Returns the entries of all found boots.
|
|
|
58b090 |
+ """
|
|
|
58b090 |
+ j = journal.Reader()
|
|
|
58b090 |
+ j.add_match(MESSAGE_ID=message_id.hex, # identify the message
|
|
|
58b090 |
+ _UID=0) # prevent spoofing of logs
|
|
|
58b090 |
+
|
|
|
58b090 |
+ oldboot = None
|
|
|
58b090 |
+ for entry in j:
|
|
|
58b090 |
+ boot = entry['_BOOT_ID']
|
|
|
58b090 |
+ if boot == oldboot:
|
|
|
58b090 |
+ continue
|
|
|
58b090 |
+ oldboot = boot
|
|
|
58b090 |
+ yield entry
|
|
|
58b090 |
+
|
|
|
58b090 |
+
|
|
|
58b090 |
+def list_logs():
|
|
|
58b090 |
+ print(_('The following boots appear to contain upgrade logs:'))
|
|
|
58b090 |
+ n = -1
|
|
|
58b090 |
+ for n, entry in enumerate(find_boots(ID_TO_IDENTIFY_BOOTS)):
|
|
|
58b090 |
+ print('{} / {.hex}: {:%Y-%m-%d %H:%M:%S} {}→{}'.format(
|
|
|
58b090 |
+ n + 1,
|
|
|
58b090 |
+ entry['_BOOT_ID'],
|
|
|
58b090 |
+ entry['__REALTIME_TIMESTAMP'],
|
|
|
58b090 |
+ entry.get('SYSTEM_RELEASEVER', '??'),
|
|
|
58b090 |
+ entry.get('TARGET_RELEASEVER', '??')))
|
|
|
58b090 |
+ if n == -1:
|
|
|
58b090 |
+ print(_('-- no logs were found --'))
|
|
|
58b090 |
+
|
|
|
58b090 |
+
|
|
|
58b090 |
+def pick_boot(message_id, n):
|
|
|
58b090 |
+ boots = list(find_boots(message_id))
|
|
|
58b090 |
+ # Positive indices index all found boots starting with 1 and going forward,
|
|
|
58b090 |
+ # zero is the current boot, and -1, -2, -3 are previous going backwards.
|
|
|
58b090 |
+ # This is the same as journalctl.
|
|
|
58b090 |
+ try:
|
|
|
58b090 |
+ if n == 0:
|
|
|
58b090 |
+ raise IndexError
|
|
|
58b090 |
+ if n > 0:
|
|
|
58b090 |
+ n -= 1
|
|
|
58b090 |
+ return boots[n]['_BOOT_ID']
|
|
|
58b090 |
+ except IndexError:
|
|
|
58b090 |
+ raise CliError(_("Cannot find logs with this index."))
|
|
|
58b090 |
+
|
|
|
58b090 |
+
|
|
|
58b090 |
+def show_log(n):
|
|
|
58b090 |
+ boot_id = pick_boot(ID_TO_IDENTIFY_BOOTS, n)
|
|
|
58b090 |
+ process = Popen(['journalctl', '--boot', boot_id.hex])
|
|
|
58b090 |
+ process.wait()
|
|
|
58b090 |
+ rc = process.returncode
|
|
|
58b090 |
+ if rc == 1:
|
|
|
58b090 |
+ raise dnf.exceptions.Error(_("Unable to match systemd journal entry"))
|
|
|
58b090 |
+
|
|
|
58b090 |
+
|
|
|
58b090 |
+CMDS = ['download', 'clean', 'reboot', 'upgrade', 'log']
|
|
|
58b090 |
+
|
|
|
58b090 |
+# --- The actual Plugin and Command objects! ----------------------------------
|
|
|
58b090 |
+
|
|
|
58b090 |
+
|
|
|
58b090 |
+class SystemUpgradePlugin(dnf.Plugin):
|
|
|
58b090 |
+ name = 'system-upgrade'
|
|
|
58b090 |
+
|
|
|
58b090 |
+ def __init__(self, base, cli):
|
|
|
58b090 |
+ super(SystemUpgradePlugin, self).__init__(base, cli)
|
|
|
58b090 |
+ if cli:
|
|
|
58b090 |
+ cli.register_command(SystemUpgradeCommand)
|
|
|
58b090 |
+ cli.register_command(OfflineUpgradeCommand)
|
|
|
58b090 |
+ cli.register_command(OfflineDistrosyncCommand)
|
|
|
58b090 |
+
|
|
|
58b090 |
+
|
|
|
58b090 |
+class SystemUpgradeCommand(dnf.cli.Command):
|
|
|
58b090 |
+ aliases = ('system-upgrade', 'fedup',)
|
|
|
58b090 |
+ summary = _("Prepare system for upgrade to a new release")
|
|
|
58b090 |
+
|
|
|
58b090 |
+ DATADIR = 'var/lib/dnf/system-upgrade'
|
|
|
58b090 |
+
|
|
|
58b090 |
+ def __init__(self, cli):
|
|
|
58b090 |
+ super(SystemUpgradeCommand, self).__init__(cli)
|
|
|
58b090 |
+ self.datadir = os.path.join(cli.base.conf.installroot, self.DATADIR)
|
|
|
58b090 |
+ self.transaction_file = os.path.join(self.datadir, 'system-upgrade-transaction.json')
|
|
|
58b090 |
+ self.magic_symlink = os.path.join(cli.base.conf.installroot, 'system-update')
|
|
|
58b090 |
+
|
|
|
58b090 |
+ self.state = State(os.path.join(self.datadir, 'system-upgrade-state.json'))
|
|
|
58b090 |
+
|
|
|
58b090 |
+ @staticmethod
|
|
|
58b090 |
+ def set_argparser(parser):
|
|
|
58b090 |
+ parser.add_argument("--no-downgrade", dest='distro_sync',
|
|
|
58b090 |
+ action='store_false',
|
|
|
58b090 |
+ help=_("keep installed packages if the new "
|
|
|
58b090 |
+ "release's version is older"))
|
|
|
58b090 |
+ parser.add_argument('tid', nargs=1, choices=CMDS,
|
|
|
58b090 |
+ metavar="[%s]" % "|".join(CMDS))
|
|
|
58b090 |
+ parser.add_argument('--number', type=int, help=_('which logs to show'))
|
|
|
58b090 |
+
|
|
|
58b090 |
+ def log_status(self, message, message_id):
|
|
|
58b090 |
+ """Log directly to the journal."""
|
|
|
58b090 |
+ journal.send(message,
|
|
|
58b090 |
+ MESSAGE_ID=message_id,
|
|
|
58b090 |
+ PRIORITY=journal.LOG_NOTICE,
|
|
|
58b090 |
+ SYSTEM_RELEASEVER=self.state.system_releasever,
|
|
|
58b090 |
+ TARGET_RELEASEVER=self.state.target_releasever,
|
|
|
58b090 |
+ DNF_VERSION=dnf.const.VERSION)
|
|
|
58b090 |
+
|
|
|
58b090 |
+ def pre_configure(self):
|
|
|
58b090 |
+ self._call_sub("check")
|
|
|
58b090 |
+ self._call_sub("pre_configure")
|
|
|
58b090 |
+
|
|
|
58b090 |
+ def configure(self):
|
|
|
58b090 |
+ self._call_sub("configure")
|
|
|
58b090 |
+
|
|
|
58b090 |
+ def run(self):
|
|
|
58b090 |
+ self._call_sub("run")
|
|
|
58b090 |
+
|
|
|
58b090 |
+ def run_transaction(self):
|
|
|
58b090 |
+ self._call_sub("transaction")
|
|
|
58b090 |
+
|
|
|
58b090 |
+ def run_resolved(self):
|
|
|
58b090 |
+ self._call_sub("resolved")
|
|
|
58b090 |
+
|
|
|
58b090 |
+ def _call_sub(self, name):
|
|
|
58b090 |
+ subfunc = getattr(self, name + '_' + self.opts.tid[0], None)
|
|
|
58b090 |
+ if callable(subfunc):
|
|
|
58b090 |
+ subfunc()
|
|
|
58b090 |
+
|
|
|
58b090 |
+ def _check_state_version(self, command):
|
|
|
58b090 |
+ if self.state.state_version != STATE_VERSION:
|
|
|
58b090 |
+ msg = _("Incompatible version of data. Rerun 'dnf {command} download [OPTIONS]'"
|
|
|
58b090 |
+ "").format(command=command)
|
|
|
58b090 |
+ raise CliError(msg)
|
|
|
58b090 |
+
|
|
|
58b090 |
+ def _set_cachedir(self):
|
|
|
58b090 |
+ # set download directories from json state file
|
|
|
58b090 |
+ self.base.conf.cachedir = self.datadir
|
|
|
58b090 |
+ self.base.conf.destdir = self.state.destdir if self.state.destdir else None
|
|
|
58b090 |
+
|
|
|
58b090 |
+ def _get_forward_reverse_pkg_reason_pairs(self):
|
|
|
58b090 |
+ """
|
|
|
58b090 |
+ forward = {repoid:{pkg_nevra: {tsi.action: tsi.reason}}
|
|
|
58b090 |
+ reverse = {pkg_nevra: {tsi.action: tsi.reason}}
|
|
|
58b090 |
+ :return: forward, reverse
|
|
|
58b090 |
+ """
|
|
|
58b090 |
+ backward_action = set(dnf.transaction.BACKWARD_ACTIONS + [libdnf.transaction.TransactionItemAction_REINSTALLED])
|
|
|
58b090 |
+ forward_actions = set(dnf.transaction.FORWARD_ACTIONS)
|
|
|
58b090 |
+
|
|
|
58b090 |
+ forward = {}
|
|
|
58b090 |
+ reverse = {}
|
|
|
58b090 |
+ for tsi in self.cli.base.transaction:
|
|
|
58b090 |
+ if tsi.action in forward_actions:
|
|
|
58b090 |
+ pkg = tsi.pkg
|
|
|
58b090 |
+ forward.setdefault(pkg.repo.id, {}).setdefault(
|
|
|
58b090 |
+ str(pkg), {})[tsi.action] = tsi.reason
|
|
|
58b090 |
+ elif tsi.action in backward_action:
|
|
|
58b090 |
+ reverse.setdefault(str(tsi.pkg), {})[tsi.action] = tsi.reason
|
|
|
58b090 |
+ return forward, reverse
|
|
|
58b090 |
+
|
|
|
58b090 |
+ # == pre_configure_*: set up action-specific demands ==========================
|
|
|
58b090 |
+ def pre_configure_download(self):
|
|
|
58b090 |
+ # only download subcommand accepts --destdir command line option
|
|
|
58b090 |
+ self.base.conf.cachedir = self.datadir
|
|
|
58b090 |
+ self.base.conf.destdir = self.opts.destdir if self.opts.destdir else None
|
|
|
58b090 |
+ if 'offline-distrosync' == self.opts.command and not self.opts.distro_sync:
|
|
|
58b090 |
+ raise CliError(
|
|
|
58b090 |
+ _("Command 'offline-distrosync' cannot be used with --no-downgrade option"))
|
|
|
58b090 |
+ elif 'offline-upgrade' == self.opts.command:
|
|
|
58b090 |
+ self.opts.distro_sync = False
|
|
|
58b090 |
+
|
|
|
58b090 |
+ def pre_configure_reboot(self):
|
|
|
58b090 |
+ self._set_cachedir()
|
|
|
58b090 |
+
|
|
|
58b090 |
+ def pre_configure_upgrade(self):
|
|
|
58b090 |
+ self._set_cachedir()
|
|
|
58b090 |
+ if self.state.enable_disable_repos:
|
|
|
58b090 |
+ self.opts.repos_ed = self.state.enable_disable_repos
|
|
|
58b090 |
+ self.base.conf.releasever = self.state.target_releasever
|
|
|
58b090 |
+
|
|
|
58b090 |
+ def pre_configure_clean(self):
|
|
|
58b090 |
+ self._set_cachedir()
|
|
|
58b090 |
+
|
|
|
58b090 |
+ # == configure_*: set up action-specific demands ==========================
|
|
|
58b090 |
+
|
|
|
58b090 |
+ def configure_download(self):
|
|
|
58b090 |
+ if 'system-upgrade' == self.opts.command or 'fedup' == self.opts.command:
|
|
|
58b090 |
+ help_url = get_url_from_os_release()
|
|
|
58b090 |
+ if help_url:
|
|
|
58b090 |
+ msg = _('Additional information for System Upgrade: {}')
|
|
|
58b090 |
+ logger.info(msg.format(ucd(help_url)))
|
|
|
58b090 |
+ if self.base._promptWanted():
|
|
|
58b090 |
+ msg = _('Before you continue ensure that your system is fully upgraded by running '
|
|
|
58b090 |
+ '"dnf --refresh upgrade". Do you want to continue')
|
|
|
58b090 |
+ if self.base.conf.assumeno or not self.base.output.userconfirm(
|
|
|
58b090 |
+ msg='{} [y/N]: '.format(msg), defaultyes_msg='{} [Y/n]: '.format(msg)):
|
|
|
58b090 |
+ logger.error(_("Operation aborted."))
|
|
|
58b090 |
+ sys.exit(1)
|
|
|
58b090 |
+ check_release_ver(self.base.conf, target=self.opts.releasever)
|
|
|
58b090 |
+ self.cli.demands.root_user = True
|
|
|
58b090 |
+ self.cli.demands.resolving = True
|
|
|
58b090 |
+ self.cli.demands.available_repos = True
|
|
|
58b090 |
+ self.cli.demands.sack_activation = True
|
|
|
58b090 |
+ self.cli.demands.freshest_metadata = True
|
|
|
58b090 |
+ # We want to do the depsolve / download / transaction-test, but *not*
|
|
|
58b090 |
+ # run the actual RPM transaction to install the downloaded packages.
|
|
|
58b090 |
+ # Setting the "test" flag makes the RPM transaction a test transaction,
|
|
|
58b090 |
+ # so nothing actually gets installed.
|
|
|
58b090 |
+ # (It also means that we run two test transactions in a row, which is
|
|
|
58b090 |
+ # kind of silly, but that's something for DNF to fix...)
|
|
|
58b090 |
+ self.base.conf.tsflags += ["test"]
|
|
|
58b090 |
+
|
|
|
58b090 |
+ def configure_reboot(self):
|
|
|
58b090 |
+ # FUTURE: add a --debug-shell option to enable debug shell:
|
|
|
58b090 |
+ # systemctl add-wants system-update.target debug-shell.service
|
|
|
58b090 |
+ self.cli.demands.root_user = True
|
|
|
58b090 |
+
|
|
|
58b090 |
+ def configure_upgrade(self):
|
|
|
58b090 |
+ # same as the download, but offline and non-interactive. so...
|
|
|
58b090 |
+ self.cli.demands.root_user = True
|
|
|
58b090 |
+ self.cli.demands.resolving = True
|
|
|
58b090 |
+ self.cli.demands.available_repos = True
|
|
|
58b090 |
+ self.cli.demands.sack_activation = True
|
|
|
58b090 |
+ # use the saved value for --allowerasing, etc.
|
|
|
58b090 |
+ self.opts.distro_sync = self.state.distro_sync
|
|
|
58b090 |
+ if self.state.gpgcheck is not None:
|
|
|
58b090 |
+ self.base.conf.gpgcheck = self.state.gpgcheck
|
|
|
58b090 |
+ if self.state.gpgcheck_repos is not None:
|
|
|
58b090 |
+ for repo in self.base.repos.values():
|
|
|
58b090 |
+ repo.gpgcheck = repo.id in self.state.gpgcheck_repos
|
|
|
58b090 |
+ if self.state.repo_gpgcheck_repos is not None:
|
|
|
58b090 |
+ for repo in self.base.repos.values():
|
|
|
58b090 |
+ repo.repo_gpgcheck = repo.id in self.state.repo_gpgcheck_repos
|
|
|
58b090 |
+ self.base.conf.module_platform_id = self.state.module_platform_id
|
|
|
58b090 |
+ # don't try to get new metadata, 'cuz we're offline
|
|
|
58b090 |
+ self.cli.demands.cacheonly = True
|
|
|
58b090 |
+ # and don't ask any questions (we confirmed all this beforehand)
|
|
|
58b090 |
+ self.base.conf.assumeyes = True
|
|
|
58b090 |
+ self.cli.demands.transaction_display = PlymouthTransactionProgress()
|
|
|
58b090 |
+ # upgrade operation already removes all element that must be removed. Additional removal
|
|
|
58b090 |
+ # could trigger unwanted changes in transaction.
|
|
|
58b090 |
+ self.base.conf.clean_requirements_on_remove = False
|
|
|
58b090 |
+ self.base.conf.install_weak_deps = False
|
|
|
58b090 |
+
|
|
|
58b090 |
+ def configure_clean(self):
|
|
|
58b090 |
+ self.cli.demands.root_user = True
|
|
|
58b090 |
+
|
|
|
58b090 |
+ def configure_log(self):
|
|
|
58b090 |
+ pass
|
|
|
58b090 |
+
|
|
|
58b090 |
+ # == check_*: do any action-specific checks ===============================
|
|
|
58b090 |
+
|
|
|
58b090 |
+ def check_reboot(self):
|
|
|
58b090 |
+ if not self.state.download_status == 'complete':
|
|
|
58b090 |
+ raise CliError(_("system is not ready for upgrade"))
|
|
|
58b090 |
+ self._check_state_version(self.opts.command)
|
|
|
58b090 |
+ if self.state.upgrade_command != self.opts.command:
|
|
|
58b090 |
+ msg = _("the transaction was not prepared for '{command}'. "
|
|
|
58b090 |
+ "Rerun 'dnf {command} download [OPTIONS]'").format(command=self.opts.command)
|
|
|
58b090 |
+ raise CliError(msg)
|
|
|
58b090 |
+ if os.path.lexists(self.magic_symlink):
|
|
|
58b090 |
+ raise CliError(_("upgrade is already scheduled"))
|
|
|
58b090 |
+ dnf.util.ensure_dir(self.datadir)
|
|
|
58b090 |
+ # FUTURE: checkRPMDBStatus(self.state.download_transaction_id)
|
|
|
58b090 |
+
|
|
|
58b090 |
+ def check_upgrade(self):
|
|
|
58b090 |
+ if not os.path.lexists(self.magic_symlink):
|
|
|
58b090 |
+ logger.info(_("trigger file does not exist. exiting quietly."))
|
|
|
58b090 |
+ raise SystemExit(0)
|
|
|
58b090 |
+ if os.readlink(self.magic_symlink) != self.datadir:
|
|
|
58b090 |
+ logger.info(_("another upgrade tool is running. exiting quietly."))
|
|
|
58b090 |
+ raise SystemExit(0)
|
|
|
58b090 |
+ # Delete symlink ASAP to avoid reboot loops
|
|
|
58b090 |
+ dnf.yum.misc.unlink_f(self.magic_symlink)
|
|
|
58b090 |
+ command = self.state.upgrade_command
|
|
|
58b090 |
+ if not command:
|
|
|
58b090 |
+ command = self.opts.command
|
|
|
58b090 |
+ self._check_state_version(command)
|
|
|
58b090 |
+ if not self.state.upgrade_status == 'ready':
|
|
|
58b090 |
+ msg = _("use 'dnf {command} reboot' to begin the upgrade").format(command=command)
|
|
|
58b090 |
+ raise CliError(msg)
|
|
|
58b090 |
+
|
|
|
58b090 |
+ # == run_*: run the action/prep the transaction ===========================
|
|
|
58b090 |
+
|
|
|
58b090 |
+ def run_prepare(self):
|
|
|
58b090 |
+ # make the magic symlink
|
|
|
58b090 |
+ os.symlink(self.datadir, self.magic_symlink)
|
|
|
58b090 |
+ # set upgrade_status so that the upgrade can run
|
|
|
58b090 |
+ with self.state as state:
|
|
|
58b090 |
+ state.upgrade_status = 'ready'
|
|
|
58b090 |
+
|
|
|
58b090 |
+ def run_reboot(self):
|
|
|
58b090 |
+ self.run_prepare()
|
|
|
58b090 |
+
|
|
|
58b090 |
+ if not self.opts.tid[0] == "reboot":
|
|
|
58b090 |
+ return
|
|
|
58b090 |
+
|
|
|
58b090 |
+ self.log_status(_("Rebooting to perform upgrade."),
|
|
|
58b090 |
+ REBOOT_REQUESTED_ID)
|
|
|
58b090 |
+ reboot()
|
|
|
58b090 |
+
|
|
|
58b090 |
+ def run_download(self):
|
|
|
58b090 |
+ # Mark everything in the world for upgrade/sync
|
|
|
58b090 |
+ if self.opts.distro_sync:
|
|
|
58b090 |
+ self.base.distro_sync()
|
|
|
58b090 |
+ else:
|
|
|
58b090 |
+ self.base.upgrade_all()
|
|
|
58b090 |
+
|
|
|
58b090 |
+ if self.opts.command not in ['offline-upgrade', 'offline-distrosync']:
|
|
|
58b090 |
+ # Mark all installed groups and environments for upgrade
|
|
|
58b090 |
+ self.base.read_comps()
|
|
|
58b090 |
+ installed_groups = [g.id for g in self.base.comps.groups if self.base.history.group.get(g.id)]
|
|
|
58b090 |
+ if installed_groups:
|
|
|
58b090 |
+ self.base.env_group_upgrade(installed_groups)
|
|
|
58b090 |
+ installed_environments = [g.id for g in self.base.comps.environments if self.base.history.env.get(g.id)]
|
|
|
58b090 |
+ if installed_environments:
|
|
|
58b090 |
+ self.base.env_group_upgrade(installed_environments)
|
|
|
58b090 |
+
|
|
|
58b090 |
+ with self.state as state:
|
|
|
58b090 |
+ state.download_status = 'downloading'
|
|
|
58b090 |
+ state.target_releasever = self.base.conf.releasever
|
|
|
58b090 |
+ state.destdir = self.base.conf.destdir
|
|
|
58b090 |
+
|
|
|
58b090 |
+ def run_upgrade(self):
|
|
|
58b090 |
+ # change the upgrade status (so we can detect crashed upgrades later)
|
|
|
58b090 |
+ command = ''
|
|
|
58b090 |
+ with self.state as state:
|
|
|
58b090 |
+ state.upgrade_status = 'incomplete'
|
|
|
58b090 |
+ command = state.upgrade_command
|
|
|
58b090 |
+ if command == 'offline-upgrade':
|
|
|
58b090 |
+ msg = _("Starting offline upgrade. This will take a while.")
|
|
|
58b090 |
+ elif command == 'offline-distrosync':
|
|
|
58b090 |
+ msg = _("Starting offline distrosync. This will take a while.")
|
|
|
58b090 |
+ else:
|
|
|
58b090 |
+ msg = _("Starting system upgrade. This will take a while.")
|
|
|
58b090 |
+
|
|
|
58b090 |
+ self.log_status(msg, UPGRADE_STARTED_ID)
|
|
|
58b090 |
+
|
|
|
58b090 |
+ # reset the splash mode and let the user know we're running
|
|
|
58b090 |
+ Plymouth.set_mode()
|
|
|
58b090 |
+ Plymouth.progress(0)
|
|
|
58b090 |
+ Plymouth.message(msg)
|
|
|
58b090 |
+
|
|
|
58b090 |
+ # disable screen blanking
|
|
|
58b090 |
+ disable_blanking()
|
|
|
58b090 |
+
|
|
|
58b090 |
+ self.replay = TransactionReplay(self.base, self.transaction_file)
|
|
|
58b090 |
+ self.replay.run()
|
|
|
58b090 |
+
|
|
|
58b090 |
+ def run_clean(self):
|
|
|
58b090 |
+ logger.info(_("Cleaning up downloaded data..."))
|
|
|
58b090 |
+ # Don't delete persistor, it contains paths for downloaded packages
|
|
|
58b090 |
+ # that are used by dnf during finalizing base to clean them up
|
|
|
58b090 |
+ clear_dir(self.base.conf.cachedir,
|
|
|
58b090 |
+ [dnf.persistor.TempfilePersistor(self.base.conf.cachedir).db_path])
|
|
|
58b090 |
+ with self.state as state:
|
|
|
58b090 |
+ state.download_status = None
|
|
|
58b090 |
+ state.state_version = None
|
|
|
58b090 |
+ state.upgrade_status = None
|
|
|
58b090 |
+ state.upgrade_command = None
|
|
|
58b090 |
+ state.destdir = None
|
|
|
58b090 |
+
|
|
|
58b090 |
+ def run_log(self):
|
|
|
58b090 |
+ if self.opts.number:
|
|
|
58b090 |
+ show_log(self.opts.number)
|
|
|
58b090 |
+ else:
|
|
|
58b090 |
+ list_logs()
|
|
|
58b090 |
+
|
|
|
58b090 |
+ # == resolved_*: do staff after succesful resolvement =====================
|
|
|
58b090 |
+
|
|
|
58b090 |
+ def resolved_upgrade(self):
|
|
|
58b090 |
+ """Adjust transaction reasons according to stored values"""
|
|
|
58b090 |
+ self.replay.post_transaction()
|
|
|
58b090 |
+
|
|
|
58b090 |
+ # == transaction_*: do stuff after a successful transaction ===============
|
|
|
58b090 |
+
|
|
|
58b090 |
+ def transaction_download(self):
|
|
|
58b090 |
+ transaction = self.base.history.get_current()
|
|
|
58b090 |
+
|
|
|
58b090 |
+ if not transaction.packages():
|
|
|
58b090 |
+ logger.info(_("The system-upgrade transaction is empty, your system is already up-to-date."))
|
|
|
58b090 |
+ return
|
|
|
58b090 |
+
|
|
|
58b090 |
+ data = serialize_transaction(transaction)
|
|
|
58b090 |
+ try:
|
|
|
58b090 |
+ with open(self.transaction_file, "w") as f:
|
|
|
58b090 |
+ json.dump(data, f, indent=4, sort_keys=True)
|
|
|
58b090 |
+ f.write("\n")
|
|
|
58b090 |
+
|
|
|
58b090 |
+ print(_("Transaction saved to {}.").format(self.transaction_file))
|
|
|
58b090 |
+
|
|
|
58b090 |
+ except OSError as e:
|
|
|
58b090 |
+ raise dnf.cli.CliError(_('Error storing transaction: {}').format(str(e)))
|
|
|
58b090 |
+
|
|
|
58b090 |
+ # Okay! Write out the state so the upgrade can use it.
|
|
|
58b090 |
+ system_ver = dnf.rpm.detect_releasever(self.base.conf.installroot)
|
|
|
58b090 |
+ with self.state as state:
|
|
|
58b090 |
+ state.download_status = 'complete'
|
|
|
58b090 |
+ state.state_version = STATE_VERSION
|
|
|
58b090 |
+ state.distro_sync = self.opts.distro_sync
|
|
|
58b090 |
+ state.gpgcheck = self.base.conf.gpgcheck
|
|
|
58b090 |
+ state.gpgcheck_repos = [
|
|
|
58b090 |
+ repo.id for repo in self.base.repos.values() if repo.gpgcheck]
|
|
|
58b090 |
+ state.repo_gpgcheck_repos = [
|
|
|
58b090 |
+ repo.id for repo in self.base.repos.values() if repo.repo_gpgcheck]
|
|
|
58b090 |
+ state.system_releasever = system_ver
|
|
|
58b090 |
+ state.target_releasever = self.base.conf.releasever
|
|
|
58b090 |
+ state.module_platform_id = self.base.conf.module_platform_id
|
|
|
58b090 |
+ state.enable_disable_repos = self.opts.repos_ed
|
|
|
58b090 |
+ state.destdir = self.base.conf.destdir
|
|
|
58b090 |
+ state.upgrade_command = self.opts.command
|
|
|
58b090 |
+
|
|
|
58b090 |
+ msg = DOWNLOAD_FINISHED_MSG.format(command=self.opts.command)
|
|
|
58b090 |
+ logger.info(msg)
|
|
|
58b090 |
+ self.log_status(_("Download finished."), DOWNLOAD_FINISHED_ID)
|
|
|
58b090 |
+
|
|
|
58b090 |
+ def transaction_upgrade(self):
|
|
|
58b090 |
+ Plymouth.message(_("Upgrade complete! Cleaning up and rebooting..."))
|
|
|
58b090 |
+ self.log_status(_("Upgrade complete! Cleaning up and rebooting..."),
|
|
|
58b090 |
+ UPGRADE_FINISHED_ID)
|
|
|
58b090 |
+ self.run_clean()
|
|
|
58b090 |
+ if self.opts.tid[0] == "upgrade":
|
|
|
58b090 |
+ reboot()
|
|
|
58b090 |
+
|
|
|
58b090 |
+
|
|
|
58b090 |
+class OfflineUpgradeCommand(SystemUpgradeCommand):
|
|
|
58b090 |
+ aliases = ('offline-upgrade',)
|
|
|
58b090 |
+ summary = _("Prepare offline upgrade of the system")
|
|
|
58b090 |
+
|
|
|
58b090 |
+
|
|
|
58b090 |
+class OfflineDistrosyncCommand(SystemUpgradeCommand):
|
|
|
58b090 |
+ aliases = ('offline-distrosync',)
|
|
|
58b090 |
+ summary = _("Prepare offline distrosync of the system")
|
|
|
58b090 |
diff --git a/tests/test_system_upgrade.py b/tests/test_system_upgrade.py
|
|
|
58b090 |
new file mode 100644
|
|
|
58b090 |
index 0000000..6ef4c21
|
|
|
58b090 |
--- /dev/null
|
|
|
58b090 |
+++ b/tests/test_system_upgrade.py
|
|
|
58b090 |
@@ -0,0 +1,502 @@
|
|
|
58b090 |
+# test_system_upgrade.py - unit tests for system-upgrade plugin
|
|
|
58b090 |
+
|
|
|
58b090 |
+import system_upgrade
|
|
|
58b090 |
+
|
|
|
58b090 |
+from system_upgrade import PLYMOUTH, CliError
|
|
|
58b090 |
+
|
|
|
58b090 |
+import os
|
|
|
58b090 |
+import tempfile
|
|
|
58b090 |
+import shutil
|
|
|
58b090 |
+import gettext
|
|
|
58b090 |
+
|
|
|
58b090 |
+from dnf.callback import (PKG_CLEANUP, PKG_DOWNGRADE, PKG_INSTALL,
|
|
|
58b090 |
+ PKG_OBSOLETE, PKG_REINSTALL, PKG_REMOVE, PKG_UPGRADE,
|
|
|
58b090 |
+ PKG_VERIFY, TRANS_POST)
|
|
|
58b090 |
+
|
|
|
58b090 |
+import unittest
|
|
|
58b090 |
+
|
|
|
58b090 |
+from tests.support import mock
|
|
|
58b090 |
+patch = mock.patch
|
|
|
58b090 |
+
|
|
|
58b090 |
+
|
|
|
58b090 |
+@patch('system_upgrade.call', return_value=0)
|
|
|
58b090 |
+class PlymouthTestCase(unittest.TestCase):
|
|
|
58b090 |
+ def setUp(self):
|
|
|
58b090 |
+ self.ply = system_upgrade.PlymouthOutput()
|
|
|
58b090 |
+ self.msg = "Hello, plymouth."
|
|
|
58b090 |
+ self.msg_args = (PLYMOUTH, "display-message", "--text", self.msg)
|
|
|
58b090 |
+
|
|
|
58b090 |
+ def test_ping(self, call):
|
|
|
58b090 |
+ self.ply.ping()
|
|
|
58b090 |
+ call.assert_called_once_with((PLYMOUTH, "--ping"))
|
|
|
58b090 |
+ self.assertTrue(self.ply.alive)
|
|
|
58b090 |
+
|
|
|
58b090 |
+ def test_ping_when_dead(self, call):
|
|
|
58b090 |
+ call.return_value = 1
|
|
|
58b090 |
+ self.ply.ping()
|
|
|
58b090 |
+ self.assertFalse(self.ply.alive)
|
|
|
58b090 |
+ call.return_value = 0
|
|
|
58b090 |
+ self.ply.ping()
|
|
|
58b090 |
+ self.assertEqual(call.call_count, 2)
|
|
|
58b090 |
+ self.assertTrue(self.ply.alive)
|
|
|
58b090 |
+
|
|
|
58b090 |
+ def test_message(self, call):
|
|
|
58b090 |
+ self.ply.message(self.msg)
|
|
|
58b090 |
+ call.assert_called_once_with(self.msg_args)
|
|
|
58b090 |
+
|
|
|
58b090 |
+ def test_hide_message(self, call):
|
|
|
58b090 |
+ messages = ("first", "middle", "BONUS", "last")
|
|
|
58b090 |
+ for m in messages:
|
|
|
58b090 |
+ self.ply.message(m)
|
|
|
58b090 |
+
|
|
|
58b090 |
+ def hidem(m):
|
|
|
58b090 |
+ return mock.call((PLYMOUTH, "hide-message", "--text", m))
|
|
|
58b090 |
+
|
|
|
58b090 |
+ def dispm(m):
|
|
|
58b090 |
+ return mock.call((PLYMOUTH, "display-message", "--text", m))
|
|
|
58b090 |
+ m1, m2, m3, m4 = messages
|
|
|
58b090 |
+ call.assert_has_calls([
|
|
|
58b090 |
+ dispm(m1),
|
|
|
58b090 |
+ hidem(m1), dispm(m2),
|
|
|
58b090 |
+ hidem(m2), dispm(m3),
|
|
|
58b090 |
+ hidem(m3), dispm(m4),
|
|
|
58b090 |
+ ])
|
|
|
58b090 |
+
|
|
|
58b090 |
+ def test_message_dupe(self, call):
|
|
|
58b090 |
+ self.ply.message(self.msg)
|
|
|
58b090 |
+ self.ply.message(self.msg)
|
|
|
58b090 |
+ call.assert_called_once_with(self.msg_args)
|
|
|
58b090 |
+
|
|
|
58b090 |
+ def test_message_dead(self, call):
|
|
|
58b090 |
+ call.return_value = 1
|
|
|
58b090 |
+ self.ply.message(self.msg)
|
|
|
58b090 |
+ self.assertFalse(self.ply.alive)
|
|
|
58b090 |
+ self.ply.message("not even gonna bother")
|
|
|
58b090 |
+ call.assert_called_once_with(self.msg_args)
|
|
|
58b090 |
+
|
|
|
58b090 |
+ def test_progress(self, call):
|
|
|
58b090 |
+ self.ply.progress(27)
|
|
|
58b090 |
+ call.assert_called_once_with(
|
|
|
58b090 |
+ (PLYMOUTH, "system-update", "--progress", str(27)))
|
|
|
58b090 |
+
|
|
|
58b090 |
+ @patch('system_upgrade.check_output',
|
|
|
58b090 |
+ return_value="this plymouth does support --system-upgrade mode")
|
|
|
58b090 |
+ def test_mode(self, check_output, call):
|
|
|
58b090 |
+ self.ply.set_mode()
|
|
|
58b090 |
+ call.assert_called_once_with((PLYMOUTH, "change-mode", "--system-upgrade"))
|
|
|
58b090 |
+
|
|
|
58b090 |
+ @patch('system_upgrade.check_output',
|
|
|
58b090 |
+ return_value="this plymouth doesn't support system-upgrade mode")
|
|
|
58b090 |
+ def test_mode_no_system_upgrade_plymouth(self, check_output, call):
|
|
|
58b090 |
+ self.ply.set_mode()
|
|
|
58b090 |
+ call.assert_called_once_with((PLYMOUTH, "change-mode", "--updates"))
|
|
|
58b090 |
+
|
|
|
58b090 |
+ def test_mode_no_plymouth(self, call):
|
|
|
58b090 |
+ call.side_effect = OSError(2, 'No such file or directory')
|
|
|
58b090 |
+ self.ply.set_mode()
|
|
|
58b090 |
+ self.assertFalse(self.ply.alive)
|
|
|
58b090 |
+
|
|
|
58b090 |
+
|
|
|
58b090 |
+@patch('system_upgrade.call', return_value=0)
|
|
|
58b090 |
+class PlymouthTransactionProgressTestCase(unittest.TestCase):
|
|
|
58b090 |
+ actions = (PKG_CLEANUP, PKG_DOWNGRADE, PKG_INSTALL, PKG_OBSOLETE,
|
|
|
58b090 |
+ PKG_REINSTALL, PKG_REMOVE, PKG_UPGRADE, PKG_VERIFY,
|
|
|
58b090 |
+ TRANS_POST)
|
|
|
58b090 |
+
|
|
|
58b090 |
+ # pylint: disable=protected-access
|
|
|
58b090 |
+ def setUp(self):
|
|
|
58b090 |
+ system_upgrade.Plymouth = system_upgrade.PlymouthOutput()
|
|
|
58b090 |
+ self.display = system_upgrade.PlymouthTransactionProgress()
|
|
|
58b090 |
+ self.pkg = "testpackage"
|
|
|
58b090 |
+
|
|
|
58b090 |
+ def test_display(self, call):
|
|
|
58b090 |
+ for action in self.actions:
|
|
|
58b090 |
+ self.display.progress(self.pkg, action, 0, 100, 1, 1000)
|
|
|
58b090 |
+ msg = self.display._fmt_event(self.pkg, action, 1, 1000)
|
|
|
58b090 |
+ # updating plymouth display means two plymouth calls
|
|
|
58b090 |
+ call.assert_has_calls([
|
|
|
58b090 |
+ mock.call((PLYMOUTH, "system-update", "--progress", "0")),
|
|
|
58b090 |
+ mock.call((PLYMOUTH, "display-message", "--text", msg))
|
|
|
58b090 |
+ ], any_order=True)
|
|
|
58b090 |
+
|
|
|
58b090 |
+ def test_filter_calls(self, call):
|
|
|
58b090 |
+ action = PKG_INSTALL
|
|
|
58b090 |
+ # first display update -> set percentage and text
|
|
|
58b090 |
+ self.display.progress(self.pkg, action, 0, 100, 1, 1000)
|
|
|
58b090 |
+ msg1 = self.display._fmt_event(self.pkg, action, 1, 1000)
|
|
|
58b090 |
+ call.assert_has_calls([
|
|
|
58b090 |
+ mock.call((PLYMOUTH, "system-update", "--progress", "0")),
|
|
|
58b090 |
+ mock.call((PLYMOUTH, "display-message", "--text", msg1)),
|
|
|
58b090 |
+ ])
|
|
|
58b090 |
+
|
|
|
58b090 |
+ # event progress on the same transaction item.
|
|
|
58b090 |
+ # no new calls to plymouth because the percentage and text don't change
|
|
|
58b090 |
+ for te_cur in range(1, 100):
|
|
|
58b090 |
+ self.display.progress(self.pkg, action, te_cur, 100, 1, 1000)
|
|
|
58b090 |
+ call.assert_has_calls([
|
|
|
58b090 |
+ mock.call((PLYMOUTH, "system-update", "--progress", "0")),
|
|
|
58b090 |
+ mock.call((PLYMOUTH, "display-message", "--text", msg1)),
|
|
|
58b090 |
+ ])
|
|
|
58b090 |
+
|
|
|
58b090 |
+ # new item: new message ("[2/1000] ..."), but percentage still 0..
|
|
|
58b090 |
+ self.display.progress(self.pkg, action, 0, 100, 2, 1000)
|
|
|
58b090 |
+ # old message hidden, new message displayed. no new percentage.
|
|
|
58b090 |
+ msg2 = self.display._fmt_event(self.pkg, action, 2, 1000)
|
|
|
58b090 |
+ call.assert_has_calls([
|
|
|
58b090 |
+ mock.call((PLYMOUTH, "system-update", "--progress", "0")),
|
|
|
58b090 |
+ mock.call((PLYMOUTH, "display-message", "--text", msg1)),
|
|
|
58b090 |
+ mock.call((PLYMOUTH, "hide-message", "--text", msg1)),
|
|
|
58b090 |
+ mock.call((PLYMOUTH, "display-message", "--text", msg2)),
|
|
|
58b090 |
+ ])
|
|
|
58b090 |
+
|
|
|
58b090 |
+
|
|
|
58b090 |
+TESTLANG = "zh_CN"
|
|
|
58b090 |
+TESTLANG_MO = "po/%s.mo" % TESTLANG
|
|
|
58b090 |
+
|
|
|
58b090 |
+
|
|
|
58b090 |
+@unittest.skipUnless(os.path.exists(TESTLANG_MO), "make %s first" %
|
|
|
58b090 |
+ TESTLANG_MO)
|
|
|
58b090 |
+# @unittest.skip("There is no translation yet to system-upgrade")
|
|
|
58b090 |
+class I18NTestCaseBase(unittest.TestCase):
|
|
|
58b090 |
+ @classmethod
|
|
|
58b090 |
+ @unittest.skip("There is no translation yet to system-upgrade")
|
|
|
58b090 |
+ def setUpClass(cls):
|
|
|
58b090 |
+ cls.localedir = tempfile.mkdtemp(prefix='system_upgrade_test_i18n-')
|
|
|
58b090 |
+ cls.msgdir = os.path.join(cls.localedir, TESTLANG + "/LC_MESSAGES")
|
|
|
58b090 |
+ cls.msgfile = "dnf-plugins-extras" + ".mo"
|
|
|
58b090 |
+ os.makedirs(cls.msgdir)
|
|
|
58b090 |
+ shutil.copy2(TESTLANG_MO, os.path.join(cls.msgdir, cls.msgfile))
|
|
|
58b090 |
+
|
|
|
58b090 |
+ @classmethod
|
|
|
58b090 |
+ def tearDownClass(cls):
|
|
|
58b090 |
+ shutil.rmtree(cls.localedir)
|
|
|
58b090 |
+
|
|
|
58b090 |
+ def setUp(self):
|
|
|
58b090 |
+ self.t = gettext.translation("dnf-plugins-extras", self.localedir,
|
|
|
58b090 |
+ languages=[TESTLANG], fallback=True)
|
|
|
58b090 |
+ self.gettext = self.t.gettext
|
|
|
58b090 |
+
|
|
|
58b090 |
+
|
|
|
58b090 |
+class I18NTestCase(I18NTestCaseBase):
|
|
|
58b090 |
+ @unittest.skip("There is no translation yet to system-upgrade")
|
|
|
58b090 |
+ def test_selftest(self):
|
|
|
58b090 |
+ self.assertIn(self.msgfile, os.listdir(self.msgdir))
|
|
|
58b090 |
+ self.assertIn(TESTLANG, os.listdir(self.localedir))
|
|
|
58b090 |
+ t = gettext.translation("dnf-plugins-extras", self.localedir,
|
|
|
58b090 |
+ languages=[TESTLANG], fallback=False)
|
|
|
58b090 |
+ info = t.info()
|
|
|
58b090 |
+ self.assertIn("language", info)
|
|
|
58b090 |
+ self.assertEqual(info["language"], TESTLANG.replace("_", "-"))
|
|
|
58b090 |
+
|
|
|
58b090 |
+ @unittest.skip("There is no translation yet to system-upgrade")
|
|
|
58b090 |
+ def test_fallback(self):
|
|
|
58b090 |
+ msg = "THIS STRING DOES NOT EXIST"
|
|
|
58b090 |
+ trans_msg = self.gettext(msg)
|
|
|
58b090 |
+ self.assertEqual(msg, trans_msg)
|
|
|
58b090 |
+
|
|
|
58b090 |
+ @unittest.skip("There is no translation yet to system-upgrade")
|
|
|
58b090 |
+ def test_translation(self):
|
|
|
58b090 |
+ msg = "the color of the sky"
|
|
|
58b090 |
+ trans_msg = self.gettext(msg)
|
|
|
58b090 |
+ self.assertNotEqual(msg, trans_msg)
|
|
|
58b090 |
+
|
|
|
58b090 |
+
|
|
|
58b090 |
+class StateTestCase(unittest.TestCase):
|
|
|
58b090 |
+ @classmethod
|
|
|
58b090 |
+ def setUpClass(cls):
|
|
|
58b090 |
+ cls.statedir = tempfile.mkdtemp(prefix="system_upgrade_test_state-")
|
|
|
58b090 |
+ cls.StateClass = system_upgrade.State
|
|
|
58b090 |
+
|
|
|
58b090 |
+ def setUp(self):
|
|
|
58b090 |
+ self.state = self.StateClass(os.path.join(self.statedir, "state"))
|
|
|
58b090 |
+
|
|
|
58b090 |
+ def test_bool_value(self):
|
|
|
58b090 |
+ with self.state:
|
|
|
58b090 |
+ self.state.distro_sync = True
|
|
|
58b090 |
+ del self.state
|
|
|
58b090 |
+ self.state = self.StateClass(os.path.join(self.statedir, "state"))
|
|
|
58b090 |
+ self.assertIs(self.state.distro_sync, True)
|
|
|
58b090 |
+
|
|
|
58b090 |
+ @classmethod
|
|
|
58b090 |
+ def tearDownClass(cls):
|
|
|
58b090 |
+ shutil.rmtree(cls.statedir)
|
|
|
58b090 |
+
|
|
|
58b090 |
+
|
|
|
58b090 |
+class UtilTestCase(unittest.TestCase):
|
|
|
58b090 |
+ def setUp(self):
|
|
|
58b090 |
+ self.tmpdir = tempfile.mkdtemp(prefix='system_upgrade_test_util-')
|
|
|
58b090 |
+ self.dirs = ["dir1", "dir2"]
|
|
|
58b090 |
+ self.files = ["file1", "dir2/file2"]
|
|
|
58b090 |
+ for d in self.dirs:
|
|
|
58b090 |
+ os.makedirs(os.path.join(self.tmpdir, d))
|
|
|
58b090 |
+ for f in self.files:
|
|
|
58b090 |
+ with open(os.path.join(self.tmpdir, f), 'wt') as fobj:
|
|
|
58b090 |
+ fobj.write("hi there\n")
|
|
|
58b090 |
+
|
|
|
58b090 |
+ def test_self_test(self):
|
|
|
58b090 |
+ for d in self.dirs:
|
|
|
58b090 |
+ self.assertTrue(os.path.isdir(os.path.join(self.tmpdir, d)))
|
|
|
58b090 |
+ for f in self.files:
|
|
|
58b090 |
+ self.assertTrue(os.path.exists(os.path.join(self.tmpdir, f)))
|
|
|
58b090 |
+
|
|
|
58b090 |
+ def test_clear_dir(self):
|
|
|
58b090 |
+ self.assertTrue(os.path.isdir(self.tmpdir))
|
|
|
58b090 |
+ system_upgrade.clear_dir(self.tmpdir)
|
|
|
58b090 |
+ self.assertTrue(os.path.isdir(self.tmpdir))
|
|
|
58b090 |
+ self.assertEqual(os.listdir(self.tmpdir), [])
|
|
|
58b090 |
+
|
|
|
58b090 |
+ def tearDown(self):
|
|
|
58b090 |
+ shutil.rmtree(self.tmpdir)
|
|
|
58b090 |
+
|
|
|
58b090 |
+
|
|
|
58b090 |
+class CommandTestCaseBase(unittest.TestCase):
|
|
|
58b090 |
+ def setUp(self):
|
|
|
58b090 |
+ self.datadir = tempfile.mkdtemp(prefix="system_upgrade_test_datadir-")
|
|
|
58b090 |
+ self.installroot = tempfile.TemporaryDirectory(prefix="system_upgrade_test_installroot-")
|
|
|
58b090 |
+ system_upgrade.SystemUpgradeCommand.DATADIR = self.datadir
|
|
|
58b090 |
+ self.cli = mock.MagicMock()
|
|
|
58b090 |
+ # the installroot is not strictly necessary for the test, but
|
|
|
58b090 |
+ # releasever detection is accessing host system files without it, and
|
|
|
58b090 |
+ # this fails on permissions in COPR srpm builds (e.g. from rpm-gitoverlay)
|
|
|
58b090 |
+ self.cli.base.conf.installroot = self.installroot.name
|
|
|
58b090 |
+ self.command = system_upgrade.SystemUpgradeCommand(cli=self.cli)
|
|
|
58b090 |
+ self.command.base.conf.cachedir = os.path.join(self.datadir, "cache")
|
|
|
58b090 |
+ self.command.base.conf.destdir = None
|
|
|
58b090 |
+
|
|
|
58b090 |
+ def tearDown(self):
|
|
|
58b090 |
+ shutil.rmtree(self.datadir)
|
|
|
58b090 |
+ self.installroot.cleanup()
|
|
|
58b090 |
+
|
|
|
58b090 |
+
|
|
|
58b090 |
+class CommandTestCase(CommandTestCaseBase):
|
|
|
58b090 |
+ # self-tests for the command test cases
|
|
|
58b090 |
+ def test_state(self):
|
|
|
58b090 |
+ # initial state: no status
|
|
|
58b090 |
+ self.assertIsNone(self.command.state.download_status)
|
|
|
58b090 |
+ self.assertIsNone(self.command.state.upgrade_status)
|
|
|
58b090 |
+
|
|
|
58b090 |
+
|
|
|
58b090 |
+class CleanCommandTestCase(CommandTestCaseBase):
|
|
|
58b090 |
+ def test_pre_configure_clean(self):
|
|
|
58b090 |
+ with self.command.state as state:
|
|
|
58b090 |
+ state.destdir = "/grape/wine"
|
|
|
58b090 |
+ self.command.pre_configure_clean()
|
|
|
58b090 |
+ self.assertEqual(self.command.base.conf.destdir, "/grape/wine")
|
|
|
58b090 |
+
|
|
|
58b090 |
+ def test_configure_clean(self):
|
|
|
58b090 |
+ self.cli.demands.root_user = None
|
|
|
58b090 |
+ self.command.configure_clean()
|
|
|
58b090 |
+ self.assertTrue(self.cli.demands.root_user)
|
|
|
58b090 |
+
|
|
|
58b090 |
+ def test_run_clean(self):
|
|
|
58b090 |
+ with self.command.state as state:
|
|
|
58b090 |
+ state.download_status = "complete"
|
|
|
58b090 |
+ state.upgrade_status = "ready"
|
|
|
58b090 |
+ # make sure the datadir and state info is set up OK
|
|
|
58b090 |
+ self.assertEqual(self.command.state.download_status, "complete")
|
|
|
58b090 |
+ self.assertEqual(self.command.state.upgrade_status, "ready")
|
|
|
58b090 |
+ # run cleanup
|
|
|
58b090 |
+ self.command.run_clean()
|
|
|
58b090 |
+ # state is cleared
|
|
|
58b090 |
+ self.assertIsNone(self.command.state.download_status)
|
|
|
58b090 |
+ self.assertIsNone(self.command.state.upgrade_status)
|
|
|
58b090 |
+
|
|
|
58b090 |
+
|
|
|
58b090 |
+class RebootCheckCommandTestCase(CommandTestCaseBase):
|
|
|
58b090 |
+ def setUp(self):
|
|
|
58b090 |
+ super(RebootCheckCommandTestCase, self).setUp()
|
|
|
58b090 |
+ self.magic_symlink = self.datadir + '/symlink'
|
|
|
58b090 |
+ self.command.magic_symlink = self.magic_symlink
|
|
|
58b090 |
+
|
|
|
58b090 |
+ def test_pre_configure_reboot(self):
|
|
|
58b090 |
+ with self.command.state as state:
|
|
|
58b090 |
+ state.destdir = "/grape/wine"
|
|
|
58b090 |
+ self.command.pre_configure_reboot()
|
|
|
58b090 |
+ self.assertEqual(self.command.base.conf.destdir, "/grape/wine")
|
|
|
58b090 |
+
|
|
|
58b090 |
+ def test_configure_reboot(self):
|
|
|
58b090 |
+ self.cli.demands.root_user = None
|
|
|
58b090 |
+ self.command.configure_reboot()
|
|
|
58b090 |
+ self.assertTrue(self.cli.demands.root_user)
|
|
|
58b090 |
+
|
|
|
58b090 |
+ def check_reboot(self, status='complete', lexists=False, command='system-upgrade',
|
|
|
58b090 |
+ state_command='system-upgrade'):
|
|
|
58b090 |
+ with patch('system_upgrade.os.path.lexists') as lexists_func:
|
|
|
58b090 |
+ self.command.state.state_version = 2
|
|
|
58b090 |
+ self.command.state.download_status = status
|
|
|
58b090 |
+ self.command.opts = mock.MagicMock()
|
|
|
58b090 |
+ self.command.opts.command = command
|
|
|
58b090 |
+ self.command.state.upgrade_command = state_command
|
|
|
58b090 |
+ lexists_func.return_value = lexists
|
|
|
58b090 |
+ self.command.check_reboot()
|
|
|
58b090 |
+
|
|
|
58b090 |
+ def test_check_reboot_ok(self):
|
|
|
58b090 |
+ self.check_reboot(status='complete', lexists=False)
|
|
|
58b090 |
+
|
|
|
58b090 |
+ def test_check_reboot_different_command(self):
|
|
|
58b090 |
+ with self.assertRaises(CliError):
|
|
|
58b090 |
+ self.check_reboot(status='complete', lexists=False, command='system-upgrade',
|
|
|
58b090 |
+ state_command='offline-upgrade')
|
|
|
58b090 |
+
|
|
|
58b090 |
+ def test_check_reboot_no_download(self):
|
|
|
58b090 |
+ with self.assertRaises(CliError):
|
|
|
58b090 |
+ self.check_reboot(status=None, lexists=False)
|
|
|
58b090 |
+
|
|
|
58b090 |
+ def test_check_reboot_link_exists(self):
|
|
|
58b090 |
+ with self.assertRaises(CliError):
|
|
|
58b090 |
+ self.check_reboot(status='complete', lexists=True)
|
|
|
58b090 |
+
|
|
|
58b090 |
+ def test_run_prepare(self):
|
|
|
58b090 |
+ self.command.run_prepare()
|
|
|
58b090 |
+ self.assertEqual(os.readlink(self.magic_symlink), self.datadir)
|
|
|
58b090 |
+ self.assertEqual(self.command.state.upgrade_status, 'ready')
|
|
|
58b090 |
+
|
|
|
58b090 |
+ @patch('system_upgrade.SystemUpgradeCommand.run_prepare')
|
|
|
58b090 |
+ @patch('system_upgrade.SystemUpgradeCommand.log_status')
|
|
|
58b090 |
+ @patch('system_upgrade.reboot')
|
|
|
58b090 |
+ def test_run_reboot(self, reboot, log_status, run_prepare):
|
|
|
58b090 |
+ self.command.opts = mock.MagicMock()
|
|
|
58b090 |
+ self.command.opts.tid = ["reboot"]
|
|
|
58b090 |
+ self.command.run_reboot()
|
|
|
58b090 |
+ run_prepare.assert_called_once_with()
|
|
|
58b090 |
+ self.assertEqual(system_upgrade.REBOOT_REQUESTED_ID,
|
|
|
58b090 |
+ log_status.call_args[0][1])
|
|
|
58b090 |
+ self.assertTrue(reboot.called)
|
|
|
58b090 |
+
|
|
|
58b090 |
+ @patch('system_upgrade.SystemUpgradeCommand.run_prepare')
|
|
|
58b090 |
+ @patch('system_upgrade.SystemUpgradeCommand.log_status')
|
|
|
58b090 |
+ @patch('system_upgrade.reboot')
|
|
|
58b090 |
+ def test_reboot_prepare_only(self, reboot, log_status, run_prepare):
|
|
|
58b090 |
+ self.command.opts = mock.MagicMock()
|
|
|
58b090 |
+ self.command.opts.tid = [None]
|
|
|
58b090 |
+ self.command.run_reboot()
|
|
|
58b090 |
+ run_prepare.assert_called_once_with()
|
|
|
58b090 |
+ self.assertFalse(log_status.called)
|
|
|
58b090 |
+ self.assertFalse(reboot.called)
|
|
|
58b090 |
+
|
|
|
58b090 |
+
|
|
|
58b090 |
+class DownloadCommandTestCase(CommandTestCase):
|
|
|
58b090 |
+ def test_pre_configure_download_default(self):
|
|
|
58b090 |
+ self.command.opts = mock.MagicMock()
|
|
|
58b090 |
+ self.command.opts.destdir = None
|
|
|
58b090 |
+ self.command.base.conf.destdir = None
|
|
|
58b090 |
+ self.command.pre_configure_download()
|
|
|
58b090 |
+ self.assertEqual(self.command.base.conf.cachedir, self.datadir)
|
|
|
58b090 |
+
|
|
|
58b090 |
+ def test_pre_configure_download_destdir(self):
|
|
|
58b090 |
+ self.command.opts = mock.MagicMock()
|
|
|
58b090 |
+ self.command.opts.destdir = self.datadir
|
|
|
58b090 |
+ self.command.pre_configure_download()
|
|
|
58b090 |
+ self.assertEqual(self.command.base.conf.destdir, self.datadir)
|
|
|
58b090 |
+
|
|
|
58b090 |
+ def test_configure_download(self):
|
|
|
58b090 |
+ self.command.opts = mock.MagicMock()
|
|
|
58b090 |
+ self.command.opts.tid = "download"
|
|
|
58b090 |
+ self.command.configure()
|
|
|
58b090 |
+ self.assertTrue(self.cli.demands.root_user)
|
|
|
58b090 |
+ self.assertTrue(self.cli.demands.resolving)
|
|
|
58b090 |
+ self.assertTrue(self.cli.demands.sack_activation)
|
|
|
58b090 |
+ self.assertTrue(self.cli.demands.available_repos)
|
|
|
58b090 |
+
|
|
|
58b090 |
+ def test_transaction_download(self):
|
|
|
58b090 |
+ pkg = mock.MagicMock()
|
|
|
58b090 |
+ repo = mock.MagicMock()
|
|
|
58b090 |
+ repo.id = 'test'
|
|
|
58b090 |
+ pkg.name = "kernel"
|
|
|
58b090 |
+ pkg.repo = repo
|
|
|
58b090 |
+ self.cli.base.transaction.install_set = [pkg]
|
|
|
58b090 |
+ self.command.opts = mock.MagicMock()
|
|
|
58b090 |
+ self.command.opts.distro_sync = True
|
|
|
58b090 |
+ self.command.opts.command = "system_upgrade"
|
|
|
58b090 |
+ self.command.opts.repos_ed = []
|
|
|
58b090 |
+ self.cli.demands.allow_erasing = "allow_erasing"
|
|
|
58b090 |
+ self.command.base.conf.best = True
|
|
|
58b090 |
+ self.command.base.conf.releasever = "35"
|
|
|
58b090 |
+ self.command.base.conf.gpgcheck = True
|
|
|
58b090 |
+ self.command.opts.destdir = self.datadir
|
|
|
58b090 |
+ self.command.base.conf.install_weak_deps = True
|
|
|
58b090 |
+ self.command.base.conf.module_platform_id = ''
|
|
|
58b090 |
+ self.command.pre_configure_download()
|
|
|
58b090 |
+ self.command.transaction_download()
|
|
|
58b090 |
+ with system_upgrade.State(self.command.state.statefile) as state:
|
|
|
58b090 |
+ self.assertEqual(state.state_version, system_upgrade.STATE_VERSION)
|
|
|
58b090 |
+ self.assertEqual(state.download_status, "complete")
|
|
|
58b090 |
+ self.assertEqual(state.distro_sync, True)
|
|
|
58b090 |
+ self.assertEqual(state.destdir, self.datadir)
|
|
|
58b090 |
+ self.assertEqual(state.upgrade_command, "system_upgrade")
|
|
|
58b090 |
+
|
|
|
58b090 |
+ def test_transaction_download_offline_upgrade(self):
|
|
|
58b090 |
+ pkg = mock.MagicMock()
|
|
|
58b090 |
+ repo = mock.MagicMock()
|
|
|
58b090 |
+ repo.id = 'test'
|
|
|
58b090 |
+ pkg.name = "kernel"
|
|
|
58b090 |
+ pkg.repo = repo
|
|
|
58b090 |
+ self.cli.base.transaction.install_set = [pkg]
|
|
|
58b090 |
+ self.command.opts = mock.MagicMock()
|
|
|
58b090 |
+ self.command.opts.distro_sync = True
|
|
|
58b090 |
+ self.command.opts.command = "offline-upgrade"
|
|
|
58b090 |
+ self.command.opts.repos_ed = []
|
|
|
58b090 |
+ self.cli.demands.allow_erasing = "allow_erasing"
|
|
|
58b090 |
+ self.command.base.conf.best = True
|
|
|
58b090 |
+ self.command.base.conf.releasever = "35"
|
|
|
58b090 |
+ self.command.base.conf.gpgcheck = True
|
|
|
58b090 |
+ self.command.opts.destdir = self.datadir
|
|
|
58b090 |
+ self.command.base.conf.install_weak_deps = True
|
|
|
58b090 |
+ self.command.base.conf.module_platform_id = ''
|
|
|
58b090 |
+ self.command.pre_configure_download()
|
|
|
58b090 |
+ self.command.transaction_download()
|
|
|
58b090 |
+ with system_upgrade.State(self.command.state.statefile) as state:
|
|
|
58b090 |
+ self.assertEqual(state.download_status, "complete")
|
|
|
58b090 |
+ self.assertEqual(state.distro_sync, False)
|
|
|
58b090 |
+ self.assertEqual(state.destdir, self.datadir)
|
|
|
58b090 |
+ self.assertEqual(state.upgrade_command, "offline-upgrade")
|
|
|
58b090 |
+
|
|
|
58b090 |
+
|
|
|
58b090 |
+class UpgradeCommandTestCase(CommandTestCase):
|
|
|
58b090 |
+ def test_pre_configure_upgrade(self):
|
|
|
58b090 |
+ with self.command.state as state:
|
|
|
58b090 |
+ state.destdir = "/grape/wine"
|
|
|
58b090 |
+ state.target_releasever = "35"
|
|
|
58b090 |
+ self.command.pre_configure_upgrade()
|
|
|
58b090 |
+ self.assertEqual(self.command.base.conf.destdir, "/grape/wine")
|
|
|
58b090 |
+ self.assertEqual(self.command.base.conf.releasever, "35")
|
|
|
58b090 |
+
|
|
|
58b090 |
+ def test_configure_upgrade(self):
|
|
|
58b090 |
+ # write state like download would have
|
|
|
58b090 |
+ with self.command.state as state:
|
|
|
58b090 |
+ state.download_status = "complete"
|
|
|
58b090 |
+ state.distro_sync = True
|
|
|
58b090 |
+ state.allow_erasing = True
|
|
|
58b090 |
+ state.best = True
|
|
|
58b090 |
+ # okay, now configure upgrade
|
|
|
58b090 |
+ self.command.opts = mock.MagicMock()
|
|
|
58b090 |
+ self.command.opts.tid = "upgrade"
|
|
|
58b090 |
+ self.command.configure()
|
|
|
58b090 |
+ # did we reset the depsolving flags?
|
|
|
58b090 |
+ self.assertTrue(self.command.opts.distro_sync)
|
|
|
58b090 |
+ self.assertTrue(self.cli.demands.allow_erasing)
|
|
|
58b090 |
+ self.assertTrue(self.command.base.conf.best)
|
|
|
58b090 |
+ # are we on autopilot?
|
|
|
58b090 |
+ self.assertTrue(self.command.base.conf.assumeyes)
|
|
|
58b090 |
+ self.assertTrue(self.cli.demands.cacheonly)
|
|
|
58b090 |
+
|
|
|
58b090 |
+
|
|
|
58b090 |
+class LogCommandTestCase(CommandTestCase):
|
|
|
58b090 |
+ def test_configure_log(self):
|
|
|
58b090 |
+ self.command.opts = mock.MagicMock()
|
|
|
58b090 |
+ self.command.opts.tid = "log"
|
|
|
58b090 |
+ self.command.configure()
|
|
|
58b090 |
+
|
|
|
58b090 |
+ def test_run_log_list(self):
|
|
|
58b090 |
+ self.command.opts = mock.MagicMock()
|
|
|
58b090 |
+ self.command.opts.number = None
|
|
|
58b090 |
+ with patch('system_upgrade.list_logs') as list_logs:
|
|
|
58b090 |
+ self.command.run_log()
|
|
|
58b090 |
+ list_logs.assert_called_once_with()
|
|
|
58b090 |
+
|
|
|
58b090 |
+ def test_run_log_prev(self):
|
|
|
58b090 |
+ with patch('system_upgrade.show_log') as show_log:
|
|
|
58b090 |
+ self.command.opts = mock.MagicMock()
|
|
|
58b090 |
+ self.command.opts.number = -2
|
|
|
58b090 |
+ self.command.run_log()
|
|
|
58b090 |
+ show_log.assert_called_once_with(-2)
|
|
|
58b090 |
--
|
|
|
58b090 |
2.38.1
|
|
|
58b090 |
|