'str' object has no attribute 'AndReturn'

Bug #1212625 reported by Kui Shi
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Glance
Fix Released
Medium
Stuart McLaren

Bug Description

Fix up for review here: https://review.openstack.org/#/c/49526/

======================================================================
ERROR: glance.tests.unit.test_store_image.TestStoreAddToBackend.test_bad_metadata_not_dict
----------------------------------------------------------------------
_StringException: Traceback (most recent call last):
  File "/opt/stack/glance/glance/tests/unit/test_store_image.py", line 788, in test_bad_metadata_not_dict
    store.__str__().AndReturn(('hello'))
AttributeError: 'str' object has no attribute 'AndReturn'

======================================================================
ERROR: glance.tests.unit.test_store_image.TestStoreAddToBackend.test_bad_nonunicode_dict_list
----------------------------------------------------------------------
_StringException: Traceback (most recent call last):
  File "/opt/stack/glance/glance/tests/unit/test_store_image.py", line 782, in test_bad_nonunicode_dict_list
    self._bad_metadata(m)
  File "/opt/stack/glance/glance/tests/unit/test_store_image.py", line 713, in _bad_metadata
    store.__str__().AndReturn(('hello'))
AttributeError: 'str' object has no attribute 'AndReturn'

======================================================================
ERROR: glance.tests.unit.test_store_image.TestStoreAddToBackend.test_bad_top_level_nonunicode
----------------------------------------------------------------------
_StringException: Traceback (most recent call last):
  File "/opt/stack/glance/glance/tests/unit/test_store_image.py", line 776, in test_bad_top_level_nonunicode
    self._bad_metadata(metadata)
  File "/opt/stack/glance/glance/tests/unit/test_store_image.py", line 713, in _bad_metadata
    store.__str__().AndReturn(('hello'))
AttributeError: 'str' object has no attribute 'AndReturn'

Kui Shi (skuicloud)
Changed in glance:
assignee: nobody → Kui Shi (skuicloud)
Changed in glance:
status: New → Confirmed
importance: Undecided → Medium
Revision history for this message
Kui Shi (skuicloud) wrote :

After the "bug 1213014" is check-in, this issue will be resolved.

Revision history for this message
Kui Shi (skuicloud) wrote :

git pull the latest code, it can work now.

Changed in glance:
status: Confirmed → Fix Released
Revision history for this message
Stuart McLaren (stuart-mclaren) wrote :

I'm seeing this with the latest code when running *not* in a virtual environment (I've installed all requirements as debian packages):

$ nosetests --tests=glance.tests.unit.test_store_image:TestStoreAddToBackend.test_bad_metadata_not_dict
glance.tests.unit.test_store_image.TestStoreAddToBackend.test_bad_metadata_not_dict ... ERROR

======================================================================
ERROR: glance.tests.unit.test_store_image.TestStoreAddToBackend.test_bad_metadata_not_dict
----------------------------------------------------------------------
_StringException: Traceback (most recent call last):
  File "/home/ubuntu/git/glance2/glance/glance/tests/unit/test_store_image.py", line 913, in test_bad_metadata_not_dict
    store.__str__().AndReturn(('hello'))
AttributeError: 'str' object has no attribute 'AndReturn'

Running in a virtual env works:

$ tox -evenv -- nosetests --tests=glance.tests.unit.test_store_image:TestStoreAddToBackend.test_bad_metadata_not_dict
GLOB sdist-make: /home/ubuntu/git/glance2/glance/setup.py
venv create: /home/ubuntu/git/glance2/glance/.tox/venv
venv installdeps: -r/home/ubuntu/git/glance2/glance/requirements.txt, -r/home/ubuntu/git/glance2/glance/test-requirements.txt
venv inst: /home/ubuntu/git/glance2/glance/.tox/dist/glance-2014.1.a2.g5048cee.zip
venv runtests: commands[0] | nosetests --tests=glance.tests.unit.test_store_image:TestStoreAddToBackend.test_bad_metadata_not_dict

TestStoreAddToBackend
    test_bad_metadata_not_dict                                   OK    0.00

----------------------------------------------------------------------
Ran 1 test in 0.005s

OK

Printing out what __str__ is defined as in both cases:

Bad case (using installed packages):

XXX store.__str__ (<bound method MockAnything.__str__ of <MockAnything instance>>)

Working case (virtual env):

XXX store.__str__ (__str__() -> None)

Revision history for this message
Stuart McLaren (stuart-mclaren) wrote :

mox from the virtual env is not the same as the ubuntu package, even though the versions
seem to match:

$ dpkg -l |grep mox
ii python-mox 0.5.3-1ubuntu5 a mock object framework for Python

.venv/lib/python2.7/site-packages/mox-0.5.3-py2.7.egg-info

$ diff -u /home/ubuntu/git/glance2/glance/.tox/venv/local/lib/python2.7/site-packages/mox.py /usr/lib/python2.7/dist-packages/mox.py |wc
    163 693 5994

If I copy /home/ubuntu/git/glance2/glance/.tox/venv/local/lib/python2.7/site-packages/mox.py to /usr/lib/python2.7/dist-packages/mox.py the test then works. A newer version of the package may be required.

Revision history for this message
Stuart McLaren (stuart-mclaren) wrote :

The latest Ubuntu package from packages.ubuntu.org is python-mox_0.5.3-3_all.deb -- I still see the issue.

Revision history for this message
Stuart McLaren (stuart-mclaren) wrote :

Downloading from pypi:

https://pypi.python.org/packages/source/m/mox/mox-0.5.3.tar.gz

Versus Ubuntu:

http://archive.ubuntu.com/ubuntu/pool/main/p/python-mox/python-mox_0.5.3.orig.tar.gz

The mox.py files don't match, which surprises me, the ubuntu one for example defines __str__ in class MockAnything:.

Revision history for this message
Stuart McLaren (stuart-mclaren) wrote :

This mox source defines __str__ in class MockAnything

https://code.google.com/p/pymox/downloads/detail?name=mox-0.5.3.tar.gz

Revision history for this message
Stuart McLaren (stuart-mclaren) wrote :

Found this:

https://code.google.com/p/pymox/issues/detail?id=40

This seems to be a known issue going back to 2011.
We should probably tweak the failing TestStoreAddToBackend
tests to work with both flavours of mox 0.5.3.

Changed in glance:
assignee: Kui Shi (skuicloud) → Stuart McLaren (stuart-mclaren)
status: Fix Released → In Progress
tags: added: havana-rc-potential
description: updated
Revision history for this message
Stuart McLaren (stuart-mclaren) wrote :
Changed in glance:
milestone: none → icehouse-1
Thierry Carrez (ttx)
Changed in glance:
milestone: icehouse-1 → havana-rc2
tags: removed: havana-rc-potential
Changed in glance:
status: In Progress → Fix Committed
Revision history for this message
Thierry Carrez (ttx) wrote :
Changed in glance:
status: Fix Committed → Fix Released
Thierry Carrez (ttx)
Changed in glance:
milestone: havana-rc2 → 2013.2
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.