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

(GH-701) Stop using scope.lookupvar() in templates #724

Merged
merged 1 commit into from
Jul 13, 2017

Conversation

Phil-Friderici
Copy link
Collaborator

Add tests for existing functionality as preparation and to proof backward compatibility.

@Phil-Friderici
Copy link
Collaborator Author

I have separated the commits to proof that the existing functionality is not changed. If prefered I can squash them into one commit.

@Phil-Friderici
Copy link
Collaborator Author

ready for review

@ghoneycutt
Copy link
Collaborator

Please squash into one commit. Thanks!

@jeffmccune
Copy link
Collaborator

This looks good to me. The tests are great! Only question is why scope.lookup var is being left in sensu-client.erb and sensu-windows-package-version.erb?

@jeffmccune jeffmccune self-requested a review July 9, 2017 16:05
Copy link
Collaborator

@jeffmccune jeffmccune left a comment

Choose a reason for hiding this comment

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

This is great, thanks! Please make a similar change to sensu-client.erb and sensu-windows-package-version.erb, or mention why they need to be preserved as they are in the commit message.

Please squash into one commit.

@Phil-Friderici
Copy link
Collaborator Author

Thanks for the positive feedback, will do the same for the other templates as well :)

@Phil-Friderici Phil-Friderici force-pushed the GH-701 branch 3 times, most recently from 720cfd9 to 49c2583 Compare July 11, 2017 19:08
@Phil-Friderici
Copy link
Collaborator Author

Phil-Friderici commented Jul 11, 2017

Here we go:

  • all appearances of scope.lookupcvar() have been removed
  • all commits squashed into one

ready for merge ;)

@@ -49,7 +108,7 @@
# $pkg_version is passed to Package[sensu] { ensure }. The Windows MSI
# provider translates hyphens to dots, e.g. '0.29.0-11' maps to
# '0.29.0.11' on the system. This mapping is necessary to converge.
$pkg_version = template('sensu/sensu-windows-package-version.erb')
$pkg_version = regsubst($::sensu::version, '-', '.')
Copy link
Collaborator

Choose a reason for hiding this comment

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

good catch!

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

same is true for sensu-version.erb. I have created the issue #731 to get it changed later on too.

@ghoneycutt
Copy link
Collaborator

@Phil-Friderici looks like we still have a few

sensu-puppet$ grep -ri scope.lookupvar .
./manifests/extension.pp:  $filename = inline_template('<%= scope.lookupvar(\'source\').split(\'/\').last %>')
./manifests/handler.pp:    $filename = inline_template('<%= scope.lookupvar(\'source\').split(\'/\').last %>')
./manifests/mutator.pp:    $filename = inline_template('<%= scope.lookupvar(\'source\').split(\'/\').last %>')
./manifests/plugin.pp:      $filename = inline_template('<%= scope.lookupvar(\'name\').split(\'/\').last %>')
./manifests/plugin.pp:      $filename = inline_template('<%= scope.lookupvar(\'name\').split(\'/\').last %>')

While you are changing these, could you have them use .erb files. I prefer to use .erb files, even for one liners, so they can be validated.

@Phil-Friderici
Copy link
Collaborator Author

have added the grep results to #731 as I think they should be refactored to Puppet code instead.

@ghoneycutt
Copy link
Collaborator

Yes, please address that in this PR.

Solves #731

@ghoneycutt
Copy link
Collaborator

@Phil-Friderici please use vagrant to confirm that all platforms still work. Here's a bash function I use to see what clients are connected, instead of poking around through the Dashboard.

function sensuclients {
  curl -s http://admin:[email protected]:4567/clients | jq .[].name | awk -F \" '{print $2}' | awk -F \. '{print $1}' | sort
}

Add tests for existing functionality as proof for backward compatibility.
@Phil-Friderici
Copy link
Collaborator Author

Think we should replace Ruby with Puppet code where possible. So I have replaced all occurrences of
inline_template('<%= scope.lookupvar(\'source\').split(\'/\').last %>') with the much simplier to read basename() function.

Sorry, haven't used vagrant yet. Will need some time to get into the details and understand it.

@@ -69,7 +128,7 @@
# The OS Release specific sub-folder
$os_release = $facts['os']['release']['major']
# e.g. '2012 R2' => '2012r2'
$pkg_url_dir = template('sensu/sensu-version.erb')
$pkg_url_dir = regsubst($os_release, '^(\d+)\s*[rR](\d+)', '\\1r\\2')
Copy link
Collaborator Author

@Phil-Friderici Phil-Friderici Jul 13, 2017

Choose a reason for hiding this comment

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

same as for line 111 above ($pkg_version in package.pp)

@ghoneycutt ghoneycutt dismissed jeffmccune’s stale review July 13, 2017 15:44

Phil made the changes

@ghoneycutt ghoneycutt merged commit 3180389 into sensu:master Jul 13, 2017
@Phil-Friderici Phil-Friderici deleted the GH-701 branch July 13, 2017 15:49
@Phil-Friderici
Copy link
Collaborator Author

sweet :)

@ghoneycutt
Copy link
Collaborator

Released in v2.22.0

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