Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: mender-inventory-provides to read the device_type from mender.conf #1701

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

MuchoLucho
Copy link
Member

Title: None
Ticket: None

External Contributor Checklist

🚨 Please review the guidelines for contributing to this repository.

  • Make sure that all commits follow the conventional commit specification for the Mender project.

The majority of our contributions are fixes, which means your commit should have
the form below:

fix: <SHORT DESCRIPTION OF FIX>

<OPTIONAL LONGER DESCRIPTION>

Changelog: <USER-FRIENDLY-CHANGE-DESCRIPTION> or <None>
Ticket: <TICKET NUMBER> or <None>
  • Make sure that all commits are signed with git --signoff. Also note that the signoff author must match the author of the commit.

Description

Please describe your pull request.

Thank you!

@mender-test-bot
Copy link

@MuchoLucho, Let me know if you want to start the integration pipeline by mentioning me and the command "start pipeline".


my commands and options

You can trigger a pipeline on multiple prs with:

  • mentioning me and start pipeline --pr mender/127 --pr mender-connect/255

You can start a fast pipeline, disabling full integration tests with:

  • mentioning me and start pipeline --fast

You can trigger GitHub->GitLab branch sync with:

  • mentioning me and sync

You can cherry pick to a given branch or branches with:

  • mentioning me and:
 cherry-pick to:
 * 1.0.x
 * 2.0.x

@MuchoLucho MuchoLucho force-pushed the fix-inventory-provides branch 2 times, most recently from ed0839d to 5f8bc8d Compare December 5, 2024 02:07
Copy link
Contributor

@lluiscampos lluiscampos left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great fix, thanks!

See comments below 👇

support/mender-inventory-provides Outdated Show resolved Hide resolved
support/mender-inventory-provides Outdated Show resolved Hide resolved
default_device_type_file="/var/lib/mender/device_type"

# Read mender.conf file to find the DeviceTypeFile key if it exists prioritizing /etc over /var/lib
if grep -q '"DeviceTypeFile"' /etc/mender/mender.conf; then
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/etc/mender/mender.conf
This can be influenced by env variables and flags

mender-update -h
NAME:
   mender-update - manage and start Mender Update
...
...
Environment variables:
   - MENDER_CONF_DIR - configuration (default: /etc/mender).
   - MENDER_DATA_DIR - identity, inventory and update modules (default: /usr/share/mender).
   - MENDER_DATASTORE_DIR - runtime datastore (default: /var/lib/mender).

COMMANDS:
...
GLOBAL OPTIONS:
   --config FILE, -c FILE           Configuration FILE path (default:
                                    /etc/mender/mender.conf)
   --fallback-config FILE, -b FILE  Fallback configuration FILE path (default:
                                    /var/lib/mender/mender.conf)

Don't have an idea on top of my head on how to approach this.
Just a note that the the hardcoded mender.conf may become the new /var/lib/mender/device_type :)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I assumed that despite you change the env variables, the /etc/mender/mender.cond and /var/lib/mender/mender.conf will not. I know it doesn't make that much sense, but otherwise we need to also alter the first three paragraphs as part of a parallel PR: https://docs.mender.io/client-installation/configuration#configuration

What do you think @TheMeaningfulEngineer ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@TheMeaningfulEngineer what do you think about bff1a4f?
I don't know how to handle if mender-update was executed with any of the follow ones:

--config FILE, -c FILE 
--fallback-config FILE, -b FILE
--data DIR, -d DIR

Any advise @lluiscampos?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We cannot possibly get the command line options of mender-auth or mender-update from the script. It is correct to use the environment variables (good call on that too!).

In a way the more we align this code with the rootfs-image the better.

Copy link
Contributor

@lluiscampos lluiscampos left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking good!

Few things:

  • Squash your three commits into one.
    • Two of your commits have a typo Title: None instead of Ticket: None 😅
  • Please consider a more user friendly changelog entry, this is a bug after all. Example: "Fix inventory reporting of device_type to correctly select the file based on Mender configuration and Mender environment variables"
  • See also nitpick below 👇

support/mender-inventory-provides Outdated Show resolved Hide resolved
@lluiscampos
Copy link
Contributor

@MuchoLucho Can you attend this one? We are going to be releasing very soon and this is a good fix to have. I can take over the work if you want.

device_type_file=$(sed -ne '/"'"$match"'" *: *"[^"]*"/ { s/.*"'"$match"'" *: *"\([^"]*\)".*/\1/; p }' "$mender_conf_dir/mender.conf" || true)
fi

if [ -z "$device_type_file" ] && [ -f "$mender_datastore_dir/mender.conf" ]; then
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If $device_type_file variable is defined (iow got a value from /etc/mender/mender.conf) but the device_type file does not exist, we'll not get here for the fallback case where a different file could be specified and could be valid.

I don't know how important this is to handle, though. Is just an observation while experimenting with your fix on my device.

Edit: to make clear my comment - it could be handled with something like:

if [ -f "$mender_datastore_dir/mender.conf" ]; then
    if [ -z "$device_type_file" ] || [ ! -f "$device_type_file" ]; then
        ...
    fi
fi

@lluiscampos lluiscampos self-assigned this Dec 12, 2024
…ic from the Mender configuration file

- Add support for reading the paths from env variables `MENDER_CONF_DIR` and `MENDER_DATASTORE_DIR` when relocating the device_type file.
- Implement configuration parsing to extract `DeviceTypeFile` from `mender.conf` despite its location.
- Fallback to the default `device_type` file if `DeviceTypeFile` is not set or the extracted file path does not exist.

Changelog: Fix inventory reporting of device_type to correctly select
the file based on Mender configuration and Mender environment variables

Ticket: None

Signed-off-by: Luis Ramirez <[email protected]>
Signed-off-by: Lluis Campos <[email protected]>
@lluiscampos lluiscampos force-pushed the fix-inventory-provides branch from 95d7fd7 to adf65a9 Compare December 12, 2024 16:26
@mender-test-bot
Copy link

Merging these commits will result in the following changelog entries:

Changelogs

mender (fix-inventory-provides)

New changes in mender since master:

Bug Fixes
  • Fix inventory reporting of device_type to correctly select
    the file based on Mender configuration and Mender environment variables

@lluiscampos
Copy link
Contributor

@mender-test-bot start pipeline

@mender-test-bot
Copy link

Hello 😺 I created a pipeline for you here: Pipeline-1586226025

Build Configuration Matrix

Key Value
BUILD_BEAGLEBONEBLACK true
BUILD_CLIENT true
BUILD_QEMUX86_64_BIOS_GRUB true
BUILD_QEMUX86_64_BIOS_GRUB_GPT true
BUILD_QEMUX86_64_UEFI_GRUB true
BUILD_VEXPRESS_QEMU true
BUILD_VEXPRESS_QEMU_FLASH true
BUILD_VEXPRESS_QEMU_UBOOT_UEFI_GRUB true
INTEGRATION_REV master
MENDER_ARTIFACT_REV master
MENDER_BINARY_DELTA_REV master
MENDER_CLI_REV master
MENDER_CONFIGURE_MODULE_REV master
MENDER_CONNECT_REV master
MENDER_CONVERT_REV master
MENDER_GATEWAY_REV master
MENDER_REV pull/1701/head
MENDER_SETUP_REV master
MENDER_SNAPSHOT_REV master
MONITOR_CLIENT_REV master
RUN_INTEGRATION_TESTS true
TEST_QEMUX86_64_BIOS_GRUB true
TEST_QEMUX86_64_BIOS_GRUB_GPT true
TEST_QEMUX86_64_UEFI_GRUB true
TEST_VEXPRESS_QEMU true
TEST_VEXPRESS_QEMU_FLASH true
TEST_VEXPRESS_QEMU_UBOOT_UEFI_GRUB true

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.

4 participants