Failed unit test due to permission on /tmp/device_images

Bug #1911997 reported by Sabeel Ansari on 2021-01-15
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
StarlingX
Low
Al Bailey

Bug Description

Running unit test on local build server (cgts4) failed. Tox reports a unit test failure locally, and another user who had run tox previously owns the permissions to the target folder.

The source code writing to /tmp/device_images needs to be mocked using either a @mock.patch('os.makedirs') or similar calls.

It appears that the culprit is this line: https://github.com/starlingx/config/blame/master/sysinv/sysinv/sysinv/sysinv/api/controllers/v1/device_image.py#L267

Captured pythonlogging:
~~~~~~~~~~~~~~~~~~~~~~~
    _host_upgrade_create system version=0.0
    None "POST /v1/device_images HTTP/1.0" status: 200 len: 0 time: 0.00612902641296 POST: NestedMultiDict([('pci_device', u'0b30'), ('bitstream_type', u'key-revocation'), ('pci_vendor', u'8086'), ('revoke_key_id', u'12345'), ('file', FieldStorage('file', u'/localdisk/designer/sansari/starlingx-0/cgcs-root/stx/config/sysinv/sysinv/sysinv/sysinv/tests/api/data/bitstream.bit'))]) host:localhost:80 agent:sysinv-test user: None tenant: None domain: None
    [Errno 13] Permission denied: '/tmp/device_images/key-revocation-8086-0b30-5ae6c262-5e03-4953-9a22-46e3595c1779.bit'
    Traceback (most recent call last):
      File "/tmp/sansari_sysinvtox/py27/lib/python2.7/site-packages/pecan/middleware/debug.py", line 78, in __call__
        return self.app(environ, start_response)
      File "/tmp/sansari_sysinvtox/py27/lib/python2.7/site-packages/pecan/middleware/recursive.py", line 56, in __call__
        return self.application(environ, start_response)
      File "sysinv/api/middleware/parsable_error.py", line 70, in __call__
        app_iter = self.app(environ, replacement_start_response)
      File "/tmp/sansari_sysinvtox/py27/lib/python2.7/site-packages/pecan/core.py", line 840, in __call__
        return super(Pecan, self).__call__(environ, start_response)
      File "/tmp/sansari_sysinvtox/py27/lib/python2.7/site-packages/pecan/core.py", line 683, in __call__
        self.invoke_controller(controller, args, kwargs, state)
      File "/tmp/sansari_sysinvtox/py27/lib/python2.7/site-packages/pecan/core.py", line 574, in invoke_controller
        result = controller(*args, **kwargs)
      File "/tmp/sansari_sysinvtox/py27/lib/python2.7/site-packages/oslo_concurrency/lockutils.py", line 328, in inner
        return f(*args, **kwargs)
      File "sysinv/api/controllers/v1/device_image.py", line 269, in post
        constants.CONFIG_FILE_PERMISSION_DEFAULT),
    OSError: [Errno 13] Permission denied: '/tmp/device_images/key-revocation-8086-0b30-5ae6c262-5e03-4953-9a22-46e3595c1779.bit'

======
Totals
======
Ran: 1480 tests in 384.0000 sec.
 - Passed: 1449
 - Skipped: 28
 - Expected Fail: 0
 - Unexpected Success: 0
 - Failed: 3
Sum of execute time for each test: 15561.9743 sec.

Al Bailey (albailey1974) wrote :

The three tox unit tests that are failing are tests that invoke the device_images API and attempt to write to that folder.

The easiest way to reproduce this problem is to make an in-accessible (000 permissions) /tmp/device_images folder, and then run tox for sysinv for the tests that fail (tests.api.test_device_image)

mkdir /tmp/device_images
chmod 000 /tmp/device_images

cd $MY_REPO/stx/config/sysinv/sysinv/sysinv/
tox -e py27 -- tests.api.test_device_image

These are the three tests that fail:
 tests.api.test_device_image.TestPostDeviceImage.test_create_revoke_key_image
 tests.api.test_device_image.TestPostDeviceImage.test_create_root_key_image
 tests.api.test_device_image.TestPostDeviceImage.test_create_functional_image

Ghada Khalil (gkhalil) wrote :

Minor / low priority - issue w/ running tox on a shared server related to specific test-cases

Changed in starlingx:
importance: Undecided → Low
status: New → Triaged
tags: added: stx.config
Changed in starlingx:
assignee: nobody → Al Bailey (albailey1974)
Al Bailey (albailey1974) wrote :
Changed in starlingx:
status: Triaged → In Progress
Al Bailey (albailey1974) wrote :

This merged on Jan 26, 2021

Changed in starlingx:
status: In Progress → Fix Committed
To post a comment you must log in.
This report contains Public information  Edit
Everyone can see this information.

Other bug subscribers