[PATCH 11/22] tests/functional: switch over to using self.data_file(...)

Daniel P. Berrangé posted 22 patches 3 weeks, 5 days ago
There is a newer version of this series
[PATCH 11/22] tests/functional: switch over to using self.data_file(...)
Posted by Daniel P. Berrangé 3 weeks, 5 days ago
This removes direct path manipulation to figure out the source dir

Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
---
 tests/functional/test_acpi_bits.py | 22 +++++++---------------
 1 file changed, 7 insertions(+), 15 deletions(-)

diff --git a/tests/functional/test_acpi_bits.py b/tests/functional/test_acpi_bits.py
index 4de5fae37e..948b134b16 100755
--- a/tests/functional/test_acpi_bits.py
+++ b/tests/functional/test_acpi_bits.py
@@ -41,7 +41,6 @@
 import tempfile
 import zipfile
 
-from pathlib import Path
 from typing import (
     List,
     Optional,
@@ -122,7 +121,6 @@ class AcpiBitsTest(QemuBaseTest): #pylint: disable=too-many-instance-attributes
     def __init__(self, *args, **kwargs):
         super().__init__(*args, **kwargs)
         self._vm = None
-        self._baseDir = None
 
         self._debugcon_addr = '0x403'
         self._debugcon_log = 'debugcon-log.txt'
@@ -137,26 +135,22 @@ def _print_log(self, log):
     def copy_bits_config(self):
         """ copies the bios bits config file into bits.
         """
-        config_file = 'bits-cfg.txt'
-        bits_config_dir = os.path.join(self._baseDir, 'acpi-bits',
-                                       'bits-config')
+        bits_config_file = self.data_file('acpi-bits',
+                                          'bits-config',
+                                          'bits-cfg.txt')
         target_config_dir = os.path.join(self.workdir,
                                          'bits-%d' %self.BITS_INTERNAL_VER,
                                          'boot')
-        self.assertTrue(os.path.exists(bits_config_dir))
+        self.assertTrue(os.path.exists(bits_config_file))
         self.assertTrue(os.path.exists(target_config_dir))
-        self.assertTrue(os.access(os.path.join(bits_config_dir,
-                                               config_file), os.R_OK))
-        shutil.copy2(os.path.join(bits_config_dir, config_file),
-                     target_config_dir)
+        shutil.copy2(bits_config_file, target_config_dir)
         self.logger.info('copied config file %s to %s',
-                         config_file, target_config_dir)
+                         bits_config_file, target_config_dir)
 
     def copy_test_scripts(self):
         """copies the python test scripts into bits. """
 
-        bits_test_dir = os.path.join(self._baseDir, 'acpi-bits',
-                                     'bits-tests')
+        bits_test_dir = self.data_file('acpi-bits', 'bits-tests')
         target_test_dir = os.path.join(self.workdir,
                                        'bits-%d' %self.BITS_INTERNAL_VER,
                                        'boot', 'python')
@@ -259,8 +253,6 @@ def setUp(self): # pylint: disable=arguments-differ
         super().setUp('qemu-system-')
         self.logger = self.log
 
-        self._baseDir = Path(__file__).parent
-
         prebuiltDir = os.path.join(self.workdir, 'prebuilt')
         if not os.path.isdir(prebuiltDir):
             os.mkdir(prebuiltDir, mode=0o775)
-- 
2.46.0


Re: [PATCH 11/22] tests/functional: switch over to using self.data_file(...)
Posted by Thomas Huth 3 weeks, 3 days ago
On 29/11/2024 18.31, Daniel P. Berrangé wrote:
> This removes direct path manipulation to figure out the source dir
> 
> Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
> ---
>   tests/functional/test_acpi_bits.py | 22 +++++++---------------
>   1 file changed, 7 insertions(+), 15 deletions(-)
> 
> diff --git a/tests/functional/test_acpi_bits.py b/tests/functional/test_acpi_bits.py
> index 4de5fae37e..948b134b16 100755
> --- a/tests/functional/test_acpi_bits.py
> +++ b/tests/functional/test_acpi_bits.py
> @@ -41,7 +41,6 @@
>   import tempfile
>   import zipfile
>   
> -from pathlib import Path
>   from typing import (
>       List,
>       Optional,
> @@ -122,7 +121,6 @@ class AcpiBitsTest(QemuBaseTest): #pylint: disable=too-many-instance-attributes
>       def __init__(self, *args, **kwargs):
>           super().__init__(*args, **kwargs)
>           self._vm = None
> -        self._baseDir = None
>   
>           self._debugcon_addr = '0x403'
>           self._debugcon_log = 'debugcon-log.txt'
> @@ -137,26 +135,22 @@ def _print_log(self, log):
>       def copy_bits_config(self):
>           """ copies the bios bits config file into bits.
>           """
> -        config_file = 'bits-cfg.txt'
> -        bits_config_dir = os.path.join(self._baseDir, 'acpi-bits',
> -                                       'bits-config')
> +        bits_config_file = self.data_file('acpi-bits',
> +                                          'bits-config',
> +                                          'bits-cfg.txt')
>           target_config_dir = os.path.join(self.workdir,
>                                            'bits-%d' %self.BITS_INTERNAL_VER,
>                                            'boot')
> -        self.assertTrue(os.path.exists(bits_config_dir))
> +        self.assertTrue(os.path.exists(bits_config_file))
>           self.assertTrue(os.path.exists(target_config_dir))
> -        self.assertTrue(os.access(os.path.join(bits_config_dir,
> -                                               config_file), os.R_OK))
> -        shutil.copy2(os.path.join(bits_config_dir, config_file),
> -                     target_config_dir)
> +        shutil.copy2(bits_config_file, target_config_dir)
>           self.logger.info('copied config file %s to %s',
> -                         config_file, target_config_dir)
> +                         bits_config_file, target_config_dir)
>   
>       def copy_test_scripts(self):
>           """copies the python test scripts into bits. """
>   
> -        bits_test_dir = os.path.join(self._baseDir, 'acpi-bits',
> -                                     'bits-tests')
> +        bits_test_dir = self.data_file('acpi-bits', 'bits-tests')
>           target_test_dir = os.path.join(self.workdir,
>                                          'bits-%d' %self.BITS_INTERNAL_VER,
>                                          'boot', 'python')
> @@ -259,8 +253,6 @@ def setUp(self): # pylint: disable=arguments-differ
>           super().setUp('qemu-system-')
>           self.logger = self.log
>   
> -        self._baseDir = Path(__file__).parent
> -
>           prebuiltDir = os.path.join(self.workdir, 'prebuilt')
>           if not os.path.isdir(prebuiltDir):
>               os.mkdir(prebuiltDir, mode=0o775)

Reviewed-by: Thomas Huth <thuth@redhat.com>


Re: [PATCH 11/22] tests/functional: switch over to using self.data_file(...)
Posted by Ani Sinha 3 weeks, 2 days ago
On Mon, Dec 2, 2024 at 3:02 PM Thomas Huth <thuth@redhat.com> wrote:
>
> On 29/11/2024 18.31, Daniel P. Berrangé wrote:
> > This removes direct path manipulation to figure out the source dir
> >
> > Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
> > ---
> >   tests/functional/test_acpi_bits.py | 22 +++++++---------------
> >   1 file changed, 7 insertions(+), 15 deletions(-)
> >
> > diff --git a/tests/functional/test_acpi_bits.py b/tests/functional/test_acpi_bits.py
> > index 4de5fae37e..948b134b16 100755
> > --- a/tests/functional/test_acpi_bits.py
> > +++ b/tests/functional/test_acpi_bits.py
> > @@ -41,7 +41,6 @@
> >   import tempfile
> >   import zipfile
> >
> > -from pathlib import Path
> >   from typing import (
> >       List,
> >       Optional,
> > @@ -122,7 +121,6 @@ class AcpiBitsTest(QemuBaseTest): #pylint: disable=too-many-instance-attributes
> >       def __init__(self, *args, **kwargs):
> >           super().__init__(*args, **kwargs)
> >           self._vm = None
> > -        self._baseDir = None
> >
> >           self._debugcon_addr = '0x403'
> >           self._debugcon_log = 'debugcon-log.txt'
> > @@ -137,26 +135,22 @@ def _print_log(self, log):
> >       def copy_bits_config(self):
> >           """ copies the bios bits config file into bits.
> >           """
> > -        config_file = 'bits-cfg.txt'
> > -        bits_config_dir = os.path.join(self._baseDir, 'acpi-bits',
> > -                                       'bits-config')
> > +        bits_config_file = self.data_file('acpi-bits',

I do not understand, Where is data_file coming from? AFAICS its not
there in QemuBaseTest or QemuSystemTest or unittest.TestCase
https://docs.python.org/3/library/unittest.html#unittest.TestCase

what am I missing or failing to see?
Re: [PATCH 11/22] tests/functional: switch over to using self.data_file(...)
Posted by Daniel P. Berrangé 3 weeks, 2 days ago
On Tue, Dec 03, 2024 at 11:09:14AM +0530, Ani Sinha wrote:
> On Mon, Dec 2, 2024 at 3:02 PM Thomas Huth <thuth@redhat.com> wrote:
> >
> > On 29/11/2024 18.31, Daniel P. Berrangé wrote:
> > > This removes direct path manipulation to figure out the source dir
> > >
> > > Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
> > > ---
> > >   tests/functional/test_acpi_bits.py | 22 +++++++---------------
> > >   1 file changed, 7 insertions(+), 15 deletions(-)
> > >
> > > diff --git a/tests/functional/test_acpi_bits.py b/tests/functional/test_acpi_bits.py
> > > index 4de5fae37e..948b134b16 100755
> > > --- a/tests/functional/test_acpi_bits.py
> > > +++ b/tests/functional/test_acpi_bits.py
> > > @@ -41,7 +41,6 @@
> > >   import tempfile
> > >   import zipfile
> > >
> > > -from pathlib import Path
> > >   from typing import (
> > >       List,
> > >       Optional,
> > > @@ -122,7 +121,6 @@ class AcpiBitsTest(QemuBaseTest): #pylint: disable=too-many-instance-attributes
> > >       def __init__(self, *args, **kwargs):
> > >           super().__init__(*args, **kwargs)
> > >           self._vm = None
> > > -        self._baseDir = None
> > >
> > >           self._debugcon_addr = '0x403'
> > >           self._debugcon_log = 'debugcon-log.txt'
> > > @@ -137,26 +135,22 @@ def _print_log(self, log):
> > >       def copy_bits_config(self):
> > >           """ copies the bios bits config file into bits.
> > >           """
> > > -        config_file = 'bits-cfg.txt'
> > > -        bits_config_dir = os.path.join(self._baseDir, 'acpi-bits',
> > > -                                       'bits-config')
> > > +        bits_config_file = self.data_file('acpi-bits',
> 
> I do not understand, Where is data_file coming from? AFAICS its not
> there in QemuBaseTest or QemuSystemTest or unittest.TestCase
> https://docs.python.org/3/library/unittest.html#unittest.TestCase
> 
> what am I missing or failing to see?

It is coming from patch 6 :-)

With regards,
Daniel
-- 
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|


Re: [PATCH 11/22] tests/functional: switch over to using self.data_file(...)
Posted by Thomas Huth 3 weeks, 2 days ago
On 03/12/2024 09.11, Daniel P. Berrangé wrote:
> On Tue, Dec 03, 2024 at 11:09:14AM +0530, Ani Sinha wrote:
>> On Mon, Dec 2, 2024 at 3:02 PM Thomas Huth <thuth@redhat.com> wrote:
>>>
>>> On 29/11/2024 18.31, Daniel P. Berrangé wrote:
>>>> This removes direct path manipulation to figure out the source dir
>>>>
>>>> Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
>>>> ---
>>>>    tests/functional/test_acpi_bits.py | 22 +++++++---------------
>>>>    1 file changed, 7 insertions(+), 15 deletions(-)
>>>>
>>>> diff --git a/tests/functional/test_acpi_bits.py b/tests/functional/test_acpi_bits.py
>>>> index 4de5fae37e..948b134b16 100755
>>>> --- a/tests/functional/test_acpi_bits.py
>>>> +++ b/tests/functional/test_acpi_bits.py
>>>> @@ -41,7 +41,6 @@
>>>>    import tempfile
>>>>    import zipfile
>>>>
>>>> -from pathlib import Path
>>>>    from typing import (
>>>>        List,
>>>>        Optional,
>>>> @@ -122,7 +121,6 @@ class AcpiBitsTest(QemuBaseTest): #pylint: disable=too-many-instance-attributes
>>>>        def __init__(self, *args, **kwargs):
>>>>            super().__init__(*args, **kwargs)
>>>>            self._vm = None
>>>> -        self._baseDir = None
>>>>
>>>>            self._debugcon_addr = '0x403'
>>>>            self._debugcon_log = 'debugcon-log.txt'
>>>> @@ -137,26 +135,22 @@ def _print_log(self, log):
>>>>        def copy_bits_config(self):
>>>>            """ copies the bios bits config file into bits.
>>>>            """
>>>> -        config_file = 'bits-cfg.txt'
>>>> -        bits_config_dir = os.path.join(self._baseDir, 'acpi-bits',
>>>> -                                       'bits-config')
>>>> +        bits_config_file = self.data_file('acpi-bits',
>>
>> I do not understand, Where is data_file coming from? AFAICS its not
>> there in QemuBaseTest or QemuSystemTest or unittest.TestCase
>> https://docs.python.org/3/library/unittest.html#unittest.TestCase
>>
>> what am I missing or failing to see?
> 
> It is coming from patch 6 :-)

Sorry, my bad, I put Ani just on CC: for this patch here, but he was not on 
CC: on the others :-/

  Thomas


Re: [PATCH 11/22] tests/functional: switch over to using self.data_file(...)
Posted by Ani Sinha 3 weeks, 2 days ago
On Tue, Dec 3, 2024 at 2:20 PM Thomas Huth <thuth@redhat.com> wrote:
>
> On 03/12/2024 09.11, Daniel P. Berrangé wrote:
> > On Tue, Dec 03, 2024 at 11:09:14AM +0530, Ani Sinha wrote:
> >> On Mon, Dec 2, 2024 at 3:02 PM Thomas Huth <thuth@redhat.com> wrote:
> >>>
> >>> On 29/11/2024 18.31, Daniel P. Berrangé wrote:
> >>>> This removes direct path manipulation to figure out the source dir
> >>>>
> >>>> Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
> >>>> ---
> >>>>    tests/functional/test_acpi_bits.py | 22 +++++++---------------
> >>>>    1 file changed, 7 insertions(+), 15 deletions(-)
> >>>>
> >>>> diff --git a/tests/functional/test_acpi_bits.py b/tests/functional/test_acpi_bits.py
> >>>> index 4de5fae37e..948b134b16 100755
> >>>> --- a/tests/functional/test_acpi_bits.py
> >>>> +++ b/tests/functional/test_acpi_bits.py
> >>>> @@ -41,7 +41,6 @@
> >>>>    import tempfile
> >>>>    import zipfile
> >>>>
> >>>> -from pathlib import Path
> >>>>    from typing import (
> >>>>        List,
> >>>>        Optional,
> >>>> @@ -122,7 +121,6 @@ class AcpiBitsTest(QemuBaseTest): #pylint: disable=too-many-instance-attributes
> >>>>        def __init__(self, *args, **kwargs):
> >>>>            super().__init__(*args, **kwargs)
> >>>>            self._vm = None
> >>>> -        self._baseDir = None
> >>>>
> >>>>            self._debugcon_addr = '0x403'
> >>>>            self._debugcon_log = 'debugcon-log.txt'
> >>>> @@ -137,26 +135,22 @@ def _print_log(self, log):
> >>>>        def copy_bits_config(self):
> >>>>            """ copies the bios bits config file into bits.
> >>>>            """
> >>>> -        config_file = 'bits-cfg.txt'
> >>>> -        bits_config_dir = os.path.join(self._baseDir, 'acpi-bits',
> >>>> -                                       'bits-config')
> >>>> +        bits_config_file = self.data_file('acpi-bits',
> >>
> >> I do not understand, Where is data_file coming from? AFAICS its not
> >> there in QemuBaseTest or QemuSystemTest or unittest.TestCase
> >> https://docs.python.org/3/library/unittest.html#unittest.TestCase
> >>
> >> what am I missing or failing to see?
> >
> > It is coming from patch 6 :-)
>
> Sorry, my bad, I put Ani just on CC: for this patch here, but he was not on
> CC: on the others :-/

Now it all makes sense :-)

>
>   Thomas
>