rspec-system 0.3.0 → 0.3.1
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.
data/lib/rspec-system/helpers.rb
CHANGED
@@ -168,15 +168,13 @@ module RSpecSystem::Helpers
|
|
168
168
|
dp = options[:dp]
|
169
169
|
|
170
170
|
log.info("system_rcp from #{sp} to #{d.name}:#{dp} executed")
|
171
|
-
|
171
|
+
results = rspec_system_node_set.rcp(options)
|
172
172
|
log.info("rcp results:\n" +
|
173
173
|
"-----------------------\n" +
|
174
|
-
|
175
|
-
"<stdout>#{stdout}</stdout>\n" +
|
176
|
-
"<stderr>#{stderr}</stderr>\n" +
|
174
|
+
results.pretty_inspect +
|
177
175
|
"-----------------------\n")
|
178
176
|
|
179
|
-
if
|
177
|
+
if results[:exit_code] == 1
|
180
178
|
return true
|
181
179
|
else
|
182
180
|
return false
|
@@ -58,6 +58,11 @@ module RSpecSystem
|
|
58
58
|
# Transfer files to a host in the NodeSet.
|
59
59
|
#
|
60
60
|
# @param opts [Hash] options
|
61
|
+
# @todo This is damn ugly, because we ssh in as vagrant, we copy to a temp
|
62
|
+
# path then move it later. Its slow and brittle and we need a better
|
63
|
+
# solution. Its also very Linux-centrix in its use of temp dirs.
|
64
|
+
# @todo Need to return more interesting information, not just the systemu
|
65
|
+
# results. This will require a formalisation of this API.
|
61
66
|
def rcp(opts)
|
62
67
|
#log.debug("[Vagrant@rcp] called with #{opts.inspect}")
|
63
68
|
|
@@ -65,18 +70,29 @@ module RSpecSystem
|
|
65
70
|
source = opts[:sp]
|
66
71
|
dest_path = opts[:dp]
|
67
72
|
|
68
|
-
# TODO: This is damn ugly, because we ssh in as vagrant, we copy to a
|
69
|
-
# temp path then move later. This pattern at the moment only really works
|
70
|
-
# on dirs.
|
71
73
|
log.info("[Vagrant#rcp] Transferring files from #{source} to #{dest}:#{dest_path}")
|
72
74
|
|
73
|
-
#
|
74
|
-
|
75
|
+
# Grab a remote path for temp transfer
|
76
|
+
tmpdest = tmppath
|
77
|
+
|
78
|
+
# Do the copy and print out results for debugging
|
79
|
+
cmd = "scp -r -F '#{ssh_config}' '#{source}' #{dest}:#{tmpdest}"
|
75
80
|
log.debug("[Vagrant#rcp] Running command: #{cmd}")
|
76
|
-
systemu cmd
|
81
|
+
r = systemu cmd
|
82
|
+
|
83
|
+
result = {
|
84
|
+
:exit_code => r[0].exitstatus,
|
85
|
+
:stdout => r[1],
|
86
|
+
:stderr => r[2]
|
87
|
+
}
|
77
88
|
|
78
|
-
|
79
|
-
|
89
|
+
log.info("system_run results:\n" +
|
90
|
+
"-----------------------\n" +
|
91
|
+
result.pretty_inspect +
|
92
|
+
"-----------------------\n")
|
93
|
+
|
94
|
+
# Now we move the file into their final destination
|
95
|
+
run(:n => opts[:d], :c => "mv #{tmpdest} #{dest_path}")
|
80
96
|
end
|
81
97
|
|
82
98
|
# Create the Vagrantfile for the NodeSet.
|
@@ -145,5 +161,24 @@ module RSpecSystem
|
|
145
161
|
end
|
146
162
|
nil
|
147
163
|
end
|
164
|
+
|
165
|
+
# Return a random string of chars, used for temp dir creation
|
166
|
+
#
|
167
|
+
# @api private
|
168
|
+
# @return [String] string of 50 random characters A-Z and a-z
|
169
|
+
def random_string
|
170
|
+
o = [('a'..'z'),('A'..'Z')].map{|i| i.to_a}.flatten
|
171
|
+
(0...50).map{ o[rand(o.length)] }.join
|
172
|
+
end
|
173
|
+
|
174
|
+
# Generates a random string for use in remote transfers.
|
175
|
+
#
|
176
|
+
# @api private
|
177
|
+
# @return [String] a random path
|
178
|
+
# @todo Very Linux dependant, probably need to consider OS X and Windows at
|
179
|
+
# least.
|
180
|
+
def tmppath
|
181
|
+
'/tmp/' + random_string
|
182
|
+
end
|
148
183
|
end
|
149
184
|
end
|
data/rspec-system.gemspec
CHANGED
@@ -0,0 +1 @@
|
|
1
|
+
Test content 1234
|
data/spec/spec_helper_system.rb
CHANGED
@@ -1,5 +1,16 @@
|
|
1
1
|
require 'rspec-system/spec_helper'
|
2
2
|
|
3
|
+
module LocalHelpers
|
4
|
+
def proj_root
|
5
|
+
Pathname.new(File.expand_path(File.join(File.dirname(__FILE__), '..')))
|
6
|
+
end
|
7
|
+
|
8
|
+
def fixture_root
|
9
|
+
proj_root + 'spec' + 'fixtures'
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
3
13
|
RSpec.configure do |c|
|
4
14
|
c.include RSpecSystem::Helpers
|
15
|
+
c.include ::LocalHelpers
|
5
16
|
end
|
data/spec/system/basic_spec.rb
CHANGED
@@ -7,4 +7,16 @@ describe "basic tests:" do
|
|
7
7
|
r[:stdout].should =~ /localhost/
|
8
8
|
end
|
9
9
|
end
|
10
|
+
|
11
|
+
it 'check system_rcp works' do
|
12
|
+
system_rcp(
|
13
|
+
:sp => fixture_root + 'example_dir',
|
14
|
+
:dp => '/tmp/example_destination'
|
15
|
+
)
|
16
|
+
|
17
|
+
system_run('cat /tmp/example_destination/example_file') do |r|
|
18
|
+
r[:exit_code].should == 0
|
19
|
+
r[:stdout].should =~ /Test content 1234/
|
20
|
+
end
|
21
|
+
end
|
10
22
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rspec-system
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -98,6 +98,7 @@ files:
|
|
98
98
|
- resources/kwalify-schemas/prefabs_schema.yml
|
99
99
|
- resources/prefabs.yml
|
100
100
|
- rspec-system.gemspec
|
101
|
+
- spec/fixtures/example_dir/example_file
|
101
102
|
- spec/fixtures/nodeset_example1.yml
|
102
103
|
- spec/fixtures/nodeset_example2.yml
|
103
104
|
- spec/spec_helper.rb
|