diff mbox series

[autotest-client-tests] UBUNTU: SAUCE: ubuntu_qrt_apparmor: on Groovy+, invoke the test using python3

Message ID 20200907151714.66629-1-paolo.pisati@canonical.com
State New
Headers show
Series [autotest-client-tests] UBUNTU: SAUCE: ubuntu_qrt_apparmor: on Groovy+, invoke the test using python3 | expand

Commit Message

Paolo Pisati Sept. 7, 2020, 3:17 p.m. UTC
BugLink: https://bugs.launchpad.net/bugs/1890771

Fix the:

The test will fail with:
  ImportError: No module named pexpect

error when invoked on Groovy+.

Signed-off-by: Paolo Pisati <paolo.pisati@canonical.com>
---
 ubuntu_qrt_apparmor/ubuntu_qrt_apparmor.py | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

Comments

Po-Hsu Lin Sept. 8, 2020, 9:30 a.m. UTC | #1
One small note, platform.dist() has been deprecated since python 3.5
Since we might need to migrate from python2 to python3 for our testing
infrastructure one day in the future, for the long term perspective
it's safter to use the following:

   try:
       series = platform.dist()[2]
   except AttributeError:
       import distro
       series = distro.codename()

Thanks for the fix, ACK'd, applied and pushed.
Sam
Paolo Pisati Sept. 8, 2020, 2:15 p.m. UTC | #2
On Tue, Sep 8, 2020 at 11:30 AM Po-Hsu Lin <po-hsu.lin@canonical.com> wrote:
>
> One small note, platform.dist() has been deprecated since python 3.5
> Since we might need to migrate from python2 to python3 for our testing
> infrastructure one day in the future, for the long term perspective
> it's safter to use the following:
>
>    try:
>        series = platform.dist()[2]
>    except AttributeError:
>        import distro
>        series = distro.codename()

Good to know, thanks.
diff mbox series

Patch

diff --git a/ubuntu_qrt_apparmor/ubuntu_qrt_apparmor.py b/ubuntu_qrt_apparmor/ubuntu_qrt_apparmor.py
index 27b5d1a1..c7a24dcc 100644
--- a/ubuntu_qrt_apparmor/ubuntu_qrt_apparmor.py
+++ b/ubuntu_qrt_apparmor/ubuntu_qrt_apparmor.py
@@ -78,7 +78,12 @@  class ubuntu_qrt_apparmor(test.test):
         if test_name == 'setup':
             return
 
-        cmd = 'python2 ./%s -v' % test_name
+        inter = 'python3'
+        series = platform.dist()[2]
+        if series in ['precise', 'trusty', 'xenial', 'bionic', 'focal']:
+            inter = 'python2'
+
+        cmd = '%s ./%s -v' % (inter, test_name)
         self.results = utils.system_output(cmd, retain_output=True)