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

New task to clean and purge certs #35

Merged
merged 1 commit into from
Dec 20, 2018
Merged

New task to clean and purge certs #35

merged 1 commit into from
Dec 20, 2018

Conversation

m0dular
Copy link
Contributor

@m0dular m0dular commented Dec 6, 2018

No description provided.

@MartyEwings
Copy link
Collaborator

Just a few things from style reference

`Offenses:

�[36mtasks/kb0317a_clean_cert.rb�[0m:26:1: �[33mC�[0m: Style/ConditionalAssignment: Use the return of the conditional for variable assignment and comparison.
if Puppet::Util::Package.versioncmp(Puppet.version, '6.0.0') >= 0 �[33m...�[0m
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
�[36mtasks/kb0317a_clean_cert.rb�[0m:53:55: �[33mC�[0m: Style/AndOr: Use �[33m&&�[0m instead of �[33mand�[0m. (https://github.com/bbatsov/ruby-style-guide#no-and-or-or)
results[agent][:result] = (output[:exit_code].zero? and !output[:stderr].include? "Error:") ? 'Certificate removed' : output
^^^
�[36mtasks/kb0317a_clean_cert.rb�[0m:53:85: �[33mC�[0m: Style/StringLiterals: Prefer single-quoted strings when you don't need string interpolation or special symbols. (https://github.com/bbatsov/ruby-style-guide#consistent-string-literals)
results[agent][:result] = (output[:exit_code].zero? and !output[:stderr].include? "Error:") ? 'Certificate removed' : output
^^^^^^^^
�[36mtasks/kb0317a_clean_cert.rb�[0m:58:5: �[35mW�[0m: Lint/ParenthesesAsGroupedExpression: �[33m(...)�[0m interpreted as grouped expression. (https://github.com/bbatsov/ruby-style-guide#parens-no-spaces)
exit (results.values.all? { |v| v[:result] == 'Certificate removed' }) ? 0 : 1
^
�[36mtasks/kb0317b_purge_node.rb�[0m:46:55: �[33mC�[0m: Style/AndOr: Use �[33m&&�[0m instead of �[33mand�[0m. (https://github.com/bbatsov/ruby-style-guide#no-and-or-or)
results[agent][:result] = (output[:exit_code].zero? and !output[:stderr].include? "Error:") ? 'Node purged' : output
^^^
�[36mtasks/kb0317b_purge_node.rb�[0m:46:85: �[33mC�[0m: Style/StringLiterals: Prefer single-quoted strings when you don't need string interpolation or special symbols. (https://github.com/bbatsov/ruby-style-guide#consistent-string-literals)
results[agent][:result] = (output[:exit_code].zero? and !output[:stderr].include? "Error:") ? 'Node purged' : output
^^^^^^^^
�[36mtasks/kb0317b_purge_node.rb�[0m:51:5: �[35mW�[0m: Lint/ParenthesesAsGroupedExpression: �[33m(...)�[0m interpreted as grouped expression. (https://github.com/bbatsov/ruby-style-guide#parens-no-spaces)
exit (results.values.all? { |v| v[:result] == 'Certificate removed' }) ? 0 : 1
^`

@m0dular
Copy link
Contributor Author

m0dular commented Dec 6, 2018

@MartyEwings I removed checking stderr after asking about the behavior of puppet node purge. It returns 0 if you pass it a certname that doesn't exist, but we decided that's expected since it behaves like rm -rf: it has ensured the node isn't there. The cert clean command does return nonzero if the certname doesn't exist, so it's not needed there.

I can't get Rubocop to like the exit command. If I don't have parenthesis, it complains with:

Style/TernaryParentheses: Use parentheses for ternary expressions with complex conditions.

But if I add them, it throws:

Lint/ParenthesesAsGroupedExpression: (...) interpreted as grouped expression.

Trying to auto fix it didn't work either. Any ideas?

@MartyEwings
Copy link
Collaborator

I think, looking at what it's flagging, removing the space between exit and the ( will prevent the flag. However I don't know enough about ruby to say if that's sensible or not !

If this is syntaxually correct we could ignore and merge

@m0dular
Copy link
Contributor Author

m0dular commented Dec 6, 2018

Very nice, that makes the warnings go away. I went ahead and tested it again just to be sure, and the exit code of the command is correct.

With certnames:

root@pe-201901-master:/etc/puppetlabs/code/environments/production/modules# puppet task run support_tasks::kb0317a_clean_cert agent_certnames=pe-201804-agent.pla
tform9.puppet.net,pe-201901-agent.puppetdebug.vlan -n pe-201901-master.puppetdebug.vlan
Starting job ...
Note: The task will run only on permitted nodes.
New job ID: 7
Nodes: 1

Started on pe-201901-master.puppetdebug.vlan ...
Finished on node pe-201901-master.puppetdebug.vlan
  pe-201901-agent.puppetdebug.vlan :
    result : Certificate removed

  pe-201804-agent.platform9.puppet.net :
    result : Certificate removed

Job completed. 1/1 nodes succeeded.
Duration: 2 sec

Without:

root@pe-201901-master:/etc/puppetlabs/code/environments/production/modules# puppet task run support_tasks::kb0317a_clean_cert agent_certnames=pe-201804-agent.pla
tform9.puppet.net,pe-201901-agent.puppetdebug.vlan -n pe-201901-master.puppetdebug.vlan
Starting job ...
Note: The task will run only on permitted nodes.
New job ID: 8
Nodes: 1

Started on pe-201901-master.puppetdebug.vlan ...
Failed on pe-201901-master.puppetdebug.vlan
  Error: Task finished with exit-code 1
  pe-201901-agent.puppetdebug.vlan :
    result :
      stderr : Error:
    Could not find files to clean for pe-201901-agent.puppetdebug.vlan
      stdout :
      exit_code : 1


  pe-201804-agent.platform9.puppet.net :
    result :
      stderr : Error:
    Could not find files to clean for pe-201804-agent.platform9.puppet.net
      stdout :
      exit_code : 1

Job failed. 1 node failed, 0 nodes skipped, 0 nodes succeeded.
Duration: 2 sec

@m0dular m0dular changed the base branch from master to release_v1.0.4 December 20, 2018 00:53
@m0dular m0dular changed the title Initial commit New task to clean and purge certs Dec 20, 2018
@m0dular m0dular merged commit 9f66c79 into puppetlabs:release_v1.0.4 Dec 20, 2018
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.

2 participants