Skip to content

Commit

Permalink
(BKR-967) Add :disable_analytics option
Browse files Browse the repository at this point in the history
Allow :disable_analytics to be set in beaker options, allowing us to block
traffic to Google Analytics.
  • Loading branch information
james-stocks committed Nov 4, 2016
1 parent 6becdbb commit c9e2565
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 3 deletions.
17 changes: 17 additions & 0 deletions lib/beaker-pe/install/pe_utils.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
[ 'aio_defaults', 'pe_defaults', 'puppet_utils', 'windows_utils' ].each do |lib|
require "beaker/dsl/install_utils/#{lib}"
end
require "beaker/host_prebuilt_steps"
require "beaker-answers"
require "timeout"
require "json"
require "beaker-pe/options/presets"

module Beaker
module DSL
module InstallUtils
Expand All @@ -22,6 +25,7 @@ module PEUtils
include PEDefaults
include PuppetUtils
include WindowsUtils
include HostPrebuiltSteps

# Version of PE when we switched from legacy installer to MEEP.
MEEP_CUTOVER_VERSION = '2016.2.0'
Expand Down Expand Up @@ -705,6 +709,12 @@ def install_pe
install_pe_on(hosts, options)
end

def disable_analytics(hosts)
logger.info("Disabling analytics on dashboard host(s)")
set_etc_hosts(hosts, "127.0.0.1\tgoogle-analytics.com\n")
set_etc_hosts(hosts, "127.0.0.1\twww.google-analytics.com\n")
end

def check_puppetdb_status_endpoint(host)
if version_is_less(host['pe_ver'], '2016.1.0')
return true
Expand Down Expand Up @@ -774,6 +784,8 @@ def check_console_status_endpoint(host)
# options, refer to {#do_install} documentation
#
def install_pe_on(install_hosts, opts)
opts = pe_presets.merge(opts)

confine_block(:to, {}, install_hosts) do
sorted_hosts.each do |host|
#process the version files if necessary
Expand All @@ -791,6 +803,11 @@ def install_pe_on(install_hosts, opts)
host['pe_ver'] ||= Beaker::Options::PEVersionScraper.load_pe_version(host[:pe_dir] || opts[:pe_dir], opts[:pe_version_file])
end
end

if opts[:disable_analytics] then
disable_analytics(dashboard)
end

do_install sorted_hosts, opts
end
end
Expand Down
9 changes: 9 additions & 0 deletions lib/beaker-pe/options/presets.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Generates an OptionsHash of preset values for Beaker options relating to PE
#
# @return [OptionsHash] The supported arguments in an OptionsHash
def pe_presets
h = Beaker::Options::OptionsHash.new
h.merge({
:disable_analytics => true,
})
end
43 changes: 40 additions & 3 deletions spec/beaker-pe/install/pe_utils_spec.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
require 'spec_helper'
require 'beaker'
require 'beaker-pe/options/presets'

class ClassMixedWithDSLInstallUtils
include Beaker::DSL::InstallUtils
Expand Down Expand Up @@ -283,6 +284,7 @@ def prep_host(host)
context 'the do_higgs_install' do
it 'submits the correct installer cmd to invoke Higgs' do
prep_host(host)
allow( subject ).to receive( :options ).and_return( {} )
subject.do_higgs_install(host, opts)
end
end
Expand All @@ -305,6 +307,7 @@ def prep_host(host)
context 'the do_higgs_install' do
it 'submits the correct installer cmd to invoke Higgs' do
prep_host(host)
allow( subject ).to receive( :options ).and_return( {} )
subject.do_higgs_install(host, opts)
end
end
Expand Down Expand Up @@ -889,6 +892,7 @@ def slice_installer_options(host)
end

allow( subject ).to receive( :hosts ).and_return( hosts )
allow( subject ).to receive( :options ).and_return( {} )
#create answers file per-host, except windows
allow( subject ).to receive( :create_remote_file ).with( hosts[0], /answers/, /q/ )
#run installer on all hosts
Expand Down Expand Up @@ -944,6 +948,7 @@ def slice_installer_options(host)
allow( subject ).to receive( :sleep ).and_return( true )

allow( subject ).to receive( :hosts ).and_return( hosts )
allow( subject ).to receive( :options ).and_return( {} )

#run higgs installer command
expect( subject ).to receive( :on ).with( hosts[0],
Expand All @@ -959,6 +964,7 @@ def slice_installer_options(host)
allow( subject ).to receive( :sleep ).and_return( true )

allow( subject ).to receive( :hosts ).and_return( hosts )
allow( subject ).to receive( :options ).and_return( {} )

#run higgs installer command
expect( subject ).to receive( :on ).with( hosts[0],
Expand All @@ -977,7 +983,35 @@ def slice_installer_options(host)
allow( subject ).to receive( :options ).and_return( {} )
allow( subject ).to receive( :hosts ).and_return( hosts_sorted )
allow( subject ).to receive( :do_install ).and_return( true )
expect( subject ).to receive( :do_install ).with( hosts, {} )
allow( subject ).to receive( :set_etc_hosts )
expect( subject ).to receive( :do_install ).with( hosts, pe_presets )
subject.install_pe
end

it 'blocks analytics by default' do
allow( subject ).to receive( :options ).and_return( {} )
allow( subject ).to receive( :hosts ).and_return( hosts_sorted )
allow( subject ).to receive( :do_install ).and_return( true )
allow( subject ).to receive( :set_etc_hosts )
expect( subject ).to receive( :do_install ).with( hosts, pe_presets )
subject.install_pe
end

it 'blocks analytics when disable_analytics is true' do
allow( subject ).to receive( :options ).and_return( {:disable_analytics => true} )
allow( subject ).to receive( :hosts ).and_return( hosts_sorted )
allow( subject ).to receive( :do_install ).and_return( true )
allow( subject ).to receive( :set_etc_hosts )
expect( subject ).to receive( :do_install ).with( hosts, {:disable_analytics => true} )
subject.install_pe
end

it 'does not block analytics when disable_analytics is false' do
allow( subject ).to receive( :options ).and_return( {:disable_analytics => false} )
allow( subject ).to receive( :hosts ).and_return( hosts_sorted )
allow( subject ).to receive( :do_install ).and_return( true )
expect( subject ).to_not receive( :set_etc_hosts )
expect( subject ).to receive( :do_install ).with( hosts, {:disable_analytics => false} )
subject.install_pe
end

Expand All @@ -989,7 +1023,8 @@ def slice_installer_options(host)
allow( subject ).to receive( :hosts ).and_return( hosts_sorted )
allow( subject ).to receive( :options ).and_return( {} )
allow( subject ).to receive( :do_install ).and_return( true )
expect( subject ).to receive( :do_install ).with( hosts, {} )
allow( subject ).to receive( :set_etc_hosts )
expect( subject ).to receive( :do_install ).with( hosts, pe_presets )
subject.install_pe
hosts.each do |h|
expect( h['pe_ver'] ).to be === '2.8'
Expand All @@ -998,8 +1033,10 @@ def slice_installer_options(host)

it 'can act upon a single host' do
allow( subject ).to receive( :hosts ).and_return( hosts )
allow( subject ).to receive( :options ).and_return( {} )
allow( subject ).to receive( :sorted_hosts ).and_return( [hosts[0]] )
expect( subject ).to receive( :do_install ).with( [hosts[0]], {} )
allow( subject ).to receive( :set_etc_hosts )
expect( subject ).to receive( :do_install ).with( [hosts[0]], pe_presets )
subject.install_pe_on(hosts[0], {})
end
end
Expand Down

0 comments on commit c9e2565

Please sign in to comment.