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

Add support to store environment variables as facts #13

Merged
merged 2 commits into from
Oct 7, 2020

Conversation

ekohl
Copy link
Member

@ekohl ekohl commented Sep 30, 2020

This code converts BEAKER_FACTER_* env vars to facts on target machines. This allows testing variations. While this is similar to tiers, it's not really the same. For example, a tier can be single node vs multi node, but those can both be run with multiple versions.

Inspired by voxpupuli/puppet-hyperglass#15 (comment)

README.md Outdated Show resolved Hide resolved
Copy link
Member

@bastelfreak bastelfreak left a comment

Choose a reason for hiding this comment

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

looks good to me. Did you test this successfully on a module?

@ekohl
Copy link
Member Author

ekohl commented Sep 30, 2020

Not in this form yet, which is why it's a draft. In theforeman/puppet-pulpcore#123 I did test the approach. Will continue on it later because I need the same thing in multiple places.

@ghoneycutt
Copy link
Member

@ekohl I actually wanted to use environment variables from CI in the hyperglass example so this is great!.

@ghoneycutt
Copy link
Member

Suggest that we always add a fact (aside from configure_beaker(configure_facts_from_env: false)) named beaker with the value true. This would allow you to make your module aware of the testing and specify data in hiera such as was done in the hyperglass PR.

---
version: 5
defaults:
  datadir: data
  data_hash: yaml_data
hierarchy:
  - name: "Acceptance testing with Beaker"
    path: "beaker/%{facts.beaker}.yaml"
  - name: "common"
    path: "common.yaml"

@ekohl
Copy link
Member Author

ekohl commented Sep 30, 2020

I did think about that. Perhaps it could be unified with the beaker tier. We don't really use it in our tests, but you can use it. Then it uses tags. However, I am hoping https://github.com/puppetlabs/beaker-hiera will be unarchived and moved to VP. Then we can properly add that supposed and easily sync over a test set without resorting to putting those in the main hierarchy. It will also be useful to configure external modules.

ekohl added 2 commits October 6, 2020 14:46
This code converts BEAKER_FACTER_* env vars to facts on target machines.
This allows testing variations. While this is similar to tiers, it's not
really the same. For example, a tier can be single node vs multi node,
but those can both be run with multiple versions.
@ekohl ekohl force-pushed the env-vars-to-facts branch from eb153e2 to 3e8bd4c Compare October 6, 2020 14:17
@ekohl ekohl marked this pull request as ready for review October 6, 2020 14:17
@ekohl
Copy link
Member Author

ekohl commented Oct 6, 2020

Updated. Now with fewer bugs and more documentation :)


if beaker_facts.any?
require 'json'
on(hosts, "mkdir -p #{File.dirname(FACT_FILE)} && cat <<VOXPUPULI_BEAKER_ENV_VARS > #{FACT_FILE}\n#{beaker_facts.to_json}\nVOXPUPULI_BEAKER_ENV_VARS")
Copy link
Member

Choose a reason for hiding this comment

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

took me a little while to wrap my head round this bash heredoc, but it does look correct.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, it's a bit obscure. However, the alternative was using scp_to and that wasn't great either. Ideally beaker would have something like write_to_file(destination, content).

@ekohl ekohl merged commit 3e8bd4c into voxpupuli:master Oct 7, 2020
@ekohl ekohl deleted the env-vars-to-facts branch October 7, 2020 14:59
@ekohl ekohl added the enhancement New feature or request label Oct 9, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants