[pve-devel] [PATCH container 5/8] setup/suse: use new os_release_var to simplify version detection
Thomas Lamprecht
t.lamprecht at proxmox.com
Tue Aug 1 11:28:56 CEST 2017
Not only simplify but also correct version detection.
Until now we checked the files 'SuSE-release' and 'SuSE-brand' for
version parsing. 'SuSE-release' is marked as obsolete and replaced by
the newer standarised 'os-release', and the fallback is plain wrong
and not guaranteed to exist or match the actual version.
'SuSE-brand' does not get supplied by the 'openSUSE-release' package
but by another package, i.e. 'branding-openSUSE' this isn't
guaranteed to be installed, at least on CT creation, and may have
another version as the actual template provides. E.g. on tumbleweed I
get version 13.3 there, while the release package tells me "20170729".
As "os-release" is available at least sine openSUSE 12.2, and we
support 13.X and newer currently, just use it instead.
Adapt the regex as the non-rolling releases have always a X.Y format.
Signed-off-by: Thomas Lamprecht <t.lamprecht at proxmox.com>
---
src/PVE/LXC/Setup/SUSE.pm | 18 ++++++------------
src/test/test-opensuse-001/etc/SuSE-brand | 2 --
src/test/test-opensuse-001/etc/os-release | 10 ++++++++++
.../usr/lib/systemd/system/container-getty at .service | 20 ++++++++++++++++++++
src/test/test-opensuse-002/etc/SuSE-brand | 2 --
src/test/test-opensuse-002/etc/os-release | 10 ++++++++++
src/test/test-opensuse-003/etc/SuSE-brand | 2 --
src/test/test-opensuse-003/etc/SuSE-release | 4 ++++
src/test/test-opensuse-003/etc/os-release | 10 ++++++++++
.../usr/lib/systemd/system/container-getty at .service | 20 ++++++++++++++++++++
10 files changed, 80 insertions(+), 18 deletions(-)
delete mode 100644 src/test/test-opensuse-001/etc/SuSE-brand
create mode 100644 src/test/test-opensuse-001/etc/os-release
create mode 100644 src/test/test-opensuse-001/usr/lib/systemd/system/container-getty at .service
delete mode 100644 src/test/test-opensuse-002/etc/SuSE-brand
create mode 100644 src/test/test-opensuse-002/etc/os-release
delete mode 100644 src/test/test-opensuse-003/etc/SuSE-brand
create mode 100644 src/test/test-opensuse-003/etc/SuSE-release
create mode 100644 src/test/test-opensuse-003/etc/os-release
create mode 100644 src/test/test-opensuse-003/usr/lib/systemd/system/container-getty at .service
diff --git a/src/PVE/LXC/Setup/SUSE.pm b/src/PVE/LXC/Setup/SUSE.pm
index 54e6d56..ffe0687 100644
--- a/src/PVE/LXC/Setup/SUSE.pm
+++ b/src/PVE/LXC/Setup/SUSE.pm
@@ -8,19 +8,13 @@ use PVE::LXC::Setup::Base;
use base qw(PVE::LXC::Setup::Base);
sub new {
- my ($class, $conf, $rootdir) = @_;
+ my ($class, $conf, $rootdir, $os_release) = @_;
- my $release = eval { -f "$rootdir/etc/SuSE-release"
- ? PVE::Tools::file_get_contents("$rootdir/etc/SuSE-release")
- : PVE::Tools::file_get_contents("$rootdir/etc/SuSE-brand") };
- die "unable to read version info\n" if $@;
+ my $version = $os_release->{VERSION_ID};
+ my $ostype = $os_release->{ID};
- my $version;
-
- # Fixme: not sure whether the minor part is optional.
- if ($release =~ m/^\s*VERSION\s*=\s*(\d+)(?:\.(\d+))?\s*$/m) {
- my ($major, $minor) = ($1, $2//0);
- $version = "$major.$minor";
+ if ($version =~ m/^(\d+)\.(\d+)$/) {
+ my ($major, $minor) = ($1, $2);
if ($major >= 42) {
# OK
} elsif ($major == 13 && $minor <= 2) {
@@ -34,7 +28,7 @@ sub new {
die "unrecognized suse release";
}
- my $self = { conf => $conf, rootdir => $rootdir, version => $version };
+ my $self = { conf => $conf, rootdir => $rootdir, version => $version, os_release => $os_release };
$conf->{ostype} = 'opensuse';
diff --git a/src/test/test-opensuse-001/etc/SuSE-brand b/src/test/test-opensuse-001/etc/SuSE-brand
deleted file mode 100644
index e696c32..0000000
--- a/src/test/test-opensuse-001/etc/SuSE-brand
+++ /dev/null
@@ -1,2 +0,0 @@
-BasedOnopenSUSE
-VERSION = 13.1
diff --git a/src/test/test-opensuse-001/etc/os-release b/src/test/test-opensuse-001/etc/os-release
new file mode 100644
index 0000000..fe22e9a
--- /dev/null
+++ b/src/test/test-opensuse-001/etc/os-release
@@ -0,0 +1,10 @@
+NAME=openSUSE
+VERSION="13.2 (Harlequin)"
+VERSION_ID="13.2"
+PRETTY_NAME="openSUSE 13.2 (Harlequin) (x86_64)"
+ID=opensuse
+ANSI_COLOR="0;32"
+CPE_NAME="cpe:/o:opensuse:opensuse:13.2"
+BUG_REPORT_URL="https://bugs.opensuse.org"
+HOME_URL="https://opensuse.org/"
+ID_LIKE="suse"
diff --git a/src/test/test-opensuse-001/usr/lib/systemd/system/container-getty at .service b/src/test/test-opensuse-001/usr/lib/systemd/system/container-getty at .service
new file mode 100644
index 0000000..9740d3d
--- /dev/null
+++ b/src/test/test-opensuse-001/usr/lib/systemd/system/container-getty at .service
@@ -0,0 +1,20 @@
+[Unit]
+Description=Container Getty on /dev/lxc/tty%I
+Documentation=man:agetty(8) man:machinectl(1)
+After=systemd-user-sessions.service plymouth-quit-wait.service
+After=rc-local.service
+Before=getty.target
+IgnoreOnIsolate=yes
+
+[Service]
+ExecStart=-/sbin/agetty --noclear --keep-baud lxc/tty%I 115200,38400,9600 $TERM
+Type=idle
+Restart=always
+RestartSec=0
+UtmpIdentifier=%I
+TTYPath=/dev/%I
+TTYReset=yes
+TTYVHangup=yes
+KillMode=process
+IgnoreSIGPIPE=no
+SendSIGHUP=yes
diff --git a/src/test/test-opensuse-002/etc/SuSE-brand b/src/test/test-opensuse-002/etc/SuSE-brand
deleted file mode 100644
index e696c32..0000000
--- a/src/test/test-opensuse-002/etc/SuSE-brand
+++ /dev/null
@@ -1,2 +0,0 @@
-BasedOnopenSUSE
-VERSION = 13.1
diff --git a/src/test/test-opensuse-002/etc/os-release b/src/test/test-opensuse-002/etc/os-release
new file mode 100644
index 0000000..9e33c69
--- /dev/null
+++ b/src/test/test-opensuse-002/etc/os-release
@@ -0,0 +1,10 @@
+NAME=openSUSE
+VERSION="13.1 (Bottle)"
+VERSION_ID="13.1"
+PRETTY_NAME="openSUSE 13.1 (Bottle) (x86_64)"
+ID=opensuse
+ANSI_COLOR="0;32"
+CPE_NAME="cpe:/o:opensuse:opensuse:13.1"
+BUG_REPORT_URL="https://bugs.opensuse.org"
+HOME_URL="https://opensuse.org/"
+ID_LIKE="suse"
diff --git a/src/test/test-opensuse-003/etc/SuSE-brand b/src/test/test-opensuse-003/etc/SuSE-brand
deleted file mode 100644
index e696c32..0000000
--- a/src/test/test-opensuse-003/etc/SuSE-brand
+++ /dev/null
@@ -1,2 +0,0 @@
-BasedOnopenSUSE
-VERSION = 13.1
diff --git a/src/test/test-opensuse-003/etc/SuSE-release b/src/test/test-opensuse-003/etc/SuSE-release
new file mode 100644
index 0000000..c802b07
--- /dev/null
+++ b/src/test/test-opensuse-003/etc/SuSE-release
@@ -0,0 +1,4 @@
+openSUSE 42.2 (x86_64)
+VERSION = 42.2
+CODENAME = Malachite
+# /etc/SuSE-release is deprecated and will be removed in the future, use /etc/os-release instead
diff --git a/src/test/test-opensuse-003/etc/os-release b/src/test/test-opensuse-003/etc/os-release
new file mode 100644
index 0000000..d85a1df
--- /dev/null
+++ b/src/test/test-opensuse-003/etc/os-release
@@ -0,0 +1,10 @@
+NAME="openSUSE Leap"
+VERSION="42.2"
+ID=opensuse
+ID_LIKE="suse"
+VERSION_ID="42.2"
+PRETTY_NAME="openSUSE Leap 42.2"
+ANSI_COLOR="0;32"
+CPE_NAME="cpe:/o:opensuse:leap:42.2"
+BUG_REPORT_URL="https://bugs.opensuse.org"
+HOME_URL="https://www.opensuse.org/
diff --git a/src/test/test-opensuse-003/usr/lib/systemd/system/container-getty at .service b/src/test/test-opensuse-003/usr/lib/systemd/system/container-getty at .service
new file mode 100644
index 0000000..9740d3d
--- /dev/null
+++ b/src/test/test-opensuse-003/usr/lib/systemd/system/container-getty at .service
@@ -0,0 +1,20 @@
+[Unit]
+Description=Container Getty on /dev/lxc/tty%I
+Documentation=man:agetty(8) man:machinectl(1)
+After=systemd-user-sessions.service plymouth-quit-wait.service
+After=rc-local.service
+Before=getty.target
+IgnoreOnIsolate=yes
+
+[Service]
+ExecStart=-/sbin/agetty --noclear --keep-baud lxc/tty%I 115200,38400,9600 $TERM
+Type=idle
+Restart=always
+RestartSec=0
+UtmpIdentifier=%I
+TTYPath=/dev/%I
+TTYReset=yes
+TTYVHangup=yes
+KillMode=process
+IgnoreSIGPIPE=no
+SendSIGHUP=yes
--
2.11.0
More information about the pve-devel
mailing list