Skip to content

Fix os resource script (bugfix)#1786

Merged
Hook25 merged 4 commits intomainfrom
fix-os-resource
Mar 10, 2025
Merged

Fix os resource script (bugfix)#1786
Hook25 merged 4 commits intomainfrom
fix-os-resource

Conversation

@pieqq
Copy link
Copy Markdown
Collaborator

@pieqq pieqq commented Mar 10, 2025

Description

Replace get_release_file_path function with get_release_file_content
that tries to access /var/lib/snapd/hostfs/etc/os-release. If this
file doesn't exist, it means we are not calling the script from within a
snap, so it tries to access /etc/os-release instead.

get_release_info now takes the content of the os-release file as
parameter and ignores empty lines.

The issue was introduced with previous PR #1748

Resolved issues

Prevent the os resource job from failing like this (example found the submission from a run using Checkbox in the edge channel):

{
            "id": "lsb",
            "full_id": "com.canonical.certification::lsb",
            "name": "[DEPRECATED, use 'os' instead] Collect information about installed operating system (os-release)",
            "certification_status": "non-blocker",
            "category": "Gathers information about the DUT",
            "category_id": "com.canonical.certification::information_gathering",
            "status": "fail",
            "outcome": "fail",
            "comments": null,
            "io_log": "Traceback (most recent call last):\n  File \"/tmp/nest-kopwzdp5.810b3c2c743e7de21a0c69775e0ca9675ca511eed3b76c394124412985b763db/os_resource.py\", line 57, in <module>\n    sys.exit(main())\n  File \"/tmp/nest-kopwzdp5.810b3c2c743e7de21a0c69775e0ca9675ca511eed3b76c394124412985b763db/os_resource.py\", line 51, in main\n    release_info = get_release_info(release_file_path)\n  File \"/tmp/nest-kopwzdp5.810b3c2c743e7de21a0c69775e0ca9675ca511eed3b76c394124412985b763db/os_resource.py\", line 39, in get_release_info\n    with open(release_file_path, \"r\") as lsb:\nFileNotFoundError: [Errno 2] No such file or directory: '/var/lib/snapd/hostfs/etc/os-release'\n",
            "type": "test",
            "project": "certification",
            "duration": 0.15081572532653809,
            "plugin": "resource",
            "template_id": null
        },

Documentation

Tests

pieqq added 2 commits March 10, 2025 11:25
Replace `get_release_file_path` function with `get_release_file_content`
that tries to access `/var/lib/snapd/hostfs/etc/os-release`. If this
file doesn't exist, it means we are not calling the script from within a
snap, so it tries to access `/etc/os-release` instead.

`get_release_info` now takes the content of the `os-release` file as
parameter and ignores empty lines.
Hook25
Hook25 previously approved these changes Mar 10, 2025
@codecov
Copy link
Copy Markdown

codecov bot commented Mar 10, 2025

Codecov Report

Attention: Patch coverage is 85.71429% with 2 lines in your changes missing coverage. Please review.

Project coverage is 49.82%. Comparing base (b6fe2e7) to head (874932d).
Report is 118 commits behind head on main.

Files with missing lines Patch % Lines
providers/resource/bin/os_resource.py 83.33% 2 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main    #1786   +/-   ##
=======================================
  Coverage   49.81%   49.82%           
=======================================
  Files         377      377           
  Lines       40701    40703    +2     
  Branches     6844     6846    +2     
=======================================
+ Hits        20277    20279    +2     
  Misses      19700    19700           
  Partials      724      724           
Flag Coverage Δ
provider-resource ∅ <85.71%> (∅)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@Hook25 Hook25 merged commit e62b68c into main Mar 10, 2025
18 of 19 checks passed
@Hook25 Hook25 deleted the fix-os-resource branch March 10, 2025 10:50
stanley31huang pushed a commit that referenced this pull request Mar 28, 2025
* Default to content from /etc/os-release

Replace `get_release_file_path` function with `get_release_file_content`
that tries to access `/var/lib/snapd/hostfs/etc/os-release`. If this
file doesn't exist, it means we are not calling the script from within a
snap, so it tries to access `/etc/os-release` instead.

`get_release_info` now takes the content of the `os-release` file as
parameter and ignores empty lines.

* Add unit tests

* Update graphics_card_resource.py to use the new function

* Fix Flake8 errors
mreed8855 pushed a commit that referenced this pull request Jul 31, 2025
* Default to content from /etc/os-release

Replace `get_release_file_path` function with `get_release_file_content`
that tries to access `/var/lib/snapd/hostfs/etc/os-release`. If this
file doesn't exist, it means we are not calling the script from within a
snap, so it tries to access `/etc/os-release` instead.

`get_release_info` now takes the content of the `os-release` file as
parameter and ignores empty lines.

* Add unit tests

* Update graphics_card_resource.py to use the new function

* Fix Flake8 errors
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants