Skip to content

Commit

Permalink
Switch from finstyle to chefstyle
Browse files Browse the repository at this point in the history
Signed-off-by: Tim Smith <tsmith@chef.io>
  • Loading branch information
tas50 committed Jan 15, 2020
1 parent 3dbec56 commit 59926a6
Show file tree
Hide file tree
Showing 10 changed files with 75 additions and 92 deletions.
18 changes: 0 additions & 18 deletions .rubocop.yml

This file was deleted.

3 changes: 1 addition & 2 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# encoding: utf-8
source "https://rubygems.org"

# Specify your gem's dependencies in kitchen-dsc.gemspec
gemspec

gem 'github_changelog_generator'
gem "github_changelog_generator"
22 changes: 15 additions & 7 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# -*- encoding: utf-8 -*-

require "bundler/gem_tasks"

require "rake/testtask"
Expand All @@ -9,21 +7,31 @@ Rake::TestTask.new(:unit) do |t|
t.verbose = true
end

require "rubocop/rake_task"
require "chefstyle"

desc "Run RuboCop on the lib directory"
RuboCop::RakeTask.new(:rubocop) do |task|
task.patterns = ["lib/**/*.rb"]
# don't abort rake on failure
task.fail_on_error = false
end

desc "Run all test suites"
task :test => [:unit]
task test: [:unit]

task :default => [:test]
task default: [:test]

begin
require "github_changelog_generator/task"
require 'kitchen-dsc/version'
require "kitchen-dsc/version"

GitHubChangelogGenerator::RakeTask.new :changelog do |config|
config.future_release = "v#{Kitchen::Dsc::VERSION}"
config.issues = false
config.pulls = true
config.user = 'test-kitchen'
config.project = 'kitchen-dsc'
config.user = "test-kitchen"
config.project = "kitchen-dsc"
end
rescue LoadError
puts "github_changelog_generator is not available. " \
Expand Down
20 changes: 9 additions & 11 deletions kitchen-dsc.gemspec
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# encoding: utf-8

$LOAD_PATH.unshift File.expand_path("../lib", __FILE__)
require "kitchen-dsc/version"

Expand All @@ -15,17 +13,17 @@ Gem::Specification.new do |s|
s.platform = Gem::Platform::RUBY
s.require_paths = ["lib"]
s.rubyforge_project = "[none]"
s.license = "Apache 2"
s.description = <<-EOF
== DESCRIPTION:
s.license = "Apache-2.0"
s.description = <<~EOF
== DESCRIPTION:
DSC Provisioner for Test Kitchen
DSC Provisioner for Test Kitchen
== FEATURES:
== FEATURES:
TBD
TBD
EOF
EOF
s.add_dependency "test-kitchen", ">= 1.9"
s.add_dependency "dsc_lcm_configuration"

Expand All @@ -43,6 +41,6 @@ EOF
# style and complexity libraries are tightly version pinned as newer releases
# may introduce new and undesireable style choices which would be immediately
# enforced in CI
s.add_development_dependency "finstyle", "1.5.0"
s.add_development_dependency "cane", "3.0.0"
s.add_development_dependency "chefstyle", "0.14"
s.add_development_dependency "cane", "3.0.0"
end
4 changes: 1 addition & 3 deletions lib/kitchen-dsc/version.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
# encoding: utf-8

module Kitchen
module Dsc
VERSION = '0.11.0'.freeze
VERSION = "0.11.0".freeze
end
end
43 changes: 23 additions & 20 deletions lib/kitchen/provisioner/dsc.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- encoding: utf-8 -*-
#
# Author:: Steven Murawski (<steven.murawski@gmail.com>)
#
Expand Down Expand Up @@ -55,9 +54,9 @@ def install_command
end

def init_command
script = <<-EOH
#{setup_config_directory_script}
#{install_module_script if install_modules?}
script = <<~EOH
#{setup_config_directory_script}
#{install_module_script if install_modules?}
EOH
wrap_powershell_code(script)
end
Expand All @@ -77,7 +76,7 @@ def create_sandbox
def prepare_command
info("Moving DSC Resources onto PSModulePath")
scripts = <<-EOH
if (Test-Path (join-path #{config[:root_path]} 'modules'))
{
dir ( join-path #{config[:root_path]} 'modules/*') -directory |
Expand All @@ -95,38 +94,38 @@ def prepare_command
ensure_array(config[:configuration_name]).each do |configuration|
info("Generating the MOF script for the configuration #{configuration}")
stage_resources_and_generate_mof_script = <<-EOH
if(Test-Path c:/configurations/#{configuration})
{
Remove-Item -Recurse -Force c:/configurations/#{configuration}
}
$Error.clear()
if (-not (test-path 'c:/configurations'))
{
mkdir 'c:/configurations' | out-null
}
if (-not (get-command #{configuration}))
{
throw "Failed to create a configuration command #{configuration}"
}
#{configuration_data_assignment unless config[:configuration_data].nil?}
try{
$null = #{configuration} -outputpath c:/configurations/#{configuration} #{"-configurationdata $" + configuration_data_variable}
}
catch{
}
if($Error -ne $null)
{
$Error[-1]
exit 1
}
EOH
scripts << stage_resources_and_generate_mof_script
end
Expand All @@ -137,7 +136,7 @@ def prepare_command
def run_command
config[:retry_on_exit_code] = [35] if config[:retry_on_exit_code].empty?
config[:max_retries] = 3 if config[:max_retries] == 1
scripts = ''
scripts = ""
ensure_array(config[:configuration_name]).each do |configuration|
info("Running the configuration #{configuration}")
run_configuration_script = <<-EOH
Expand Down Expand Up @@ -177,12 +176,12 @@ def setup_config_directory_script
end

def powershell_module_params(module_specification_hash)
keys = module_specification_hash.keys.reject { |k| k.to_s.casecmp('force') == 0 }
unless keys.any? { |k| k.to_s.downcase == 'repository' }
keys = module_specification_hash.keys.reject { |k| k.to_s.casecmp("force") == 0 }
unless keys.any? { |k| k.to_s.downcase == "repository" }
keys.push(:repository)
module_specification_hash[:repository] = psmodule_repository_name
end
keys.map { |key| "-#{key} #{module_specification_hash[key]}" }.join(' ')
keys.map { |key| "-#{key} #{module_specification_hash[key]}" }.join(" ")
end

def powershell_modules
Expand All @@ -198,24 +197,28 @@ def powershell_modules

def nuget_force_bootstrap
return unless config[:nuget_force_bootstrap]

info("Bootstrapping the nuget package provider for PowerShell PackageManagement.")
"install-packageprovider nuget -force -forcebootstrap | out-null"
end

def psmodule_repository_name
return "PSGallery" if config[:gallery_name].nil? && config[:gallery_uri].nil?
return "testing" if config[:gallery_name].nil?

config[:gallery_name]
end

def register_psmodule_repository
return if config[:gallery_uri].nil?

info("Registering a new PowerShellGet Repository - #{psmodule_repository_name}")
"register-packagesource -providername PowerShellGet -name '#{psmodule_repository_name}' -location '#{config[:gallery_uri]}' -force -trusted"
end

def install_module_script
return if config[:modules_from_gallery].nil?

<<-EOH
#{nuget_force_bootstrap}
#{register_psmodule_repository}
Expand Down Expand Up @@ -270,7 +273,7 @@ def prepare_resource_style_directory
FileUtils.mkdir_p(File.dirname(dest))
debug("Staging #{src} ")
debug(" at #{dest}")
FileUtils.cp(src, dest, :preserve => true)
FileUtils.cp(src, dest, preserve: true)
end
end

Expand Down Expand Up @@ -318,9 +321,9 @@ def prepare_configuration_script

def ensure_array(thing)
if thing.is_a?(Array)
return thing
thing
else
return [thing]
[thing]
end
end
end
Expand Down
18 changes: 8 additions & 10 deletions lib/kitchen/provisioner/dsc_lcm/lcm_base.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- encoding: utf-8 -*-
#
# Author:: Steven Murawski (<steven.murawski@gmail.com>)
#
Expand All @@ -15,17 +14,15 @@ module Provisioner
module DscLcm
class LcmBase



def lcm_properties
{
:allow_module_overwrite => false,
:certificate_id => nil,
:configuration_mode => "ApplyAndAutoCorrect",
:configuration_mode_frequency_mins => 30,
:reboot_if_needed => false,
:refresh_mode => "PUSH",
:refresh_frequency_mins => 15
allow_module_overwrite: false,
certificate_id: nil,
configuration_mode: "ApplyAndAutoCorrect",
configuration_mode_frequency_mins: 30,
reboot_if_needed: false,
refresh_mode: "PUSH",
refresh_frequency_mins: 15,
}
end

Expand All @@ -42,6 +39,7 @@ def initialize(config = {})

def method_missing(name, *args)
return super unless lcm_properties.keys.include?(name)

if args.length == 1
instance_variable_set("@#{name}", args.first)
else
Expand Down
19 changes: 9 additions & 10 deletions lib/kitchen/provisioner/dsc_lcm/lcm_v4.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- encoding: utf-8 -*-
#
# Author:: Steven Murawski (<steven.murawski@gmail.com>)
#
Expand All @@ -16,15 +15,15 @@ class LcmV4 < LcmBase

def lcm_properties
{
:action_after_reboot => "StopConfiguration",
:allow_module_overwrite => false,
:certificate_id => nil,
:configuration_mode => "ApplyAndAutoCorrect",
:configuration_mode_frequency_mins => 30,
:debug_mode => "All",
:reboot_if_needed => false,
:refresh_mode => "PUSH",
:refresh_frequency_mins => 15
action_after_reboot: "StopConfiguration",
allow_module_overwrite: false,
certificate_id: nil,
configuration_mode: "ApplyAndAutoCorrect",
configuration_mode_frequency_mins: 30,
debug_mode: "All",
reboot_if_needed: false,
refresh_mode: "PUSH",
refresh_frequency_mins: 15,
}
end

Expand Down
19 changes: 9 additions & 10 deletions lib/kitchen/provisioner/dsc_lcm/lcm_v5.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- encoding: utf-8 -*-
#
# Author:: Steven Murawski (<steven.murawski@gmail.com>)
#
Expand All @@ -16,15 +15,15 @@ class LcmV5 < LcmBase

def lcm_properties
{
:action_after_reboot => "StopConfiguration",
:allow_module_overwrite => false,
:certificate_id => nil,
:configuration_mode => "ApplyAndAutoCorrect",
:configuration_mode_frequency_mins => 15,
:debug_mode => "All",
:reboot_if_needed => false,
:refresh_mode => "PUSH",
:refresh_frequency_mins => 30
action_after_reboot: "StopConfiguration",
allow_module_overwrite: false,
certificate_id: nil,
configuration_mode: "ApplyAndAutoCorrect",
configuration_mode_frequency_mins: 15,
debug_mode: "All",
reboot_if_needed: false,
refresh_mode: "PUSH",
refresh_frequency_mins: 30,
}
end

Expand Down
1 change: 0 additions & 1 deletion spec/spec_helper.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- encoding: utf-8 -*-
#
# Author:: Fletcher Nichol (<fnichol@nichol.ca>)
#
Expand Down

0 comments on commit 59926a6

Please sign in to comment.