[PATCH 6/9] tests/avocado/virtiofs_submounts.py: shared_dir may not exist

Cleber Rosa posted 9 patches 3 years, 11 months ago
Maintainers: "Alex Bennée" <alex.bennee@linaro.org>, "Philippe Mathieu-Daudé" <f4bug@amsat.org>, Thomas Huth <thuth@redhat.com>, Wainer dos Santos Moschetta <wainersm@redhat.com>, Beraldo Leal <bleal@redhat.com>, Cleber Rosa <crosa@redhat.com>, Aurelien Jarno <aurelien@aurel32.net>, Antony Pavlov <antonynpavlov@gmail.com>, Peter Maydell <peter.maydell@linaro.org>, Michael Rolnik <mrolnik@gmail.com>, "Edgar E. Iglesias" <edgar.iglesias@gmail.com>, Huacai Chen <chenhuacai@kernel.org>, Jiaxun Yang <jiaxun.yang@flygoat.com>, Yoshinori Sato <ysato@users.sourceforge.jp>, Halil Pasic <pasic@linux.ibm.com>, Christian Borntraeger <borntraeger@linux.ibm.com>, Eric Farman <farman@linux.ibm.com>, Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>, Fabien Chouteau <chouteau@adacore.com>, KONRAD Frederic <frederic.konrad@adacore.com>, "Hervé Poussineau" <hpoussin@reactos.org>, "Cédric Le Goater" <clg@kaod.org>, Daniel Henrique Barboza <danielhb413@gmail.com>, David Gibson <david@gibson.dropbear.id.au>, Greg Kurz <groug@kaod.org>, Pavel Dovgalyuk <pavel.dovgaluk@ispras.ru>, Paolo Bonzini <pbonzini@redhat.com>, Eric Auger <eric.auger@redhat.com>, Alexandre Iooss <erdnaxe@crans.org>, Mahmoud Mandour <ma.mandourr@gmail.com>
[PATCH 6/9] tests/avocado/virtiofs_submounts.py: shared_dir may not exist
Posted by Cleber Rosa 3 years, 11 months ago
If the test is skipped because of their conditionals, the shared_dir
attribute may not exist.

Check for its existence in the tearDown() method to avoid and
AttributeError.

Signed-off-by: Cleber Rosa <crosa@redhat.com>
---
 tests/avocado/virtiofs_submounts.py | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/tests/avocado/virtiofs_submounts.py b/tests/avocado/virtiofs_submounts.py
index e6dc32ffd4..d9c2c9d9ef 100644
--- a/tests/avocado/virtiofs_submounts.py
+++ b/tests/avocado/virtiofs_submounts.py
@@ -157,9 +157,10 @@ def tearDown(self):
         except:
             pass
 
-        scratch_dir = os.path.join(self.shared_dir, 'scratch')
-        self.run(('bash', self.get_data('cleanup.sh'), scratch_dir),
-                 ignore_error=True)
+        if hasattr(self, 'shared_dir'):
+            scratch_dir = os.path.join(self.shared_dir, 'scratch')
+            self.run(('bash', self.get_data('cleanup.sh'), scratch_dir),
+                     ignore_error=True)
 
     def test_pre_virtiofsd_set_up(self):
         self.set_up_shared_dir()
-- 
2.35.1


Re: [PATCH 6/9] tests/avocado/virtiofs_submounts.py: shared_dir may not exist
Posted by Beraldo Leal 3 years, 11 months ago
On Fri, Feb 25, 2022 at 04:01:53PM -0500, Cleber Rosa wrote:
> If the test is skipped because of their conditionals, the shared_dir
> attribute may not exist.
> 
> Check for its existence in the tearDown() method to avoid and
> AttributeError.
> 
> Signed-off-by: Cleber Rosa <crosa@redhat.com>
> ---
>  tests/avocado/virtiofs_submounts.py | 7 ++++---
>  1 file changed, 4 insertions(+), 3 deletions(-)
> 
> diff --git a/tests/avocado/virtiofs_submounts.py b/tests/avocado/virtiofs_submounts.py
> index e6dc32ffd4..d9c2c9d9ef 100644
> --- a/tests/avocado/virtiofs_submounts.py
> +++ b/tests/avocado/virtiofs_submounts.py
> @@ -157,9 +157,10 @@ def tearDown(self):
>          except:
>              pass
>  
> -        scratch_dir = os.path.join(self.shared_dir, 'scratch')
> -        self.run(('bash', self.get_data('cleanup.sh'), scratch_dir),
> -                 ignore_error=True)
> +        if hasattr(self, 'shared_dir'):
> +            scratch_dir = os.path.join(self.shared_dir, 'scratch')
> +            self.run(('bash', self.get_data('cleanup.sh'), scratch_dir),
> +                     ignore_error=True)
>  
>      def test_pre_virtiofsd_set_up(self):
>          self.set_up_shared_dir()

Reviewed-by: Beraldo Leal <bleal@redhat.com>

--
Beraldo