Stx/config/sysinv unit tests fail in python3.9 environment

Bug #1940281 reported by Dan Voiculeasa
12
This bug affects 2 people
Affects Status Importance Assigned to Milestone
StarlingX
In Progress
Low
Dan Voiculeasa

Bug Description

Brief Description
-----------------
Working towards migrating to Debian OS.
Enabling tox tests in a Python3.9 environment: https://review.opendev.org/c/starlingx/config/+/804086
Tox tests fail.

Fixing some of the issues:
https://review.opendev.org/c/starlingx/config/+/804850
https://review.opendev.org/c/starlingx/config/+/804851
Cherry-pick to master of: https://review.opendev.org/c/starlingx/config/+/803591

There is still one more issue.

Severity
--------
Minor

Steps to Reproduce
------------------
tox -e py39

Expected Behavior
------------------
tests pass

Actual Behavior
----------------
A few tests fail with sqlalchemy.orm.exc.DetachedInstanceError

Reproducibility
---------------
100%

System Configuration
--------------------
-

Branch/Pull Time/Commit
-----------------------
August 2021

Last Pass
---------
-

Timestamp/Logs
-----------tests.api.test_sensorgroup.sensorgroupTestCase.test_sensor_post
---------------------------------------------------------------

Captured traceback:
~~~~~~~~~~~~~~~~~~~
    Traceback (most recent call last):

      File "/my/starlingx-master1/cgcs-root/stx/config/sysinv/sysinv/sysinv/sysinv/tests/api/test_sensorgroup.py", line 234, in test_sensor_post
    self.get_json('/isensors/%s/' %

      File "/my/starlingx-master1/cgcs-root/stx/config/sysinv/sysinv/sysinv/sysinv/tests/api/base.py", line 180, in get_json
    response = self.app.get(full_path,

      File "/tmp/root_sysinvtox/py39/lib/python3.9/site-packages/webtest/app.py", line 327, in get
    return self.do_request(req, status=status,

      File "/tmp/root_sysinvtox/py39/lib/python3.9/site-packages/webtest/app.py", line 649, in do_request
    self._check_status(status, res)

      File "/tmp/root_sysinvtox/py39/lib/python3.9/site-packages/webtest/app.py", line 678, in _check_status
    raise AppError(

    webtest.app.AppError: Bad response: 500 Internal Server Error (not 200 OK or 3xx redirect for http://localhost/v1/isensors/2dce7955-5678-4a2f-ab4f-f0e8bff64a0d/)
b'{"error_message": "{\\"faultcode\\": \\"Server\\", \\"faultstring\\": \\"Instance <SensorsAnalog at 0x7f3bcec312e0> is not bound to a Session; attribute refresh operation cannot proceed (Background on this error at: http://sqlalche.me/e/13/bhk3)\\", \\"debuginfo\\": null}"}'

Captured pythonlogging:
~~~~~~~~~~~~~~~~~~~~~~~
    _host_upgrade_create system version=0.0
None "POST /v1/isensors HTTP/1.0" status: 200 len: 914 time: 0.05324959754943848 POST: {'host_uuid': '1a6b9450-c98c-4219-ae12-d9c3e1cd4cf6', 'datatype': 'analog', 'sensortype': 'testsensortype', 'sensorname': 'testsensorname'} host:localhost:80 agent:None user: None tenant: None domain: None
Server-side error: "Instance <SensorsAnalog at 0x7f3bcec312e0> is not bound to a Session; attribute refresh operation cannot proceed (Background on this error at: http://sqlalche.me/e/13/bhk3)". Detail:
Traceback (most recent call last):

  File "/tmp/root_sysinvtox/py39/lib/python3.9/site-packages/wsmeext/pecan.py", line 82, in callfunction
    result = f(self, *args, **kwargs)

  File "/my/starlingx-master1/cgcs-root/stx/config/sysinv/sysinv/sysinv/sysinv/api/controllers/v1/sensor.py", line 358, in get_one
    rpc_sensor = objects.sensor.get_by_uuid(

  File "/my/starlingx-master1/cgcs-root/stx/config/sysinv/sysinv/sysinv/sysinv/objects/base.py", line 103, in wrapper
    result = fn(cls, context, *args, **kwargs)

  File "/my/starlingx-master1/cgcs-root/stx/config/sysinv/sysinv/sysinv/sysinv/objects/sensor.py", line 77, in get_by_uuid
    return cls.dbapi.isensor_get(uuid)

  File "/my/starlingx-master1/cgcs-root/stx/config/sysinv/sysinv/sysinv/sysinv/objects/__init__.py", line 116, in wrapper
    return klass.from_db_object(result)

  File "/my/starlingx-master1/cgcs-root/stx/config/sysinv/sysinv/sysinv/sysinv/objects/base.py", line 485, in from_db_object
    return cls._from_db_object(cls(), db_obj)

  File "/my/starlingx-master1/cgcs-root/stx/config/sysinv/sysinv/sysinv/sysinv/objects/base.py", line 475, in _from_db_object
    if not hasattr(db_object, field):

  File "/tmp/root_sysinvtox/py39/lib/python3.9/site-packages/sqlalchemy/orm/attributes.py", line 294, in __get__
    return self.impl.get(instance_state(instance), dict_)

  File "/tmp/root_sysinvtox/py39/lib/python3.9/site-packages/sqlalchemy/orm/attributes.py", line 725, in get
    value = state._load_expired(state, passive)

  File "/tmp/root_sysinvtox/py39/lib/python3.9/site-packages/sqlalchemy/orm/state.py", line 652, in _load_expired
    self.manager.deferred_scalar_loader(self, toload)

  File "/tmp/root_sysinvtox/py39/lib/python3.9/site-packages/sqlalchemy/orm/loading.py", line 942, in load_scalar_attributes
    raise orm_exc.DetachedInstanceError(

sqlalchemy.orm.exc.DetachedInstanceError: Instance <SensorsAnalog at 0x7f3bcec312e0> is not bound to a Session; attribute refresh operation cannot proceed (Background on this error at: http://sqlalche.me/e/13/bhk3)

---

Test Activity
-------------
Developer Testing

Workaround
----------
Temporary downgrade SQLAlchemy to 1.2.0(or 1.2.X?) in mock environment.

Tags: stx.python3
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix proposed to root (master)

Fix proposed to branch: master
Review: https://review.opendev.org/c/starlingx/root/+/804845

Changed in starlingx:
status: New → In Progress
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix merged to root (master)

Reviewed: https://review.opendev.org/c/starlingx/root/+/804845
Committed: https://opendev.org/starlingx/root/commit/e7bcb271418a5b308cbd281b5b1f75532a5a5577
Submitter: "Zuul (22348)"
Branch: master

commit e7bcb271418a5b308cbd281b5b1f75532a5a5577
Author: Dan Voiculeasa <email address hidden>
Date: Tue Aug 17 11:16:38 2021 +0000

    Temporary downgrade SQLAlchemy version in mock environments

    Downgrade SQLAlchemy version to allow stx/config/sysinv tests to pass.
    This will allow the zuul gate to pass. This allows py39 tests zuul
    gate for stx/config/sysinv to be successfully set up.

    Story: 2009101
    Task: 42976
    Partial-Bug: 1940281
    Signed-off-by: Dan Voiculeasa <email address hidden>
    Change-Id: Ifd76bff0761554d3c53f46877fecbc4bbcec5ad4

Ghada Khalil (gkhalil)
tags: added: stx.python3
Changed in starlingx:
assignee: nobody → Dan Voiculeasa (dvoicule)
importance: Undecided → Low
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.