specinfra 2.0.0.beta2 → 2.0.0.beta3

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,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: affb586181cbed5a5df08b7051e34fe1b825862b
4
- data.tar.gz: 38a773ddead03328e9f581ff9ba2bae517f7968d
3
+ metadata.gz: e6f99779115167f0d7345a3ba9261f32f01754b5
4
+ data.tar.gz: f9643ec0810fddd98b30816509711d7d6b64db09
5
5
  SHA512:
6
- metadata.gz: 76f82c0a871297f8b98ee2bad8fa982bdae82d06515200fe9ac5ccc8ea896d1194f6354dddeb49d896ebb5da10df1e906a6f8e5a398cbda9f6ccb624e06a80e0
7
- data.tar.gz: d5f364ea6e222a2d8ac6d82e7a4b4759ae6f126b5a0f14cb1d1dbe2ff3af8778b78e3792ee6212948e38a6cfbc24cb5cc03ce436c951557be3e1f37ba54669c8
6
+ metadata.gz: eb6aee27e06d5116f93650bec947195de18b01abc9d2be7eeabf4491827549e166e568cb2261187f15bc24001b6f56eee31cbb3332f455504c096e63c0a2a8fb
7
+ data.tar.gz: 9c80d72827ac059467fcd71b34d562fb3232220a40cd5c204c9f9a7d5cbcb04761d1dc9cade8dc79deb8d1e56b43fc3333d966ba3cb7055622ed703b14eb4cc4
data/lib/specinfra.rb CHANGED
@@ -1,9 +1,10 @@
1
- require "specinfra/version"
2
- require "specinfra/helper"
3
- require "specinfra/backend"
4
- require "specinfra/command"
5
- require "specinfra/command_result"
6
- require "specinfra/configuration"
1
+ require 'specinfra/version'
2
+ require 'specinfra/helper'
3
+ require 'specinfra/backend'
4
+ require 'specinfra/command'
5
+ require 'specinfra/command_result'
6
+ require 'specinfra/configuration'
7
+ require 'specinfra/runner'
7
8
 
8
9
  include Specinfra
9
10
 
@@ -185,20 +185,34 @@ module Specinfra
185
185
 
186
186
  def check_os
187
187
  return Specinfra.configuration.os if Specinfra.configuration.os
188
- if run_command('ls /etc/redhat-release').success?
188
+ arch = run_command('uname -m').stdout.strip
189
+ # Fedora also has an /etc/redhat-release so the Fedora check must
190
+ # come before the RedHat check
191
+ if run_command('ls /etc/fedora-release').success?
192
+ line = run_command('cat /etc/redhat-release').stdout
193
+ if line =~ /release (\d[\d]*)/
194
+ release = $1
195
+ end
196
+ { :family => 'Fedora', :release => release }
197
+ elsif run_command('ls /etc/redhat-release').success?
189
198
  line = run_command('cat /etc/redhat-release').stdout
190
199
  if line =~ /release (\d[\d.]*)/
191
200
  release = $1
192
201
  end
193
- { :family => 'RedHat', :release => release }
202
+
203
+ if release =~ /7./
204
+ { :family => 'RedHat7', :release => release, :arch => arch }
205
+ else
206
+ { :family => 'RedHat', :release => release, :arch => arch }
207
+ end
194
208
  elsif run_command('ls /etc/system-release').success?
195
- { :family => 'RedHat', :release => nil } # Amazon Linux
209
+ { :family => 'RedHat', :release => nil, :arch => arch } # Amazon Linux
196
210
  elsif run_command('ls /etc/SuSE-release').success?
197
211
  line = run_command('cat /etc/SuSE-release').stdout
198
212
  if line =~ /SUSE Linux Enterprise Server (\d+)/
199
213
  release = $1
200
214
  end
201
- { :family => 'SuSE', :release => release }
215
+ { :family => 'SuSE', :release => release, :arch => arch }
202
216
  elsif run_command('ls /etc/debian_version').success?
203
217
  lsb_release = run_command("lsb_release -ir")
204
218
  if lsb_release.success?
@@ -217,37 +231,37 @@ module Specinfra
217
231
  end
218
232
  distro ||= 'Debian'
219
233
  release ||= nil
220
- { :family => distro.strip, :release => release }
234
+ { :family => distro.strip, :release => release, :arch => arch }
221
235
  elsif run_command('ls /etc/gentoo-release').success?
222
- { :family => 'Gentoo', :release => nil }
236
+ { :family => 'Gentoo', :release => nil, :arch => arch }
223
237
  elsif run_command('ls /usr/lib/setup/Plamo-*').success?
224
- { :family => 'Plamo', :release => nil }
238
+ { :family => 'Plamo', :release => nil, :arch => arch }
225
239
  elsif run_command('uname -s').stdout =~ /AIX/i
226
- { :family => 'AIX', :release => nil }
227
- elsif (os = run_command('uname -sr').stdout) && os =~ /SunOS/i
228
- if os =~ /5.10/
229
- { :family => 'Solaris10', :release => nil }
240
+ { :family => 'AIX', :release => nil, :arch => arch }
241
+ elsif ( uname = run_command('uname -sr').stdout) && uname =~ /SunOS/i
242
+ if uname =~ /5.10/
243
+ { :family => 'Solaris10', :release => nil, :arch => arch }
230
244
  elsif run_command('grep -q "Oracle Solaris 11" /etc/release').success?
231
- { :family => 'Solaris11', :release => nil }
245
+ { :family => 'Solaris11', :release => nil, :arch => arch }
232
246
  elsif run_command('grep -q SmartOS /etc/release').success?
233
- { :family => 'SmartOS', :release => nil }
247
+ { :family => 'SmartOS', :release => nil, :arch => arch }
234
248
  else
235
- { :family => 'Solaris', :release => nil }
249
+ { :family => 'Solaris', :release => nil, :arch => arch }
236
250
  end
237
251
  elsif run_command('uname -s').stdout =~ /Darwin/i
238
252
  { :family => 'Darwin', :release => nil }
239
- elsif (os = run_command('uname -sr').stdout) && os =~ /FreeBSD/i
240
- if os =~ /10./
241
- { :family => 'FreeBSD10', :release => nil }
253
+ elsif ( uname = run_command('uname -sr').stdout ) && uname =~ /FreeBSD/i
254
+ if uname =~ /10./
255
+ { :family => 'FreeBSD10', :release => nil, :arch => arch }
242
256
  else
243
- { :family => 'FreeBSD', :release => nil }
257
+ { :family => 'FreeBSD', :release => nil, :arch => arch }
244
258
  end
245
259
  elsif run_command('uname -sr').stdout =~ /Arch/i
246
- { :family => 'Arch', :release => nil }
260
+ { :family => 'Arch', :release => nil, :arch => arch }
247
261
  elsif run_command('uname -s').stdout =~ /OpenBSD/i
248
- { :family => 'OpenBSD', :release => nil }
262
+ { :family => 'OpenBSD', :release => nil, :arch => arch }
249
263
  else
250
- { :family => 'Base', :release => nil }
264
+ { :family => 'Base', :release => nil, :arch => arch }
251
265
  end
252
266
  end
253
267
 
@@ -0,0 +1,7 @@
1
+ function FindScheduledTask
2
+ {
3
+ param($name)
4
+
5
+ $task = schtasks /query /v /fo csv /TN "$name" | ConvertFrom-CSV
6
+ return $task
7
+ }
@@ -8,7 +8,9 @@ require "specinfra/command/ubuntu"
8
8
  require "specinfra/command/gentoo"
9
9
  require "specinfra/command/plamo"
10
10
  require "specinfra/command/redhat"
11
+ require "specinfra/command/redhat7"
11
12
  require "specinfra/command/suse"
13
+ require "specinfra/command/fedora"
12
14
 
13
15
  # Solaris
14
16
  require "specinfra/command/solaris"
@@ -0,0 +1,29 @@
1
+ module Specinfra
2
+ module Command
3
+ class Fedora < RedHat
4
+ def check_enabled(service, target="multi-user.target")
5
+ host = Specinfra.configuration.ssh ? Specinfra.configuration.ssh.host : 'localhost'
6
+ if property.has_key?(:os_by_host) && property[:os_by_host][host][:release].to_i < 15
7
+ super
8
+ else
9
+ # Fedora 15+ uses systemd which no longer has runlevels but targets
10
+ # For backwards compatibility, Fedora provides pseudo targets for
11
+ # runlevels
12
+ if target.is_a? Integer
13
+ target = "runlevel#{target}.target"
14
+ end
15
+ "systemctl --plain list-dependencies #{target} | grep '^#{escape(service)}.service$'"
16
+ end
17
+ end
18
+
19
+ def check_running(service)
20
+ host = Specinfra.configuration.ssh ? Specinfra.configuration.ssh.host : 'localhost'
21
+ if property.has_key?(:os_by_host) && property[:os_by_host][host][:release].to_i < 15
22
+ super
23
+ else
24
+ "systemctl is-active #{escape(service)}.service"
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,9 @@
1
+ module Specinfra
2
+ module Command
3
+ class RedHat7 < RedHat
4
+ def check_enabled(service, level=3)
5
+ "systemctl --plain list-dependencies runlevel#{level}.target | grep '^#{escape(service)}.service$'"
6
+ end
7
+ end
8
+ end
9
+ end
@@ -305,6 +305,13 @@ module Specinfra
305
305
  end
306
306
  end
307
307
 
308
+ def check_scheduled_task(name)
309
+ Backend::PowerShell::Command.new do
310
+ using 'find_scheduled_task.ps1'
311
+ exec "(FindScheduledTask -name '#{name}').TaskName -eq '\\#{name}'"
312
+ end
313
+ end
314
+
308
315
  private
309
316
 
310
317
  def item_has_attribute item, attribute
@@ -20,6 +20,15 @@ module Specinfra
20
20
  VALID_OPTIONS_KEYS.inject({}) { |o, k| o.merge!(k => send(k)) }
21
21
  end
22
22
 
23
+ # Define os method explicitly to avoid stack level
24
+ # too deep caused by Helpet::DetectOS#os
25
+ def os
26
+ if @os.nil? && defined?(RSpec) && RSpec.configuration.respond_to?(:os)
27
+ @os = RSpec.configuration.os
28
+ end
29
+ @os
30
+ end
31
+
23
32
  def method_missing(meth, val=nil)
24
33
  key = meth.to_s
25
34
  key.gsub!(/=$/, '')
@@ -2,17 +2,21 @@ module Specinfra
2
2
  module Helper
3
3
  module DetectOS
4
4
  def commands
5
+ self.class.const_get('Specinfra').const_get('Command').const_get(os[:family]).new
6
+ end
7
+
8
+ def os
5
9
  property[:os_by_host] = {} if ! property[:os_by_host]
6
10
  host = Specinfra.configuration.ssh ? Specinfra.configuration.ssh.host : 'localhost'
7
11
 
8
12
  if property[:os_by_host][host]
9
- os = property[:os_by_host][host]
13
+ os_by_host = property[:os_by_host][host]
10
14
  else
11
15
  # Set command object explicitly to avoid `stack too deep`
12
- os = backend(Specinfra::Command::Base.new).check_os
13
- property[:os_by_host][host] = os
16
+ os_by_host = backend(Specinfra::Command::Base.new).check_os
17
+ property[:os_by_host][host] = os_by_host
14
18
  end
15
- self.class.const_get('Specinfra').const_get('Command').const_get(os[:family]).new
19
+ os_by_host
16
20
  end
17
21
  end
18
22
  end
@@ -6,12 +6,14 @@ module Specinfra
6
6
  'Arch',
7
7
  'Darwin',
8
8
  'Debian',
9
+ 'Fedora',
9
10
  'FreeBSD',
10
11
  'FreeBSD10',
11
12
  'Gentoo',
12
13
  'OpenBSD',
13
14
  'Plamo',
14
15
  'RedHat',
16
+ 'RedHat7',
15
17
  'SuSE',
16
18
  'SmartOS',
17
19
  'Solaris',
@@ -0,0 +1,8 @@
1
+ module Specinfra
2
+ class Runner
3
+ include Singleton
4
+ def method_missing(meth, *args, &block)
5
+ backend.send(meth, *args)
6
+ end
7
+ end
8
+ end
@@ -1,3 +1,3 @@
1
1
  module Specinfra
2
- VERSION = "2.0.0.beta2"
2
+ VERSION = "2.0.0.beta3"
3
3
  end
@@ -78,56 +78,61 @@ describe 'check_os' do
78
78
  context 'test ubuntu with lsb_release command' do
79
79
  subject { backend.check_os }
80
80
  it do
81
- mock_success_response = double(
82
- :run_command_response,
83
- :success? => true,
84
- :stdout => "Distributor ID:\tUbuntu\nRelease:\t12.04\n"
85
- )
86
- mock_failure_response = double :run_command_response, :success? => false
87
81
  backend.should_receive(:run_command).at_least(1).times do |args|
88
82
  if ['ls /etc/debian_version', 'lsb_release -ir'].include? args
89
- mock_success_response
83
+ double(
84
+ :run_command_response,
85
+ :success? => true,
86
+ :stdout => "Distributor ID:\tUbuntu\nRelease:\t12.04\n"
87
+ )
88
+ elsif args == 'uname -m'
89
+ double :run_command_response, :success? => true, :stdout => "x86_64\n"
90
90
  else
91
- mock_failure_response
91
+ double :run_command_response, :success? => false
92
92
  end
93
93
  end
94
- should eq({:family => 'Ubuntu', :release => '12.04'})
94
+ should eq({:family => 'Ubuntu', :release => '12.04', :arch => 'x86_64' })
95
95
  end
96
96
  end
97
97
 
98
98
  context 'test ubuntu with /etc/lsb-release' do
99
99
  subject { backend.check_os }
100
100
  it do
101
- mock_success_response = double(
102
- :run_command_response,
103
- :success? => true,
104
- :stdout => %Q(DISTRIB_ID=Ubuntu
101
+ backend.should_receive(:run_command).at_least(1).times do |args|
102
+ if ['ls /etc/debian_version', 'cat /etc/lsb-release'].include? args
103
+ double(
104
+ :run_command_response,
105
+ :success? => true,
106
+ :stdout => <<-EOF
107
+ DISTRIB_ID=Ubuntu
105
108
  DISTRIB_RELEASE=12.04
106
109
  DISTRIB_CODENAME=precise
107
110
  DISTRIB_DESCRIPTION="Ubuntu 12.04.2 LTS"
108
- )
109
- )
110
- mock_failure_response = double :run_command_response, :success? => false
111
- backend.should_receive(:run_command).at_least(1).times do |args|
112
- if ['ls /etc/debian_version', 'cat /etc/lsb-release'].include? args
113
- mock_success_response
111
+ EOF
112
+ )
113
+ elsif args == 'uname -m'
114
+ double :run_command_response, :success? => true, :stdout => "x86_64\n"
114
115
  else
115
- mock_failure_response
116
+ double :run_command_response, :success? => false
116
117
  end
117
118
  end
118
- should eq({:family => 'Ubuntu', :release => '12.04'})
119
+ should eq({:family => 'Ubuntu', :release => '12.04', :arch => 'x86_64' })
119
120
  end
120
121
  end
121
122
 
122
123
  context 'test debian (no lsb_release or lsb-release)' do
123
124
  subject { backend.check_os }
124
125
  it do
125
- mock_success_response = double :run_command_response, :success? => true
126
- mock_failure_response = double :run_command_response, :success? => false
127
126
  backend.should_receive(:run_command).at_least(1).times do |args|
128
- args == 'ls /etc/debian_version' ? mock_success_response : mock_failure_response
127
+ if args == 'ls /etc/debian_version'
128
+ double :run_command_response, :success? => true
129
+ elsif args == 'uname -m'
130
+ double :run_command_response, :success? => true, :stdout => "x86_64\n"
131
+ else
132
+ double :run_command_response, :success? => false
133
+ end
129
134
  end
130
- should eq({:family => 'Debian', :release => nil})
135
+ should eq({:family => 'Debian', :release => nil, :arch => 'x86_64' })
131
136
  end
132
137
  end
133
138
  end
@@ -7,3 +7,8 @@ end
7
7
  describe RSpec.configuration.path do
8
8
  it { should eq Specinfra.configuration.path }
9
9
  end
10
+
11
+ Specinfra.configuration.os = 'foo'
12
+ describe Specinfra.configuration.os do
13
+ it { should eq 'foo' }
14
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: specinfra
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.0.beta2
4
+ version: 2.0.0.beta3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gosuke Miyashita
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-05-06 00:00:00.000000000 Z
11
+ date: 2014-05-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -110,6 +110,7 @@ files:
110
110
  - lib/specinfra/backend/powershell/support/find_iis_component.ps1
111
111
  - lib/specinfra/backend/powershell/support/find_installed_application.ps1
112
112
  - lib/specinfra/backend/powershell/support/find_installed_hot_fix.ps1
113
+ - lib/specinfra/backend/powershell/support/find_scheduled_task.ps1
113
114
  - lib/specinfra/backend/powershell/support/find_service.ps1
114
115
  - lib/specinfra/backend/powershell/support/find_user.ps1
115
116
  - lib/specinfra/backend/powershell/support/find_usergroup.ps1
@@ -125,6 +126,7 @@ files:
125
126
  - lib/specinfra/command/base.rb
126
127
  - lib/specinfra/command/darwin.rb
127
128
  - lib/specinfra/command/debian.rb
129
+ - lib/specinfra/command/fedora.rb
128
130
  - lib/specinfra/command/freebsd.rb
129
131
  - lib/specinfra/command/freebsd10.rb
130
132
  - lib/specinfra/command/gentoo.rb
@@ -132,6 +134,7 @@ files:
132
134
  - lib/specinfra/command/openbsd.rb
133
135
  - lib/specinfra/command/plamo.rb
134
136
  - lib/specinfra/command/redhat.rb
137
+ - lib/specinfra/command/redhat7.rb
135
138
  - lib/specinfra/command/smartos.rb
136
139
  - lib/specinfra/command/solaris.rb
137
140
  - lib/specinfra/command/solaris10.rb
@@ -150,6 +153,7 @@ files:
150
153
  - lib/specinfra/helper/os.rb
151
154
  - lib/specinfra/helper/properties.rb
152
155
  - lib/specinfra/properties.rb
156
+ - lib/specinfra/runner.rb
153
157
  - lib/specinfra/version.rb
154
158
  - spec/backend/exec/build_command_spec.rb
155
159
  - spec/backend/ssh/build_command_spec.rb