diff mbox series

[v2,05/10] Acceptance Tests: add port redirection for ssh by default

Message ID 20210323221539.3532660-6-crosa@redhat.com
State New
Headers show
Series Acceptance Test: introduce base class for Linux based tests | expand

Commit Message

Cleber Rosa March 23, 2021, 10:15 p.m. UTC
For users of the LinuxTest class, let's set up the VM with the port
redirection for SSH, instead of requiring each test to set the same
arguments.

Signed-off-by: Cleber Rosa <crosa@redhat.com>
---
 tests/acceptance/avocado_qemu/__init__.py | 4 +++-
 tests/acceptance/virtiofs_submounts.py    | 4 ----
 2 files changed, 3 insertions(+), 5 deletions(-)

Comments

Marc-André Lureau March 24, 2021, 8:30 a.m. UTC | #1
Hi

On Wed, Mar 24, 2021 at 2:23 AM Cleber Rosa <crosa@redhat.com> wrote:

> For users of the LinuxTest class, let's set up the VM with the port
> redirection for SSH, instead of requiring each test to set the same
> arguments.
>
> Signed-off-by: Cleber Rosa <crosa@redhat.com>
> ---
>  tests/acceptance/avocado_qemu/__init__.py | 4 +++-
>  tests/acceptance/virtiofs_submounts.py    | 4 ----
>  2 files changed, 3 insertions(+), 5 deletions(-)
>
> diff --git a/tests/acceptance/avocado_qemu/__init__.py
> b/tests/acceptance/avocado_qemu/__init__.py
> index 67f75f66e5..e75b002c70 100644
> --- a/tests/acceptance/avocado_qemu/__init__.py
> +++ b/tests/acceptance/avocado_qemu/__init__.py
> @@ -309,10 +309,12 @@ class LinuxTest(Test, LinuxSSHMixIn):
>      timeout = 900
>      chksum = None
>
> -    def setUp(self, ssh_pubkey=None):
> +    def setUp(self, ssh_pubkey=None, network_device_type='virtio-net'):
>          super(LinuxTest, self).setUp()
>          self.vm.add_args('-smp', '2')
>          self.vm.add_args('-m', '1024')
> +        self.vm.add_args('-netdev', 'user,id=vnet,hostfwd=:127.0.0.1:0
> -:22',
> +                         '-device', '%s,netdev=vnet' %
> network_device_type)
>          self.set_up_boot()
>          if ssh_pubkey is None:
>              ssh_pubkey, self.ssh_key = self.set_up_existing_ssh_keys()
> diff --git a/tests/acceptance/virtiofs_submounts.py
> b/tests/acceptance/virtiofs_submounts.py
> index bed8ce44df..e10a935ac4 100644
> --- a/tests/acceptance/virtiofs_submounts.py
> +++ b/tests/acceptance/virtiofs_submounts.py
> @@ -207,10 +207,6 @@ def setUp(self):
>              self.vm.add_args('-kernel', vmlinuz,
>                               '-append', 'console=ttyS0 root=/dev/sda1')
>
> -        # Allow us to connect to SSH
> -        self.vm.add_args('-netdev', 'user,id=vnet,hostfwd=:127.0.0.1:0
> -:22',
> -                         '-device', 'virtio-net,netdev=vnet')
> -
>          self.require_accelerator("kvm")
>          self.vm.add_args('-accel', 'kvm')
>
> --
> 2.25.4
>
>
Looks fine, I suppose it could eventually be in LinuxSSHMixIn too for other
users.

Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Eric Auger March 24, 2021, 9:10 a.m. UTC | #2
Hi Cleber,

On 3/23/21 11:15 PM, Cleber Rosa wrote:
> For users of the LinuxTest class, let's set up the VM with the port
> redirection for SSH, instead of requiring each test to set the same
also sets the network device to virtio-net. This may be worth mentioning
here in the commit msg.
> arguments.
> 
> Signed-off-by: Cleber Rosa <crosa@redhat.com>
Reviewed-by: Eric Auger <eric.auger@redhat.com>

Thanks

Eric

> ---
>  tests/acceptance/avocado_qemu/__init__.py | 4 +++-
>  tests/acceptance/virtiofs_submounts.py    | 4 ----
>  2 files changed, 3 insertions(+), 5 deletions(-)
> 
> diff --git a/tests/acceptance/avocado_qemu/__init__.py b/tests/acceptance/avocado_qemu/__init__.py
> index 67f75f66e5..e75b002c70 100644
> --- a/tests/acceptance/avocado_qemu/__init__.py
> +++ b/tests/acceptance/avocado_qemu/__init__.py
> @@ -309,10 +309,12 @@ class LinuxTest(Test, LinuxSSHMixIn):
>      timeout = 900
>      chksum = None
>  
> -    def setUp(self, ssh_pubkey=None):
> +    def setUp(self, ssh_pubkey=None, network_device_type='virtio-net'):
>          super(LinuxTest, self).setUp()
>          self.vm.add_args('-smp', '2')
>          self.vm.add_args('-m', '1024')
> +        self.vm.add_args('-netdev', 'user,id=vnet,hostfwd=:127.0.0.1:0-:22',
> +                         '-device', '%s,netdev=vnet' % network_device_type)
>          self.set_up_boot()
>          if ssh_pubkey is None:
>              ssh_pubkey, self.ssh_key = self.set_up_existing_ssh_keys()
> diff --git a/tests/acceptance/virtiofs_submounts.py b/tests/acceptance/virtiofs_submounts.py
> index bed8ce44df..e10a935ac4 100644
> --- a/tests/acceptance/virtiofs_submounts.py
> +++ b/tests/acceptance/virtiofs_submounts.py
> @@ -207,10 +207,6 @@ def setUp(self):
>              self.vm.add_args('-kernel', vmlinuz,
>                               '-append', 'console=ttyS0 root=/dev/sda1')
>  
> -        # Allow us to connect to SSH
> -        self.vm.add_args('-netdev', 'user,id=vnet,hostfwd=:127.0.0.1:0-:22',
> -                         '-device', 'virtio-net,netdev=vnet')
> -
>          self.require_accelerator("kvm")
>          self.vm.add_args('-accel', 'kvm')
>  
>
Eric Auger March 24, 2021, 10:36 a.m. UTC | #3
Hi Cleber,
On 3/23/21 11:15 PM, Cleber Rosa wrote:
> For users of the LinuxTest class, let's set up the VM with the port
> redirection for SSH, instead of requiring each test to set the same
> arguments.
> 
> Signed-off-by: Cleber Rosa <crosa@redhat.com>
> ---
>  tests/acceptance/avocado_qemu/__init__.py | 4 +++-
>  tests/acceptance/virtiofs_submounts.py    | 4 ----
>  2 files changed, 3 insertions(+), 5 deletions(-)
> 
> diff --git a/tests/acceptance/avocado_qemu/__init__.py b/tests/acceptance/avocado_qemu/__init__.py
> index 67f75f66e5..e75b002c70 100644
> --- a/tests/acceptance/avocado_qemu/__init__.py
> +++ b/tests/acceptance/avocado_qemu/__init__.py
> @@ -309,10 +309,12 @@ class LinuxTest(Test, LinuxSSHMixIn):
>      timeout = 900
>      chksum = None
>  
> -    def setUp(self, ssh_pubkey=None):
> +    def setUp(self, ssh_pubkey=None, network_device_type='virtio-net'):
I would be interested in testing with HW bridging too, when a bridge is
available. Do you think we could have the netdev configurable too?
This would be helpful to test vhost for instance.

With respect the network device type, I am currently working on SMMU
test and I need to call the parent setUp-) with the following args now:

super(IOMMU, self).setUp(pubkey,
'virtio-net-pci,iommu_platform=on,disable-modern=off,disable-legacy=on')

It works but I am not sure you had such kind of scenario in mind?

Thanks

Eric

>          super(LinuxTest, self).setUp()
>          self.vm.add_args('-smp', '2')
>          self.vm.add_args('-m', '1024')
> +        self.vm.add_args('-netdev', 'user,id=vnet,hostfwd=:127.0.0.1:0-:22',
> +                         '-device', '%s,netdev=vnet' % network_device_type)
>          self.set_up_boot()
>          if ssh_pubkey is None:
>              ssh_pubkey, self.ssh_key = self.set_up_existing_ssh_keys()
> diff --git a/tests/acceptance/virtiofs_submounts.py b/tests/acceptance/virtiofs_submounts.py
> index bed8ce44df..e10a935ac4 100644
> --- a/tests/acceptance/virtiofs_submounts.py
> +++ b/tests/acceptance/virtiofs_submounts.py
> @@ -207,10 +207,6 @@ def setUp(self):
>              self.vm.add_args('-kernel', vmlinuz,
>                               '-append', 'console=ttyS0 root=/dev/sda1')
>  
> -        # Allow us to connect to SSH
> -        self.vm.add_args('-netdev', 'user,id=vnet,hostfwd=:127.0.0.1:0-:22',
> -                         '-device', 'virtio-net,netdev=vnet')
> -
>          self.require_accelerator("kvm")
>          self.vm.add_args('-accel', 'kvm')
>  
>
Willian Rampazzo March 24, 2021, 8:39 p.m. UTC | #4
On Tue, Mar 23, 2021 at 7:16 PM Cleber Rosa <crosa@redhat.com> wrote:
>
> For users of the LinuxTest class, let's set up the VM with the port
> redirection for SSH, instead of requiring each test to set the same
> arguments.
>
> Signed-off-by: Cleber Rosa <crosa@redhat.com>
> ---
>  tests/acceptance/avocado_qemu/__init__.py | 4 +++-
>  tests/acceptance/virtiofs_submounts.py    | 4 ----
>  2 files changed, 3 insertions(+), 5 deletions(-)
>

Reviewed-by: Willian Rampazzo <willianr@redhat.com>
Cleber Rosa March 24, 2021, 10:27 p.m. UTC | #5
On Wed, Mar 24, 2021 at 10:10:50AM +0100, Auger Eric wrote:
> Hi Cleber,
> 
> On 3/23/21 11:15 PM, Cleber Rosa wrote:
> > For users of the LinuxTest class, let's set up the VM with the port
> > redirection for SSH, instead of requiring each test to set the same
> also sets the network device to virtio-net. This may be worth mentioning
> here in the commit msg.

Absolutely, I've added that note.

> > arguments.
> > 
> > Signed-off-by: Cleber Rosa <crosa@redhat.com>
> Reviewed-by: Eric Auger <eric.auger@redhat.com>
> 
> Thanks
> 
> Eric
>

Thank you!
- Cleber
Cleber Rosa March 24, 2021, 10:28 p.m. UTC | #6
On Wed, Mar 24, 2021 at 12:30:18PM +0400, Marc-André Lureau wrote:
> Hi
> 
> On Wed, Mar 24, 2021 at 2:23 AM Cleber Rosa <crosa@redhat.com> wrote:
> 
> > For users of the LinuxTest class, let's set up the VM with the port
> > redirection for SSH, instead of requiring each test to set the same
> > arguments.
> >
> > Signed-off-by: Cleber Rosa <crosa@redhat.com>
> > ---
> >  tests/acceptance/avocado_qemu/__init__.py | 4 +++-
> >  tests/acceptance/virtiofs_submounts.py    | 4 ----
> >  2 files changed, 3 insertions(+), 5 deletions(-)
> >
> > diff --git a/tests/acceptance/avocado_qemu/__init__.py
> > b/tests/acceptance/avocado_qemu/__init__.py
> > index 67f75f66e5..e75b002c70 100644
> > --- a/tests/acceptance/avocado_qemu/__init__.py
> > +++ b/tests/acceptance/avocado_qemu/__init__.py
> > @@ -309,10 +309,12 @@ class LinuxTest(Test, LinuxSSHMixIn):
> >      timeout = 900
> >      chksum = None
> >
> > -    def setUp(self, ssh_pubkey=None):
> > +    def setUp(self, ssh_pubkey=None, network_device_type='virtio-net'):
> >          super(LinuxTest, self).setUp()
> >          self.vm.add_args('-smp', '2')
> >          self.vm.add_args('-m', '1024')
> > +        self.vm.add_args('-netdev', 'user,id=vnet,hostfwd=:127.0.0.1:0
> > -:22',
> > +                         '-device', '%s,netdev=vnet' %
> > network_device_type)
> >          self.set_up_boot()
> >          if ssh_pubkey is None:
> >              ssh_pubkey, self.ssh_key = self.set_up_existing_ssh_keys()
> > diff --git a/tests/acceptance/virtiofs_submounts.py
> > b/tests/acceptance/virtiofs_submounts.py
> > index bed8ce44df..e10a935ac4 100644
> > --- a/tests/acceptance/virtiofs_submounts.py
> > +++ b/tests/acceptance/virtiofs_submounts.py
> > @@ -207,10 +207,6 @@ def setUp(self):
> >              self.vm.add_args('-kernel', vmlinuz,
> >                               '-append', 'console=ttyS0 root=/dev/sda1')
> >
> > -        # Allow us to connect to SSH
> > -        self.vm.add_args('-netdev', 'user,id=vnet,hostfwd=:127.0.0.1:0
> > -:22',
> > -                         '-device', 'virtio-net,netdev=vnet')
> > -
> >          self.require_accelerator("kvm")
> >          self.vm.add_args('-accel', 'kvm')
> >
> > --
> > 2.25.4
> >
> >
> Looks fine, I suppose it could eventually be in LinuxSSHMixIn too for other
> users.
>

That's a good point, should be possible.  I'll look into that.

> Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
> 
> 
> -- 
> Marc-André Lureau

Thanks,
- Cleber.
Cleber Rosa March 24, 2021, 10:40 p.m. UTC | #7
On Wed, Mar 24, 2021 at 11:36:53AM +0100, Auger Eric wrote:
> Hi Cleber,
> On 3/23/21 11:15 PM, Cleber Rosa wrote:
> > For users of the LinuxTest class, let's set up the VM with the port
> > redirection for SSH, instead of requiring each test to set the same
> > arguments.
> > 
> > Signed-off-by: Cleber Rosa <crosa@redhat.com>
> > ---
> >  tests/acceptance/avocado_qemu/__init__.py | 4 +++-
> >  tests/acceptance/virtiofs_submounts.py    | 4 ----
> >  2 files changed, 3 insertions(+), 5 deletions(-)
> > 
> > diff --git a/tests/acceptance/avocado_qemu/__init__.py b/tests/acceptance/avocado_qemu/__init__.py
> > index 67f75f66e5..e75b002c70 100644
> > --- a/tests/acceptance/avocado_qemu/__init__.py
> > +++ b/tests/acceptance/avocado_qemu/__init__.py
> > @@ -309,10 +309,12 @@ class LinuxTest(Test, LinuxSSHMixIn):
> >      timeout = 900
> >      chksum = None
> >  
> > -    def setUp(self, ssh_pubkey=None):
> > +    def setUp(self, ssh_pubkey=None, network_device_type='virtio-net'):
> I would be interested in testing with HW bridging too, when a bridge is
> available. Do you think we could have the netdev configurable too?
> This would be helpful to test vhost for instance.
>

Right, I knew from the start that the user mode network would only
go so far.  TBH, I think it went too further than I expected.  But,
requiring, or supporting, other network modes can add quite a bit
of complexity, depending on how much you want the framework to do.

Anyway, this is a valid point/request.  For the lack of a better place,
and given that this may be a larger effort, I'm tracking it here:

  https://gitlab.com/cleber.gnu/qemu/-/issues/3

> With respect the network device type, I am currently working on SMMU
> test and I need to call the parent setUp-) with the following args now:
> 
> super(IOMMU, self).setUp(pubkey,
> 'virtio-net-pci,iommu_platform=on,disable-modern=off,disable-legacy=on')
> 
> It works but I am not sure you had such kind of scenario in mind?
>

I see where you're coming from, and I share the slight feeling of abusing
the feature... but I think it's OK at this point.  I mean, I believe it's
better to focus on say, the HW bridging support as this at least works.

> Thanks
> 
> Eric
>

Cheers,
- Cleber.
Wainer dos Santos Moschetta March 25, 2021, 5:57 p.m. UTC | #8
Hi,

On 3/24/21 6:10 AM, Auger Eric wrote:
> Hi Cleber,
>
> On 3/23/21 11:15 PM, Cleber Rosa wrote:
>> For users of the LinuxTest class, let's set up the VM with the port
>> redirection for SSH, instead of requiring each test to set the same
> also sets the network device to virtio-net. This may be worth mentioning
> here in the commit msg.
>> arguments.
>>
>> Signed-off-by: Cleber Rosa <crosa@redhat.com>
> Reviewed-by: Eric Auger <eric.auger@redhat.com>
>
> Thanks
>
> Eric
>
>> ---
>>   tests/acceptance/avocado_qemu/__init__.py | 4 +++-
>>   tests/acceptance/virtiofs_submounts.py    | 4 ----
>>   2 files changed, 3 insertions(+), 5 deletions(-)
>>
>> diff --git a/tests/acceptance/avocado_qemu/__init__.py b/tests/acceptance/avocado_qemu/__init__.py
>> index 67f75f66e5..e75b002c70 100644
>> --- a/tests/acceptance/avocado_qemu/__init__.py
>> +++ b/tests/acceptance/avocado_qemu/__init__.py
>> @@ -309,10 +309,12 @@ class LinuxTest(Test, LinuxSSHMixIn):
>>       timeout = 900
>>       chksum = None
>>   
>> -    def setUp(self, ssh_pubkey=None):
>> +    def setUp(self, ssh_pubkey=None, network_device_type='virtio-net'):
>>           super(LinuxTest, self).setUp()
>>           self.vm.add_args('-smp', '2')
>>           self.vm.add_args('-m', '1024')
>> +        self.vm.add_args('-netdev', 'user,id=vnet,hostfwd=:127.0.0.1:0-:22',
>> +                         '-device', '%s,netdev=vnet' % network_device_type)
>>           self.set_up_boot()
>>           if ssh_pubkey is None:
>>               ssh_pubkey, self.ssh_key = self.set_up_existing_ssh_keys()
>> diff --git a/tests/acceptance/virtiofs_submounts.py b/tests/acceptance/virtiofs_submounts.py
>> index bed8ce44df..e10a935ac4 100644
>> --- a/tests/acceptance/virtiofs_submounts.py
>> +++ b/tests/acceptance/virtiofs_submounts.py
>> @@ -207,10 +207,6 @@ def setUp(self):
>>               self.vm.add_args('-kernel', vmlinuz,
>>                                '-append', 'console=ttyS0 root=/dev/sda1')
>>   
>> -        # Allow us to connect to SSH

Somewhat related with Eric's suggestion: keep the above comment along 
with the netdev setup code.

- Wainer

>> -        self.vm.add_args('-netdev', 'user,id=vnet,hostfwd=:127.0.0.1:0-:22',
>> -                         '-device', 'virtio-net,netdev=vnet')
>> -
>>           self.require_accelerator("kvm")
>>           self.vm.add_args('-accel', 'kvm')
>>   
>>
>
Cleber Rosa April 12, 2021, 2:47 a.m. UTC | #9
On Thu, Mar 25, 2021 at 02:57:48PM -0300, Wainer dos Santos Moschetta wrote:
> Hi,
> 
> On 3/24/21 6:10 AM, Auger Eric wrote:
> > Hi Cleber,
> > 
> > On 3/23/21 11:15 PM, Cleber Rosa wrote:
> > > For users of the LinuxTest class, let's set up the VM with the port
> > > redirection for SSH, instead of requiring each test to set the same
> > also sets the network device to virtio-net. This may be worth mentioning
> > here in the commit msg.
> > > arguments.
> > > 
> > > Signed-off-by: Cleber Rosa <crosa@redhat.com>
> > Reviewed-by: Eric Auger <eric.auger@redhat.com>
> > 
> > Thanks
> > 
> > Eric
> > 
> > > ---
> > >   tests/acceptance/avocado_qemu/__init__.py | 4 +++-
> > >   tests/acceptance/virtiofs_submounts.py    | 4 ----
> > >   2 files changed, 3 insertions(+), 5 deletions(-)
> > > 
> > > diff --git a/tests/acceptance/avocado_qemu/__init__.py b/tests/acceptance/avocado_qemu/__init__.py
> > > index 67f75f66e5..e75b002c70 100644
> > > --- a/tests/acceptance/avocado_qemu/__init__.py
> > > +++ b/tests/acceptance/avocado_qemu/__init__.py
> > > @@ -309,10 +309,12 @@ class LinuxTest(Test, LinuxSSHMixIn):
> > >       timeout = 900
> > >       chksum = None
> > > -    def setUp(self, ssh_pubkey=None):
> > > +    def setUp(self, ssh_pubkey=None, network_device_type='virtio-net'):
> > >           super(LinuxTest, self).setUp()
> > >           self.vm.add_args('-smp', '2')
> > >           self.vm.add_args('-m', '1024')
> > > +        self.vm.add_args('-netdev', 'user,id=vnet,hostfwd=:127.0.0.1:0-:22',
> > > +                         '-device', '%s,netdev=vnet' % network_device_type)
> > >           self.set_up_boot()
> > >           if ssh_pubkey is None:
> > >               ssh_pubkey, self.ssh_key = self.set_up_existing_ssh_keys()
> > > diff --git a/tests/acceptance/virtiofs_submounts.py b/tests/acceptance/virtiofs_submounts.py
> > > index bed8ce44df..e10a935ac4 100644
> > > --- a/tests/acceptance/virtiofs_submounts.py
> > > +++ b/tests/acceptance/virtiofs_submounts.py
> > > @@ -207,10 +207,6 @@ def setUp(self):
> > >               self.vm.add_args('-kernel', vmlinuz,
> > >                                '-append', 'console=ttyS0 root=/dev/sda1')
> > > -        # Allow us to connect to SSH
> 
> Somewhat related with Eric's suggestion: keep the above comment along with
> the netdev setup code.
> 
> - Wainer
>

Sure, good point.

Thanks,
- Cleber.
diff mbox series

Patch

diff --git a/tests/acceptance/avocado_qemu/__init__.py b/tests/acceptance/avocado_qemu/__init__.py
index 67f75f66e5..e75b002c70 100644
--- a/tests/acceptance/avocado_qemu/__init__.py
+++ b/tests/acceptance/avocado_qemu/__init__.py
@@ -309,10 +309,12 @@  class LinuxTest(Test, LinuxSSHMixIn):
     timeout = 900
     chksum = None
 
-    def setUp(self, ssh_pubkey=None):
+    def setUp(self, ssh_pubkey=None, network_device_type='virtio-net'):
         super(LinuxTest, self).setUp()
         self.vm.add_args('-smp', '2')
         self.vm.add_args('-m', '1024')
+        self.vm.add_args('-netdev', 'user,id=vnet,hostfwd=:127.0.0.1:0-:22',
+                         '-device', '%s,netdev=vnet' % network_device_type)
         self.set_up_boot()
         if ssh_pubkey is None:
             ssh_pubkey, self.ssh_key = self.set_up_existing_ssh_keys()
diff --git a/tests/acceptance/virtiofs_submounts.py b/tests/acceptance/virtiofs_submounts.py
index bed8ce44df..e10a935ac4 100644
--- a/tests/acceptance/virtiofs_submounts.py
+++ b/tests/acceptance/virtiofs_submounts.py
@@ -207,10 +207,6 @@  def setUp(self):
             self.vm.add_args('-kernel', vmlinuz,
                              '-append', 'console=ttyS0 root=/dev/sda1')
 
-        # Allow us to connect to SSH
-        self.vm.add_args('-netdev', 'user,id=vnet,hostfwd=:127.0.0.1:0-:22',
-                         '-device', 'virtio-net,netdev=vnet')
-
         self.require_accelerator("kvm")
         self.vm.add_args('-accel', 'kvm')