public inbox for pve-devel@lists.proxmox.com
 help / color / mirror / Atom feed
* [pve-devel] [PATCH container] fix creating unmanaged containers
@ 2021-10-04 14:55 Oguz Bektas
  2021-10-05  4:17 ` Thomas Lamprecht
  0 siblings, 1 reply; 2+ messages in thread
From: Oguz Bektas @ 2021-10-04 14:55 UTC (permalink / raw)
  To: pve-devel

$keynames was not a hash reference since nothing was returned by
ssh_host_key_types_to_generate for unmanaged containers, this causes the
post_create_hook to fail and no container is created.

fix by returning an empty hash so that $keynames can be a hashref and
processed accordingly.

also dropped a remaining unmanaged return (should have no effect anymore
anyways, since $self->{plugin} is now set to 'unmanaged' instead of
empty)

---

note that we can still allow generating ssh keys for unmanaged
containers, i have another patch like that (i can send if you wish),
which doesn't skip creating ssh keys -- however for that to work we need
to use functions from PVE::Tools (so that we can have ct_file_exists and
friends)

 src/PVE/LXC/Setup.pm           | 2 --
 src/PVE/LXC/Setup/Unmanaged.pm | 1 +
 2 files changed, 1 insertion(+), 2 deletions(-)

diff --git a/src/PVE/LXC/Setup.pm b/src/PVE/LXC/Setup.pm
index cfbe02c..4e211ef 100644
--- a/src/PVE/LXC/Setup.pm
+++ b/src/PVE/LXC/Setup.pm
@@ -228,8 +228,6 @@ my sub generate_ssh_key { # create temporary key in hosts' /run, then read and u
 sub rewrite_ssh_host_keys {
     my ($self) = @_;
 
-    return if !$self->{plugin}; # unmanaged
-
     my $plugin = $self->{plugin};
 
     my $keynames = $plugin->ssh_host_key_types_to_generate();
diff --git a/src/PVE/LXC/Setup/Unmanaged.pm b/src/PVE/LXC/Setup/Unmanaged.pm
index 38e245f..2ca2898 100644
--- a/src/PVE/LXC/Setup/Unmanaged.pm
+++ b/src/PVE/LXC/Setup/Unmanaged.pm
@@ -51,6 +51,7 @@ sub unified_cgroupv2_support {
 
 sub ssh_host_key_types_to_generate {
     my ($self) = @_;
+    return {};
 }
 
 # hooks
-- 
2.30.2





^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [pve-devel] [PATCH container] fix creating unmanaged containers
  2021-10-04 14:55 [pve-devel] [PATCH container] fix creating unmanaged containers Oguz Bektas
@ 2021-10-05  4:17 ` Thomas Lamprecht
  0 siblings, 0 replies; 2+ messages in thread
From: Thomas Lamprecht @ 2021-10-05  4:17 UTC (permalink / raw)
  To: Proxmox VE development discussion, Oguz Bektas

On 04.10.21 16:55, Oguz Bektas wrote:
> $keynames was not a hash reference since nothing was returned by
> ssh_host_key_types_to_generate for unmanaged containers, this causes the
> post_create_hook to fail and no container is created.

While $keynames is not a hash ref it isn't supposed to always be one, that's
why the check is:

return if !$keynames || !scalar(keys $keynames->%*);

so this patch seems wrong? At least in regards on the fix's reasoning

> 
> fix by returning an empty hash so that $keynames can be a hashref and
> processed accordingly.
> 
> also dropped a remaining unmanaged return (should have no effect anymore
> anyways, since $self->{plugin} is now set to 'unmanaged' instead of
> empty)

good catch, but should be another, separate patch..

> 
> ---
> 
> note that we can still allow generating ssh keys for unmanaged
> containers, i have another patch like that (i can send if you wish),
> which doesn't skip creating ssh keys -- however for that to work we need
> to use functions from PVE::Tools (so that we can have ct_file_exists and
> friends)
> 
>  src/PVE/LXC/Setup.pm           | 2 --
>  src/PVE/LXC/Setup/Unmanaged.pm | 1 +
>  2 files changed, 1 insertion(+), 2 deletions(-)
> 
> diff --git a/src/PVE/LXC/Setup.pm b/src/PVE/LXC/Setup.pm
> index cfbe02c..4e211ef 100644
> --- a/src/PVE/LXC/Setup.pm
> +++ b/src/PVE/LXC/Setup.pm
> @@ -228,8 +228,6 @@ my sub generate_ssh_key { # create temporary key in hosts' /run, then read and u
>  sub rewrite_ssh_host_keys {
>      my ($self) = @_;
>  
> -    return if !$self->{plugin}; # unmanaged
> -
>      my $plugin = $self->{plugin};
>  
>      my $keynames = $plugin->ssh_host_key_types_to_generate();
> diff --git a/src/PVE/LXC/Setup/Unmanaged.pm b/src/PVE/LXC/Setup/Unmanaged.pm
> index 38e245f..2ca2898 100644
> --- a/src/PVE/LXC/Setup/Unmanaged.pm
> +++ b/src/PVE/LXC/Setup/Unmanaged.pm
> @@ -51,6 +51,7 @@ sub unified_cgroupv2_support {
>  
>  sub ssh_host_key_types_to_generate {
>      my ($self) = @_;
> +    return {};
>  }
>  
>  # hooks
> 





^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2021-10-05  4:19 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-10-04 14:55 [pve-devel] [PATCH container] fix creating unmanaged containers Oguz Bektas
2021-10-05  4:17 ` Thomas Lamprecht

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal