specinfra 2.0.0.beta17 → 2.0.0.beta18

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9141ed5f23cd671075173286b85cc67b619889f7
4
- data.tar.gz: 28a674a6cc109c73a8fb4a50c47eda6daddac8c0
3
+ metadata.gz: 6af2a5fa821f3d2f51a4982137e50c24b32cec22
4
+ data.tar.gz: 630f65f9b762a5d48429a99931f3c612c420843b
5
5
  SHA512:
6
- metadata.gz: f328422b57af471639714cb4c9f327e296d78f9063d47db3df43687458da33d61446a3207bbea9d65141b6e5c4931e4215791ef74a10f095b325404a9d3315d8
7
- data.tar.gz: 797567cf8b7aef533bb050a615a842f7621e60167613ac22497538153961ba667a99f62bd48cfa30777d05b59bec98f71909ae330f9229b3eabe65e476dd5d84
6
+ metadata.gz: 85b58ab0d41c0327d9fbac11ff03787f82192e21a818bf8a224195c8615982015165a3d296922d9de69382bec2055e905871d83980926a2f7481640a5976dbc8
7
+ data.tar.gz: 342e63846bff9fb14ce8d2b601352e47f865ff7c2c0340cdf68505edc859c80863aaef63e2efd4f8036e0ad0937c1a864f815accccb7a6abd63d8ce01923558c
data/lib/specinfra.rb CHANGED
@@ -19,8 +19,11 @@ module Specinfra
19
19
  end
20
20
 
21
21
  def backend
22
- type = Specinfra.configuration.backend.to_s.to_camel_case
23
- eval "Specinfra::Backend::#{type}.instance"
22
+ type = Specinfra.configuration.backend
23
+ if type.nil?
24
+ raise "No backend type is specified. Please specify backend type by `set :backend, :type'"
25
+ end
26
+ eval "Specinfra::Backend::#{type.to_s.to_camel_case}.instance"
24
27
  end
25
28
  end
26
29
  end
@@ -1,6 +1,6 @@
1
1
  require 'specinfra/backend/exec'
2
2
  require 'net/ssh'
3
-
3
+ require 'net/scp'
4
4
  module Specinfra
5
5
  module Backend
6
6
  class Ssh < Exec
@@ -58,6 +58,10 @@ module Specinfra
58
58
  end
59
59
 
60
60
  def copy_file(from, to)
61
+ if Specinfra.configuration.scp.nil?
62
+ Specinfra.configuration.scp = create_scp
63
+ end
64
+
61
65
  scp = Specinfra.configuration.scp
62
66
  begin
63
67
  scp.upload!(from, to)
@@ -68,6 +72,22 @@ module Specinfra
68
72
  end
69
73
 
70
74
  private
75
+ def create_ssh
76
+ Net::SSH.start(
77
+ Specinfra.configuration.host,
78
+ Specinfra.configuration.ssh_options[:user],
79
+ Specinfra.configuration.ssh_options
80
+ )
81
+ end
82
+
83
+ def create_scp
84
+ ssh = Specinfra.configuration.ssh
85
+ if ssh.nil?
86
+ ssh = create_ssh
87
+ end
88
+ Net::SCP.new(ssh)
89
+ end
90
+
71
91
  def ssh_exec!(command)
72
92
  stdout_data = ''
73
93
  stderr_data = ''
@@ -75,11 +95,7 @@ module Specinfra
75
95
  exit_signal = nil
76
96
 
77
97
  if Specinfra.configuration.ssh.nil?
78
- Specinfra.configuration.ssh = Net::SSH.start(
79
- Specinfra.configuration.host,
80
- Specinfra.configuration.ssh_options[:user],
81
- Specinfra.configuration.ssh_options
82
- )
98
+ Specinfra.configuration.ssh = create_ssh
83
99
  end
84
100
 
85
101
  ssh = Specinfra.configuration.ssh
@@ -36,7 +36,7 @@ class Specinfra::Command::Base
36
36
  family = os[:family]
37
37
  version = os[:release] ? "V#{os[:release].to_i}" : nil
38
38
 
39
- common_class = self.class.const_get('Specinfra').const_get('Command')
39
+ common_class = Specinfra::Command
40
40
  base_class = common_class.const_get('Base')
41
41
  os_class = family.nil? ? base_class : common_class.const_get(family.capitalize)
42
42
 
@@ -93,5 +93,18 @@ class Specinfra::Command::Base::File < Specinfra::Command::Base
93
93
  def get_size(file)
94
94
  "stat -c %s #{escape(file)}"
95
95
  end
96
+
97
+ def change_mode(file, mode)
98
+ "chmod #{mode} #{escape(file)}"
99
+ end
100
+
101
+ def change_owner(file, owner, group=nil)
102
+ owner = "#{owner}:#{group}" if group
103
+ "chown #{owner} #{escape(file)}"
104
+ end
105
+
106
+ def change_group(file, group)
107
+ "chgrp #{group} #{escape(file)}"
108
+ end
96
109
  end
97
110
  end
@@ -1,5 +1,7 @@
1
1
  class Specinfra::Command::Opensuse::Base::Service < Specinfra::Command::Suse::Base::Service
2
2
  class << self
3
- include Specinfra::Command::Module::Systemd
3
+ def check_is_running(service)
4
+ "service #{escape(service)} status"
5
+ end
4
6
  end
5
7
  end
@@ -1,3 +1,3 @@
1
1
  module Specinfra
2
- VERSION = "2.0.0.beta17"
2
+ VERSION = "2.0.0.beta18"
3
3
  end
@@ -2,10 +2,28 @@ require 'spec_helper'
2
2
 
3
3
  set :os, { :family => nil }
4
4
 
5
- describe Specinfra.command.check_file_is_directory('/tmp') do
5
+ describe 'File related commands' do
6
6
  after do
7
7
  property[:os_by_host] = nil
8
8
  end
9
9
 
10
- it { should eq 'test -d /tmp' }
10
+ context Specinfra.command.check_file_is_directory('/tmp') do
11
+ it { should eq 'test -d /tmp' }
12
+ end
13
+
14
+ context Specinfra.command.change_file_mode('/tmp', '0644') do
15
+ it { should eq 'chmod 0644 /tmp' }
16
+ end
17
+
18
+ context Specinfra.command.change_file_owner('/tmp', 'root') do
19
+ it { should eq 'chown root /tmp' }
20
+ end
21
+
22
+ context Specinfra.command.change_file_owner('/tmp', 'root', 'root') do
23
+ it { should eq 'chown root:root /tmp' }
24
+ end
25
+
26
+ context Specinfra.command.change_file_group('/tmp', 'root') do
27
+ it { should eq 'chgrp root /tmp' }
28
+ end
11
29
  end
data/specinfra.gemspec CHANGED
@@ -19,6 +19,7 @@ Gem::Specification.new do |spec|
19
19
  spec.require_paths = ["lib"]
20
20
 
21
21
  spec.add_runtime_dependency "net-ssh"
22
+ spec.add_runtime_dependency "net-scp"
22
23
 
23
24
  spec.add_development_dependency "bundler", "~> 1.3"
24
25
  spec.add_development_dependency "rake", "~> 10.1.1"
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.beta17
4
+ version: 2.0.0.beta18
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-08-03 00:00:00.000000000 Z
11
+ date: 2014-08-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: net-ssh
@@ -24,6 +24,20 @@ dependencies:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: net-scp
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
27
41
  - !ruby/object:Gem::Dependency
28
42
  name: bundler
29
43
  requirement: !ruby/object:Gem::Requirement