Update to Python3 82/67782/4
authorCédric Ollivier <cedric.ollivier@orange.com>
Tue, 7 May 2019 08:42:23 +0000 (10:42 +0200)
committerCédric Ollivier <cedric.ollivier@orange.com>
Tue, 7 May 2019 12:44:14 +0000 (14:44 +0200)
Now Xtesting containers use Python3 instead of python2.
https://mail.python.org/pipermail/python-dev/2018-March/152348.html

It also updates robotframework to latest release.

Change-Id: I57e0d8b1af9aeaae0c445941a9bdf0b8bd346834
Signed-off-by: Cédric Ollivier <cedric.ollivier@orange.com>
docker/Dockerfile
docker/testcases.yaml
upper-constraints.txt
xtesting/ci/testcases.yaml
xtesting/core/feature.py
xtesting/core/unit.py
xtesting/tests/unit/core/test_unit.py

index 310ec86..e6d9537 100644 (file)
@@ -3,18 +3,18 @@ FROM alpine:3.9
 ARG BRANCH=master
 ARG OPENSTACK_TAG=master
 
-RUN apk --no-cache add --update python py-pip bash git && \
+RUN apk --no-cache add --update python3 bash git && \
     apk --no-cache add --virtual .build-deps --update \
-        python-dev build-base && \
+        python3-dev build-base && \
     git init /src/functest-xtesting && \
     (cd /src/functest-xtesting && \
         git fetch --tags https://gerrit.opnfv.org/gerrit/functest-xtesting $BRANCH && \
         git checkout FETCH_HEAD) && \
-    pip install --no-cache-dir --src /src \
+    pip3 install --no-cache-dir --src /src \
         -chttps://opendev.org/openstack/requirements/raw/branch/$OPENSTACK_TAG/upper-constraints.txt \
         -chttps://git.opnfv.org/functest-xtesting/plain/upper-constraints.txt?h=$BRANCH \
         /src/functest-xtesting && \
     rm -r /src/functest-xtesting && \
     apk del .build-deps
-COPY testcases.yaml /usr/lib/python2.7/site-packages/xtesting/ci/testcases.yaml
+COPY testcases.yaml /usr/lib/python3.6/site-packages/xtesting/ci/testcases.yaml
 CMD ["run_tests", "-t", "all"]
index 6b787d2..0738e0d 100644 (file)
@@ -60,7 +60,7 @@ tiers:
                     name: 'robotframework'
                     args:
                         suites:
-                            - /usr/lib/python2.7/site-packages/xtesting/samples/HelloWorld.txt
+                            - /usr/lib/python3.6/site-packages/xtesting/samples/HelloWorld.txt
                         variable:
                             - 'var01:foo'
                             - 'var02:bar'
index a884d02..2ef2671 100644 (file)
@@ -1 +1 @@
-robotframework===3.0.2
+robotframework===3.1.1
index 8113718..b32a45f 100644 (file)
@@ -61,7 +61,7 @@ tiers:
                     name: 'robotframework'
                     args:
                         suites:
-                            - /usr/lib/python2.7/site-packages/xtesting/samples/HelloWorld.txt
+                            - /usr/lib/python3.6/site-packages/xtesting/samples/HelloWorld.txt
                         variable:
                             - 'var01:foo'
                             - 'var02:bar'
index 2730179..f28e720 100644 (file)
@@ -111,10 +111,10 @@ class BashFeature(Feature):
                 process = subprocess.Popen(
                     cmd, shell=True, stdout=subprocess.PIPE,
                     stderr=subprocess.STDOUT)
-                for line in iter(process.stdout.readline, ''):
+                for line in iter(process.stdout.readline, b''):
                     if console:
-                        sys.stdout.write(line)
-                    f_stdout.write(line)
+                        sys.stdout.write(line.decode("utf-8"))
+                    f_stdout.write(line.decode("utf-8"))
                 process.wait()
             with open(self.result_file, 'r') as f_stdin:
                 self.__logger.debug("$ %s\n%s", cmd, f_stdin.read().rstrip())
index f874d01..774411a 100644 (file)
@@ -48,7 +48,7 @@ class Suite(testcase.TestCase):
         stats = subprocess.Popen(
             ['subunit-stats'], stdin=subprocess.PIPE, stdout=subprocess.PIPE)
         output, _ = stats.communicate(stream.read())
-        cls.__logger.info("\n\n%s", output)
+        cls.__logger.info("\n\n%s", output.decode("utf-8"))
 
     def generate_xunit(self, stream):
         """Generate junit report from subunit stream
@@ -62,7 +62,7 @@ class Suite(testcase.TestCase):
                 ['subunit2junitxml'], stdin=subprocess.PIPE,
                 stdout=subprocess.PIPE)
             output, _ = stats.communicate(stream.read())
-            xml.write(output)
+            xml.write(output.decode("utf-8"))
 
     def generate_html(self, stream):
         """Generate html report from subunit stream
@@ -113,12 +113,12 @@ class Suite(testcase.TestCase):
             self.start_time = time.time()
             if not os.path.isdir(self.res_dir):
                 os.makedirs(self.res_dir)
-            stream = six.StringIO()
+            stream = six.BytesIO()
             result = SubunitTestRunner(
                 stream=stream, verbosity=2).run(self.suite).decorated
             self.generate_stats(stream)
             self.generate_xunit(stream)
-            with open('{}/subunit_stream'.format(self.res_dir), 'w') as subfd:
+            with open('{}/subunit_stream'.format(self.res_dir), 'wb') as subfd:
                 stream.seek(0)
                 shutil.copyfileobj(stream, subfd)
             self.generate_html('{}/subunit_stream'.format(self.res_dir))
index 20fd695..0af3ddc 100644 (file)
@@ -59,7 +59,7 @@ class SuiteTesting(unittest.TestCase):
                 return_value=mock.Mock(
                     communicate=mock.Mock(return_value=("foo", "bar"))))
     def test_generate_xunit_ok(self, *args):
-        stream = six.StringIO()
+        stream = six.BytesIO()
         with mock.patch('six.moves.builtins.open',
                         mock.mock_open()) as mock_open:
             self.psrunner.generate_xunit(stream)
@@ -96,7 +96,7 @@ class SuiteTesting(unittest.TestCase):
         with mock.patch('six.moves.builtins.open', mock.mock_open()) as m_open:
             self.assertEqual(self.psrunner.run(), status)
         m_open.assert_called_once_with(
-            '{}/subunit_stream'.format(self.psrunner.res_dir), 'w')
+            '{}/subunit_stream'.format(self.psrunner.res_dir), 'wb')
         self.assertEqual(self.psrunner.is_successful(), result)
         args[0].assert_called_once_with(self.psrunner.suite)
         args[1].assert_not_called()
@@ -115,7 +115,7 @@ class SuiteTesting(unittest.TestCase):
         with mock.patch('six.moves.builtins.open', mock.mock_open()) as m_open:
             self.assertEqual(self.psrunner.run(name=name), status)
         m_open.assert_called_once_with(
-            '{}/subunit_stream'.format(self.psrunner.res_dir), 'w')
+            '{}/subunit_stream'.format(self.psrunner.res_dir), 'wb')
         self.assertEqual(self.psrunner.is_successful(), result)
         args[0].assert_called_once_with(self.psrunner.suite)
         args[1].assert_called_once_with()