pennyworth-tool 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (45) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +38 -4
  3. data/examples/README.md +1 -1
  4. data/examples/{kiwi → boxes}/definitions/base_opensuse13.1_kvm/config.sh +0 -0
  5. data/examples/{kiwi → boxes}/definitions/base_opensuse13.1_kvm/config.xml +0 -0
  6. data/examples/{kiwi → boxes}/definitions/base_opensuse13.1_kvm/root/etc/sysconfig/network/ifcfg-eth0 +0 -0
  7. data/examples/{kiwi → boxes}/definitions/base_opensuse13.1_kvm/root/home/vagrant/.ssh/authorized_keys +0 -0
  8. data/lib/pennyworth/cli.rb +11 -11
  9. data/lib/pennyworth/commands/base_command.rb +8 -8
  10. data/lib/pennyworth/commands/build_base_command.rb +36 -14
  11. data/lib/pennyworth/commands/import_base_command.rb +4 -4
  12. data/lib/pennyworth/commands/list_command.rb +1 -1
  13. data/lib/pennyworth/commands/setup_command.rb +43 -10
  14. data/lib/pennyworth/exceptions.rb +0 -12
  15. data/lib/pennyworth/local_command_runner.rb +0 -2
  16. data/lib/pennyworth/matchers.rb +148 -0
  17. data/lib/pennyworth/remote_command_runner.rb +1 -2
  18. data/lib/pennyworth/runner.rb +1 -1
  19. data/lib/pennyworth/settings.rb +2 -2
  20. data/lib/pennyworth/spec.rb +1 -0
  21. data/lib/pennyworth/version.rb +1 -3
  22. data/lib/pennyworth/vm.rb +26 -1
  23. data/spec/build_base_command_spec.rb +18 -10
  24. data/spec/data/{kiwi → boxes}/definitions/base_opensuse12.3_kvm/config.sh +0 -0
  25. data/spec/data/{kiwi → boxes}/definitions/base_opensuse12.3_kvm/config.xml +0 -0
  26. data/spec/data/{kiwi → boxes}/definitions/base_opensuse12.3_kvm/root/home/vagrant/.ssh/authorized_keys +0 -0
  27. data/spec/data/{kiwi → boxes}/definitions/base_opensuse13.1_kvm/config.sh +0 -0
  28. data/spec/data/{kiwi → boxes}/definitions/base_opensuse13.1_kvm/config.xml +0 -0
  29. data/spec/data/{kiwi → boxes}/definitions/base_opensuse13.1_kvm/root/home/vagrant/.ssh/authorized_keys +0 -0
  30. data/spec/data/{kiwi3/definitions/base_opensuse12.3_kvm/.gitkeep → boxes/definitions/veewee_definition/definition.rb} +0 -0
  31. data/spec/data/{kiwi2 → boxes2}/definitions/base_opensuse12.3_kvm/config.sh +0 -0
  32. data/spec/data/{kiwi2 → boxes2}/definitions/base_opensuse12.3_kvm/config.xml +0 -0
  33. data/spec/data/{kiwi2 → boxes2}/definitions/base_opensuse12.3_kvm/root/home/vagrant/.ssh/authorized_keys +0 -0
  34. data/spec/data/{kiwi2 → boxes2}/definitions/base_opensuse13.1_kvm/config.sh +0 -0
  35. data/spec/data/{kiwi2 → boxes2}/definitions/base_opensuse13.1_kvm/config.xml +0 -0
  36. data/spec/data/{kiwi2 → boxes2}/definitions/base_opensuse13.1_kvm/root/home/vagrant/.ssh/authorized_keys +0 -0
  37. data/spec/data/{kiwi3/definitions/base_opensuse13.1_kvm → boxes3/definitions/base_opensuse12.3_kvm}/.gitkeep +0 -0
  38. data/spec/data/{kiwi4/definitions/base_opensuse12.3_kvm → boxes3/definitions/base_opensuse13.1_kvm}/.gitkeep +0 -0
  39. data/spec/data/{kiwi4/definitions/base_opensuse13.1_kvm → boxes4/definitions/base_opensuse12.3_kvm}/.gitkeep +0 -0
  40. data/spec/data/boxes4/definitions/base_opensuse13.1_kvm/.gitkeep +0 -0
  41. data/spec/import_base_command_spec.rb +15 -15
  42. data/spec/matchers_spec.rb +175 -0
  43. data/spec/remote_command_runner_spec.rb +5 -15
  44. data/spec/setup_command_spec.rb +63 -1
  45. metadata +33 -29
@@ -0,0 +1,175 @@
1
+ # Copyright (c) 2013-2014 SUSE LLC
2
+ #
3
+ # This program is free software; you can redistribute it and/or
4
+ # modify it under the terms of version 3 of the GNU General Public License as
5
+ # published by the Free Software Foundation.
6
+ #
7
+ # This program is distributed in the hope that it will be useful,
8
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
9
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10
+ # GNU General Public License for more details.
11
+ #
12
+ # You should have received a copy of the GNU General Public License
13
+ # along with this program; if not, contact SUSE LLC.
14
+ #
15
+ # To contact SUSE about this file by physical or electronic mail,
16
+ # you may find current contact information at www.suse.com
17
+
18
+ require "pennyworth/spec"
19
+ require "pennyworth/vm"
20
+
21
+ describe "VM matchers" do
22
+ describe "succeed" do
23
+ it "passes" do
24
+ expect(command_result("", "", 0)).to succeed
25
+ end
26
+
27
+ it "fails on exit code != 0" do
28
+ expect {
29
+ expect(command_result("", "", 1)).to succeed
30
+ }.to raise_error(/Expected.*the command.*but it returned with exit code 1/m)
31
+ end
32
+
33
+ context "with .with_or_without_stderr" do
34
+ it "passes if there is stderr" do
35
+ expect(command_result("", "foo", 0)).to succeed.with_or_without_stderr
36
+ end
37
+
38
+ it "passes if there is no stderr" do
39
+ expect(command_result("", "", 0)).to succeed.with_or_without_stderr
40
+ end
41
+ end
42
+
43
+ context "with stderr output" do
44
+ let(:result) { command_result("", "foo", 0) }
45
+
46
+ it "fails" do
47
+ expect {
48
+ expect(result).to succeed
49
+ }.to raise_error(/Expected.*the command.*but it had stderr output/m)
50
+ end
51
+
52
+ it "passes if '.with_stderr' was used" do
53
+ expect(result).to succeed.with_stderr
54
+ end
55
+ end
56
+ end
57
+
58
+ describe "fail" do
59
+ it "passes" do
60
+ expect(command_result("", "", 1)).to fail
61
+ end
62
+
63
+ it "fails" do
64
+ expect {
65
+ expect(command_result("", "", 0)).to fail
66
+ }.to raise_error(/but it succeeded/)
67
+ end
68
+
69
+ context ".with_exit_code" do
70
+ it "passes on exit code" do
71
+ expect(command_result("", "", 3)).to fail.with_exit_code(3)
72
+ end
73
+
74
+ it "fails on exit code" do
75
+ expect {
76
+ expect(command_result("", "", 3)).to fail.with_exit_code(2)
77
+ }.to raise_error(/Expected.*the command.*but it exited with 3/m)
78
+ end
79
+ end
80
+ end
81
+
82
+ describe "have_stderr" do
83
+ let(:result) { command_result("", "foo", 1) }
84
+
85
+ context "with a Regexp" do
86
+ it "passes" do
87
+ expect(result).to have_stderr(/f.o/)
88
+ end
89
+
90
+ it "fails" do
91
+ expect {
92
+ expect(result).to have_stderr(/g.o/)
93
+ }.to raise_error(/to match \/g.o\//)
94
+ end
95
+ end
96
+
97
+ context "with a String" do
98
+ it "passes" do
99
+ expect(result).to have_stderr("foo")
100
+ end
101
+
102
+ it "fails" do
103
+ expect {
104
+ expect(result).to have_stderr("bar")
105
+ }.to raise_error(/to be 'bar'/)
106
+ end
107
+ end
108
+ end
109
+
110
+ describe "include_stderr" do
111
+ let(:result) { command_result("", "foo", 1) }
112
+
113
+ it "passes" do
114
+ expect(result).to include_stderr("fo")
115
+ end
116
+
117
+ it "fails" do
118
+ expect {
119
+ expect(result).to include_stderr("ba")
120
+ }.to raise_error(/to include 'ba'/)
121
+ end
122
+ end
123
+
124
+ describe "have_stdout" do
125
+ let(:result) { command_result("foo", "", 0) }
126
+
127
+ context "with a Regexp" do
128
+ it "passes" do
129
+ expect(result).to have_stdout(/f.o/)
130
+ end
131
+
132
+ it "fails" do
133
+ expect {
134
+ expect(result).to have_stdout(/g.o/)
135
+ }.to raise_error(/to match \/g.o\//)
136
+ end
137
+ end
138
+
139
+ context "with a String" do
140
+ it "passes" do
141
+ expect(result).to have_stdout("foo")
142
+ end
143
+
144
+ it "fails" do
145
+ expect {
146
+ expect(result).to have_stdout("bar")
147
+ }.to raise_error(/to be 'bar'/)
148
+ end
149
+ end
150
+ end
151
+
152
+ describe "include_stdout" do
153
+ let(:result) { command_result("foo", "", 0) }
154
+
155
+ it "passes" do
156
+ expect(result).to include_stdout("fo")
157
+ end
158
+
159
+ it "fails" do
160
+ expect {
161
+ expect(result).to include_stdout("ba")
162
+ }.to raise_error(/to include 'ba'/)
163
+ end
164
+ end
165
+
166
+ def command_result(stdout, stderr, exit_code)
167
+ res = Pennyworth::VM::CommandResult.new
168
+ res.cmd = "the command"
169
+ res.stdout = stdout
170
+ res.stderr = stderr
171
+ res.exit_code = exit_code
172
+
173
+ res
174
+ end
175
+ end
@@ -36,22 +36,12 @@ describe Pennyworth::RemoteCommandRunner do
36
36
  it "executes commands as given user" do
37
37
  expect(Cheetah).to receive(:run).
38
38
  with(
39
- "ssh", "-o", "UserKnownHostsFile=/dev/null", "-o", "StrictHostKeyChecking=no",
40
- "root@1.2.3.4", "LC_ALL=C", "su", "-l", "vagrant", "-c", "ls", "-l", "/etc/hosts",
41
- stdout: :capture).
42
- and_return(ssh_output)
43
-
44
- output = command_runner.run("ls", "-l", "/etc/hosts", as: "vagrant", stdout: :capture)
45
-
46
- expect(output).to eq (ssh_output)
47
- end
48
-
49
- it "raises ExecutionFailed in case of errors" do
50
- expect(Cheetah).to receive(:run).and_raise(Cheetah::ExecutionFailed.new(nil, nil, nil, nil))
39
+ "ssh", "-q", "-o", "UserKnownHostsFile=/dev/null", "-o", "StrictHostKeyChecking=no",
40
+ "root@1.2.3.4", "LC_ALL=C", "su", "-l", "vagrant", "-c", "ls", "-l", "/etc/hosts",
41
+ any_args
42
+ ).and_return(ssh_output)
51
43
 
52
- expect {
53
- command_runner.run("foo")
54
- }.to raise_error(Pennyworth::ExecutionFailed)
44
+ command_runner.run("ls", "-l", "/etc/hosts", as: "vagrant")
55
45
  end
56
46
  end
57
47
 
@@ -14,6 +14,7 @@
14
14
  #
15
15
  # To contact SUSE about this file by physical or electronic mail,
16
16
  # you may find current contact information at www.suse.com
17
+ require "spec_helper"
17
18
  require_relative "../lib/pennyworth/commands/setup_command.rb"
18
19
 
19
20
  describe Pennyworth::SetupCommand do
@@ -36,7 +37,7 @@ EOF
36
37
 
37
38
  it "shows no warning for supported SLES 12 distribution" do
38
39
  sles12_release_file = <<-EOF
39
- NAME="SLES"
40
+ NAME=SLES
40
41
  VERSION="12"
41
42
  VERSION_ID="12"
42
43
  PRETTY_NAME="SUSE Linux Enterprise Server 12"
@@ -46,4 +47,65 @@ EOF
46
47
  setup_command.show_warning_for_unsupported_platforms
47
48
  end
48
49
  end
50
+
51
+ describe "#vagrant_installed?" do
52
+ context "when a valid version of vagrant already exists" do
53
+ it "returns true" do
54
+ expect(Cheetah).to receive(:run).with("rpm", "-q", "vagrant", stdout: :capture).and_return(
55
+ "vagrant-1.7.2-1.x86_64"
56
+ )
57
+
58
+ expect(subject.vagrant_installed?).to be_truthy
59
+ end
60
+ end
61
+
62
+ context "when no valid version of vagrant already exists" do
63
+ it "returns false" do
64
+ expect(Cheetah).to receive(:run).with("rpm", "-q", "vagrant", stdout: :capture).and_return(
65
+ "vagrant-1.7.0.x86_64"
66
+ )
67
+
68
+ expect(subject.vagrant_installed?).to be_falsey
69
+ end
70
+ end
71
+
72
+ context "when no version of vagrant is installed" do
73
+ it "returns false" do
74
+ expect(Cheetah).to receive(:run).with("rpm", "-q", "vagrant", stdout: :capture).
75
+ and_raise
76
+
77
+ expect(subject.vagrant_installed?).to be_falsey
78
+ end
79
+ end
80
+ end
81
+
82
+ describe "#vagrant_libvirt_installed?" do
83
+ context "when a valid version of vagrant-libvirt already exists" do
84
+ it "returns true" do
85
+ expect(Cheetah).to receive(:run).with("vagrant", "plugin", "list", stdout: :capture).
86
+ and_return("vagrant-libvirt (0.0.29)\nvagrant-share (1.1.3, system)")
87
+
88
+ expect(subject.vagrant_libvirt_installed?).to be_truthy
89
+ end
90
+ end
91
+
92
+ context "when no valid version of vagrant-libvirt already exists" do
93
+ it "returns false" do
94
+ expect(Cheetah).to receive(:run).with("vagrant", "plugin", "list", stdout: :capture).
95
+ and_return("vagrant-libvirt (0.0.28)\nvagrant-share (1.1.3, system)"
96
+ )
97
+
98
+ expect(subject.vagrant_libvirt_installed?).to be_falsey
99
+ end
100
+ end
101
+
102
+ context "when no version of vagrant-libvirt is installed" do
103
+ it "returns false" do
104
+ expect(Cheetah).to receive(:run).with("vagrant", "plugin", "list", stdout: :capture).
105
+ and_raise
106
+
107
+ expect(subject.vagrant_libvirt_installed?).to be_falsey
108
+ end
109
+ end
110
+ end
49
111
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pennyworth-tool
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - SUSE
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-05-28 00:00:00.000000000 Z
11
+ date: 2015-06-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: gli
@@ -133,10 +133,10 @@ files:
133
133
  - bin/pennyworth
134
134
  - config/setup.yml
135
135
  - examples/README.md
136
- - examples/kiwi/definitions/base_opensuse13.1_kvm/config.sh
137
- - examples/kiwi/definitions/base_opensuse13.1_kvm/config.xml
138
- - examples/kiwi/definitions/base_opensuse13.1_kvm/root/etc/sysconfig/network/ifcfg-eth0
139
- - examples/kiwi/definitions/base_opensuse13.1_kvm/root/home/vagrant/.ssh/authorized_keys
136
+ - examples/boxes/definitions/base_opensuse13.1_kvm/config.sh
137
+ - examples/boxes/definitions/base_opensuse13.1_kvm/config.xml
138
+ - examples/boxes/definitions/base_opensuse13.1_kvm/root/etc/sysconfig/network/ifcfg-eth0
139
+ - examples/boxes/definitions/base_opensuse13.1_kvm/root/home/vagrant/.ssh/authorized_keys
140
140
  - examples/vagrant/Vagrantfile
141
141
  - files/99-libvirt.rules
142
142
  - files/image_test-template.xml
@@ -167,6 +167,7 @@ files:
167
167
  - lib/pennyworth/local_command_runner.rb
168
168
  - lib/pennyworth/local_runner.rb
169
169
  - lib/pennyworth/lock_service.rb
170
+ - lib/pennyworth/matchers.rb
170
171
  - lib/pennyworth/remote_command_runner.rb
171
172
  - lib/pennyworth/runner.rb
172
173
  - lib/pennyworth/settings.rb
@@ -187,30 +188,32 @@ files:
187
188
  - spec/base_command_spec.rb
188
189
  - spec/build_base_command_spec.rb
189
190
  - spec/cli_host_controller_spec.rb
191
+ - spec/data/boxes/base_opensuse12.3_kvm.box
192
+ - spec/data/boxes/base_opensuse13.1_kvm.box
193
+ - spec/data/boxes/box_state.yaml
194
+ - spec/data/boxes/definitions/base_opensuse12.3_kvm/config.sh
195
+ - spec/data/boxes/definitions/base_opensuse12.3_kvm/config.xml
196
+ - spec/data/boxes/definitions/base_opensuse12.3_kvm/root/home/vagrant/.ssh/authorized_keys
197
+ - spec/data/boxes/definitions/base_opensuse13.1_kvm/config.sh
198
+ - spec/data/boxes/definitions/base_opensuse13.1_kvm/config.xml
199
+ - spec/data/boxes/definitions/base_opensuse13.1_kvm/root/home/vagrant/.ssh/authorized_keys
200
+ - spec/data/boxes/definitions/veewee_definition/definition.rb
201
+ - spec/data/boxes2/box_state.yaml
202
+ - spec/data/boxes2/definitions/base_opensuse12.3_kvm/config.sh
203
+ - spec/data/boxes2/definitions/base_opensuse12.3_kvm/config.xml
204
+ - spec/data/boxes2/definitions/base_opensuse12.3_kvm/root/home/vagrant/.ssh/authorized_keys
205
+ - spec/data/boxes2/definitions/base_opensuse13.1_kvm/config.sh
206
+ - spec/data/boxes2/definitions/base_opensuse13.1_kvm/config.xml
207
+ - spec/data/boxes2/definitions/base_opensuse13.1_kvm/root/home/vagrant/.ssh/authorized_keys
208
+ - spec/data/boxes3/box_state.yaml
209
+ - spec/data/boxes3/definitions/base_opensuse12.3_kvm/.gitkeep
210
+ - spec/data/boxes3/definitions/base_opensuse13.1_kvm/.gitkeep
211
+ - spec/data/boxes3/import_state.yaml
212
+ - spec/data/boxes4/definitions/base_opensuse12.3_kvm/.gitkeep
213
+ - spec/data/boxes4/definitions/base_opensuse13.1_kvm/.gitkeep
214
+ - spec/data/boxes4/import_state.yaml
215
+ - spec/data/boxes5/import_state.yaml
190
216
  - spec/data/hosts.yaml
191
- - spec/data/kiwi/base_opensuse12.3_kvm.box
192
- - spec/data/kiwi/base_opensuse13.1_kvm.box
193
- - spec/data/kiwi/definitions/base_opensuse12.3_kvm/config.sh
194
- - spec/data/kiwi/definitions/base_opensuse12.3_kvm/config.xml
195
- - spec/data/kiwi/definitions/base_opensuse12.3_kvm/root/home/vagrant/.ssh/authorized_keys
196
- - spec/data/kiwi/definitions/base_opensuse13.1_kvm/config.sh
197
- - spec/data/kiwi/definitions/base_opensuse13.1_kvm/config.xml
198
- - spec/data/kiwi/definitions/base_opensuse13.1_kvm/root/home/vagrant/.ssh/authorized_keys
199
- - spec/data/kiwi2/box_state.yaml
200
- - spec/data/kiwi2/definitions/base_opensuse12.3_kvm/config.sh
201
- - spec/data/kiwi2/definitions/base_opensuse12.3_kvm/config.xml
202
- - spec/data/kiwi2/definitions/base_opensuse12.3_kvm/root/home/vagrant/.ssh/authorized_keys
203
- - spec/data/kiwi2/definitions/base_opensuse13.1_kvm/config.sh
204
- - spec/data/kiwi2/definitions/base_opensuse13.1_kvm/config.xml
205
- - spec/data/kiwi2/definitions/base_opensuse13.1_kvm/root/home/vagrant/.ssh/authorized_keys
206
- - spec/data/kiwi3/box_state.yaml
207
- - spec/data/kiwi3/definitions/base_opensuse12.3_kvm/.gitkeep
208
- - spec/data/kiwi3/definitions/base_opensuse13.1_kvm/.gitkeep
209
- - spec/data/kiwi3/import_state.yaml
210
- - spec/data/kiwi4/definitions/base_opensuse12.3_kvm/.gitkeep
211
- - spec/data/kiwi4/definitions/base_opensuse13.1_kvm/.gitkeep
212
- - spec/data/kiwi4/import_state.yaml
213
- - spec/data/kiwi5/import_state.yaml
214
217
  - spec/data/vagrant/.gitkeep
215
218
  - spec/host_config_spec.rb
216
219
  - spec/host_runner_spec.rb
@@ -219,6 +222,7 @@ files:
219
222
  - spec/local_command_runner_spec.rb
220
223
  - spec/local_runner_spec.rb
221
224
  - spec/lock_service_spec.rb
225
+ - spec/matchers_spec.rb
222
226
  - spec/remote_command_runner_spec.rb
223
227
  - spec/settings_spec.rb
224
228
  - spec/setup_command_spec.rb