From 692e0877f4e9bef54d1a47c5df681ac5b8d04d31 Mon Sep 17 00:00:00 2001 From: Nathan Haneysmith Date: Mon, 13 Nov 2017 13:15:35 -0800 Subject: [PATCH] use cookstyle, chef13 prep --- .kitchen.yml | 3 +- .rubocop.yml | 35 -------------------- CONTRIBUTING.md | 10 +++--- Gemfile | 4 +-- Rakefile | 10 ++++-- Vagrantfile | 6 ++-- attributes/default.rb | 44 ++++++++++++-------------- metadata.rb | 2 +- recipes/alertmanager.rb | 12 +++---- recipes/default.rb | 2 +- recipes/service.rb | 10 ++---- resources/job.rb | 2 +- spec/unit/recipes/alertmanager_spec.rb | 2 -- spec/unit/recipes/default_spec.rb | 2 -- 14 files changed, 50 insertions(+), 94 deletions(-) delete mode 100644 .rubocop.yml diff --git a/.kitchen.yml b/.kitchen.yml index 7262f3c..4c1b0c8 100644 --- a/.kitchen.yml +++ b/.kitchen.yml @@ -3,6 +3,8 @@ driver: provisioner: name: chef_zero + deprecations_as_errors: true + resource_cloning: false data_path: test/shared platforms: @@ -53,7 +55,6 @@ suites: - recipe[prometheus::default] provisioner: name: chef_zero - require_chef_omnibus: 11.12.4 attributes: prometheus: init_style: 'init' diff --git a/.rubocop.yml b/.rubocop.yml deleted file mode 100644 index 1f91990..0000000 --- a/.rubocop.yml +++ /dev/null @@ -1,35 +0,0 @@ -AllCops: - Exclude: - - vendor/**/* - - .kitchen/**/* - - Vagrantfile - -ClassLength: - Enabled: false -Documentation: - Enabled: false -Encoding: - Enabled: false -LineLength: - Enabled: false -MethodLength: - Enabled: false -NumericLiterals: - Enabled: false -Style/StringLiterals: - Enabled: true - EnforcedStyle: single_quotes -Metrics/LineLength: - Enabled: false -Style/ExtraSpacing: - Enabled: false -Style/SpaceBeforeFirstArg: - Enabled: false -Style/FrozenStringLiteralComment: - Enabled: false -Lint/AmbiguousBlockAssociation: - Enabled: false -Style/PercentLiteralDelimiters: - Enabled: false -Style/SymbolArray: - Enabled: false diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 4bb6599..6ef7586 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -14,10 +14,10 @@ Coding Standards The submitted code should be compatible with the standard Ruby coding guidelines. Here are some additional resources: -- [Ruby Style Guide](https://github.com/bbatsov/ruby-style-guide) +- [Cookstyle Guide](https://github.com/chef/cookstyle) - [GitHub Styleguide](https://github.com/styleguide/ruby) -This cookbook is equipped with Rubocop, which will fail the build for violating +This cookbook is equipped with Cookstyle, which will fail the build for violating these standards. Testing @@ -29,7 +29,7 @@ re-introduced. We understand that not all users are familiar with the testing ecosystem. This cookbook is fully-tested using [Foodcritic](https://github.com/acrmp/foodcritic), -[Rubocop](https://github.com/bbatsov/rubocop), +[Cookstyle](https://github.com/chef/cookstyle), and [Test Kitchen](https://github.com/test-kitchen/test-kitchen) with [Serverspec](https://github.com/serverspec/serverspec) bussers. @@ -39,9 +39,9 @@ Process $ git clone git@github.com:rayrod2030/chef-prometheus.git -2. Make sure you have a sane [ChefDK][] development environment: +2. Make sure you have a sane [ChefDK][] development environment (2.X): - $ chef version + $ chef --version 3. Make any changes 4. Write tests to support those changes. diff --git a/Gemfile b/Gemfile index 96ab45c..0dd9884 100644 --- a/Gemfile +++ b/Gemfile @@ -6,8 +6,8 @@ group :unit do end group :lint do - gem 'foodcritic', '~> 8.1.0' - gem 'rubocop', '~> 0.47.1' + gem 'foodcritic' + gem 'cookstyle' end group :kitchen_common do diff --git a/Rakefile b/Rakefile index 190487b..2744308 100644 --- a/Rakefile +++ b/Rakefile @@ -1,4 +1,5 @@ require 'bundler/setup' +require 'cookstyle' require 'rubocop/rake_task' require 'foodcritic' require 'kitchen' @@ -7,15 +8,18 @@ require 'rspec/core/rake_task' # Unit Tests. rspec/chefspec RSpec::Core::RakeTask.new(:unit) -# Style tests. Rubocop and Foodcritic +# Style tests. Cookstyle and Foodcritic namespace :style do desc 'Run Ruby style checks' - RuboCop::RakeTask.new(:ruby) + # RuboCop::RakeTask.new(:ruby) + RuboCop::RakeTask.new(:ruby) do |task| + task.options << '--display-cop-names' + end desc 'Run Chef style checks' FoodCritic::Rake::LintTask.new(:chef) do |t| t.options = { - fail_tags: ['any'] + fail_tags: ['any'], } end end diff --git a/Vagrantfile b/Vagrantfile index d2c6b39..628e76c 100644 --- a/Vagrantfile +++ b/Vagrantfile @@ -78,13 +78,13 @@ Vagrant.configure(VAGRANTFILE_API_VERSION) do |config| mysql: { server_root_password: 'rootpass', server_debian_password: 'debpass', - server_repl_password: 'replpass' - } + server_repl_password: 'replpass', + }, } chef.run_list = [ 'recipe[prometheus::default]', - 'recipe[prometheus::alertmanager]' + 'recipe[prometheus::alertmanager]', ] end end diff --git a/attributes/default.rb b/attributes/default.rb index ff0fcde..e02be33 100644 --- a/attributes/default.rb +++ b/attributes/default.rb @@ -16,26 +16,24 @@ default['prometheus']['install_method'] = 'binary' # Init style. -# rubocop:disable Style/ConditionalAssignment -case node['platform_family'] -when 'debian' - if node['platform'] == 'ubuntu' && node['platform_version'].to_f < 15.04 - default['prometheus']['init_style'] = 'upstart' - elsif node['platform'] == 'debian' && node['platform_version'].to_f < 8.0 - default['prometheus']['init_style'] = 'runit' - else - default['prometheus']['init_style'] = 'systemd' - end -when 'rhel', 'fedora' - if node['platform_version'].to_i >= 7 - default['prometheus']['init_style'] = 'systemd' - else - default['prometheus']['init_style'] = 'init' - end -else - default['prometheus']['init_style'] = 'init' -end -# rubocop:enable Style/ConditionalAssignment +default['prometheus']['init_style'] = case node['platform_family'] + when 'debian' + if node['platform'] == 'ubuntu' && node['platform_version'].to_f < 15.04 + 'upstart' + elsif node['platform'] == 'debian' && node['platform_version'].to_f < 8.0 + 'runit' + else + 'systemd' + end + when 'rhel', 'fedora' + if node['platform_version'].to_i >= 7 + 'systemd' + else + 'init' + end + else + 'init' + end # Location for Prometheus logs default['prometheus']['log_dir'] = '/var/log/prometheus' @@ -88,8 +86,8 @@ # Prometheus configuration file name. default['prometheus']['v2_cli_flags'] = [ - 'web.enable-lifecycle' - ] + 'web.enable-lifecycle', +] default['prometheus']['flags']['config.file'] = "#{node['prometheus']['dir']}/prometheus.yml" default['prometheus']['v2_cli_opts']['config.file'] = "#{node['prometheus']['dir']}/prometheus.yml" @@ -214,7 +212,7 @@ # web.use-local-assets flag got removed in 0.17 # https://github.com/prometheus/prometheus/commit/a542cc86096e1bad694e04d307301a807583dfc6 if Gem::Version.new(node['prometheus']['version']) <= Gem::Version.new('0.16.2') - default['prometheus']['flags']['web.use-local-assets'] = false + default['prometheus']['flags']['web.use-local-assets'] = false end # Path to static asset directory, available at /user. diff --git a/metadata.rb b/metadata.rb index ccab9ca..8ac0fd8 100644 --- a/metadata.rb +++ b/metadata.rb @@ -1,7 +1,7 @@ name 'prometheus' maintainer 'Elijah Wright' maintainer_email 'elijah.wright@gmail.com' -license 'Apache 2.0' +license 'Apache-2.0' description 'Installs/Configures Prometheus' long_description IO.read(File.join(File.dirname(__FILE__), 'README.md')) version '0.6.4' diff --git a/recipes/alertmanager.rb b/recipes/alertmanager.rb index ef5a814..0083a3c 100644 --- a/recipes/alertmanager.rb +++ b/recipes/alertmanager.rb @@ -58,7 +58,7 @@ variables( notification_config: node['prometheus']['alertmanager']['notification'] ) - notifies :restart, 'service[alertmanager]' + notifies :restart, 'service[alertmanager]' end # -- Do the install -- # @@ -84,7 +84,6 @@ action [:enable, :load] end when 'systemd' - # rubocop:disable Style/HashSyntax dist_dir, conf_dir, env_file = value_for_platform_family( ['fedora'] => %w(fedora sysconfig alertmanager), ['rhel'] => %w(redhat sysconfig alertmanager), @@ -94,7 +93,7 @@ template '/etc/systemd/system/alertmanager.service' do source 'systemd/alertmanager.service.erb' mode '0644' - variables(:sysconfig_file => "/etc/#{conf_dir}/#{env_file}") + variables(sysconfig_file: "/etc/#{conf_dir}/#{env_file}") notifies :restart, 'service[alertmanager]', :delayed end @@ -105,10 +104,9 @@ end service 'alertmanager' do - supports :status => true, :restart => true + supports status: true, restart: true action [:enable, :start] end - # rubocop:enable Style/HashSyntax when 'upstart' template '/etc/init/alertmanager.conf' do source 'upstart/alertmanager.service.erb' @@ -130,11 +128,9 @@ end end -# rubocop:disable Style/HashSyntax service 'alertmanager' do - supports :status => true, :restart => true + supports status: true, restart: true end -# rubocop:enable Style/HashSyntax service 'alertmanager' do action [:enable, :start] diff --git a/recipes/default.rb b/recipes/default.rb index 5ef9dd2..5f652a2 100644 --- a/recipes/default.rb +++ b/recipes/default.rb @@ -60,7 +60,7 @@ variables( rule_filenames: node['prometheus']['rule_filenames'] ) - notifies :reload, 'service[prometheus]' + notifies :reload, 'service[prometheus]' end # monitor our server instance diff --git a/recipes/service.rb b/recipes/service.rb index 7ff84e8..3103f42 100644 --- a/recipes/service.rb +++ b/recipes/service.rb @@ -34,7 +34,6 @@ action [:enable, :load] end when 'systemd' - # rubocop:disable Style/HashSyntax dist_dir, conf_dir, env_file = value_for_platform_family( ['fedora'] => %w(fedora sysconfig prometheus), ['rhel'] => %w(redhat sysconfig prometheus), @@ -44,7 +43,7 @@ template '/etc/systemd/system/prometheus.service' do source 'systemd/prometheus.service.erb' mode '0644' - variables(:sysconfig_file => "/etc/#{conf_dir}/#{env_file}") + variables(sysconfig_file: "/etc/#{conf_dir}/#{env_file}") notifies :restart, 'service[prometheus]', :delayed end @@ -55,10 +54,9 @@ end service 'prometheus' do - supports :status => true, :restart => true + supports status: true, restart: true action [:enable, :start] end - # rubocop:enable Style/HashSyntax when 'upstart' template '/etc/init/prometheus.conf' do source 'upstart/prometheus.service.erb' @@ -80,8 +78,6 @@ end end -# rubocop:disable Style/HashSyntax service 'prometheus' do - supports :status => true, :restart => true, :reload => true + supports status: true, restart: true, reload: true end -# rubocop:enable Style/HashSyntax diff --git a/resources/job.rb b/resources/job.rb index a7279b2..99e83c4 100644 --- a/resources/job.rb +++ b/resources/job.rb @@ -11,7 +11,7 @@ action :create do with_run_context :root do - edit_resource(:template, config_file) do |new_resource| + edit_resource(:template, new_resource.config_file) do |new_resource| cookbook new_resource.source variables[:jobs] ||= {} variables[:jobs][new_resource.name] ||= {} diff --git a/spec/unit/recipes/alertmanager_spec.rb b/spec/unit/recipes/alertmanager_spec.rb index 5a4b779..d985285 100644 --- a/spec/unit/recipes/alertmanager_spec.rb +++ b/spec/unit/recipes/alertmanager_spec.rb @@ -8,8 +8,6 @@ require 'spec_helper' # Caution: This is a carbon-copy of default_spec.rb with some variable replacements. - -# rubocop:disable Metrics/BlockLength describe 'prometheus::alertmanager' do let(:chef_run) do ChefSpec::SoloRunner.new(platform: 'ubuntu', version: '16.04', file_cache_path: '/tmp/chef/cache').converge(described_recipe) diff --git a/spec/unit/recipes/default_spec.rb b/spec/unit/recipes/default_spec.rb index e484454..b611448 100644 --- a/spec/unit/recipes/default_spec.rb +++ b/spec/unit/recipes/default_spec.rb @@ -1,6 +1,4 @@ require 'spec_helper' - -# rubocop:disable Metrics/BlockLength describe 'prometheus::default' do let(:chef_run) do ChefSpec::SoloRunner.new(platform: 'ubuntu', version: '16.04', file_cache_path: '/tmp/chef/cache').converge(described_recipe)