serverspec-runner 1.2.2 → 1.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,15 +1,7 @@
1
1
  ---
2
- !binary "U0hBMQ==":
3
- metadata.gz: !binary |-
4
- M2E3MjEzYmE1NGQyYTQxODk2ZGJlODNmOGRiZDJkMTgyMTY4NzM4Nw==
5
- data.tar.gz: !binary |-
6
- Y2I3MDliZTAwZmQ3YzMxYzNlZTAyMzA2MDA2Y2U1OTA1YWVhN2JkNw==
2
+ SHA256:
3
+ metadata.gz: 501b9ebe71d9843ce7b2395c9aadd866d216691a33f1ccc833c87290fcc363dc
4
+ data.tar.gz: 6aef5a317e062fdde40b9651ed01b61ed4fb9d03ae5c5ed519771b12f7b08d7d
7
5
  SHA512:
8
- metadata.gz: !binary |-
9
- OTVjZTg5M2FlNDkyNzdmMTZhYzc5NzE0MzM1YzZhZmY1N2M1MGUyNjgzM2Ix
10
- YzhjYWU3ZWE0ODliYTNlYmU2OTcxMWZmZWI2OTM5MTIyN2VjYzU2M2FiYjA3
11
- MjE0Nzg1MDUwM2VlY2U3MGM1ZjQ3NjI1N2VhYjQ0M2UzODcxNjk=
12
- data.tar.gz: !binary |-
13
- MjJmYmM2YjdmNWE2NGUxNDY5NWUzNDBiZTFmOTg2OTAyMjEyN2UyZDY0ZjRk
14
- NDNkNzJjYWY1YmYzOTM0YjE0ZTcwMzgzNzliZDFkOWNlZGM3ZjlmODE1NDMz
15
- ZGRhMzU2MTRiNjc0MjcwODY4ODk3NzU3MjY3YzE2OGExNzhlYjk=
6
+ metadata.gz: 2dfec5c6a8c0f7a1317afa51185f74186b760fb57e543828688e5553df91e2c9454f4b20c84ca6a0cd5c6a2cbb239faee1889881ca8ff9d3b7bd3c094b5c2cfc
7
+ data.tar.gz: 5bc13affbfbda46d6404ece51317bb076167f478ba2a4cbb44de079e22dbb07961622f86dd626853e41364420bdbd0b13058819629355475a1191ba3012ee901
data/.gitignore CHANGED
@@ -17,3 +17,6 @@ test/version_tmp
17
17
  tmp
18
18
  .DS_Store
19
19
  .rvmrc
20
+
21
+ _platforms.yml
22
+ _serverspec_result.csv
data/.travis.yml CHANGED
@@ -1,7 +1,7 @@
1
1
  language: ruby
2
2
 
3
3
  rvm:
4
- - 1.9.3
4
+ # - 1.9.3
5
5
  - 2.0.0
6
6
  - 2.1.5
7
7
  - 2.2.0
data/README.md CHANGED
@@ -1,7 +1,7 @@
1
1
  serverspec-runner [![Gem Version](https://badge.fury.io/rb/serverspec-runner.svg)](http://badge.fury.io/rb/serverspec-runner) [![BuildStatus](https://secure.travis-ci.org/hiracy/serverspec-runner.png)](http://travis-ci.org/hiracy/serverspec-runner)
2
2
  ======================
3
3
 
4
- Simple execution framework for [serverspec](http://serverspec.org/).
4
+ Simple execution framework for [serverspec](http://serverspec.org/) run.
5
5
 
6
6
  ----
7
7
 
@@ -21,7 +21,7 @@ Edit your [spec-files](http://serverspec.org/resource_types.html).
21
21
 
22
22
  $ vim /path/to/your_serverspec_root/test_top_dir/.../your_serverspec_test.rb
23
23
 
24
- Edit your infrastructure or middleware tests scenario to "scenario.yml".
24
+ Edit your infrastructure or middleware tests scenario to "[scenario.yml](scenario.yml)".
25
25
 
26
26
  ```
27
27
  test_top_dir: # test directory top
data/Rakefile CHANGED
@@ -7,6 +7,7 @@ require 'net/ssh'
7
7
  require 'open-uri'
8
8
  require 'serverspec-runner'
9
9
  require 'serverspec-runner/util/hash'
10
+ require 'serverspec-runner/ansible/inventory'
10
11
 
11
12
  desc "Run serverspec to all scenario"
12
13
  task :spec => 'spec:all'
@@ -128,6 +129,9 @@ namespace :spec do
128
129
  t.fail_on_error = false
129
130
  ENV['TARGET_HOST'] = host_alias
130
131
  ENV['TARGET_SSH_HOST'] = platform[host_alias.to_sym][:host] || host_alias
132
+ if platform[host_alias.to_sym].key?(:ssh_opts) && platform[host_alias.to_sym][:ssh_opts].key?(:port)
133
+ ENV['TARGET_CONNECTION'] = 'ssh'
134
+ end
131
135
  end
132
136
  end
133
137
 
@@ -161,21 +165,41 @@ namespace :spec do
161
165
  ENV['scenario'] = ENV['scenario_tmp']
162
166
  end
163
167
 
168
+ if !File.file?(ENV['scenario']) && !File.file?("#{ENV['specroot']}/scenario.yml")
169
+ print "\e[31m"
170
+ puts "scenario.yml is not found.(--help option can display manual))"
171
+ print "\e[m"
172
+ exit 1
173
+ end
174
+
164
175
  File.open(ENV['scenario'] || "#{ENV['specroot']}/scenario.yml") do |f|
165
176
  YAML.load_documents(f).each_with_index do |data, idx|
166
177
  if idx == 0
167
178
  scenarios = data
168
179
  else
169
- data.each do |k, v|
170
- platform[k.to_sym] = v.deep_symbolize_keys
180
+ if data != nil
181
+ data.each do |k, v|
182
+ platform[k.to_sym] = v.deep_symbolize_keys
183
+ end
171
184
  end
172
185
  end
173
186
  end
174
187
  end
175
188
 
189
+ if ENV['inventory']
190
+ if !File.file?(ENV['inventory'])
191
+ print "\e[31m"
192
+ puts "inventory file is not found.(--help option can display manual))"
193
+ print "\e[m"
194
+ exit 1
195
+ end
196
+
197
+ platform = Inventory.inventory_to_platform(YAML.load_file(ENV['inventory']))
198
+ end
199
+
176
200
  if !scenarios
177
201
  print "\e[31m"
178
- puts "scenario.yml is empty."
202
+ puts "scenario is empty."
179
203
  print "\e[m"
180
204
  exit 1
181
205
  end
@@ -11,6 +11,7 @@ showtasks = false
11
11
 
12
12
  opts = GetoptLong.new(
13
13
  ["--scenario", "-s", GetoptLong::REQUIRED_ARGUMENT],
14
+ ["--inventory", "-i", GetoptLong::REQUIRED_ARGUMENT],
14
15
  ["--specroot", "-r", GetoptLong::REQUIRED_ARGUMENT],
15
16
  ["--ssh_options", "-o", GetoptLong::REQUIRED_ARGUMENT],
16
17
  ["--explain", "-e", GetoptLong::REQUIRED_ARGUMENT],
@@ -26,6 +27,8 @@ opts.each do |opt, arg|
26
27
  case opt
27
28
  when '--scenario'
28
29
  ENV['scenario'] = arg
30
+ when '--inventory'
31
+ ENV['inventory'] = arg
29
32
  when '--specroot'
30
33
  ENV['specroot'] = arg
31
34
  when '--ssh_options'
@@ -45,6 +48,7 @@ opts.each do |opt, arg|
45
48
  else
46
49
  puts "Usage: serverspec-runner (options)"
47
50
  puts "-s, --scenario SCENARIO_FILE path to scenario yml file"
51
+ puts "-i, --inventory INVENTORY_FILE path to ansible inventory yml file"
48
52
  puts "-r, --specroot SPEC_ROOT path to spec tests root dir"
49
53
  puts "-o, --ssh_options SSH_OPTIONS_FILE path to ssh options yml file"
50
54
  puts "-e, --explain (short|long) specify result explain length(default: short)"
@@ -0,0 +1,52 @@
1
+ module Inventory
2
+ def self.inventory_to_platform(data)
3
+ platform = {}
4
+
5
+ data.each do |k, v|
6
+ v.each do |gk, gv|
7
+ if gk == 'hosts'
8
+ if gv.kind_of?(Hash)
9
+ gv.each do |hk, hv|
10
+ platform[hk] = convert_ssh_opt(v['vars']).merge(convert_ssh_opt(hv))
11
+ end
12
+ elsif gv.kind_of?(Array)
13
+ gv.each do |h|
14
+ platform[h.to_sym] = convert_ssh_opt(v['vars'])
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
20
+
21
+ platform
22
+ end
23
+
24
+ private
25
+
26
+ def self.convert_ssh_opt(src)
27
+ serverspec_opt = {}
28
+ serverspec_opt[:ssh_opts] = {}
29
+ src.each do |k, v|
30
+ case k
31
+ when 'ansible_host'
32
+ serverspec_opt[:host] = v
33
+ when 'ansible_user'
34
+ serverspec_opt[:ssh_opts][:user] = v
35
+ when 'ansible_port'
36
+ serverspec_opt[:ssh_opts][:port] = v
37
+ when 'ansible_ssh_private_key_file'
38
+ serverspec_opt[:ssh_opts][:keys] = Array(v)
39
+ when 'ansible_ssh_pass'
40
+ serverspec_opt[:ssh_opts][:password] = v
41
+ when 'ansible_ssh_common_args'
42
+ if v.include?('StrictHostKeyChecking=no')
43
+ serverspec_opt[:ssh_opts][:verify_host_key] = false
44
+ elsif v.include?('UserKnownHostsFile=/dev/null')
45
+ serverspec_opt[:ssh_opts][:user_known_hosts_file] = '/dev/null'
46
+ end
47
+ end
48
+ end
49
+
50
+ serverspec_opt
51
+ end
52
+ end
@@ -1,3 +1,3 @@
1
1
  module ServerspecRunner
2
- VERSION = "1.2.2"
2
+ VERSION = "1.3.0"
3
3
  end
@@ -0,0 +1,18 @@
1
+ require 'spec_helper_win'
2
+
3
+ describe command('hostname') do
4
+ its(:stdout) { should match /HOSTNAME/ }
5
+ end
6
+
7
+ describe file('c:/windows') do
8
+ it { should be_directory }
9
+ end
10
+
11
+ describe command('tzutil /g') do
12
+ its(:stdout) { should match /Tokyo Standard Time/ }
13
+ end
14
+
15
+ describe windows_feature('notepad') do
16
+ it{ should be_installed }
17
+ end
18
+
data/spec/spec_helper.rb CHANGED
@@ -52,7 +52,7 @@ RSpec.configure do |c|
52
52
 
53
53
  set_property (YAML.load_file(ENV['platforms_tmp']))[ENV['TARGET_HOST'].to_sym]
54
54
 
55
- if ENV['TARGET_SSH_HOST'] !~ /localhost|127\.0\.0\.1/
55
+ if ENV['TARGET_CONNECTION'] == 'ssh' || ENV['TARGET_SSH_HOST'] !~ /localhost|127\.0\.0\.1/
56
56
  c.host = ENV['TARGET_SSH_HOST']
57
57
  options = Net::SSH::Config.for(c.host, files=["~/.ssh/config"])
58
58
  ssh_opts ||= ssh_opts_default
@@ -0,0 +1,132 @@
1
+ require 'serverspec'
2
+ require 'pathname'
3
+ require 'net/ssh'
4
+ require 'net/ssh/proxy/command'
5
+ require 'yaml'
6
+ require 'csv'
7
+ require 'serverspec-runner/util/hash'
8
+ require 'winrm'
9
+
10
+ # require extension libraries
11
+ Dir.glob([
12
+ ENV['specroot'] + '/lib/extension/serverspec/**/*.rb',
13
+ ENV['specroot'] + '/lib/extension/specinfra/**/*.rb']).each {|f| require f}
14
+
15
+ ssh_opts_default = YAML.load_file(ENV['ssh_options'])
16
+ csv_path = ENV['result_csv']
17
+ explains = []
18
+ results = []
19
+ row_num = []
20
+ spacer_char = ' ' unless ENV['tableformat'] == 'csv'
21
+ spacer_char = ',' if ENV['tableformat'] == 'csv'
22
+
23
+ def get_example_desc(example_group, descriptions)
24
+
25
+ descriptions << example_group[:description]
26
+ return descriptions if example_group[:parent_example_group] == nil
27
+
28
+ get_example_desc(example_group[:parent_example_group], descriptions)
29
+ end
30
+
31
+ RSpec.configure do |c|
32
+
33
+ c.expose_current_running_example_as :example
34
+ c.path = ENV['EXEC_PATH']
35
+
36
+ run_path = c.files_to_run[0].split('/')
37
+
38
+ speck_i = 0
39
+ run_path.reverse.each_with_index do |r,i|
40
+ if r == 'spec'
41
+ speck_i = ((run_path.size - 1) - i)
42
+ end
43
+ end
44
+ sliced = run_path.slice((speck_i + 1)..(run_path.size - 2))
45
+ role_name = sliced.join('/')
46
+
47
+ if ENV['ASK_SUDO_PASSWORD']
48
+ require 'highline/import'
49
+ c.sudo_password = ask("Enter sudo password: ") { |q| q.echo = false }
50
+ else
51
+ c.sudo_password = ENV['SUDO_PASSWORD']
52
+ end
53
+
54
+ set_property (YAML.load_file(ENV['platforms_tmp']))[ENV['TARGET_HOST'].to_sym]
55
+
56
+ if ENV['TARGET_SSH_HOST'] !~ /localhost|127\.0\.0\.1/
57
+ c.host = ENV['TARGET_SSH_HOST']
58
+ options = Net::SSH::Config.for(c.host, files=["~/.ssh/config"])
59
+ ssh_opts ||= ssh_opts_default
60
+ property[:ssh_opts].each { |k, v| ssh_opts[k.to_sym] = v } if property[:ssh_opts]
61
+ ssh_opts[:proxy] = Kernel.eval(ssh_opts[:proxy]) if ssh_opts[:proxy]
62
+ user = options[:user] || ssh_opts[:user] || Etc.getlogin
63
+ options.merge!(ssh_opts)
64
+ set :ssh_options, options
65
+ set :backend, :ssh
66
+ set :request_pty, true
67
+ else
68
+ set :backend, :exec
69
+ end
70
+
71
+ prev_desc_hierarchy = nil
72
+
73
+ c.before(:suite) do
74
+ entity_host = (((ENV['TARGET_HOST'] != ENV['TARGET_SSH_HOST']) && (ENV['TARGET_SSH_HOST'] != nil)) ? "(#{ENV['TARGET_SSH_HOST']})" : "")
75
+ puts "\e[33m"
76
+ puts "### start [#{role_name}@#{ENV['TARGET_HOST']}] #{entity_host} serverspec... ###"
77
+ print "\e[m"
78
+
79
+ explains << "#{role_name}@#{ENV['TARGET_HOST']}#{entity_host}"
80
+ results << ""
81
+ row_num << 1
82
+ end
83
+
84
+ c.after(:each) do
85
+
86
+ if ENV['explain'] == 'long'
87
+ explains << spacer_char + example.metadata[:full_description]
88
+ results << (self.example.exception ? 'NG' : 'OK')
89
+ row_num << 1
90
+ else
91
+
92
+ spacer = ''
93
+ desc_hierarchy = get_example_desc(self.example.metadata[:example_group], []).reverse
94
+ desc_hierarchy.each_with_index do |ex, i|
95
+ spacer += spacer_char
96
+
97
+ if prev_desc_hierarchy != nil && prev_desc_hierarchy.length > i && prev_desc_hierarchy[i] == desc_hierarchy[i]
98
+ else
99
+ explains << spacer + ex
100
+ results << ''
101
+ row_num << i + 1
102
+ end
103
+ end
104
+
105
+ explains << spacer + spacer_char + (self.example.metadata[:description] || '')
106
+ results << (self.example.exception ? 'NG' : 'OK')
107
+ row_num << desc_hierarchy.length + 1
108
+
109
+ prev_desc_hierarchy = desc_hierarchy
110
+ end
111
+ end
112
+
113
+ c.after(:suite) do
114
+ CSV.open(csv_path, 'a') do |writer|
115
+ explains.each_with_index do |v, i|
116
+ writer << [v, results[i], row_num[i]]
117
+ end
118
+ end
119
+ end
120
+ end
121
+
122
+ set :backend, :winrm
123
+
124
+ opts = {
125
+ user: "Username", # ex.) Administrator
126
+ password: "Password", # connection password
127
+ endpoint: "http://IPaddress:5985/wsman",
128
+ operation_timeout: 300,
129
+ }
130
+
131
+ winrm = WinRM::Connection.new(opts)
132
+ Specinfra.configuration.winrm = winrm
metadata CHANGED
@@ -1,83 +1,83 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: serverspec-runner
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.2
4
+ version: 1.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - hiracy
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-11-06 00:00:00.000000000 Z
11
+ date: 2018-08-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: serverspec
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ! '>='
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
19
  version: '0'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ! '>='
24
+ - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: net-ssh
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ! '>='
31
+ - - ">="
32
32
  - !ruby/object:Gem::Version
33
33
  version: '0'
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - ! '>='
38
+ - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rake
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - ! '>='
45
+ - - ">="
46
46
  - !ruby/object:Gem::Version
47
47
  version: '0'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - ! '>='
52
+ - - ">="
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: rspec-core
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - ! '>='
59
+ - - ">="
60
60
  - !ruby/object:Gem::Version
61
61
  version: '0'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - ! '>='
66
+ - - ">="
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: bundler
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
- - - ~>
73
+ - - "~>"
74
74
  - !ruby/object:Gem::Version
75
75
  version: '1.3'
76
76
  type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
- - - ~>
80
+ - - "~>"
81
81
  - !ruby/object:Gem::Version
82
82
  version: '1.3'
83
83
  description: simple execution framework for serverspec
@@ -88,9 +88,9 @@ executables:
88
88
  extensions: []
89
89
  extra_rdoc_files: []
90
90
  files:
91
- - .gitignore
92
- - .rspec
93
- - .travis.yml
91
+ - ".gitignore"
92
+ - ".rspec"
93
+ - ".travis.yml"
94
94
  - Gemfile
95
95
  - LICENSE
96
96
  - README.md
@@ -103,12 +103,15 @@ files:
103
103
  - lib/extension/specinfra/command/base/file.rb
104
104
  - lib/extension/specinfra/command/linux/base/mysql.rb
105
105
  - lib/serverspec-runner.rb
106
+ - lib/serverspec-runner/ansible/inventory.rb
106
107
  - lib/serverspec-runner/util/hash.rb
107
108
  - lib/serverspec-runner/version.rb
108
109
  - scenario.yml
109
110
  - serverspec-runner.gemspec
110
111
  - spec/example/default.rb
112
+ - spec/example_win/default.rb
111
113
  - spec/spec_helper.rb
114
+ - spec/spec_helper_win.rb
112
115
  - ssh_options_default.yml
113
116
  homepage: https://github.com/hiracy/serverspec-runner
114
117
  licenses:
@@ -120,20 +123,22 @@ require_paths:
120
123
  - lib
121
124
  required_ruby_version: !ruby/object:Gem::Requirement
122
125
  requirements:
123
- - - ! '>='
126
+ - - ">="
124
127
  - !ruby/object:Gem::Version
125
128
  version: '0'
126
129
  required_rubygems_version: !ruby/object:Gem::Requirement
127
130
  requirements:
128
- - - ! '>='
131
+ - - ">="
129
132
  - !ruby/object:Gem::Version
130
133
  version: '0'
131
134
  requirements: []
132
135
  rubyforge_project:
133
- rubygems_version: 2.4.8
136
+ rubygems_version: 2.7.7
134
137
  signing_key:
135
138
  specification_version: 4
136
139
  summary: simple execution framework for serverspec
137
140
  test_files:
138
141
  - spec/example/default.rb
142
+ - spec/example_win/default.rb
139
143
  - spec/spec_helper.rb
144
+ - spec/spec_helper_win.rb