Skip to content

(CAT-1731) improve handling of pinned nodes #80

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

Conversation

jonathannewman
Copy link
Contributor

@jonathannewman jonathannewman commented May 24, 2024

Within the Puppet Enterprise UI console the concept of pinned nodes allows more complex rules to be expressed while including pinned nodes.

Pinned nodes are formed by having a top level "or" clause, with expressions in the form

['=', 'name', 'hostname']

Prior to this change, the code would not properly maintain pinned nodes, nor correctly handle merging expressions like:

['and',
  ['~',
    ['fact', 'pe_server_version'],
    '.+']]

with

['or', ['~',
    ['trusted', 'extensions', '1.3.6.1.4.1.34380.1.1.9812'],
    '^puppet/']]

Incorrectly combining them into an and clause when logically they should be an "or" clause.

With this change, pinned nodes are separated our from the other rules and then recombined later (if they are present) with a top-level "or" clause.

Test are added to demonstrate the behaviors.

Summary

Provide a detailed description of all the changes present in this pull request.

Additional Context

Add any additional context about the problem here.

  • Root cause and the steps to reproduce. (If applicable)
  • Thought process behind the implementation.

Related Issues (if any)

Mention any related issues or pull requests.

Checklist

  • 🟢 Spec tests.
  • 🟢 Acceptance tests.
  • Manually verified. (For example puppet apply)

@jonathannewman jonathannewman requested a review from a team as a code owner May 24, 2024 20:13
@jonathannewman
Copy link
Contributor Author

@timidri I believe this is correct and complete. I put it up against your branch as I think we would like to merge the whole thing as one package?

Within the Puppet Enterprise UI console the concept of pinned nodes
allows more complex rules to be expressed while including pinned nodes.

Pinned nodes are formed by having a top level "or" clause, with
expressions in the form

`['=', 'name', 'hostname']`

Prior to this change, the code would not properly maintain pinned nodes,
nor correctly handle merging expressions like:

```
['and',
  ['~',
    ['fact', 'pe_server_version'],
    '.+']]
```

with
```
['or', ['~',
    ['trusted', 'extensions', '1.3.6.1.4.1.34380.1.1.9812'],
    '^puppet/']]
```

Incorrectly combining them into an `and` clause when logically they should be an "or" clause.

With this change, pinned nodes are separated our from the other rules
and then recombined later (if they are present) with a top-level "or" clause.

Test are added to demonstrate the behaviors.
@jonathannewman jonathannewman force-pushed the CAT-1731-add-rules-tests branch from 0a6af59 to 7456c65 Compare May 24, 2024 20:15
@jonathannewman
Copy link
Contributor Author

node_groups
  input validation
    is expected to run node_groups("", "", [], "", "extra") and raise an ArgumentError with the message matching /Function accepts a single String/i
    is expected to run node_groups([]) and raise an ArgumentError with the message matching /Function accepts a single String/i
  without an argument
    is expected to run node_groups() and return {"All Nodes"=>{"classes"=>{}, "environment"=>"production", "environment_trumps"=>false, "id"=>"00000000-0000-4000-8000-000000000000", "name"=>"All Nodes", "parent"=>"00000000-0000-4000-8000-000000000000", "rule"=>["and", ["~", "name", ".*"]], "variables"=>{}}, "Production environment"=>{"classes"=>{}, "environment"=>"production", "environment_trumps"=>false, "id"=>"7233f964-951e-4a7f-88ea-72676ed3104d", "name"=>"Production environment", "parent"=>"00000000-0000-4000-8000-000000000000", "rule"=>["and", ["~", "name", ".*"]], "variables"=>{}}}
  with 1 String argument
    is expected to run node_groups("All Nodes") and return {"All Nodes"=>{"classes"=>{}, "environment"=>"production", "environment_trumps"=>false, "id"=>"00000000-0000-4000-8000-000000000000", "name"=>"All Nodes", "parent"=>"00000000-0000-4000-8000-000000000000", "rule"=>["and", ["~", "name", ".*"]], "variables"=>{}}}

Puppet::Type::Node_group::ProviderHttps
  #instances
WARN: Unresolved or ambiguous specs during Gem::Specification.reset:
      rake (~> 13.0)
      Available/installed versions of this gem:
      - 13.2.1
      - 13.1.0
      - 13.0.6
WARN: Clearing out unresolved specs. Try 'gem cleanup <gem>'
Please report a bug if this causes problems.
    returns each node group
  .create
    creates the node group
  .destroy
    deletes the node group
  .flush
    updates the node group

Puppet::Type::Node_group::ProviderHttps
  .add_nulls
    if we change one value from true to false in a hash of multiple keys
      is expected to return a hash with a false value
    if we set a new key to true
      is expected to return a hash with a true value
    if we set a new key to false
      is expected to return a hash with a false value
    if we set a new key to zero
      is expected to return a hash with a zero
    if we set a new key to a string
      is expected to return a hash with a true value
    if we set a new key to a non-zero number
      is expected to return a hash the same non-zero number
    if we change a value from true to false
      is expected to return a hash with a false value
    if we change a value from nil to false
      is expected to return a hash with a false value
    if we change a value from 0 to false
      is expected to return a hash with a false value
    if we change a value from a string to false
      is expected to return a hash with a false value
    if we change a value from false to true
      is expected to return a hash with a true value
    if we change a value from nil to true
      is expected to return a hash with a true value
    if we change a value from true to true
      is expected to return a hash with a true value
    if we change a value from one string to another string
      is expected to return a hash with a true value

Puppet::Type::Node_group
  allows agent-specified environment
  allows environment name with an underscore
  allows environment name with a number
  allows environment name without an underscore
  allows environment name 'agent-specified'
  does not allow environment name with a dash
  allows name with symbols, numbers, and whitespace
  accepts a description parameter
  purge_behavior
    group_with_rule
      replaces by default
      merges when purge behaviour set to :none
      replaces rule when purge behaviour set to :all
      updates rule when purge behaviour set to :rule
    group with pinned nodes
      matches rule exactly by default
      merges and rule correctly when purge behaviour set to :none
      merges or rule correctly when purge behaviour set to :none
      merges pinned node correctly when purge behaviour set to :none
      replaces rule when purge behaviour set to :all
      replaces rule when purge behaviour set to :rule
    group with top-level and clause
      replaces rule exactly by default
start
end
      merges and rule correctly when purge behaviour set to :none
      merges or rule correctly when purge behaviour set to :none
      merges pinned node correctly when purge behaviour set to :none
      replaces rule when purge behaviour set to :all
      replaces rule when purge behaviour set to :rule
    resource hash
      matches classes and data exactly by default
      merges in classes and data when set to :none
      merges in classes and match data exactly when set to :data
      merges in data and match classes exactly when set to :classes
  .insync? for data, classes
    is insync when `is` and `should` are identical
    is insync when `is` and `should` are identical but have different ordering
    is not insync when `is` is only a subset of `should`

Finished in 1.2 seconds (files took 8.8 seconds to load)
53 examples, 0 failures

@timidri
Copy link
Contributor

timidri commented May 27, 2024

@timidri I believe this is correct and complete. I put it up against your branch as I think we would like to merge the whole thing as one package?

@jonathannewman Yes, thank you, that seems the easiest way forward to me.
The logic is looking good to me.

@jonathannewman
Copy link
Contributor Author

Going to merge into Dimitri's branch and open a PR from that branch.

@jonathannewman jonathannewman merged commit e1eb4de into puppetlabs:CAT-1731-add-rules-tests May 28, 2024
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants