Zuul error "cannot import name 'Mapping' from 'collections'"

Bug #2017719 reported by Kenta Fukaya
This bug affects 1 person
Affects Status Importance Assigned to Milestone
In Progress
Navum Gupta

Bug Description

Zuul raised the error "cannot import name 'Mapping' from 'collections'",
when I run FT(function test) that tacker-compliance-devstack-multinode-sol[1].
This FT causes this error including code that can only run on python3.9 or lower.

The Robotframework used in this FT calls "from collections import Mapping",[2]
but this code can only be used with Python 3.9 or lower.
If you use Python 3.10+,
this program should call 'from collections.abc import Mapping'.

However, the latest version of the robotframework fixes this error,
but this FT uses version 3.1[3][4].

We can choose two methods to fix this error.
1. Downgrade Python 3.9 or lower running in zuul.
2. Upgrade the Robotframework.

[1] https://zuul.opendev.org/t/openstack/build/821d9e0ca36b46ad8113c8a1d02b9ce3
[2] https://github.com/robotframework/robotframework/blob/v3.1/src/robot/utils/robottypes3.py#L16
[3] https://github.com/openstack/tacker/blob/master/tox.ini#L127
[4] https://forge.etsi.org/rep/nfv/api-tests/-/blob/2.6.1-fix-plu/requirements.txt#L8

error log

  from .misc import plural_or_not
  File "/home/zuul/src/opendev.org/openstack/tacker/.tox/dsvm-compliance-sol-api/lib/python3.10/site-packages/robot/utils/misc.py", line 21, in <module>
    from .robottypes import is_integer
  File "/home/zuul/src/opendev.org/openstack/tacker/.tox/dsvm-compliance-sol-api/lib/python3.10/site-packages/robot/utils/robottypes.py", line 25, in <module>
    from .robottypes3 import (is_bytes, is_dict_like, is_integer, is_list_like,
  File "/home/zuul/src/opendev.org/openstack/tacker/.tox/dsvm-compliance-sol-api/lib/python3.10/site-packages/robot/utils/robottypes3.py", line 16, in <module>
    from collections import Mapping, UserString
ImportError: cannot import name 'Mapping' from 'collections' (/usr/lib/python3.10/collections/__init__.py)

Ran: 3 tests in 0.0022 sec.
 - Passed: 0
 - Skipped: 0
 - Expected Fail: 0
 - Unexpected Success: 0
 - Failed: 3
Sum of execute time for each test: 0.0004 sec.

Worker Balance
 - Worker 0 (3 tests) => 0:00:00.002190
Test id Runtime (s)
----------------------------------------------------------------------- -----------
unittest.loader._FailedTest.tacker.tests.compliance.sol002.test_vnflcm 0.000
unittest.loader._FailedTest.tacker.tests.compliance.sol003.test_vnflcm 0.000
unittest.loader._FailedTest.tacker.tests.compliance.sol005.test_vnfpkgm 0.000
dsvm-compliance-sol-api: 44008 C exit 1 (0.75 seconds) /home/zuul/src/opendev.org/openstack/tacker/.tox/dsvm-compliance-sol-api> stestr --test-path=/home/zuul/src/opendev.org/openstack/tacker/tacker/tests/compliance --top-dir=/home/zuul/src/opendev.org/openstack/tacker run --slowest --concurrency 1 pid=30208 [tox/execute/api.py:275]
dsvm-compliance-sol-api: 44008 W commands_post[0] /home/zuul/src/opendev.org/openstack/tacker/.tox/dsvm-compliance-sol-api> rm -rf api-tests [tox/tox_env/api.py:428]
dsvm-compliance-sol-api: 44043 I exit 0 (0.03 seconds) /home/zuul/src/opendev.org/openstack/tacker/.tox/dsvm-compliance-sol-api> rm -rf api-tests pid=30240 [tox/execute/api.py:275]
.pkg: 44044 W _exit> python /usr/local/lib/python3.10/dist-packages/pyproject_api/_backend.py True setuptools.build_meta __legacy__ [tox/tox_env/api.py:428]
Backend: run command _exit with args {}
Backend: Wrote response {'return': 0} to /tmp/pep517__exit-u9qnqvzf.json
.pkg: 44046 I exit None (0.00 seconds) /home/zuul/src/opendev.org/openstack/tacker> python /usr/local/lib/python3.10/dist-packages/pyproject_api/_backend.py True setuptools.build_meta __legacy__ pid=29133 [tox/execute/api.py:275]
.pkg: 44119 D delete package /home/zuul/src/opendev.org/openstack/tacker/.tox/.tmp/package/2/tacker-9.1.0.dev8-0.editable-py3-none-any.whl [tox/tox_env/python/virtual_env/package/pyproject.py:179]
  dsvm-compliance-sol-api: FAIL code 1 (43.59=setup[4.50]+cmd[19.69,0.19,18.43,0.75,0.03] seconds)
  evaluation failed :( (44.00 seconds)

Kenta Fukaya (fukayan)
summary: - Zuul error cannot import name 'Mapping' from 'collections'
+ Zuul error "cannot import name 'Mapping' from 'collections'"
description: updated
Yasufumi Ogawa (yasufum)
Changed in tacker:
importance: Undecided → Low
Navum Gupta (navum)
Changed in tacker:
assignee: nobody → Navum Gupta (navum)
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix proposed to tacker (master)

Fix proposed to branch: master
Review: https://review.opendev.org/c/openstack/tacker/+/892135

Changed in tacker:
status: New → In Progress
Revision history for this message
Navum Gupta (navum) wrote (last edit ):

while doing execution of compliance test in ubunty-Jammy machines, it raised similar error importerror: cannot import name ‘mapping’ from ‘collections’, it occurs while importing Mapping class from collections module in higher version of python (3.10 +).

In python 3.10 + version Mapping class is now moved in collections.abc class and in most of the case we do not know the run time version of python.

And Ubuntu-Jammy by default uses python 3.10 as its run time version so, if we upgrade `robotframework` = 3.2 in `requirements.txt` file our issue gets resolved because if we check [2] it calls 'from collections.abc import Mapping'.

Moreover, the current robot framework version (`robotframework==3.1`) mentioned in ‘requirement.txt’ file of api-tests repository calls - "from collections import Mapping" - [1], but this robotframework version perfectly works with Python 3.9 or lower.


we have also opened bug in NFV-TST side to upgrade robotframework version from v3.1 to v3.2 in requirements.txt

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.