[pve-devel] [PATCH container] fix os-release mapping for similar flavoured distros

Fabian Grünbichler f.gruenbichler at proxmox.com
Mon Aug 21 16:55:27 CEST 2017


On Fri, Aug 18, 2017 at 02:59:33PM +0200, Thomas Lamprecht wrote:
> This avoid failing the check where the auto detected type differs
> from the configs ostype.
> 
> Signed-off-by: Thomas Lamprecht <t.lamprecht at proxmox.com>
> ---
>  src/PVE/LXC/Setup.pm | 10 ++++++++--
>  1 file changed, 8 insertions(+), 2 deletions(-)
> 
> diff --git a/src/PVE/LXC/Setup.pm b/src/PVE/LXC/Setup.pm
> index a503461..8be1b90 100644
> --- a/src/PVE/LXC/Setup.pm
> +++ b/src/PVE/LXC/Setup.pm
> @@ -20,13 +20,17 @@ my $plugins = {
>      centos    => 'PVE::LXC::Setup::CentOS',
>      fedora    => 'PVE::LXC::Setup::Fedora',
>      opensuse  => 'PVE::LXC::Setup::SUSE',
> -    sles      => 'PVE::LXC::Setup::SUSE',
>      archlinux => 'PVE::LXC::Setup::ArchLinux',
> -    arch      => 'PVE::LXC::Setup::ArchLinux',
>      alpine    => 'PVE::LXC::Setup::Alpine',
>      gentoo    => 'PVE::LXC::Setup::Gentoo',
>  };
>  
> +# a map to allow supporting related distro flavours
> +my $os_release_vendor_map = {
> +    arch => 'archlinux',
> +    sles => 'opensuse',
> +};
> +
>  my $autodetect_type = sub {
>      my ($self, $rootdir, $os_release) = @_;
>  
> @@ -76,6 +80,8 @@ sub new {
>      } elsif (!defined($type)) {
>  	# try to autodetect type
>  	$type = &$autodetect_type($self, $rootdir, $os_release);
> +	# fixup type if needed, i.e. SLES can be handled by our SUSE class
> +	$type = $os_release_vendor_map->{$type} if $os_release_vendor_map->{$type};
>  	my $expected_type = $conf->{ostype} || $type;

why not compare the plugin strings via $plugins instead? or,
altenatively:

shouldn't conf->ostype always be one of the following, according to
src/PVE/LXC.pm:356f:

my $ostype = $conf->{ostype} || die "missing 'ostype' - internal error";
    if ($ostype =~ /^(?:debian | ubuntu | centos | fedora | opensuse | archlinux | alpine | gentoo | unmanaged)$/x) {

but $autodetect_type in srv/PVE/LXC/Setup.pm:34 allows

/^(?:alpine|arch|centos|debian|fedora|gentoo|opensuse|sles|ubuntu)$/

via the containers /etc/os-release file, but otherwise only returns
(39ff) one of ubuntu debian opensuse fedora centos archlinux alpine
gentoo - note the absense of sles / arch!

so if there is a place to replace arch => archlinux and sles =>
opensuse, it is in $autodetect_type IMHO

(also - why do we need to have almost the same RE/qw in three places,
but with different ordering and different spacing? for bonus points,
there is one variant with just debian, ubuntu and centos in
pve-update-lxc-config, where the actual enum values are unused anyway?)

>  
>  	die "got unexpected ostype ($type != $expected_type)\n"
> -- 
> 2.11.0
> 
> 
> _______________________________________________
> pve-devel mailing list
> pve-devel at pve.proxmox.com
> https://pve.proxmox.com/cgi-bin/mailman/listinfo/pve-devel




More information about the pve-devel mailing list