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 legacy Facts #790

Merged
merged 3 commits into from
Oct 26, 2023
Merged

Fix legacy Facts #790

merged 3 commits into from
Oct 26, 2023

Conversation

cocker-cc
Copy link
Contributor

Since Puppet 4 “structured Facts” are available.
The “non-strucured Facts” are legacy and deprecated. So this Commit is a Fix for that.

The legacy Facts are kept in Rspec-Tests for now, but can be deleted in near Future.

@cocker-cc cocker-cc requested a review from a team as a code owner October 19, 2023 22:16
Copy link
Member

@chouetz chouetz left a comment

Choose a reason for hiding this comment

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

Will trigger the CI before final approval

@@ -7,6 +7,7 @@
let(:facts) do
{
ipaddress: '1.2.3.4',
Copy link
Member

Choose a reason for hiding this comment

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

Eventually this should be removed, correct?
And the same for other spec files.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I planned to remove the legacy Facts from the Rspec-Tests, as soon as the Tests succeed. But currently they don't.

Honestly, I don't know, whats wrong. In my own Projects I am used to use the Facts from the Gem facterdb like so:

  on_supported_os.each do |os, os_facts|
    context "on #{os}" do
      let(:facts) { os_facts }

      it { is_expected.to compile.with_all_deps }
    end
  end

os_facts comes out of facterdb.
on_supported_os.each iterates over all OS-Releases stated in metadata.json. So you don't have to specify the Facts yourself for each OS's Context.

But here, the Tests are designed differently, which leaves me a bit lost…
Perhaps you find the Problem. I am a bit short of Time right now.

I invested an Amount of Time in this Module. More PRs are already prepared:

  • migrate to PDK 3 with most recent Version of PDK-Templates
  • fix all the Linters' Complaints

Copy link
Member

Choose a reason for hiding this comment

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

@cocker-cc the CI errors are fixed on #791.
You can do the updates or cherry-pick my commits (the second one is merge of main branch because there were additional errors see #793) to be able to merge you PR
Many thanks in advance

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Wow, that's cool. I cherry-picked, rebased against main and force-pushed. Checks seem okay now.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'd like to remove the legacy Facts from the Rspec-Tests now in the next Step.

Copy link
Member

Choose a reason for hiding this comment

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

you can maybe remove in a next PR, seems it raises new errors :/

@chouetz
Copy link
Member

chouetz commented Oct 23, 2023

I think I understand the failures in CI:
As you define $facts['os']['name'] which is used in other module, you can run into conditions that were ignored in the past.
As a consequence there is maybe a minimum definition that is expected by default (ie do not define ['os']['name'] without ['os']['release'])

@chouetz chouetz mentioned this pull request Oct 24, 2023
@cocker-cc cocker-cc force-pushed the Fix_legacy_Facts branch 3 times, most recently from ff79961 to 45b5af4 Compare October 24, 2023 17:53
cocker-cc and others added 2 commits October 24, 2023 19:54
Since Puppet 4 “structured Facts” are available.
The “non-strucured Facts” are legacy and deprecated.
So this Commit is a Fix for that.

The legacy Facts are kept in Rspec-Tests for now, but can be deleted in
near Future.
@cocker-cc cocker-cc force-pushed the Fix_legacy_Facts branch 2 times, most recently from fb62320 to 64269e3 Compare October 24, 2023 18:22
@cocker-cc cocker-cc requested a review from a team as a code owner October 24, 2023 18:22
@cocker-cc
Copy link
Contributor Author

Please don't squash, when merging.

facts_array: ['one', 'two'],
osfamily: 'redhat',
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
osfamily: 'redhat',

You probably missed this one

Copy link
Contributor Author

@cocker-cc cocker-cc Oct 25, 2023

Choose a reason for hiding this comment

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

Actually not. The Test fails in this Case.
If I specify…

          facts_to_tags: ['os.family', 'facts_array'],

… then datadog_agent::tag5 tries to find it via…

     $value = getvar($tag_name)

… and $os.family does not exist, in Contrast to getvar('facts.os.family'). (see getvar())

But there could be Help: stdlib got a Function called fact(). So this could be changed to…

  if $lookup_fact {
    $value = fact($tag_name)

… but not in this Change.

@chouetz
Copy link
Member

chouetz commented Oct 25, 2023

Please don't squash, when merging.

It's the repository policy, can I ask you why you require this? The change is pretty uniform.

@cocker-cc
Copy link
Contributor Author

Please don't squash, when merging.

It's the repository policy, can I ask you why you require this? The change is pretty uniform.

Even though I find this Policy stupid, for God's Sake then let it squash.

@chouetz chouetz merged commit 3de85cd into DataDog:main Oct 26, 2023
2 checks passed
@cocker-cc cocker-cc deleted the Fix_legacy_Facts branch October 26, 2023 17:30
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