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

Various refactoring to improve code readability #149

Merged
merged 1 commit into from
Oct 15, 2018

Conversation

alexjfisher
Copy link
Member

Refactor (and hopefully simplify) some of the conditional logic and relationships.

I've initially submitted this as a series of commits to make it easier to review (and find mistakes!).
If everything looks ok, I'll rebase and squash before merging.

In a future PR it should then be easy to move resources to separate classes and follow the Install -> Config ~> Service pattern.

@@ -437,6 +432,16 @@
}
}

if $::osfamily == 'Suse' {
exec { 'install /etc/init.d/snmptrapd':
Copy link
Member

Choose a reason for hiding this comment

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

Equivalent:

file { '/etc/init.d/snmptrapd':
  source  => '/usr/share/doc/packages/net-snmp/rc.snmptrapd',
  owner   => 'root',
  group   => 'root',
  mode    => '0755',
  require => Package['snmpd'],
  before  => Service['snmptrapd'],
}

Possibly with a replace => false to emulate the creates => on exec.

Copy link
Member Author

Choose a reason for hiding this comment

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

PR updated. I thought about the replace => false and decided it probably isn't needed.

path: '/etc/snmp/snmp.conf',
require: ['Package[snmp-client]', 'File[/etc/snmp]']
)
path: '/etc/snmp/snmp.conf'
Copy link
Member

Choose a reason for hiding this comment

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

I'd be happy with trailing commas. Much smaller diff :)

Copy link
Member Author

Choose a reason for hiding this comment

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

rubocop won't be though :(

Copy link
Member

Choose a reason for hiding this comment

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

We may have to teach rubocop a lesson then. There's an option for it.

Copy link
Member Author

Choose a reason for hiding this comment

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

meh. Just think of the noise correcting all 100 odd modules to the new style! ;)

Copy link
Contributor

Choose a reason for hiding this comment

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

thats what the rubocop:autocorrect task is for? :)

@alexjfisher
Copy link
Member Author

@ekohl @vStone This is about as much refactoring I want to put in a single PR. If you're happy that it's correct (and an improvement!), could you approve it? I'll then rebase/squash, fix up the PR title etc and merge.

Copy link
Contributor

@vStone vStone left a comment

Choose a reason for hiding this comment

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

I probably missed the 'no absolute class references' movement. I'm rather fond of those, but style is always up for discussion :)

Copy link
Member

@ekohl ekohl left a comment

Choose a reason for hiding this comment

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

With a squash 👍

@alexjfisher
Copy link
Member Author

Cool. I'll rebase now.

@alexjfisher alexjfisher changed the title DO NOT MERGE (needs squash): Refactoring Various refactoring to improve code readability Oct 14, 2018
Hopefully some of the logic in (especially) `init.pp` is less complicated.
It should now also be possible to split `init.pp` into the
`package -> config ~> service` pattern if someone wants to take on that
work.

* Replace `if != and !=` with `unless == or ==`
* Replace `$snmptrapd_conf_notify` with `subscribes`
* Refactor `snmpv3_user` by replacing `require` with `before`
* Remove duplication of identical `Service['snmptrapd']` resources
* Remove some redundant relationships and reorder resources in init.pp
* Refactor client.pp
* Don't use absolute class names
* Use proper relationship matchers in tests
* Replace Exec with File resource for `/etc/init.d/snmptrapd` on Suse
@alexjfisher
Copy link
Member Author

Of course, it always helps to do a git pull before rebasing and force pushing... (I accidentally threw away the last commit that fixed up the tests because I did it on a different workstation).

@alexjfisher alexjfisher merged commit e1132ca into voxpupuli:master Oct 15, 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.

4 participants