Skip to content
This repository has been archived by the owner on Feb 25, 2022. It is now read-only.

Commit

Permalink
(SLV-458) rubocop cleanup
Browse files Browse the repository at this point in the history
This commit cleans up (or disables) rubocop errors in order to get
a clean rubocop run.
  • Loading branch information
johnduarte committed Jun 3, 2019
1 parent 03827f7 commit 5759b41
Show file tree
Hide file tree
Showing 104 changed files with 1,718 additions and 1,562 deletions.
4 changes: 4 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ Layout/AlignHash:
EnforcedHashRocketStyle: table
Style/StringLiterals:
EnforcedStyle: double_quotes
Metrics/LineLength:
Max: 120
Metrics/MethodLength:
Max: 99
Metrics/BlockLength:
Expand All @@ -16,3 +18,5 @@ Metrics/PerceivedComplexity:
Max: 15
Style/MultilineIfModifier:
Enabled: false
Naming/FileName:
Enabled: false
34 changes: 17 additions & 17 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
source ENV['GEM_SOURCE'] || 'https://artifactory.delivery.puppetlabs.net/artifactory/api/gems/rubygems/'
# frozen_string_literal: true

gem 'beaker', '~>4.0'
gem 'beaker-benchmark', '~>0.0'
gem 'beaker-pe', '~>2.0'
gem 'beaker-aws'
gem 'beaker-abs', '~>0.1'
gem 'beaker-pe-large-environments', '~>0.3'
gem 'scooter', '~>4.3'
gem 'rototiller', '~>1.0'
gem 'rspec', '~>3.0'
gem 'master_manipulator', '~>2.1'
gem 'beaker-puppet', '~>1.0'
source ENV["GEM_SOURCE"] || "https://artifactory.delivery.puppetlabs.net/artifactory/api/gems/rubygems/"

if File.exists? "#{__FILE__}.local"
eval(File.read("#{__FILE__}.local"), binding)
end
gem "beaker", "~>4.0"
gem "beaker-abs", "~>0.1"
gem "beaker-aws"
gem "beaker-benchmark", "~>0.0"
gem "beaker-pe", "~>2.0"
gem "beaker-pe-large-environments", "~>0.3"
gem "beaker-puppet", "~>1.0"
gem "master_manipulator", "~>2.1"
gem "rototiller", "~>1.0"
gem "rspec", "~>3.0"
gem "scooter", "~>4.3"

gem 'google-cloud', '~> 0.52.0'
gem 'google-api-client', '~> 0.19.0'
eval(File.read("#{__FILE__}.local"), binding) if File.exist? "#{__FILE__}.local" # rubocop:disable Security/Eval

gem "google-api-client", "~> 0.19.0"
gem "google-cloud", "~> 0.52.0"
16 changes: 8 additions & 8 deletions jenkins-integration/Gemfile
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
source ENV['GEM_SOURCE'] || 'https://rubygems.org'
# frozen_string_literal: true

gem 'beaker', '~>3.2.0'
gem 'beaker-hostgenerator', '0.8.0'
gem 'beaker-pe', '~>1.4'
source ENV["GEM_SOURCE"] || "https://rubygems.org"

gem 'scooter', '~> 3.2.0'
gem "beaker", "~>3.2.0"
gem "beaker-hostgenerator", "0.8.0"
gem "beaker-pe", "~>1.4"

if File.exists? "#{__FILE__}.local"
eval(File.read("#{__FILE__}.local"), binding)
end
gem "scooter", "~> 3.2.0"

eval(File.read("#{__FILE__}.local"), binding) if File.exist? "#{__FILE__}.local" # rubocop:disable Security/Eval
60 changes: 33 additions & 27 deletions jenkins-integration/beaker/install/foss/30_install_dev_repos.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
install_opts = options.merge( { :dev_builds_repos => ["PC1"] })
repo_config_dir = 'tmp/repo_configs'
# frozen_string_literal: true

require 'net/http'
# rubocop: disable Naming/PredicateName, Naming/AccessorMethodName
install_opts = options.merge(dev_builds_repos: ["PC1"])
repo_config_dir = "tmp/repo_configs"

BASE_URL = 'http://builds.puppetlabs.lan'
require "net/http"

BASE_URL = "http://builds.puppetlabs.lan"

def has_cent7_repo?(package, version)
cent7_uri = URI("#{BASE_URL}/#{package}/#{version}/repo_configs/rpm/pl-#{package}-#{version}-el-7-x86_64.repo")
Expand All @@ -22,23 +25,24 @@ def has_cent7_repo?(package, version)
end

def get_cent7_repo(response_lines, package)
response_lines.
map { |l| l.match(/^.*href="([^"]+)\/\?C=M&O=D".*$/)[1] }.
find { |v| has_cent7_repo?(package, v) }
response_lines
.map { |l| l.match(%r{^.*href="([^"]+)/\?C=M&O=D".*$})[1] }
.find { |v| has_cent7_repo?(package, v) }
end

def get_latest_server_version(version)
response = Net::HTTP.get(URI(BASE_URL + '/puppetserver/?C=M&O=D'))
response = Net::HTTP.get(URI(BASE_URL + "/puppetserver/?C=M&O=D"))

# Scrape the puppetserver repo page for available puppetserver builds and
# filter down to only ones matching the specified branch. The list of builds
# is ordered from most recent to oldest. The resulting list is passed along
# to the get_cent7_repo routine, which returns a URL for the first build which
# has a cent7 repo in it.
get_cent7_repo(
response.lines.
select { |l| l =~ /<td><a / }.
select { |l| l =~ /">.*#{version}.*\/<\/a>/}, "puppetserver")
response.lines
.select { |l| l =~ /<td><a / }
.select { |l| l =~ %r{">.*#{version}.*/</a>} }, "puppetserver"
)
end

def get_latest_agent_version
Expand All @@ -51,64 +55,66 @@ def get_latest_agent_version
json = JSON.parse(response.body)
json["suite-commit"].strip
else
Beaker::Log.notify("Unable to get last successful build from: #{url}, " +
Beaker::Log.notify("Unable to get last successful build from: #{url}, " \
"error: #{response.code}, #{response.message}")
nil
end
end

def get_latest_release_agent_version
response = Net::HTTP.get(URI(BASE_URL + '/puppet-agent/?C=M&O=D'))
response = Net::HTTP.get(URI(BASE_URL + "/puppet-agent/?C=M&O=D"))

# Scrape the puppet-agent repo page for available puppet-agent builds and
# filter down to only released builds (e.g., 1.2.3) vs.
# some mergely/SHA version. The list of builds is ordered from most recent to
# oldest. The resulting list is passed along to the get_cent7_repo routine,
# which returns a URL for the first build which has a cent7 repo in it.
get_cent7_repo(
response.lines.
select { |l| l =~ /<td><a / }.
select { |l| l.match(/^.*href="(\d+\.\d+\.\d+)\/\?C=M&amp;O=D".*$/) },
"puppet-agent")
response.lines
.select { |l| l =~ /<td><a / }
.select { |l| l.match(%r{^.*href="(\d+\.\d+\.\d+)/\?C=M&amp;O=D".*$}) },
"puppet-agent"
)
end

step "Setup Puppet Server repositories." do
package_build_version = ENV['PACKAGE_BUILD_VERSION']
package_build_version = ENV["PACKAGE_BUILD_VERSION"]

if package_build_version == "latest"
Beaker::Log.notify("Looking for the very latest Puppet Server build")
package_build_version = "master"
end

if ((package_build_version =~ /SNAPSHOT$/) ||
(package_build_version == "master"))
if (package_build_version =~ /SNAPSHOT$/) ||
(package_build_version == "master")
package_build_version = get_latest_server_version(package_build_version)
end

if package_build_version
Beaker::Log.notify("Installing OSS Puppet Server version '#{package_build_version}'")
install_puppetlabs_dev_repo master, 'puppetserver', package_build_version,
install_puppetlabs_dev_repo master, "puppetserver", package_build_version,
repo_config_dir, install_opts
else
abort("Environment variable PACKAGE_BUILD_VERSION required for package installs!")
end
end

step "Setup Puppet repositories" do
puppet_agent_version = ENV['PUPPET_AGENT_VERSION']
puppet_agent_version = ENV["PUPPET_AGENT_VERSION"]

case puppet_agent_version
when "latest"
puppet_agent_version = get_latest_agent_version
when "latest-release"
puppet_agent_version = get_latest_release_agent_version
when "latest"
puppet_agent_version = get_latest_agent_version
when "latest-release"
puppet_agent_version = get_latest_release_agent_version
end

if puppet_agent_version
Beaker::Log.notify("Installing OSS Puppet AGENT version '#{puppet_agent_version}'")
install_puppetlabs_dev_repo master, 'puppet-agent', puppet_agent_version,
install_puppetlabs_dev_repo master, "puppet-agent", puppet_agent_version,
repo_config_dir, install_opts
else
abort("Environment variable PUPPET_AGENT_VERSION required for package installs!")
end
end
# rubocop: enable Naming/PredicateName, Naming/AccessorMethodName
13 changes: 7 additions & 6 deletions jenkins-integration/beaker/install/foss/70_install_puppet.rb
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
# frozen_string_literal: true

step "Upgrade nss to version that is hopefully compatible with jdk version puppetserver will use." do
nss_package=nil
variant, _, _, _ = master['platform'].to_array
variant, = master["platform"].to_array
case variant
when /^(debian|ubuntu)$/
nss_package_name="libnss3"
nss_package_name = "libnss3"
when /^(redhat|el|centos)$/
nss_package_name="nss"
nss_package_name = "nss"
end
if nss_package_name
if defined?(nss_package_name)
master.upgrade_package(nss_package_name)
else
Beaker::Log.warn("Don't know what nss package to use for #{variant} so not installing one")
end
end

step "Install Puppet Server." do
install_package master, 'puppetserver'
install_package master, "puppetserver"
end
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
test_name 'Run puppet agent on the master to prime directories' do
# frozen_string_literal: true

test_name "Run puppet agent on the master to prime directories" do
# Before kicking off a Gatling run, we run the agent on the master against
# itself one time. This ensures that the master will create any directories
# in which it will need to store artifacts for future agent runs. Doing this
Expand Down
4 changes: 3 additions & 1 deletion jenkins-integration/beaker/install/pe/10_install_pe.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
test_name 'Install PE'
# frozen_string_literal: true

test_name "Install PE"

# Environment variables:
# (required) pe_dir="http://enterprise.delivery.puppetlabs.net/2016.2/ci-ready/"
Expand Down
6 changes: 4 additions & 2 deletions jenkins-integration/beaker/install/pe/50_install_modules.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
require 'puppet/gatling/config'
# frozen_string_literal: true

test_name 'Install Puppet modules into code-staging directory'
require "puppet/gatling/config"

test_name "Install Puppet modules into code-staging directory"

# environmentsdir = '/etc/puppetlabs/code-staging/environments'
# modules = modules_per_environment(node_configs(get_scenario_from_env()))
Expand Down
27 changes: 15 additions & 12 deletions jenkins-integration/beaker/install/pe/60_classify_nodes_via_NC.rb
Original file line number Diff line number Diff line change
@@ -1,37 +1,40 @@
require 'puppet/gatling/config'
require 'scooter'
# frozen_string_literal: true

require "puppet/gatling/config"
require "scooter"

test_name "Classify PE agents via Node Classifier"

def classify_pe_nodes(classifier, nodes)
production_id = classifier.get_node_group_id_by_name('Production environment')
production_id = classifier.get_node_group_id_by_name("Production environment")
nodes = group_by_environment(nodes)
nodes.each_pair do |env, node_configs|
node_configs.each do |config|
classifier.find_or_create_node_group_model(
'name' => "#{config['certname_prefix']}-group",
'parent' => production_id,
'environment' => env,
'environment_trumps' => true,
'rule' => ['~', ['fact', 'clientcert'], "#{config['certname_prefix']}.*"],
'classes' => Hash[config['classes'].map { |klass| [klass, {}] }])
"name" => "#{config['certname_prefix']}-group",
"parent" => production_id,
"environment" => env,
"environment_trumps" => true,
"rule" => ["~", %w[fact clientcert], "#{config['certname_prefix']}.*"],
"classes" => Hash[config["classes"].map { |klass| [klass, {}] }]
)
end
end
end

# this code gets the list of node -> class name mappings by parsing
# the g-p-l-t 'scenario' json file.

nodes = node_configs(get_scenario_from_env())
nodes = node_configs(get_scenario_from_env)
classifier = Scooter::HttpDispatchers::ConsoleDispatcher.new(dashboard)

# Updating classes can take a VERY long time, like the OPS deployment
# which has ~80 environments each with hundreds of classes.
# Set the connection timeout to 60 minutes to accomodate this.
classifier.connection.options.timeout = 3600
classifier.update_classes()
classifier.update_classes

classify_pe_nodes(classifier, nodes)

# TODO validate classes by asking for the classes for the each node and
# TODO: validate classes by asking for the classes for the each node and
# asserting they're the same ones that are in the JSON config
14 changes: 8 additions & 6 deletions jenkins-integration/beaker/install/pe/97_enable_file_sync.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
require 'scooter'
test_name 'Enable file_sync' do
# frozen_string_literal: true

require "scooter"
test_name "Enable file_sync" do
api = Scooter::HttpDispatchers::ConsoleDispatcher.new(dashboard)
pe_master_group = api.get_node_group_by_name('PE Master')
pe_master_group['classes']['puppet_enterprise::profile::master']['file_sync_enabled'] = true
api.replace_node_group(pe_master_group['id'], pe_master_group)
on(master, 'puppet agent -t', :acceptable_exit_codes => [0,2])
pe_master_group = api.get_node_group_by_name("PE Master")
pe_master_group["classes"]["puppet_enterprise::profile::master"]["file_sync_enabled"] = true
api.replace_node_group(pe_master_group["id"], pe_master_group)
on(master, "puppet agent -t", acceptable_exit_codes: [0, 2])
end
22 changes: 12 additions & 10 deletions jenkins-integration/beaker/install/pe/98_sync_codedir.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
test_name 'Sync code-staging to code via File Sync'
# frozen_string_literal: true

test_name "Sync code-staging to code via File Sync"

# Do a File Sync commit
curl = 'curl '
curl += '--cert $(puppet config print hostcert) '
curl += '--key $(puppet config print hostprivkey) '
curl += '--cacert $(puppet config print localcacert) '
curl = "curl "
curl += "--cert $(puppet config print hostcert) "
curl += "--key $(puppet config print hostprivkey) "
curl += "--cacert $(puppet config print localcacert) "
curl += '-H "Content-type: application/json" '
curl += "https://#{master}:8140/file-sync/v1/commit "
curl += '-d \'{"commit-all": true}\''
Expand All @@ -16,11 +18,11 @@
# trigger a synchronous sync of the files. Ideally that means that when
# this curl command returns, we know that the sync is complete and that the
# files have been deployed successfully.
curl = 'curl '
curl += '-X POST '
curl += '--cert $(puppet config print hostcert) '
curl += '--key $(puppet config print hostprivkey) '
curl += '--cacert $(puppet config print localcacert) '
curl = "curl "
curl += "-X POST "
curl += "--cert $(puppet config print hostcert) "
curl += "--key $(puppet config print hostprivkey) "
curl += "--cacert $(puppet config print localcacert) "
curl += '-H "Content-type: application/json" '
curl += "https://#{master}:8140/file-sync/v1/force-sync "

Expand Down

This file was deleted.

Loading

0 comments on commit 5759b41

Please sign in to comment.