producer-core 0.1.13 → 0.1.14
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/features/actions/file_append.feature +17 -0
- data/features/actions/file_replace_content.feature +5 -7
- data/features/actions/file_write.feature +1 -2
- data/lib/producer/core/actions/file_append.rb +23 -0
- data/lib/producer/core/actions/shell_command.rb +2 -1
- data/lib/producer/core/remote.rb +3 -4
- data/lib/producer/core/task/dsl.rb +4 -2
- data/lib/producer/core/testing/mock_remote.rb +5 -3
- data/lib/producer/core/version.rb +1 -1
- data/lib/producer/core.rb +1 -0
- data/spec/producer/core/actions/file_append_spec.rb +42 -0
- data/spec/producer/core/remote_spec.rb +11 -1
- data/spec/producer/core/task/dsl_spec.rb +8 -1
- data/spec/support/test_env_helpers.rb +3 -1
- metadata +6 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1c2475905b4f530aaa6299d8ff7a85c05c588bb3
|
4
|
+
data.tar.gz: f2cfa1b86883199dee6760ae43dfbed5e8dcbe70
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6b7b4f2e271d4731f99256bc3f44be758e821b1ec44c82ace19cf3c59b846ef1d77dc7bb433159ba2686fdd5acf7aad632b6269e520202725a790770cf373d7d
|
7
|
+
data.tar.gz: 7dda9db4a723a9d479ff4e589bb9d3dbb9295d8dc939320287021b35b42468e12e22d4f5a8a91da590bd28983e89fe37dcf54c105fe99c5749095b922af98511
|
@@ -0,0 +1,17 @@
|
|
1
|
+
@sshd
|
2
|
+
Feature: `file_append' task action
|
3
|
+
|
4
|
+
Background:
|
5
|
+
Given a remote file named "some_file" with "some content"
|
6
|
+
|
7
|
+
Scenario: appends given content to requested file
|
8
|
+
Given a recipe with:
|
9
|
+
"""
|
10
|
+
target 'some_host.test'
|
11
|
+
|
12
|
+
task :append_content_to_file do
|
13
|
+
file_append 'some_file', ' added'
|
14
|
+
end
|
15
|
+
"""
|
16
|
+
When I successfully execute the recipe
|
17
|
+
Then the remote file "some_file" must contain exactly "some content added"
|
@@ -4,7 +4,7 @@ Feature: `file_replace_content' task action
|
|
4
4
|
Background:
|
5
5
|
Given a remote file named "some_file" with "some content"
|
6
6
|
|
7
|
-
Scenario:
|
7
|
+
Scenario: replaces a string by another in the requested file
|
8
8
|
Given a recipe with:
|
9
9
|
"""
|
10
10
|
target 'some_host.test'
|
@@ -13,19 +13,17 @@ Feature: `file_replace_content' task action
|
|
13
13
|
file_replace_content 'some_file', 'content', 'other content'
|
14
14
|
end
|
15
15
|
"""
|
16
|
-
When I execute the recipe
|
17
|
-
Then the exit status must be 0
|
16
|
+
When I successfully execute the recipe
|
18
17
|
And the remote file "some_file" must contain exactly "some other content"
|
19
18
|
|
20
|
-
Scenario:
|
19
|
+
Scenario: replaces a regular expression by a string in the requested file
|
21
20
|
Given a recipe with:
|
22
21
|
"""
|
23
22
|
target 'some_host.test'
|
24
23
|
|
25
|
-
task :
|
24
|
+
task :replace_regexp_in_file do
|
26
25
|
file_replace_content 'some_file', /\w+\z/, 'other content'
|
27
26
|
end
|
28
27
|
"""
|
29
|
-
When I execute the recipe
|
30
|
-
Then the exit status must be 0
|
28
|
+
When I successfully execute the recipe
|
31
29
|
And the remote file "some_file" must contain exactly "some other content"
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module Producer
|
2
|
+
module Core
|
3
|
+
module Actions
|
4
|
+
class FileAppend < Action
|
5
|
+
def apply
|
6
|
+
fs.file_write path, combined_content
|
7
|
+
end
|
8
|
+
|
9
|
+
def path
|
10
|
+
arguments[0]
|
11
|
+
end
|
12
|
+
|
13
|
+
def content
|
14
|
+
arguments[1]
|
15
|
+
end
|
16
|
+
|
17
|
+
def combined_content
|
18
|
+
fs.file_read(path) + content
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
data/lib/producer/core/remote.rb
CHANGED
@@ -23,9 +23,8 @@ module Producer
|
|
23
23
|
@fs ||= Remote::FS.new(session.sftp.connect)
|
24
24
|
end
|
25
25
|
|
26
|
-
def execute(command)
|
27
|
-
|
28
|
-
session.open_channel do |channel|
|
26
|
+
def execute(command, output = '')
|
27
|
+
channel = session.open_channel do |channel|
|
29
28
|
channel.exec command do |ch, success|
|
30
29
|
ch.on_data do |c, data|
|
31
30
|
output << data
|
@@ -37,7 +36,7 @@ module Producer
|
|
37
36
|
end
|
38
37
|
end
|
39
38
|
end
|
40
|
-
|
39
|
+
channel.wait
|
41
40
|
output
|
42
41
|
end
|
43
42
|
|
@@ -13,9 +13,11 @@ module Producer
|
|
13
13
|
define_action :echo, Actions::Echo
|
14
14
|
define_action :sh, Actions::ShellCommand
|
15
15
|
|
16
|
-
define_action :mkdir,
|
17
|
-
|
16
|
+
define_action :mkdir, Actions::Mkdir
|
17
|
+
|
18
|
+
define_action :file_append, Actions::FileAppend
|
18
19
|
define_action :file_replace_content, Actions::FileReplaceContent
|
20
|
+
define_action :file_write, Actions::FileWriter
|
19
21
|
|
20
22
|
attr_reader :env, :block, :actions
|
21
23
|
|
@@ -6,18 +6,20 @@ module Producer
|
|
6
6
|
raise 'no session for mock remote!'
|
7
7
|
end
|
8
8
|
|
9
|
-
def execute(command)
|
9
|
+
def execute(command, output = '')
|
10
10
|
tokens = command.split
|
11
11
|
program = tokens.shift
|
12
12
|
|
13
13
|
case program
|
14
14
|
when 'echo'
|
15
|
-
tokens.join
|
15
|
+
output << tokens.join(' ')
|
16
16
|
when 'true'
|
17
|
-
''
|
17
|
+
output << ''
|
18
18
|
when 'false'
|
19
19
|
raise RemoteCommandExecutionError
|
20
20
|
end
|
21
|
+
|
22
|
+
output
|
21
23
|
end
|
22
24
|
end
|
23
25
|
end
|
data/lib/producer/core.rb
CHANGED
@@ -10,6 +10,7 @@ require 'producer/core/action'
|
|
10
10
|
require 'producer/core/actions/echo'
|
11
11
|
require 'producer/core/actions/shell_command'
|
12
12
|
require 'producer/core/actions/mkdir'
|
13
|
+
require 'producer/core/actions/file_append'
|
13
14
|
require 'producer/core/actions/file_replace_content'
|
14
15
|
require 'producer/core/actions/file_writer'
|
15
16
|
|
@@ -0,0 +1,42 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module Producer::Core
|
4
|
+
module Actions
|
5
|
+
describe FileAppend, :env do
|
6
|
+
let(:path) { 'some_path' }
|
7
|
+
let(:content) { 'some content' }
|
8
|
+
let(:added_content) { ' added' }
|
9
|
+
subject(:action) { FileAppend.new(env, path, added_content) }
|
10
|
+
|
11
|
+
it_behaves_like 'action'
|
12
|
+
|
13
|
+
before { allow(remote_fs).to receive(:file_read).with(path) { content } }
|
14
|
+
|
15
|
+
describe '#apply' do
|
16
|
+
it 'appends given content to requested file on remote filesystem' do
|
17
|
+
expect(remote_fs)
|
18
|
+
.to receive(:file_write).with(path, action.combined_content)
|
19
|
+
action.apply
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
describe '#path' do
|
24
|
+
it 'returns the file path' do
|
25
|
+
expect(action.path).to eq path
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
describe '#content' do
|
30
|
+
it 'returns the content to append' do
|
31
|
+
expect(action.content).to eq added_content
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
describe '#combined_content' do
|
36
|
+
it 'returns original content and added content combined' do
|
37
|
+
expect(action.combined_content).to eq 'some content added'
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -79,6 +79,7 @@ module Producer::Core
|
|
79
79
|
describe '#execute', :ssh do
|
80
80
|
let(:arguments) { 'some remote command' }
|
81
81
|
let(:command) { "echo #{arguments}" }
|
82
|
+
let(:output) { StringIO.new }
|
82
83
|
|
83
84
|
it 'executes the given command in a new channel' do
|
84
85
|
story_with_new_channel do |ch|
|
@@ -88,7 +89,7 @@ module Producer::Core
|
|
88
89
|
expect_story_completed { remote.execute command }
|
89
90
|
end
|
90
91
|
|
91
|
-
it 'returns the output' do
|
92
|
+
it 'returns the command standard output output' do
|
92
93
|
story_with_new_channel do |ch|
|
93
94
|
ch.sends_exec command
|
94
95
|
ch.gets_data arguments
|
@@ -96,6 +97,15 @@ module Producer::Core
|
|
96
97
|
expect(remote.execute command).to eq arguments
|
97
98
|
end
|
98
99
|
|
100
|
+
it 'writes command standard output to provided output' do
|
101
|
+
story_with_new_channel do |ch|
|
102
|
+
ch.sends_exec command
|
103
|
+
ch.gets_data arguments
|
104
|
+
end
|
105
|
+
remote.execute command, output
|
106
|
+
expect(output.string).to eq arguments
|
107
|
+
end
|
108
|
+
|
99
109
|
it 'raises an exception when the exit status code is not 0' do
|
100
110
|
story_with_new_channel do |ch|
|
101
111
|
ch.sends_exec command
|
@@ -7,7 +7,14 @@ module Producer::Core
|
|
7
7
|
let(:env) { Env.new }
|
8
8
|
subject(:dsl) { DSL.new(env, &block) }
|
9
9
|
|
10
|
-
%w[
|
10
|
+
%w[
|
11
|
+
echo
|
12
|
+
sh
|
13
|
+
mkdir
|
14
|
+
file_append
|
15
|
+
file_replace_content
|
16
|
+
file_write
|
17
|
+
].each do |action|
|
11
18
|
it "has `#{action}' action defined" do
|
12
19
|
expect(dsl).to respond_to action.to_sym
|
13
20
|
end
|
@@ -15,7 +15,9 @@ module TestEnvHelpers
|
|
15
15
|
|
16
16
|
def expect_execution(command)
|
17
17
|
opts = { expected_from: caller.first }
|
18
|
-
RSpec::Mocks
|
18
|
+
RSpec::Mocks
|
19
|
+
.expect_message(env.remote, :execute, opts)
|
20
|
+
.with(command, env.output)
|
19
21
|
end
|
20
22
|
|
21
23
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: producer-core
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.14
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Thibault Jouan
|
@@ -109,6 +109,7 @@ files:
|
|
109
109
|
- Rakefile
|
110
110
|
- bin/producer
|
111
111
|
- features/actions/echo.feature
|
112
|
+
- features/actions/file_append.feature
|
112
113
|
- features/actions/file_replace_content.feature
|
113
114
|
- features/actions/file_write.feature
|
114
115
|
- features/actions/mkdir.feature
|
@@ -139,6 +140,7 @@ files:
|
|
139
140
|
- lib/producer/core.rb
|
140
141
|
- lib/producer/core/action.rb
|
141
142
|
- lib/producer/core/actions/echo.rb
|
143
|
+
- lib/producer/core/actions/file_append.rb
|
142
144
|
- lib/producer/core/actions/file_replace_content.rb
|
143
145
|
- lib/producer/core/actions/file_writer.rb
|
144
146
|
- lib/producer/core/actions/mkdir.rb
|
@@ -171,6 +173,7 @@ files:
|
|
171
173
|
- spec/fixtures/recipes/throw.rb
|
172
174
|
- spec/producer/core/action_spec.rb
|
173
175
|
- spec/producer/core/actions/echo_spec.rb
|
176
|
+
- spec/producer/core/actions/file_append_spec.rb
|
174
177
|
- spec/producer/core/actions/file_replace_content_spec.rb
|
175
178
|
- spec/producer/core/actions/file_writer_spec.rb
|
176
179
|
- spec/producer/core/actions/mkdir_spec.rb
|
@@ -226,6 +229,7 @@ specification_version: 4
|
|
226
229
|
summary: Provisioning tool
|
227
230
|
test_files:
|
228
231
|
- features/actions/echo.feature
|
232
|
+
- features/actions/file_append.feature
|
229
233
|
- features/actions/file_replace_content.feature
|
230
234
|
- features/actions/file_write.feature
|
231
235
|
- features/actions/mkdir.feature
|
@@ -258,6 +262,7 @@ test_files:
|
|
258
262
|
- spec/fixtures/recipes/throw.rb
|
259
263
|
- spec/producer/core/action_spec.rb
|
260
264
|
- spec/producer/core/actions/echo_spec.rb
|
265
|
+
- spec/producer/core/actions/file_append_spec.rb
|
261
266
|
- spec/producer/core/actions/file_replace_content_spec.rb
|
262
267
|
- spec/producer/core/actions/file_writer_spec.rb
|
263
268
|
- spec/producer/core/actions/mkdir_spec.rb
|