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 Package[sensu] on windows #699

Merged
merged 18 commits into from
Jun 30, 2017

Conversation

jeffmccune
Copy link
Collaborator

@jeffmccune jeffmccune commented Jun 29, 2017

Seeking feedback on how to handle ensure => latest on Windows with this error:

Error: Parameter ensure failed on Package[sensu]: Provider windows
must have features 'upgradeable' to set 'ensure' to 'latest' at
sensu/manifests/package.pp:64

Partially resolves #646 (Need to overcome ensure => latest error)
Partially resolves #681 (Windows)

Todo

  • Decide how to handle the 404 on http://repositories.sensuapp.org/msi/sensu-latest.msi
  • Fix Remote_file[C:\Windows\Temp\sensu-latest.msi] to handle version => installed
  • Fix Provider sensu_gem is not functional on windows
  • Add an explicit, fully qualified, source_url param for the end user to override the behavior of computing the URL. The computed URL is sure to be wrong in some cases, the user will need an escape hatch.
  • Resolve ==> win2012r2-client: Error: /Stage[main]/Sensu::Client::Service/Exec[install-sensu-client]: Could not evaluate: Could not find command 'powershell.exe'
  • Investigate $pkg_name and $pkg_title variables, possibly refactor.
  • Investigate getting sensu_gem working on windows. (Moved to Investigate getting sensu_gem working on windows #700)
  • Fix MSI being re-installed every run. Stage[main]/Sensu::Package/Package[sensu]/ensure: created
  • Replace $facts['networking']['ip'] in vagrant provisioning, it's non-deterministic over the two interfaces.
  • Fix package being re-installed on Notice: /Stage[main]/Sensu::Package/Package[sensu]/ensure: ensure changed '0.29.0.11' to '0.29.0-11' This explains the string substitution I removed and didn't understand.
  • Use 1 vcpu
  • Change RDC port to 3389 with autocorrect.
  • Remote log only if present.

@jeffmccune jeffmccune force-pushed the 646_fix_error_on_win2012r2 branch 2 times, most recently from 6d8fc94 to be06678 Compare June 29, 2017 01:05
@jeffmccune
Copy link
Collaborator Author

jeffmccune commented Jun 29, 2017

I'm looking into changing the package version from latest to installed. This will likely require a change to the download_file resource on windows.

This issue with sensu_gem also needs to be addressed on Windows:

Error: /Stage[main]/Sensu::Package/Package[sensu-plugin]: Provider sensu_gem is not functional on this 

@jeffmccune
Copy link
Collaborator Author

Looking at http://repositories.sensuapp.org/msi/, there is no sensu-latest.msi, so ensure => installed poses a problem. We still need to figure out an URL to download the package from.

I see two options:

  1. Embed the version in the module, e.g. in Hieradata. This would require ongoing maintenance of the module and some end-user documentation explaining the need to specify sensu::version appropriately.
  2. Add a symlink for http://repositories.sensuapp.org/msi/sensu-latest.msi which is updated as new releases come out. This would require a change to Sensu's release process.

@jeffmccune jeffmccune changed the title [WIP] Fix Package[sensu] on windows Fix Package[sensu] on windows Jun 29, 2017
$sensu_plugin_provider = $::osfamily ? {
'windows' => 'gem',
default => undef,
},
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This avoids Provider sensu_gem is not functional on windows. Considered moving the behavior to package.pp, put it here to make it clear.

Copy link
Collaborator

Choose a reason for hiding this comment

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

is it not embedded on windows?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Gem is embedded on windows, e.g. https://github.com/sensu/sensu-puppet/blob/30fe995/lib/puppet/provider/package/sensu_gem.rb#L16

It seems the parent gem provider in puppet has a confinement preventing it from working on Windows. My guess is sensu_gem is inheriting this. I'll see if I can override and sensu_gem works.

$pkg_url_version = $::sensu::version ? {
installed => 'latest',
default => $pkg_version,
}
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This assumes http://repositories.sensuapp.org/msi/sensu-latest.msi exists, but it does not at the moment.

Copy link
Collaborator

Choose a reason for hiding this comment

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

@cwjohnston @agoddard could you please create this link

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The specific links will be based on the OS architecture and Major release. For example, the default computed links look like:

  • https://repositories.sensuapp.org/msi/2012r2/sensu-latest-x86.msi
  • https://repositories.sensuapp.org/msi/2012r2/sensu-latest-x64.msi
  • https://repositories.sensuapp.org/msi/2012/sensu-latest-x86.msi
  • https://repositories.sensuapp.org/msi/2012/sensu-latest-x64.msi
  • https://repositories.sensuapp.org/msi/2008r2/sensu-latest-x86.msi
  • https://repositories.sensuapp.org/msi/2008r2/sensu-latest-x64.msi

Copy link
Collaborator

Choose a reason for hiding this comment

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

@agoddard said he would create it manually and talk to the dev team to get it part of the release process

@@ -0,0 +1,9 @@
# Note: Check http://repositories.sensuapp.org/msi/ for the latest version.
class { '::sensu':
version => '0.26.5-1',
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Moving this back to WIP, this still doesn't work with Vagrant, getting a 404.

Copy link
Collaborator

Choose a reason for hiding this comment

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

i think we want 0.29.0-7 at http://repositories.sensuapp.org/msi/2012r2/sensu-0.29.0-7-x86.msi

You might be having troubles with such an old version.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Thanks for the catch, I noticed newer releases are in the 2012r2 directory. Updating it to https://repositories.sensuapp.org/msi/2012r2/sensu-0.29.0-11-x64.msi

@jeffmccune jeffmccune changed the title Fix Package[sensu] on windows [WIP] Fix Package[sensu] on windows Jun 29, 2017
default => $pkg_version,
}
$pkg_title = 'sensu'
$pkg_name = 'sensu'
Copy link
Collaborator

Choose a reason for hiding this comment

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

why two variables here? why not just pkg_name ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I'm not sure, this behavior existed prior to the patch. I'll look into if they're necessary.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

tl;dr $pkg_name should be Sensu on windows to match Add/Remove Programs, $pkg_title should be sensu to match internal catalog relationships.

$pkg_name and $pkg_title are both necessary because the title is for internal Puppet references and relationships. This provides Package[sensu] consistently across platforms. On windows, the name of the MSI in Add/Remove programs is Sensu (capitalized). The MSI provider needs the name parameter to line up with Add/Remove programs, otherwise it will always report the package as absent.

@jeffmccune jeffmccune force-pushed the 646_fix_error_on_win2012r2 branch 2 times, most recently from b413eeb to b5611c1 Compare June 29, 2017 15:05
# [*windows_pkg_url*]
# String. If specified, override the behavior of computing the package source
# URL from windows_repo_prefix and os major release fact. This parameter is
# intended to provide an escape hatch to the situation where the package URL
Copy link
Collaborator

Choose a reason for hiding this comment

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

docs should not reflect a problem with computing the URL incorrectly and should instead allow a user to use their own URL.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Fixed. Updated to:

# [*windows_pkg_url*]
#   String.  If specified, override the behavior of computing the package source
#   URL from windows_repo_prefix and os major release fact.  This parameter is
#   intended to allow the end user to override the source URL used to install
#   the Windows package.  For example:
#   `"https://repositories.sensuapp.org/msi/2012r2/sensu-0.29.0-11-x64.msi"`
#   Default: undef

# The OS Release specific sub-folder
$os_release = $facts['os']['release']['major']
# e.g. '2012 R2' => '2012r2'
$pkg_url_dir = inline_template("<%= @os_release.sub(/^(\\d+)\s*[rR](\\d+)/, '\\1r\\2') %>")
Copy link
Collaborator

Choose a reason for hiding this comment

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

please convert this to use an .erb file, that it can be validated

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Converted to an erb for validation.

@jeffmccune jeffmccune force-pushed the 646_fix_error_on_win2012r2 branch from b1b125b to 987d04e Compare June 29, 2017 16:28
class { '::sensu':
version => '0.29.0-11',
windows_pkg_url => "${pkg_repo}/2012r2/sensu-0.29.0-11-x64.msi",
Copy link
Collaborator

Choose a reason for hiding this comment

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

this is great for testing, though we should use the default of just specifying the version and see that the module does the right thing and figures out how to build the url appropriately.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Fixed, changed back to use version.

@jeffmccune jeffmccune force-pushed the 646_fix_error_on_win2012r2 branch 2 times, most recently from 975f6ab to d8b6fb1 Compare June 29, 2017 16:51
@jeffmccune
Copy link
Collaborator Author

@ghoneycutt FYI, for the Exec[install-sensu-client] powershell error, I'm proceeding to add a new dependency on the powershell module to get the powershell provider.

rabbitmq_host => '192.168.56.10',
rabbitmq_vhost => '/sensu',
subscriptions => 'all',
client_address => $facts['networking']['ip'],
Copy link
Collaborator

Choose a reason for hiding this comment

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

In your vagrant, this should use the 192. IP and not the 10.

I check in http://localhost:3000/#/clients

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This must be non-deterministic behavior in the networking fact. Joy. In my vagrant vm $facts['networking']['ip'] resolves to 192.168.56.15. I assume this resolves to 10.0.2.15 for you?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@ghoneycutt Please LMK if $facts['networking']['ip'] is resolving to the incorrect 10.0.2.15 address for you. Digging into this, the networking fact returns the IP of the primary interface, and the opentable wind2012r2 VM has the second network interface marked as primary. With this information I expect $facts['networking']['ip'] to be robust.

I've also confirmed the IP shows up as 192.168.56.15 at http://localhost:3000/#/clients

Copy link
Collaborator

Choose a reason for hiding this comment

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

we can also check with curl -s http://admin:[email protected]:4567/clients | jq .

Warning is a lot scarier than a notice.
Without this patch there is no test coverage for Package[sensu] when the
client is a windows node.  This patch adds test coverage to fix the bug
reported in sensuGH-646.
Without this patch there isn't a Vagrant VM for Win2012r2.  Windows is
necessary to reproduce the issue in sensuGH-646 and smoke test the fix.

Using opentable/win-2012r2 Vagrant vm client

RDP port is exposed.  Login is vagrant / vagrant.

Relates to sensu#681
@cwjohnston
Copy link
Contributor

@ghoneycutt @jeffmccune

I've manually created symlinks for sensu-latest-x86.msi and sensu-latest-x64.msi in each windows platform version directory, e.g. https://repositories.sensuapp.org/msi/2012r2/sensu-latest-x64.msi

@jeffmccune
Copy link
Collaborator Author

jeffmccune commented Jun 29, 2017 via email

Partially resolves sensu#646

Still running into this error:

    Error: Parameter ensure failed on Package[sensu]: Provider windows
    must have features 'upgradeable' to set 'ensure' to 'latest' at
    sensu/manifests/package.pp:64
Without this patch the default package version for sensu is `latest`.
This is a problem for two reasons, first the package may be
automatically upgraded on Linux systems, which is a burden for
Operations when behavior changes.  Second, Windows does not have a
provider supporting the upgradable feature which results in an error in
the default case.

This path addresses both issues by defaulting the version to
`installed`.

For the Windows 2012r2 Vagrant box, the version is explicitly passed in
tests/sensu-client-windows.pp because
http://repositories.sensuapp.org/msi/ does not have sensu-latest.msi,
which is used in the default case.
Without this patch the computation of the package source URL will
inevitably be incorrect for some users.  To avoid support issues, this
patch adds an override as an escape hatch.  The user may specific the
specific package source URL which will override the computation.
@jeffmccune
Copy link
Collaborator Author

Huzzah! Finally got a clean puppet run on Windows 2012r2 with 7c523c3 Needed to bump the VM memory up to 2048 MB otherwise Puppet just kept hanging indefinitely.

==> win2012r2-client: Info: Applying configuration version '1498762972'
==> win2012r2-client: Notice: /Stage[main]/Sensu::Package/Remote_file[sensu]/ensure: created
==> win2012r2-client: Notice: /Stage[main]/Sensu::Package/Package[sensu]/ensure: created
==> win2012r2-client: Notice: /Stage[main]/Sensu::Package/Package[sensu-plugin]/ensure: created
==> win2012r2-client: Notice: /Stage[main]/Sensu::Package/File[C:/opt/sensu/conf.d]/ensure: created
==> win2012r2-client: Notice: /Stage[main]/Sensu::Package/File[C:/opt/sensu/conf.d/handlers]/ensure: created
==> win2012r2-client: Notice: /Stage[main]/Sensu::Package/File[C:/opt/sensu/conf.d/checks]/ensure: created
==> win2012r2-client: Notice: /Stage[main]/Sensu::Package/File[C:/opt/sensu/conf.d/filters]/ensure: created
==> win2012r2-client: Notice: /Stage[main]/Sensu::Package/File[C:/opt/sensu/conf.d/extensions]/ensure: created
==> win2012r2-client: Notice: /Stage[main]/Sensu::Package/File[C:/opt/sensu/conf.d/mutators]/ensure: created
==> win2012r2-client: Notice: /Stage[main]/Sensu::Package/File[C:/opt/sensu/handlers]/ensure: created
==> win2012r2-client: Notice: /Stage[main]/Sensu::Package/File[C:/opt/sensu/extensions]/ensure: created
==> win2012r2-client: Notice: /Stage[main]/Sensu::Package/File[C:/opt/sensu/extensions/handlers]/ensure: created
==> win2012r2-client: Notice: /Stage[main]/Sensu::Package/File[C:/opt/sensu/mutators]/ensure: created
==> win2012r2-client: Notice: /Stage[main]/Sensu::Package/File[C:/opt/sensu/plugins]/ensure: created
==> win2012r2-client: Info: Class[Sensu::Package]: Scheduling refresh of Service[sensu-client]
==> win2012r2-client: Notice: /Stage[main]/Sensu::Rabbitmq::Config/File[C:/opt/sensu/conf.d/rabbitmq.json]/ensure: created
==> win2012r2-client: Notice: /Stage[main]/Sensu::Rabbitmq::Config/Sensu_rabbitmq_config[win2012r2-client]/ensure: created
==> win2012r2-client: Info: Class[Sensu::Rabbitmq::Config]: Scheduling refresh of Service[sensu-client]
==> win2012r2-client: Notice: /Stage[main]/Sensu::Api::Config/File[C:/opt/sensu/conf.d/api.json]/ensure: created
==> win2012r2-client: Notice: /Stage[main]/Sensu::Api::Config/Sensu_api_config[win2012r2-client]/ensure: created
==> win2012r2-client: Notice: /Stage[main]/Sensu::Redis::Config/File[C:/opt/sensu/conf.d/redis.json]/ensure: created
==> win2012r2-client: Notice: /Stage[main]/Sensu::Redis::Config/Sensu_redis_config[win2012r2-client]/ensure: created
==> win2012r2-client: Notice: /Stage[main]/Sensu::Client::Config/File[C:/opt/sensu/conf.d/client.json]/ensure: created
==> win2012r2-client: Notice: /Stage[main]/Sensu::Client::Config/Sensu_client_config[win2012r2-client]/ensure: created
==> win2012r2-client: Info: Class[Sensu::Client::Config]: Scheduling refresh of Service[sensu-client]
==> win2012r2-client: Info: Computing checksum on file C:/opt/sensu/bin/sensu-client.xml
==> win2012r2-client: Info: /Stage[main]/Sensu::Client::Service/File[C:/opt/sensu/bin/sensu-client.xml]: Filebucketed C:/opt/sensu/bin/sensu-client.xml to puppet with sum 5dd4feefb65905221641722d60335bc1
==> win2012r2-client: Notice: /Stage[main]/Sensu::Client::Service/File[C:/opt/sensu/bin/sensu-client.xml]/content: content changed '{md5}5dd4feefb65905221641722d60335bc1' to '{md5}67dcc6c38ffcf0b5c887891c185f5856'
==> win2012r2-client: Notice: /Stage[main]/Sensu::Client::Service/Exec[install-sensu-client]/returns: executed successfully
==> win2012r2-client: Notice: /Stage[main]/Sensu::Client::Service/Service[sensu-client]/ensure: ensure changed 'stopped' to 'running'
==> win2012r2-client: Info: /Stage[main]/Sensu::Client::Service/Service[sensu-client]: Unscheduling refresh on Service[sensu-client]
==> win2012r2-client: Info: Creating state file C:/ProgramData/PuppetLabs/puppet/cache/state/state.yaml
==> win2012r2-client: Notice: Applied catalog in 108.81 seconds

The resulting Vagrant VM shows up correctly with a 192.168.56.15 address at http://localhost:3000/#/clients

@jeffmccune jeffmccune force-pushed the 646_fix_error_on_win2012r2 branch 2 times, most recently from 0b20e39 to d928ca6 Compare June 29, 2017 19:35
The name parameter of Package[sensu] needs to match Add/Remove programs,
which is `Sensu`
The OS expects version numbers to be dotted, e.g. 0.29.0.11, whereas the
file paths have a hyphen denoting the release component.  This patch
maps the file version ID to the package version ID to allow the catalog
to converge.
@jeffmccune jeffmccune force-pushed the 646_fix_error_on_win2012r2 branch from d928ca6 to 98513d0 Compare June 29, 2017 19:37
@jeffmccune jeffmccune changed the title [WIP] Fix Package[sensu] on windows Fix Package[sensu] on windows Jun 29, 2017
@jeffmccune
Copy link
Collaborator Author

@ghoneycutt This is finally ready for review / merge (hopefully).

Provisioning win2012r2-client works, the puppet run converges in a single run, and the windows sensu client registers with sensu-server using 192.168.56.15 as the client IP. All other comments up to now have been addressed.

@ghoneycutt
Copy link
Collaborator

Testing this now

} else {
Write-Output "Installing Puppet from $agent_url"
Write-Output "Log will be written to $log"
Remove-Item $log
Copy link
Collaborator

Choose a reason for hiding this comment

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

why the remove here? seems to be causing issues.

==> win2012r2-client: Log will be written to C:/vagrant/puppet-agent.log
==> win2012r2-client: Remove-Item : Cannot find path 'C:\vagrant\puppet-agent.log' because it does
==> win2012r2-client: not exist.
==> win2012r2-client: At C:\tmp\vagrant-shell.ps1:9 char:3
==> win2012r2-client: +   Remove-Item $log
==> win2012r2-client: +   ~~~~~~~~~~~~~~~~
==> win2012r2-client:     + CategoryInfo          : ObjectNotFound: (C:\vagrant\puppet-agent.log:Str
==> win2012r2-client:    ing) [Remove-Item], ItemNotFoundException
==> win2012r2-client:     + FullyQualifiedErrorId : PathNotFound,Microsoft.PowerShell.Commands.Remov
==> win2012r2-client:    eItemCommand

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Removed the log because it was originally verbose, huge, and grew indefinitely. I'll add a test to remove only if present.

Vagrantfile Outdated
client.vm.box = "opentable/win-2012r2-standard-amd64-nocm"
client.vm.provider :virtualbox do |vb|
vb.customize ["modifyvm", :id, "--memory", "2048"]
vb.customize ["modifyvm", :id, "--cpus", "2"]
Copy link
Collaborator

Choose a reason for hiding this comment

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

can we use 1 cpu here?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Sure, will change.

@ghoneycutt
Copy link
Collaborator

This works, just need clarification on using 1 cpu and the remove log part in the windows provisioner

@ghoneycutt
Copy link
Collaborator

Also, please change the port to use '3389'. The microsoft remote desktop client for osx doesnt allow you to specify a port. Also add auto_correct: true as the sensu-server does. Then if 3389 is in use, it will use a different port automatically.

@jeffmccune
Copy link
Collaborator Author

Also, please change the port to use '3389'. The microsoft remote desktop client for osx doesnt allow you to specify a port. Also add auto_correct: true as the sensu-server does. Then if 3389 is in use, it will use a different port automatically.

Will change. As an FYI, I added the PC Name as 127.0.0.1:33389 and it seems to work fine with Microsoft Remote Desktop 8.0.40 on OSX.

Remove agent install log only if the log exists.  Avoids this error:

    ==> win2012r2-client: Log will be written to C:/vagrant/puppet-agent.log
    ==> win2012r2-client: Remove-Item : Cannot find path 'C:\vagrant\puppet-agent.log' because it does
    ==> win2012r2-client: not exist.
    ==> win2012r2-client: At C:\tmp\vagrant-shell.ps1:9 char:3
    ==> win2012r2-client: +   Remove-Item $log
    ==> win2012r2-client: +   ~~~~~~~~~~~~~~~~
    ==> win2012r2-client:     + CategoryInfo          : ObjectNotFound: (C:\vagrant\puppet-agent.log:Str
    ==> win2012r2-client:    ing) [Remove-Item], ItemNotFoundException
    ==> win2012r2-client:     + FullyQualifiedErrorId : PathNotFound,Microsoft.PowerShell.Commands.Remov
    ==> win2012r2-client:    eItemCommand
@jeffmccune
Copy link
Collaborator Author

@ghoneycutt Updated with 1 CPU, remove puppet-agent.log if present, and RDP on 3389.

@ghoneycutt ghoneycutt merged commit 366bc4f into sensu:master Jun 30, 2017
@ghoneycutt
Copy link
Collaborator

Solves #646

@ghoneycutt
Copy link
Collaborator

Solves #681

@ghoneycutt
Copy link
Collaborator

Thanks @jeffmccune !

@ghoneycutt
Copy link
Collaborator

Released in v2.8.0

@jeffmccune jeffmccune mentioned this pull request Jun 30, 2017
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.

Vagrant should have clients for other platforms Error installing Sensu on Windows Server 2012R2
5 participants