vmth 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Binary file
@@ -0,0 +1 @@
1
+ v0.1. Initial Release
@@ -0,0 +1,7 @@
1
+ == Config file format
2
+
3
+ Here's the format of the test config file. it is a yaml file and specified
4
+ by the '-c' parameter to vmth. It is included with the gem named 'sample_config.yaml'
5
+
6
+ :include: sample_config.yaml
7
+
@@ -0,0 +1 @@
1
+ The VMTH (Virtual Machine Test Harness) provides a mechanism to unit-test your infrastructure automation - puppet policies, chef rules, release deployment scripts, etc. It uses features of modern VM monitors (like qemu) to snapshot system state, and then reset that state after each test, so that a series of tests can be performed on a VM instance in rapid succession.
data/LICENSE ADDED
@@ -0,0 +1,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright 2011 Greg Retkowski
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
@@ -0,0 +1,18 @@
1
+ CHANGELOG
2
+ CONFIG.rdoc
3
+ DESCRIPTION
4
+ LICENSE
5
+ Manifest
6
+ QUICKSTART.rdoc
7
+ README.rdoc
8
+ Rakefile
9
+ bin/virb
10
+ bin/vmth
11
+ lib/defaults.yaml
12
+ lib/virb.rb
13
+ lib/vmth.rb
14
+ sample_config.yaml
15
+ test/helpers.rb
16
+ test/test_virb.rb
17
+ test/test_vmth.rb
18
+ vmth.gemspec
@@ -0,0 +1,44 @@
1
+ This is a not-so-quickstart introduction to getting vmth up and running in your environment.
2
+
3
+ == Setting up system images
4
+
5
+ Get a copy of one of your system images
6
+
7
+ One way to do this would be to boot from a rescue CD, then 'dd if=/dev/sda of=/some/other/filesystem/my-system.img'. presumably you'd want your system to have a fairly small harddrive to do this!
8
+
9
+ If your system image is shrunk down (as we do) you can add space to the end of it via: 'dd if=/dev/zero bs=10240 count=5000000 >>your.img'
10
+
11
+ Next convert the system image to a qemu compatable cow (copy-on-write) file.
12
+
13
+ qemu-img convert -f raw linux-img-6.img -O qcow2 linux-img-6-large.cow
14
+
15
+ == Setting up your 'host' system..
16
+ Make sure you have qemu & kvm installed - and the kernel module loaded. Performance was unacceptably slow when running with the CPU emulated instead of directly accessed via kvm.
17
+
18
+ == Editing your disk image.
19
+
20
+ use 'vmth -q -i /your/image/file.cow
21
+
22
+ This will spit out the qemu command line to launch your image.
23
+ Run that - log into your system and configure it to be ready for vmth to interact with it. Some changes you may want to make are: removing the root password, ensuring sshd will allow root to login w/o a password.. change /etc/hosts if you have to hard-code some of the hosts your system will talk to, etc...
24
+
25
+ Once you are done enter 'savevm init-test' and quit qemu.
26
+
27
+ This saves the current state of the VM - so that when the vmth runs the test it doesn't have to boot the vm - it starts from that precise moment.
28
+
29
+ == Creating the yaml specification for your tests
30
+
31
+ Next you'll want to edit the test config yaml for your test. You can use the 'sample_config.yaml' as a starting point. The 'prep' steps are completed once before testing starts - the 'applying' applies changes to your system in preparation for a test. The 'testing' runs your unit test script. and the teardown is done after applying and testing has completed. Most commands are passed through ERB, so you can put expansions here.
32
+
33
+ Put a list of scenarios you want to test into a file, like testable_scenarios.txt. Each scenario should be a single word on its own line.
34
+
35
+ == Running the test
36
+ sudo bin/vmth -e testable_scenarios.txt -i /data/vms/system-test.cow -p /path/to/my/automation/code -c my_config.yaml -d -o my_config.output.yaml
37
+
38
+ After your run completes, the vmth will print a report of what passed or failed via the 'applying' and the 'testing' steps. You can use 'virb' to look at your output yaml and understand where tests may have failed.
39
+
40
+ == Debugging
41
+
42
+ use 'vmth --console' for debugging; it'll launch the vm, apply all the prep steps, and then leave you at a qemu prompt.. From here you can ssh into the machine and interact with it at will.. and you can always reset via 'loadvm init-test' or 'loadvm test-freeze' to get you back to the start.
43
+
44
+
@@ -0,0 +1,37 @@
1
+ === Introduction
2
+
3
+ :include: DESCRIPTION
4
+
5
+ It can be integrated with your continuous integration environment and triggered each time a commit is made to your automation code.
6
+
7
+
8
+ === What it does
9
+
10
+ It will go through a series of scenarios (a scenario is usualy a service name). It will run the 'prep' steps, freeze the vm, then run one scenario at a time, and unfreeze after
11
+ each scenario.
12
+
13
+ == Getting started
14
+
15
+ See QUICKSTART[link:files/QUICKSTART_rdoc.html] to get started.
16
+
17
+ == Command-line tools
18
+
19
+ * vmth[link:files/bin/vmth.html]: vm test harness command-line tool
20
+ * virb[link:files/bin/virb.html]: Interactive vm test debugger...
21
+
22
+ == Gochas
23
+
24
+ Took a while to track down a bug where our VM instance was running out of memory and then crashing. It just appeared that qemu just plain exited without error. traced it to the guest having vm.panic_on_oom to 1 - which causes the kernel to panic and exit if we run out of memory.
25
+
26
+ Here is the Vmth[link:classes/Vmth.html] class documentation.
27
+
28
+ == Config file format
29
+
30
+ See sample_config.yaml[link:files/CONFIG_rdoc.html] for the vmth config file format.
31
+
32
+ == Support
33
+
34
+ For support or to report bugs open an issue at the gitub issue tracker:
35
+
36
+ https://github.com/gregretkowski/vmth/issues
37
+
@@ -0,0 +1,22 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+ require 'echoe'
4
+
5
+ Echoe.new('vmth', '0.0.1') do |p|
6
+ p.description = File.open(File.dirname(__FILE__+"/DESCRIPTION")).read
7
+ p.summary = "A VM test harness for testing operational configurations"
8
+ p.url = "http://github.com/gregretkowski/vmth"
9
+ p.author = "Greg Retkowski"
10
+ p.email = "greg@rage.net"
11
+ p.ignore_pattern = ["tmp/*", "script/*", "ol/*"]
12
+ p.rdoc_template = nil
13
+ p.rdoc_pattern = /^(lib|bin|tasks|ext)|^README|^CHANGELOG|^TODO|^LICENSE|^QUICKSTART|^CONFIG|^COPYING$/
14
+ # p.rdoc_template = ""
15
+ p.development_dependencies = []
16
+ p.runtime_dependencies = [
17
+ 'formatr',
18
+ 'net-ssh',
19
+ 'net-scp',
20
+ ]
21
+
22
+ end
@@ -0,0 +1,41 @@
1
+ #!/usr/bin/ruby
2
+
3
+
4
+ =begin rdoc
5
+
6
+ This tool helps you to debug and browse through results from the
7
+ VM test harness. Use to examine the output yaml produced by vmth.
8
+
9
+ It is an extension to irb, so all irb commands work. The loaded
10
+ yaml is stored in global variable $y. To get started use:
11
+
12
+ load_obj 'filename'
13
+
14
+ .. that will load the yaml output into virb.. Then use these
15
+ commands to examine the outout..
16
+
17
+ p_apply 'scenario' # Shows output of apply step
18
+
19
+ p_test 'scenario' # Shows output of test step
20
+
21
+ f_apply 'scenario','filename' # Write out a scenario's output to a file
22
+
23
+ =end
24
+
25
+ #--
26
+ # Copyright 2011 Greg Retkowski
27
+ #
28
+ # Licensed under the Apache License, Version 2.0 (the "License");
29
+ # you may not use this file except in compliance with the License.
30
+ # You may obtain a copy of the License at
31
+ #
32
+ # http://www.apache.org/licenses/LICENSE-2.0
33
+ #
34
+ # Unless required by applicable law or agreed to in writing, software
35
+ # distributed under the License is distributed on an "AS IS" BASIS,
36
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
37
+ # See the License for the specific language governing permissions and
38
+ # limitations under the License.
39
+ #++
40
+
41
+ exec "irb -r virb.rb --simple-prompt"
@@ -0,0 +1,232 @@
1
+ #!/usr/bin/ruby
2
+
3
+ =begin rdoc
4
+ This is the command line tool to invoke the puppet test harness.
5
+
6
+ Usage: vmth [options]
7
+ -s, --service service_name Test this service
8
+ -q, --vmm-cmd-line Just output the vm monitor command line and exit
9
+ -t, --console Prep a vm and allocate it to a user
10
+ -c, --config-yaml file.yaml The file used to configure the vmth
11
+ -d, --debug Run in debugging mode
12
+ -n, --no-vmm Run w/o VM management (for dev/debug)
13
+ -i /path/to/image.cow Specify the vm disk image file
14
+ --image-file
15
+ -y, --yaml Output Yaml instead of formatted text
16
+ -e /path/to/scenarios Specify the scenarios list file
17
+ --scenarios-file
18
+ -o, --output-file output.yaml Output results to a yaml file
19
+ -p /path/to/your/source/dir Path to your source directory
20
+ --path
21
+ -h, -? Show this message
22
+
23
+ One example command-line may look like:
24
+
25
+ sudo vmth -e testable_services.txt -i /data/greg-test.cow -p /home/greg/puppet -c testpup26.yaml -d -o testpup26.output.yaml
26
+
27
+ See sample_config.yaml for what the config file specified by '-c' should contain.
28
+
29
+ The output of the test harness looks something like...
30
+
31
+ VM Test Harness Results....
32
+ Elapsed time to complete testing: 06:08:14
33
+ ------------------+------------+------------+----------------+
34
+ Scenario | Apply | Test | Execution Time |
35
+ ------------------+------------+------------+----------------+
36
+ 0nulltest | Passed | Passed | 00:22:37 |
37
+ dbserver | Passed | Passed | 00:09:29 |
38
+ loadbalancer | Passed | Passed | 00:04:04 |
39
+ webserver | Passed | Passed | 00:04:03 |
40
+ ...
41
+
42
+ =end
43
+
44
+ #--
45
+ # Copyright 2011 Greg Retkowski
46
+ #
47
+ # Licensed under the Apache License, Version 2.0 (the "License");
48
+ # you may not use this file except in compliance with the License.
49
+ # You may obtain a copy of the License at
50
+ #
51
+ # http://www.apache.org/licenses/LICENSE-2.0
52
+ #
53
+ # Unless required by applicable law or agreed to in writing, software
54
+ # distributed under the License is distributed on an "AS IS" BASIS,
55
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
56
+ # See the License for the specific language governing permissions and
57
+ # limitations under the License.
58
+ #++
59
+
60
+ require 'rubygems'
61
+ require 'vmth'
62
+ require 'optparse'
63
+ require 'formatr'
64
+ progname = File.basename($0)
65
+
66
+ # PARSE COMMAND LINE OPTIONS
67
+
68
+ options = {
69
+ :action => "all",
70
+ :qemu => true,
71
+ :path => ".",
72
+ :output => 'text',
73
+ :debug => false
74
+ }
75
+ op = OptionParser.new do |opts|
76
+ opts.banner = "Usage: #{progname} [options]"
77
+ opts.on("-s", "--service service_name", "Test this service") do |s|
78
+ options[:action] = 'service'
79
+ options[:services] ||= Array.new()
80
+ options[:services] << s
81
+ end
82
+ opts.on("-q", "--vmm-cmd-line", "Just output the vm monitor command line and exit") do
83
+ options[:action] = "vmm-command-line"
84
+ end
85
+ opts.on("-t", "--console", "Prep a vm and allocate it to a user") do
86
+ options[:action] = "console"
87
+ end
88
+
89
+ opts.on("-c", "--config-yaml file.yaml", "The file used to configure the vmth") do |f|
90
+ options[:config_file] = f
91
+ end
92
+ opts.on("-d", "--debug", "Run in debugging mode") do
93
+ options[:debug] = true
94
+ end
95
+ opts.on("-n", "--no-vmm","Run w/o VM management (for dev/debug)") do
96
+ options[:vmm_enabled] = false
97
+ end
98
+ opts.on("-i", "--image-file /path/to/image.cow","Specify the vm disk image file") do |i|
99
+ options[:image_file] = i
100
+ end
101
+ opts.on("-y", "--yaml","Output Yaml instead of formatted text") do
102
+ options[:out_format] = 'yaml'
103
+ end
104
+ opts.on("-e", "--scenarios-file /path/to/scenarios","Specify the scenarios list file") do |e|
105
+ options[:scenarios_file] = e
106
+ end
107
+ opts.on("-o", "--output-file output.yaml","Output results to a yaml file") do |o|
108
+ options[:out_file] = o
109
+ end
110
+ opts.on("-p", "--path /path/to/your/source/dir","Path to your source directory") do |p|
111
+ options[:source_path] = p
112
+ end
113
+ opts.on_tail("-h", "-?", "Show this message") do
114
+ puts "Runs the VM Test Harness"
115
+ puts
116
+ puts opts
117
+ exit
118
+ end
119
+ end.order!
120
+
121
+ # FORMATTING FOR PRETTY OUTPUT
122
+
123
+ include FormatR
124
+ @top_ex = <<DOT
125
+ VM Test Harness Results....
126
+ Elapsed time to complete testing: @<<<<<<<<<<<<<<<<<<<<<
127
+ s[:total_elapsed]
128
+ +------------------+------------+------------+----------------+
129
+ | Scenario | Apply | Test | Execution Time |
130
+ +------------------+------------+------------+----------------+
131
+ DOT
132
+ @ex = <<TO
133
+ | @<<<<<<<<<<<<<<<<|@>>>>>>>>>> |@>>>>>>>>>> |@>>>>>>>>>>>>>> |
134
+ s[:name], s[:apply], s[:test], s[:elapsed]
135
+ TO
136
+ @footer_ex = <<DOD
137
+ +------------------+------------+------------+----------------+
138
+ DOD
139
+ @body_fmt = Format.new(@top_ex,@ex,@footer_ex)
140
+ @body_fmt.setPageLength(1000)
141
+
142
+ def pretty_secs(s) #:nodoc:
143
+ begin
144
+ h,s=s.divmod(3600)
145
+ m,s=s.divmod(60)
146
+ return "%02i:%02i:%02i"%[h,m,s.to_i]
147
+ rescue
148
+ return "Unknown"
149
+ end
150
+ end
151
+
152
+ def print_pretty(results) #:nodoc:
153
+ results['tests'].keys.sort.each do |k|
154
+ v = results['tests'][k]
155
+ s = {
156
+ :name => k,
157
+ :apply => (v['apply']['passed'] ? "Passed" : "FAILED" ),
158
+ :test => (v['test']['passed'] ? "Passed" : "FAILED" ),
159
+ :elapsed => (pretty_secs(v['elapsed_time'])),
160
+ :total_elapsed => (pretty_secs(results['elapsed_time']))
161
+ }
162
+ @body_fmt.printFormat(binding)
163
+ end
164
+ end
165
+
166
+ # EXECUTE TESTS AND PRINT RESULTS
167
+
168
+ def err_catcher() #:nodoc:
169
+ begin
170
+ yield
171
+ rescue PTY::ChildExited, Errno::EIO => e
172
+ @qemu_r.flush rescue nil
173
+ $stderr.puts "Bad things happened to vmm!"
174
+ $stderr.puts "#{e.class}: #{e.message}"
175
+ $stderr.puts "Last output:"
176
+ $stderr.puts @qemu_r
177
+ raise e.class, e.message
178
+ end
179
+ end
180
+
181
+ @test = Vmth.new(options)
182
+
183
+
184
+ unless options[:image_file]
185
+ $stderr.puts "Image file is mandatory"
186
+ exit 1
187
+ end
188
+ unless options[:config_file]
189
+ $stderr.puts "Config file is mandatory"
190
+ exit 1
191
+ end
192
+
193
+ if options[:action] == "vmm-command-line"
194
+ puts @test.vmcl
195
+ exit
196
+ elsif options[:action] == 'console'
197
+ @test.console
198
+ exit
199
+ elsif options[:action] == 'service'
200
+ err_catcher { results = @test.test_services(options[:services]) }
201
+ elsif options[:action] == 'all'
202
+ err_catcher { results = @test.test }
203
+ end
204
+ results = @test.results
205
+
206
+ if options[:out_file]
207
+ File.open(options[:out_file],"w") do |f|
208
+ f.puts YAML.dump(results)
209
+ end
210
+ end
211
+ if options[:output] == 'yaml'
212
+ puts YAML.dump(results)
213
+ elsif options[:output] == 'text'
214
+ print_pretty(results)
215
+ end
216
+
217
+ # Handle the exit code.. Exit with the number of 'fails'
218
+ # we have.. That'll indicate to a continuous integration
219
+ # system that it 'failed' if exits != 0.
220
+ def get_exit_code(results) #:nodoc:
221
+ pass_array = results['tests'].collect do |k,v|
222
+ v['test']['passed'] and v['apply']['passed']
223
+ end
224
+ if pass_array.size == 0
225
+ return 255
226
+ end
227
+ return pass_array.select{|g| g == false}.size
228
+ end
229
+ # remove state file.
230
+ @test.cleanup
231
+ exit get_exit_code(results)
232
+