rockstor / rockstor-core

Linux/BTRFS based Network Attached Storage(NAS)
http://rockstor.com/docs/contribute_section.html
GNU General Public License v3.0
550 stars 137 forks source link

Unit test host sensitivity - rpmbuild - TW JeOS #2799

Open phillxnet opened 6 months ago

phillxnet commented 6 months ago

When running rpmbuild for the first time on a 'clean' TW 20240205 host, we have 3 remaining tests that are 'sensitive' to prior host conditions.

======================================================================
ERROR: test_delete_valid (rockstor.smart_manager.tests.test_task_scheduler.TaskSchedulerTests.test_delete_valid)
Test delete request with valid tdid
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/usr/lib64/python3.11/shutil.py", line 825, in move
    os.rename(src, real_dst)
FileNotFoundError: [Errno 2] No such file or directory: '/tmp/tmpmubg6ere' -> '/etc/cron.d/rockstortab'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
  File "/home/buildbot/rockstor-buildbot/worker/Poetry-Build-on-Tumbleweed-aarch64/rpmbuild/rockstor-core-5.0.7-2797/src/rockstor/smart_manager/tests/test_task_scheduler.py", line 235, in test_delete_valid
    response = self.client.delete("{}/{}".format(self.BASE_URL, tdid), data=data)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/buildbot/rockstor-buildbot/worker/Poetry-Build-on-Tumbleweed-aarch64/rpmbuild/rockstor-core-5.0.7-2797/.venv/lib/python3.11/site-packages/rest_framework/test.py", line 320, in delete
    response = super().delete(
               ^^^^^^^^^^^^^^^
  File "/home/buildbot/rockstor-buildbot/worker/Poetry-Build-on-Tumbleweed-aarch64/rpmbuild/rockstor-core-5.0.7-2797/.venv/lib/python3.11/site-packages/rest_framework/test.py", line 222, in delete
    return self.generic('DELETE', path, data, content_type, **extra)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/buildbot/rockstor-buildbot/worker/Poetry-Build-on-Tumbleweed-aarch64/rpmbuild/rockstor-core-5.0.7-2797/.venv/lib/python3.11/site-packages/rest_framework/test.py", line 234, in generic
    return super().generic(
           ^^^^^^^^^^^^^^^^
  File "/home/buildbot/rockstor-buildbot/worker/Poetry-Build-on-Tumbleweed-aarch64/rpmbuild/rockstor-core-5.0.7-2797/.venv/lib/python3.11/site-packages/django/test/client.py", line 609, in generic
    return self.request(**r)
           ^^^^^^^^^^^^^^^^^
  File "/home/buildbot/rockstor-buildbot/worker/Poetry-Build-on-Tumbleweed-aarch64/rpmbuild/rockstor-core-5.0.7-2797/.venv/lib/python3.11/site-packages/rest_framework/test.py", line 286, in request
    return super().request(**kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/buildbot/rockstor-buildbot/worker/Poetry-Build-on-Tumbleweed-aarch64/rpmbuild/rockstor-core-5.0.7-2797/.venv/lib/python3.11/site-packages/rest_framework/test.py", line 238, in request
    request = super().request(**kwargs)
              ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/buildbot/rockstor-buildbot/worker/Poetry-Build-on-Tumbleweed-aarch64/rpmbuild/rockstor-core-5.0.7-2797/.venv/lib/python3.11/site-packages/django/test/client.py", line 891, in request
    self.check_exception(response)
  File "/home/buildbot/rockstor-buildbot/worker/Poetry-Build-on-Tumbleweed-aarch64/rpmbuild/rockstor-core-5.0.7-2797/.venv/lib/python3.11/site-packages/django/test/client.py", line 738, in check_exception
    raise exc_value
  File "/home/buildbot/rockstor-buildbot/worker/Poetry-Build-on-Tumbleweed-aarch64/rpmbuild/rockstor-core-5.0.7-2797/.venv/lib/python3.11/site-packages/django/core/handlers/exception.py", line 55, in inner
    response = get_response(request)
               ^^^^^^^^^^^^^^^^^^^^^
  File "/home/buildbot/rockstor-buildbot/worker/Poetry-Build-on-Tumbleweed-aarch64/rpmbuild/rockstor-core-5.0.7-2797/.venv/lib/python3.11/site-packages/django/core/handlers/base.py", line 197, in _get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/buildbot/rockstor-buildbot/worker/Poetry-Build-on-Tumbleweed-aarch64/rpmbuild/rockstor-core-5.0.7-2797/.venv/lib/python3.11/site-packages/django/views/decorators/csrf.py", line 56, in wrapper_view
    return view_func(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/buildbot/rockstor-buildbot/worker/Poetry-Build-on-Tumbleweed-aarch64/rpmbuild/rockstor-core-5.0.7-2797/.venv/lib/python3.11/site-packages/django/views/generic/base.py", line 104, in view
    return self.dispatch(request, *args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/buildbot/rockstor-buildbot/worker/Poetry-Build-on-Tumbleweed-aarch64/rpmbuild/rockstor-core-5.0.7-2797/.venv/lib/python3.11/site-packages/rest_framework/views.py", line 509, in dispatch
    response = self.handle_exception(exc)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/buildbot/rockstor-buildbot/worker/Poetry-Build-on-Tumbleweed-aarch64/rpmbuild/rockstor-core-5.0.7-2797/.venv/lib/python3.11/site-packages/rest_framework/views.py", line 469, in handle_exception
    self.raise_uncaught_exception(exc)
  File "/home/buildbot/rockstor-buildbot/worker/Poetry-Build-on-Tumbleweed-aarch64/rpmbuild/rockstor-core-5.0.7-2797/.venv/lib/python3.11/site-packages/rest_framework/views.py", line 480, in raise_uncaught_exception
    raise exc
  File "/home/buildbot/rockstor-buildbot/worker/Poetry-Build-on-Tumbleweed-aarch64/rpmbuild/rockstor-core-5.0.7-2797/.venv/lib/python3.11/site-packages/rest_framework/views.py", line 506, in dispatch
    response = handler(request, *args, **kwargs)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib64/python3.11/contextlib.py", line 81, in inner
    return func(*args, **kwds)
           ^^^^^^^^^^^^^^^^^^^
  File "/home/buildbot/rockstor-buildbot/worker/Poetry-Build-on-Tumbleweed-aarch64/rpmbuild/rockstor-core-5.0.7-2797/src/rockstor/smart_manager/views/task_scheduler.py", line 218, in delete
    self._refresh_crontab()
  File "/home/buildbot/rockstor-buildbot/worker/Poetry-Build-on-Tumbleweed-aarch64/rpmbuild/rockstor-core-5.0.7-2797/src/rockstor/smart_manager/views/task_scheduler.py", line 141, in _refresh_crontab
    shutil.move(npath, "/etc/cron.d/rockstortab")
  File "/usr/lib64/python3.11/shutil.py", line 845, in move
    copy_function(src, real_dst)
  File "/usr/lib64/python3.11/shutil.py", line 436, in copy2
    copyfile(src, dst, follow_symlinks=follow_symlinks)
  File "/usr/lib64/python3.11/shutil.py", line 258, in copyfile
    with open(dst, 'wb') as fdst:
         ^^^^^^^^^^^^^^^
FileNotFoundError: [Errno 2] No such file or directory: '/etc/cron.d/rockstortab'
======================================================================
FAIL: test_post_valid (rockstor.smart_manager.tests.test_task_scheduler.TaskSchedulerTests.test_post_valid)
Test valid POST request
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/buildbot/rockstor-buildbot/worker/Poetry-Build-on-Tumbleweed-aarch64/rpmbuild/rockstor-core-5.0.7-2797/src/rockstor/smart_manager/tests/test_task_scheduler.py", line 117, in test_post_valid
    self.assertEqual(
AssertionError: 500 != 200 : b'["[Errno 2] No such file or directory: \'/etc/cron.d/rockstortab\'","Traceback (most recent call last):\\n  File \\"/usr/lib64/python3.11/shutil.py\\", line 825, in move\\n    os.rename(src, real_dst)\\nFileNotFoundError: [Errno 2] No such file or directory: \'/tmp/tmpl5vnk0bv\' -> \'/etc/cron.d/rockstortab\'\\n\\nDuring handling of the above exception, another exception occurred:\\n\\nTraceback (most recent call last):\\n  File \\"/home/buildbot/rockstor-buildbot/worker/Poetry-Build-on-Tumbleweed-aarch64/rpmbuild/rockstor-core-5.0.7-2797/src/rockstor/rest_framework_custom/generic_view.py\\", line 41, in _handle_exception\\n    yield\\n  File \\"/home/buildbot/rockstor-buildbot/worker/Poetry-Build-on-Tumbleweed-aarch64/rpmbuild/rockstor-core-5.0.7-2797/src/rockstor/smart_manager/views/task_scheduler.py\\", line 184, in post\\n    self._refresh_crontab()\\n  File \\"/home/buildbot/rockstor-buildbot/worker/Poetry-Build-on-Tumbleweed-aarch64/rpmbuild/rockstor-core-5.0.7-2797/src/rockstor/smart_manager/views/task_scheduler.py\\", line 141, in _refresh_crontab\\n    shutil.move(npath, \\"/etc/cron.d/rockstortab\\")\\n  File \\"/usr/lib64/python3.11/shutil.py\\", line 845, in move\\n    copy_function(src, real_dst)\\n  File \\"/usr/lib64/python3.11/shutil.py\\", line 436, in copy2\\n    copyfile(src, dst, follow_symlinks=follow_symlinks)\\n  File \\"/usr/lib64/python3.11/shutil.py\\", line 258, in copyfile\\n    with open(dst, \'wb\') as fdst:\\n         ^^^^^^^^^^^^^^^\\nFileNotFoundError: [Errno 2] No such file or directory: \'/etc/cron.d/rockstortab\'\\n"]'
======================================================================
FAIL: test_put_valid (rockstor.smart_manager.tests.test_task_scheduler.TaskSchedulerTests.test_put_valid)
Test PUT request with valid tdid
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/buildbot/rockstor-buildbot/worker/Poetry-Build-on-Tumbleweed-aarch64/rpmbuild/rockstor-core-5.0.7-2797/src/rockstor/smart_manager/tests/test_task_scheduler.py", line 186, in test_put_valid
    self.assertEqual(response.status_code, status.HTTP_200_OK, msg=response.content)
AssertionError: 500 != 200 : b'["[Errno 2] No such file or directory: \'/etc/cron.d/rockstortab\'","Traceback (most recent call last):\\n  File \\"/usr/lib64/python3.11/shutil.py\\", line 825, in move\\n    os.rename(src, real_dst)\\nFileNotFoundError: [Errno 2] No such file or directory: \'/tmp/tmp5xc022wb\' -> \'/etc/cron.d/rockstortab\'\\n\\nDuring handling of the above exception, another exception occurred:\\n\\nTraceback (most recent call last):\\n  File \\"/home/buildbot/rockstor-buildbot/worker/Poetry-Build-on-Tumbleweed-aarch64/rpmbuild/rockstor-core-5.0.7-2797/src/rockstor/rest_framework_custom/generic_view.py\\", line 41, in _handle_exception\\n    yield\\n  File \\"/home/buildbot/rockstor-buildbot/worker/Poetry-Build-on-Tumbleweed-aarch64/rpmbuild/rockstor-core-5.0.7-2797/src/rockstor/smart_manager/views/task_scheduler.py\\", line 211, in put\\n    self._refresh_crontab()\\n  File \\"/home/buildbot/rockstor-buildbot/worker/Poetry-Build-on-Tumbleweed-aarch64/rpmbuild/rockstor-core-5.0.7-2797/src/rockstor/smart_manager/views/task_scheduler.py\\", line 141, in _refresh_crontab\\n    shutil.move(npath, \\"/etc/cron.d/rockstortab\\")\\n  File \\"/usr/lib64/python3.11/shutil.py\\", line 845, in move\\n    copy_function(src, real_dst)\\n  File \\"/usr/lib64/python3.11/shutil.py\\", line 436, in copy2\\n    copyfile(src, dst, follow_symlinks=follow_symlinks)\\n  File \\"/usr/lib64/python3.11/shutil.py\\", line 258, in copyfile\\n    with open(dst, \'wb\') as fdst:\\n         ^^^^^^^^^^^^^^^\\nFileNotFoundError: [Errno 2] No such file or directory: \'/etc/cron.d/rockstortab\'\\n"]'
----------------------------------------------------------------------
Ran 279 tests in 87.454s
FAILED (failures=2, errors=1)
phillxnet commented 6 months ago

All faulty tests are from: rockstor.smart_manager.tests.test_task_scheduler

And all fail as there is no pre-existing (on host) /etc/cron.d/rockstortab

FileNotFoundError: [Errno 2] No such file or directory: '/etc/cron.d/rockstortab'

FroggyFlox commented 6 months ago

Looks like this was my doing... feel stupid for not thinking of mocking that :-\ Sorry for the additional work it creates now.

phillxnet commented 6 months ago

@FroggyFlox No worries on that front. I was actually going to look at your more recent (and our first) proper file mocking in testing to fix this as it goes. Given we are now on new-enough Python. I think it was a more recent addition, from memory.

Maybe this was it: https://github.com/rockstor/rockstor-core/pull/2718

phillxnet commented 6 months ago

Work-around

To probe for any other outlier unit tests:

After

# for the missing dir - owned by the following rpm dependency:
zypper in --no-recommends cronie
# for the inadvertently sensitive file, created in a prior rockstor-run/unit-test-run:
touch /etc/cron.d/rockstortab

We have, on the same 'clean' system:

Found 279 test(s).
Creating test database for alias 'smart_manager'...
System check identified no issues (0 silenced).
.......................................................................................................................................................................................................................................................................................
----------------------------------------------------------------------
Ran 279 tests in 87.304s
OK

@FroggyFlox from the above these look to be the last of their kind (hopefully) and all within a single test.

I'll not tend to these for now as I've got a significant backlog currently. But just wanted to issue this while I had the reproducer here. If anyone fancies looking at these failure they should be reproducible via the sensitive file's removal (the one that shouldn't yet exist on a clean system :) ). If this one takes any-ones fancy just assign yourself so we don't duplicate effort.