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

ds-identify: Improve ds-identify testing flexibility #5047

Merged
merged 4 commits into from
Mar 18, 2024

Conversation

holmanb
Copy link
Member

@holmanb holmanb commented Mar 12, 2024

ds-identify: Improve ds-identify testing flexibility

- DI_MAIN: if DI_MAIN isn't a builtin function, exec() it
- /usr/libexec/ds-identify-env may be sourced to set variables

The purpose of these changes is to improve ds-identify testing capabilities and to allow testing alternative ds-identify implementations. Use of these capabilities is not supported in cloud-init deployments and therefore generates warnings in the ds-identify log.

Systemd gives generators no ability to run with custom environment variables. To set ds-identify variables at runtime, sourcing an environment file is required.

Example no-op side-loading with env var:

    $ DI_MAIN='echo' ./tools/ds-identify "hello world"
    WARN: side-loading alternate implementation: [echo]
    hello world

Example no-op side-loading with environment variable config:

    $ PATH_ROOT=. ./tools/ds-identify "test"
    WARN: loading environment file [./usr/libexec/ds-identify-env]
    WARN: side-loading alternate implementation: [echo]
    test
    $ cat ./usr/libexec/ds-identify-env
    export DI_MAIN=echo

Example side-loader that can only identify one cloud:

    $ cat nocloud-identifier.sh
    #!/bin/sh
    echo "creating nocloud config"
    echo "datasource_list: [ NoCloud ]" > cloud.cfg
    $ DI_MAIN=./nocloud-identifier.sh ./tools/ds-identify
    WARN: side-loading alternate implementation: [./nocloud-identifier.sh]
    creating nocloud config
    $ cat cloud.cfg
    datasource_list: [ NoCloud ]

Merge type

  • Squash merge using "Proposed Commit Message"
  • Rebase and merge unique commits. Requires commit messages per-commit each referencing the pull request number (#<PR_NUM>)

- DI_MAIN: if DI_MAIN isn't a builtin function, exec() it
- /usr/libexec/ds-identify-env may be sourced to set variables

The purpose of these changes is to improve ds-identify testing capabilities and
to allow testing alternative ds-identify implementations. Use of these
capabilities is not supported in cloud-init deployments and therefore generates
warnings in the ds-identify log.

Systemd gives generators no ability to run with custom environment variables.
To set ds-identify variables at runtime, sourcing an environment file is
required.

Example no-op side-loading:

    $ DI_MAIN='echo' ./tools/ds-identify "hello world"
    WARN: side-loading alternate implementation: [echo]
    hello world

Example side-loader that can only identify one cloud:

    $ cat nocloud-identifier.sh
    #!/bin/sh
    echo "creating nocloud config"
    echo "datasource_list: [ NoCloud ]" > cloud.cfg
    $ DI_MAIN=./nocloud-identifier.sh ./tools/ds-identify
    WARN: side-loading alternate implementation: [./nocloud-identifier.sh]
    creating nocloud config
    $ cat cloud.cfg
    datasource_list: [ NoCloud ]
Copy link
Contributor

@CalvoM CalvoM left a comment

Choose a reason for hiding this comment

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

LGTM.

Copy link
Contributor

@CalvoM CalvoM left a comment

Choose a reason for hiding this comment

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

Learnt alot about the power of exec while reviewing.

Copy link
Member

@TheRealFalcon TheRealFalcon left a comment

Choose a reason for hiding this comment

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

These feel like two unrelated changes. Is the get_environment() part related to the side-loading part? In the side-loading case, main->get_environment() would never get a chance to get called, right?

@holmanb
Copy link
Member Author

holmanb commented Mar 15, 2024

These feel like two unrelated changes. Is the get_environment() part related to the side-loading part? In the side-loading case, main->get_environment() would never get a chance to get called, right?

Good point - the code never calls get_environment().

Fixed in the latest commit.

@holmanb holmanb requested a review from TheRealFalcon March 15, 2024 23:11
Copy link
Member

@TheRealFalcon TheRealFalcon left a comment

Choose a reason for hiding this comment

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

LGTM!

In order for get_environment to be of any use, it needs to be called
before $DI_MAIN is referenced.

Shift the call to get_environment before main() is called.
@holmanb holmanb requested a review from TheRealFalcon March 18, 2024 16:53
@holmanb
Copy link
Member Author

holmanb commented Mar 18, 2024

@TheRealFalcon I know you already reviewed this code, but I just updated this PR since DI_MAIN would be referenced before get_environment would be set, so the call wasn't useful.

tested get_environment:

$ cat ./usr/libexec/ds-identify-env
export DI_MAIN=echo
$ PATH_ROOT=. ./tools/ds-identify "test"
WARN: loading environment file [./usr/libexec/ds-identify-env]
WARN: side-loading alternate implementation: [echo]
test

Copy link
Member

@TheRealFalcon TheRealFalcon left a comment

Choose a reason for hiding this comment

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

Doh. +1

@holmanb holmanb merged commit d8e3a4b into canonical:main Mar 18, 2024
29 checks passed
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.

3 participants