pennyworth-tool 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (112) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +8 -0
  3. data/.hound.yml +3 -0
  4. data/.rspec +2 -0
  5. data/.rubocop.yml +18 -0
  6. data/CONTRIBUTING.md +67 -0
  7. data/COPYING +674 -0
  8. data/Gemfile +28 -0
  9. data/README.md +339 -0
  10. data/Rakefile +33 -0
  11. data/bin/pennyworth +26 -0
  12. data/config/setup.yml +17 -0
  13. data/examples/README.md +23 -0
  14. data/examples/kiwi/definitions/base_opensuse13.1_kvm/config.sh +87 -0
  15. data/examples/kiwi/definitions/base_opensuse13.1_kvm/config.xml +64 -0
  16. data/examples/kiwi/definitions/base_opensuse13.1_kvm/root/etc/sysconfig/network/ifcfg-eth0 +2 -0
  17. data/examples/kiwi/definitions/base_opensuse13.1_kvm/root/home/vagrant/.ssh/authorized_keys +1 -0
  18. data/examples/vagrant/Vagrantfile +14 -0
  19. data/files/99-libvirt.rules +2 -0
  20. data/files/image_test-template.xml +43 -0
  21. data/files/pool-default.xml +6 -0
  22. data/lib/image_runner.rb +89 -0
  23. data/lib/pennyworth.rb +65 -0
  24. data/lib/pennyworth/cli.rb +339 -0
  25. data/lib/pennyworth/cli_host_controller.rb +107 -0
  26. data/lib/pennyworth/commands/base_command.rb +96 -0
  27. data/lib/pennyworth/commands/boot_command.rb +29 -0
  28. data/lib/pennyworth/commands/build_base_command.rb +103 -0
  29. data/lib/pennyworth/commands/command.rb +43 -0
  30. data/lib/pennyworth/commands/down_command.rb +25 -0
  31. data/lib/pennyworth/commands/import_base_command.rb +112 -0
  32. data/lib/pennyworth/commands/import_ssh_keys_command.rb +27 -0
  33. data/lib/pennyworth/commands/list_command.rb +41 -0
  34. data/lib/pennyworth/commands/setup_command.rb +209 -0
  35. data/lib/pennyworth/commands/shutdown_command.rb +28 -0
  36. data/lib/pennyworth/commands/status_command.rb +26 -0
  37. data/lib/pennyworth/commands/up_command.rb +27 -0
  38. data/lib/pennyworth/exceptions.rb +39 -0
  39. data/lib/pennyworth/helper.rb +39 -0
  40. data/lib/pennyworth/host_config.rb +86 -0
  41. data/lib/pennyworth/host_runner.rb +133 -0
  42. data/lib/pennyworth/image_runner.rb +89 -0
  43. data/lib/pennyworth/libvirt.rb +93 -0
  44. data/lib/pennyworth/local_command_runner.rb +77 -0
  45. data/lib/pennyworth/local_runner.rb +34 -0
  46. data/lib/pennyworth/lock_service.rb +87 -0
  47. data/lib/pennyworth/remote_command_runner.rb +144 -0
  48. data/lib/pennyworth/runner.rb +27 -0
  49. data/lib/pennyworth/settings.rb +42 -0
  50. data/lib/pennyworth/spec.rb +96 -0
  51. data/lib/pennyworth/spec_profiler.rb +85 -0
  52. data/lib/pennyworth/ssh_keys_importer.rb +107 -0
  53. data/lib/pennyworth/urls.rb +28 -0
  54. data/lib/pennyworth/vagrant.rb +81 -0
  55. data/lib/pennyworth/vagrant_command.rb +120 -0
  56. data/lib/pennyworth/vagrant_runner.rb +44 -0
  57. data/lib/pennyworth/version.rb +22 -0
  58. data/lib/pennyworth/vm.rb +62 -0
  59. data/man/.gitignore +2 -0
  60. data/man/pennyworth.1.md +28 -0
  61. data/pennyworth.gemspec +57 -0
  62. data/prophet/Gemfile +3 -0
  63. data/prophet/prophet.rb +82 -0
  64. data/spec/base_command_spec.rb +30 -0
  65. data/spec/build_base_command_spec.rb +147 -0
  66. data/spec/cli_host_controller_spec.rb +113 -0
  67. data/spec/data/hosts.yaml +10 -0
  68. data/spec/data/kiwi/base_opensuse12.3_kvm.box +1 -0
  69. data/spec/data/kiwi/base_opensuse13.1_kvm.box +1 -0
  70. data/spec/data/kiwi/definitions/base_opensuse12.3_kvm/config.sh +1 -0
  71. data/spec/data/kiwi/definitions/base_opensuse12.3_kvm/config.xml +1 -0
  72. data/spec/data/kiwi/definitions/base_opensuse12.3_kvm/root/home/vagrant/.ssh/authorized_keys +1 -0
  73. data/spec/data/kiwi/definitions/base_opensuse13.1_kvm/config.sh +1 -0
  74. data/spec/data/kiwi/definitions/base_opensuse13.1_kvm/config.xml +1 -0
  75. data/spec/data/kiwi/definitions/base_opensuse13.1_kvm/root/home/vagrant/.ssh/authorized_keys +1 -0
  76. data/spec/data/kiwi2/box_state.yaml +14 -0
  77. data/spec/data/kiwi2/definitions/base_opensuse12.3_kvm/config.sh +1 -0
  78. data/spec/data/kiwi2/definitions/base_opensuse12.3_kvm/config.xml +1 -0
  79. data/spec/data/kiwi2/definitions/base_opensuse12.3_kvm/root/home/vagrant/.ssh/authorized_keys +1 -0
  80. data/spec/data/kiwi2/definitions/base_opensuse13.1_kvm/config.sh +1 -0
  81. data/spec/data/kiwi2/definitions/base_opensuse13.1_kvm/config.xml +1 -0
  82. data/spec/data/kiwi2/definitions/base_opensuse13.1_kvm/root/home/vagrant/.ssh/authorized_keys +1 -0
  83. data/spec/data/kiwi3/box_state.yaml +13 -0
  84. data/spec/data/kiwi3/definitions/base_opensuse12.3_kvm/.gitkeep +0 -0
  85. data/spec/data/kiwi3/definitions/base_opensuse13.1_kvm/.gitkeep +0 -0
  86. data/spec/data/kiwi3/import_state.yaml +3 -0
  87. data/spec/data/kiwi4/definitions/base_opensuse12.3_kvm/.gitkeep +0 -0
  88. data/spec/data/kiwi4/definitions/base_opensuse13.1_kvm/.gitkeep +0 -0
  89. data/spec/data/kiwi4/import_state.yaml +3 -0
  90. data/spec/data/kiwi5/import_state.yaml +3 -0
  91. data/spec/data/vagrant/.gitkeep +0 -0
  92. data/spec/host_config_spec.rb +197 -0
  93. data/spec/host_runner_spec.rb +112 -0
  94. data/spec/image_runner_spec.rb +62 -0
  95. data/spec/import_base_command_spec.rb +189 -0
  96. data/spec/local_command_runner_spec.rb +117 -0
  97. data/spec/local_runner_spec.rb +42 -0
  98. data/spec/lock_service_spec.rb +95 -0
  99. data/spec/remote_command_runner_spec.rb +115 -0
  100. data/spec/settings_spec.rb +26 -0
  101. data/spec/setup_command_spec.rb +49 -0
  102. data/spec/spec_helper.rb +50 -0
  103. data/spec/spec_profiler_spec.rb +63 -0
  104. data/spec/spec_spec.rb +99 -0
  105. data/spec/support/command_runner_examples.rb +29 -0
  106. data/spec/support/runner_examples.rb +34 -0
  107. data/spec/urls_spec.rb +46 -0
  108. data/spec/vagrant_command_spec.rb +51 -0
  109. data/spec/vagrant_runner_spec.rb +40 -0
  110. data/spec/vagrant_spec.rb +288 -0
  111. data/spec/vm_spec.rb +56 -0
  112. metadata +257 -0
@@ -0,0 +1,10 @@
1
+ ---
2
+ lock_server_address: lock.example.com:9999
3
+ hosts:
4
+ test_host:
5
+ address: host.example.com
6
+ base_snapshot_id: 5
7
+ missing_address:
8
+ base_snapshot_id: 5
9
+ missing_snapshot_id:
10
+ address: host.example.com
@@ -0,0 +1 @@
1
+ This is a dummy image of opensuse12.3
@@ -0,0 +1 @@
1
+ This is a dummy image of opensuse13.1
@@ -0,0 +1 @@
1
+ This is a dummy config.sh file for base_opensuse12.3_kvm
@@ -0,0 +1 @@
1
+ This is a dummy config.xml file for base_opensuse12.3_kvm
@@ -0,0 +1 @@
1
+ ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEA6NF8iallvQVp22WDkTkyrtvp9eWW6A8YVr+kz4TjGYe7gHzIw+niNltGEFHzD8+v1I2YJ6oXevct1YeS0o9HZyN1Q9qgCgzUFtdOKLv6IedplqoPkcmF0aYet2PkEDo3MlTBckFXPITAMzF8dJSIFo9D8HfdOV0IAdx4O7PtixWKn5y2hMNG0zQPyUecp4pzC6kivAIhyfHilFR61RGL+GPXQ2MWZWFYbAGjyiYJnAmCP3NOTd0jMZEnDkbUvxhMmBYSdETk1rRgm+R4LOzFUGaHqHDLKLX+FIPKcF96hrucXzcWyLbIbEgE98OHlnVYCzRdK8jlqm8tehUc9c9WhQ== vagrant insecure public key
@@ -0,0 +1 @@
1
+ This is a dummy config.sh file for base_opensuse13.1_kvm
@@ -0,0 +1 @@
1
+ This is a dummy config.xml file for base_opensuse13.1_kvm
@@ -0,0 +1 @@
1
+ ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEA6NF8iallvQVp22WDkTkyrtvp9eWW6A8YVr+kz4TjGYe7gHzIw+niNltGEFHzD8+v1I2YJ6oXevct1YeS0o9HZyN1Q9qgCgzUFtdOKLv6IedplqoPkcmF0aYet2PkEDo3MlTBckFXPITAMzF8dJSIFo9D8HfdOV0IAdx4O7PtixWKn5y2hMNG0zQPyUecp4pzC6kivAIhyfHilFR61RGL+GPXQ2MWZWFYbAGjyiYJnAmCP3NOTd0jMZEnDkbUvxhMmBYSdETk1rRgm+R4LOzFUGaHqHDLKLX+FIPKcF96hrucXzcWyLbIbEgE98OHlnVYCzRdK8jlqm8tehUc9c9WhQ== vagrant insecure public key
@@ -0,0 +1,14 @@
1
+ ---
2
+ base_opensuse13.1_kvm:
3
+ sources:
4
+ config.sh: changed
5
+ config.xml: 43dd3b9cd11bc9d882f8f82ac108b74a
6
+ root/home/vagrant/.ssh/authorized_keys: b440b5086dd12c3fd8abb762476b9f40
7
+ target: 115469c104dcc69455f321eb086ffb11
8
+ base_opensuse12.3_kvm:
9
+ sources:
10
+ config.sh: c6640ba00ab345b7491b836d517a637b
11
+ config.xml: a3d3de67d84f7792bf2755f7a3ae4e3f
12
+ root/home/vagrant/.ssh/authorized_keys: b440b5086dd12c3fd8abb762476b9f40
13
+ target: e4e743b5340686d8488dbce54b5644d8
14
+
@@ -0,0 +1 @@
1
+ This is a dummy config.sh file for base_opensuse12.3_kvm
@@ -0,0 +1 @@
1
+ This is a dummy config.xml file for base_opensuse12.3_kvm
@@ -0,0 +1 @@
1
+ ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEA6NF8iallvQVp22WDkTkyrtvp9eWW6A8YVr+kz4TjGYe7gHzIw+niNltGEFHzD8+v1I2YJ6oXevct1YeS0o9HZyN1Q9qgCgzUFtdOKLv6IedplqoPkcmF0aYet2PkEDo3MlTBckFXPITAMzF8dJSIFo9D8HfdOV0IAdx4O7PtixWKn5y2hMNG0zQPyUecp4pzC6kivAIhyfHilFR61RGL+GPXQ2MWZWFYbAGjyiYJnAmCP3NOTd0jMZEnDkbUvxhMmBYSdETk1rRgm+R4LOzFUGaHqHDLKLX+FIPKcF96hrucXzcWyLbIbEgE98OHlnVYCzRdK8jlqm8tehUc9c9WhQ== vagrant insecure public key
@@ -0,0 +1 @@
1
+ This is a dummy config.sh file for base_opensuse13.1_kvm
@@ -0,0 +1 @@
1
+ This is a dummy config.xml file for base_opensuse13.1_kvm
@@ -0,0 +1 @@
1
+ ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEA6NF8iallvQVp22WDkTkyrtvp9eWW6A8YVr+kz4TjGYe7gHzIw+niNltGEFHzD8+v1I2YJ6oXevct1YeS0o9HZyN1Q9qgCgzUFtdOKLv6IedplqoPkcmF0aYet2PkEDo3MlTBckFXPITAMzF8dJSIFo9D8HfdOV0IAdx4O7PtixWKn5y2hMNG0zQPyUecp4pzC6kivAIhyfHilFR61RGL+GPXQ2MWZWFYbAGjyiYJnAmCP3NOTd0jMZEnDkbUvxhMmBYSdETk1rRgm+R4LOzFUGaHqHDLKLX+FIPKcF96hrucXzcWyLbIbEgE98OHlnVYCzRdK8jlqm8tehUc9c9WhQ== vagrant insecure public key
@@ -0,0 +1,13 @@
1
+ ---
2
+ base_opensuse13.1_kvm:
3
+ sources:
4
+ config.sh: changed
5
+ config.xml: a3d3de67d84f7792bf2755f7a3ae4e3f
6
+ root/home/vagrant/.ssh/authorized_keys: b440b5086dd12c3fd8abb762476b9f40
7
+ target: 115469c104dcc69455f321eb086ffb11
8
+ base_opensuse12.3_kvm:
9
+ sources:
10
+ config.sh: 00cd92ac20df539d7d6f7930a339c622
11
+ config.xml: 43dd3b9cd11bc9d882f8f82ac108b74a
12
+ root/home/vagrant/.ssh/authorized_keys: b440b5086dd12c3fd8abb762476b9f40
13
+ target: e4e743b5340686d8488dbce54b5644d8
@@ -0,0 +1,3 @@
1
+ ---
2
+ base_opensuse13.1_kvm: 115469c104dcc69455f321eb086ffb11
3
+ base_opensuse12.3_kvm: old_hash
@@ -0,0 +1,3 @@
1
+ ---
2
+ base_opensuse13.1_kvm: 115469c104dcc69455f321eb086ffb11
3
+ base_opensuse12.3_kvm: old_hash
@@ -0,0 +1,3 @@
1
+ ---
2
+ base_opensuse13.1_kvm: 381e4a37372ed592fb10d25fea514489
3
+ base_opensuse13.2_kvm: 7410410022642e7ed1af5e31cb69cddb
File without changes
@@ -0,0 +1,197 @@
1
+ # Copyright (c) 2013-2015 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 "spec_helper"
19
+
20
+ include GivenFilesystemSpecHelpers
21
+
22
+ describe Pennyworth::HostConfig do
23
+ use_given_filesystem
24
+
25
+ it "creates config object for config dir" do
26
+ config_dir = given_directory
27
+ host_config = Pennyworth::HostConfig.for_directory(config_dir)
28
+ expect(host_config.config_file).to eq(File.join(config_dir, "hosts.yaml"))
29
+ end
30
+
31
+ it "reads config file" do
32
+ host_config = Pennyworth::HostConfig.for_directory(test_data_dir)
33
+ host_config.read
34
+ expect(host_config.hosts).to eq(["test_host", "missing_address", "missing_snapshot_id"])
35
+ end
36
+
37
+ it "raises error when it cannot read the file" do
38
+ config_dir = given_directory
39
+ File.write(File.join(config_dir, "hosts.yaml"), "")
40
+
41
+ host_config = Pennyworth::HostConfig.for_directory(config_dir)
42
+
43
+ expect {
44
+ host_config.read
45
+ }.to raise_error Pennyworth::HostFileError
46
+ end
47
+
48
+ it "returns host" do
49
+ host_config = Pennyworth::HostConfig.for_directory(test_data_dir)
50
+ host_config.read
51
+ expect(host_config.host("test_host")).
52
+ to eq("address" => "host.example.com", "base_snapshot_id" => 5)
53
+ end
54
+
55
+ it "returns lock server address" do
56
+ host_config = Pennyworth::HostConfig.for_directory(test_data_dir)
57
+ host_config.read
58
+ expect(host_config.lock_server_address).to eq("lock.example.com:9999")
59
+ end
60
+
61
+ describe "#setup" do
62
+ it "fails if config file already exists" do
63
+ config_file = nil
64
+ config_dir = given_directory do
65
+ config_file = given_file "hosts.yaml"
66
+ end
67
+
68
+ host_config = Pennyworth::HostConfig.for_directory(config_dir)
69
+
70
+ expect {
71
+ host_config.setup("http://example.com/pennyworth/hosts.yaml")
72
+ }.to raise_error(Pennyworth::HostFileError)
73
+
74
+ expected_config_file = File.join(test_data_dir, "hosts.yaml")
75
+ expect(File.read(config_file)).to eq(File.read(expected_config_file))
76
+ end
77
+
78
+ it "writes initial config file" do
79
+ config_base_dir = given_directory
80
+
81
+ config_dir = File.join(config_base_dir, ".pennyworth")
82
+
83
+ host_config = Pennyworth::HostConfig.for_directory(config_dir)
84
+ host_config.setup("http://example.com/pennyworth/hosts.yaml")
85
+
86
+ expected_config = <<EOT
87
+ ---
88
+ include: http://example.com/pennyworth/hosts.yaml
89
+ EOT
90
+
91
+ expect(File.read(File.join(config_dir, "hosts.yaml"))).
92
+ to eq(expected_config)
93
+ end
94
+ end
95
+
96
+ describe "include" do
97
+ it "throws error when included file doesn't exist" do
98
+ host_config = Pennyworth::HostConfig.new(given_directory)
99
+
100
+ file = <<EOT
101
+ ---
102
+ include: inexistent
103
+ EOT
104
+
105
+ expect {
106
+ host_config.parse(file)
107
+ }.to raise_error(Pennyworth::HostFileError)
108
+ end
109
+
110
+ it "takes host from remote file" do
111
+ body = <<EOT
112
+ ---
113
+ hosts:
114
+ test_host_1:
115
+ address: a.example.com
116
+ EOT
117
+ stub_request(:get, "http://ci.example.com/pennyworth/hosts.yaml").
118
+ with(headers:
119
+ {
120
+ "Accept" => "*/*",
121
+ "Accept-Encoding" => "gzip;q=1.0,deflate;q=0.6,identity;q=0.3",
122
+ "User-Agent" => "Ruby"
123
+ }).
124
+ to_return(status: 200, body: body, headers: {})
125
+
126
+ file = <<EOT
127
+ ---
128
+ include: http://ci.example.com/pennyworth/hosts.yaml
129
+ EOT
130
+
131
+ host_config = Pennyworth::HostConfig.new(given_directory)
132
+ host_config.parse(file)
133
+
134
+ expect(host_config.host("test_host_1")["address"]).to eq("a.example.com")
135
+ end
136
+
137
+ it "takes host from local file" do
138
+ body = <<EOT
139
+ ---
140
+ hosts:
141
+ test_host_1:
142
+ address: a.example.com
143
+ EOT
144
+ stub_request(:get, "http://ci.example.com/pennyworth/hosts.yaml").
145
+ with(headers:
146
+ {
147
+ "Accept" => "*/*",
148
+ "Accept-Encoding" => "gzip;q=1.0,deflate;q=0.6,identity;q=0.3",
149
+ "User-Agent" => "Ruby"
150
+ }).
151
+ to_return(status: 200, body: body, headers: {})
152
+
153
+ file = <<EOT
154
+ ---
155
+ include: http://ci.example.com/pennyworth/hosts.yaml
156
+ hosts:
157
+ test_host_2:
158
+ address: b.example.com
159
+ EOT
160
+
161
+ host_config = Pennyworth::HostConfig.new(given_directory)
162
+ host_config.parse(file)
163
+
164
+ expect(host_config.host("test_host_2")["address"]).to eq("b.example.com")
165
+ end
166
+
167
+ it "overwrite host from remote file by host from local file" do
168
+ body = <<EOT
169
+ ---
170
+ hosts:
171
+ test_host_3:
172
+ address: c.example.com
173
+ EOT
174
+ stub_request(:get, "http://ci.example.com/pennyworth/hosts.yaml").
175
+ with(headers:
176
+ {
177
+ "Accept" => "*/*",
178
+ "Accept-Encoding" => "gzip;q=1.0,deflate;q=0.6,identity;q=0.3",
179
+ "User-Agent" => "Ruby"
180
+ }).
181
+ to_return(status: 200, body: body, headers: {})
182
+
183
+ file = <<EOT
184
+ ---
185
+ include: http://ci.example.com/pennyworth/hosts.yaml
186
+ hosts:
187
+ test_host_3:
188
+ address: x.example.com
189
+ EOT
190
+
191
+ host_config = Pennyworth::HostConfig.new(given_directory)
192
+ host_config.parse(file)
193
+
194
+ expect(host_config.host("test_host_3")["address"]).to eq("x.example.com")
195
+ end
196
+ end
197
+ end
@@ -0,0 +1,112 @@
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 "spec_helper"
19
+
20
+ describe Pennyworth::HostRunner do
21
+ let(:host_config) {
22
+ config = Pennyworth::HostConfig.for_directory(test_data_dir)
23
+ config.read
24
+ config
25
+ }
26
+ let(:runner) {
27
+ Pennyworth::HostRunner.new("test_host", host_config, "root")
28
+ }
29
+
30
+ it_behaves_like "a runner"
31
+
32
+ describe "#initialize" do
33
+ it "fails with error, if host is not known" do
34
+ expect {
35
+ Pennyworth::HostRunner.new("invalid_name", host_config, "root")
36
+ }.to raise_error(Pennyworth::InvalidHostError)
37
+ end
38
+
39
+ it "fails with error, if address is not set" do
40
+ expect {
41
+ Pennyworth::HostRunner.new("missing_address", host_config, "root")
42
+ }.to raise_error(Pennyworth::InvalidHostError)
43
+ end
44
+
45
+ it "fails with error, if base_snapshot_id is not set" do
46
+ expect {
47
+ Pennyworth::HostRunner.new("missing_snapshot_id", host_config, "root")
48
+ }.to raise_error(Pennyworth::InvalidHostError)
49
+ end
50
+ end
51
+
52
+ describe "#start" do
53
+ it "returns the IP address of the started system" do
54
+ expect_any_instance_of(Pennyworth::LockService).to receive(:request_lock).
55
+ and_return(true)
56
+ expect(runner).to receive(:connect)
57
+ expect(runner).to receive(:check_cleanup_capabilities)
58
+
59
+ expect(runner.start).to eq("host.example.com")
60
+ end
61
+ end
62
+
63
+ describe "#stop" do
64
+ before(:each) do
65
+ expect_any_instance_of(Pennyworth::LockService).to receive(:release_lock).
66
+ and_return(true)
67
+ end
68
+
69
+ it "triggers a cleanup when the host was connected" do
70
+ runner.instance_variable_set(:@connected, true)
71
+ expect(runner).to receive(:cleanup)
72
+
73
+ runner.stop
74
+ end
75
+
76
+ it "does not trigger a cleanup when SKIP_HOST_CLEANUP is set" do
77
+ runner.instance_variable_set(:@connected, true)
78
+ expect(runner).to_not receive(:cleanup)
79
+
80
+ with_env "SKIP_HOST_CLEANUP" => "true" do
81
+ runner.stop
82
+ end
83
+ end
84
+ end
85
+
86
+ describe "#cleanup" do
87
+ it "cleans up the host" do
88
+ runner.instance_variable_set(:@connected, true)
89
+ runner.instance_variable_set(:@cleaned_up, false)
90
+ command_runner = double(:run)
91
+ expect(command_runner).to receive(:run).at_least(:once)
92
+ expect(Pennyworth::RemoteCommandRunner).to receive(:new).and_return(command_runner)
93
+
94
+ runner.cleanup
95
+ end
96
+ it "does not clean up when the host was not connected" do
97
+ runner.instance_variable_set(:@connected, false)
98
+ runner.instance_variable_set(:@cleaned_up, false)
99
+ expect(Pennyworth::RemoteCommandRunner).to_not receive(:new)
100
+
101
+ runner.cleanup
102
+ end
103
+
104
+ it "does not clean up when the host was already cleaned up" do
105
+ runner.instance_variable_set(:@connected, true)
106
+ runner.instance_variable_set(:@cleaned_up, true)
107
+ expect(Pennyworth::RemoteCommandRunner).to_not receive(:new)
108
+
109
+ runner.cleanup
110
+ end
111
+ end
112
+ end
@@ -0,0 +1,62 @@
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 "spec_helper"
19
+
20
+ describe Pennyworth::ImageRunner do
21
+ let(:libvirt_xml) {
22
+ <<-EOF
23
+ <domain type='kvm' id='52'>
24
+ <devices>
25
+ <interface type='bridge'>
26
+ <mac address='52:54:01:60:3c:95'/>
27
+ </interface>
28
+ </devices>
29
+ </domain>
30
+ EOF
31
+ }
32
+ let(:lease_file) {
33
+ ["1390553648 52:54:01:60:3c:95 192.168.122.186 vagrant-opensuse 52:54:01:60:3c:95"]
34
+ }
35
+ let(:runner) { Pennyworth::ImageRunner.new("/path/to/image", "root") }
36
+
37
+ describe "runner" do
38
+ before(:each) do
39
+ allow(Libvirt).to receive(:open)
40
+ end
41
+
42
+ it_behaves_like "a runner"
43
+ end
44
+
45
+ describe "#start" do
46
+ it "returns the IP address from the lease file" do
47
+ libvirt = double
48
+ system = double
49
+ expect(::Libvirt).to receive(:open) { libvirt }
50
+
51
+ expect(libvirt).to receive(:create_domain_xml)
52
+ expect(libvirt).to receive(:lookup_domain_by_name) { system }
53
+
54
+ expect(system).to receive(:xml_desc) { libvirt_xml }
55
+ expect(File).to receive(:readlines) { lease_file }
56
+
57
+ allow(runner).to receive(:cleanup)
58
+
59
+ expect(runner.start).to eq("192.168.122.186")
60
+ end
61
+ end
62
+ end