testlab 0.0.1 → 0.0.2

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.
@@ -0,0 +1,71 @@
1
+ class TestLab
2
+
3
+ # Router Error Class
4
+ class RouterError < TestLabError; end
5
+
6
+ # Router Class
7
+ #
8
+ # @author Zachary Patten <zachary@jovelabs.net>
9
+ class Router < ZTK::DSL::Base
10
+ belongs_to :node, :class_name => 'TestNode::Node'
11
+
12
+ attribute :interfaces
13
+
14
+ def initialize(*args)
15
+ super(*args)
16
+
17
+ @ui = TestLab.ui
18
+ end
19
+
20
+ # Create the router
21
+ def create
22
+ @ui.logger.debug { "Router Create: #{self.id} " }
23
+ end
24
+
25
+ # Destroy the router
26
+ def destroy
27
+ @ui.logger.debug { "Router Destroy: #{self.id} " }
28
+ end
29
+
30
+ # Start the router
31
+ def up
32
+ @ui.logger.debug { "Router Up: #{self.id} " }
33
+ end
34
+
35
+ # Stop the router
36
+ def down
37
+ @ui.logger.debug { "Router Down: #{self.id} " }
38
+ end
39
+
40
+ # Reload the router
41
+ def reload
42
+ self.down
43
+ self.up
44
+ end
45
+
46
+ # State of the router
47
+ def state
48
+ end
49
+
50
+ # Router Callback: after_up
51
+ def after_up
52
+ @ui.logger.debug { "Router Callback: After Up: #{self.id} " }
53
+ self.create
54
+ self.up
55
+ end
56
+
57
+ # Router Callback: before_down
58
+ def before_down
59
+ @ui.logger.debug { "Router Callback: Before Down: #{self.id} " }
60
+ self.down
61
+ end
62
+
63
+ # Method missing handler
64
+ def method_missing(method_name, *method_args)
65
+ @ui.logger.debug { "ROUTER METHOD MISSING: #{method_name.inspect}(#{method_args.inspect})" }
66
+ super(method_name, *method_args)
67
+ end
68
+
69
+ end
70
+
71
+ end
@@ -1,3 +1,6 @@
1
- module TestLab
2
- VERSION = "0.0.1"
1
+ class TestLab
2
+ unless const_defined?(:VERSION)
3
+ # TestLab Gem Version
4
+ VERSION = "0.0.2"
5
+ end
3
6
  end
data/lib/testlab.rb CHANGED
@@ -1,5 +1,123 @@
1
- require "testlab/version"
1
+ require 'ztk'
2
+
3
+ require 'testlab/version'
4
+
5
+ # Top-Level LXC Class
6
+ #
7
+ # @author Zachary Patten <zachary@jovelabs.net>
8
+ class TestLab
9
+
10
+ # Top-Level Error Class
11
+ class TestLabError < StandardError; end
12
+
13
+ autoload :Provider, 'testlab/provider'
14
+ autoload :Provisioner, 'testlab/provisioner'
15
+
16
+ autoload :Labfile, 'testlab/labfile'
17
+ autoload :Node, 'testlab/node'
18
+ autoload :Router, 'testlab/router'
19
+ autoload :Container, 'testlab/container'
20
+ autoload :Network, 'testlab/network'
21
+ autoload :Link, 'testlab/link'
22
+
23
+ @@ui ||= nil
24
+
25
+ def initialize(ui=ZTK::UI.new)
26
+ labfile = ZTK::Locator.find('Labfile')
27
+
28
+ @@ui = ui
29
+ @labfile = TestLab::Labfile.load(labfile)
30
+ end
31
+
32
+ def nodes
33
+ TestLab::Node.all
34
+ end
35
+
36
+ def containers
37
+ TestLab::Container.all
38
+ end
39
+
40
+ def routers
41
+ TestLab::Router.all
42
+ end
43
+
44
+ def networks
45
+ TestLab::Network.all
46
+ end
47
+
48
+ # def config
49
+ # @labfile.config
50
+ # end
51
+
52
+ def alive?
53
+ nodes.map(&:state).all?{ |state| state == :running }
54
+ end
55
+
56
+ def dead?
57
+ !alive?
58
+ end
59
+
60
+ def status
61
+ if alive?
62
+ @@ui.stdout.puts("NODES:")
63
+ ZTK::Report.new(:ui => @@ui).spreadsheet(TestLab::Node.all, TestLab::Node::STATUS_KEYS) do |node|
64
+ OpenStruct.new(node.status.merge(:id => node.id))
65
+ end
66
+ @@ui.stdout.puts
67
+ @@ui.stdout.puts("NETWORKS:")
68
+ ZTK::Report.new(:ui => @@ui).spreadsheet(TestLab::Network.all, TestLab::Network::STATUS_KEYS) do |network|
69
+ OpenStruct.new(network.status.merge(:id => network.id))
70
+ end
71
+ @@ui.stdout.puts
72
+ @@ui.stdout.puts("CONTAINERS:")
73
+ ZTK::Report.new(:ui => @@ui).spreadsheet(TestLab::Container.all, TestLab::Container::STATUS_KEYS) do |container|
74
+ OpenStruct.new(container.status.merge(:id => container.id))
75
+ end
76
+
77
+ true
78
+ else
79
+ @@ui.stdout.puts("Looks like your test lab is dead; fix this and try again.")
80
+
81
+ false
82
+ end
83
+ end
84
+
85
+ # Proxy various method calls to our subordinate classes
86
+ def method_proxy(method_name, *method_args)
87
+ @@ui.logger.debug { "TestLab.#{method_name}" }
88
+ TestLab::Node.all.map do |node|
89
+ node.send(method_name.to_sym, *method_args)
90
+ end
91
+ end
92
+
93
+ # Method missing handler
94
+ def method_missing(method_name, *method_args)
95
+ @@ui.logger.debug { "TESTLAB METHOD MISSING: #{method_name.inspect}(#{method_args.inspect})" }
96
+
97
+ if TestLab::Provider::PROXY_METHODS.include?(method_name)
98
+ method_proxy(method_name, *method_args)
99
+ else
100
+ super(method_name, *method_args)
101
+ end
102
+ end
103
+
104
+ # Class Helpers
105
+ class << self
106
+
107
+ def ui
108
+ @@ui ||= ZTK::UI.new
109
+ end
110
+
111
+ def gem_dir
112
+ directory = File.join(File.dirname(__FILE__), "..")
113
+ File.expand_path(directory, File.dirname(__FILE__))
114
+ end
115
+
116
+ def build_command(name, *args)
117
+ executable = (ZTK::Locator.find('bin', name) rescue "/bin/env #{name}")
118
+ [executable, args].flatten.compact.join(' ')
119
+ end
120
+
121
+ end
2
122
 
3
- module TestLab
4
- # Your code goes here...
5
123
  end
@@ -0,0 +1,15 @@
1
+ require "spec_helper"
2
+
3
+ describe TestLab::Provider do
4
+
5
+ subject { TestLab::Provider.new }
6
+
7
+ describe "class" do
8
+
9
+ it "should be an instance of TestLab::Provider" do
10
+ subject.should be_an_instance_of TestLab::Provider
11
+ end
12
+
13
+ end
14
+
15
+ end
@@ -0,0 +1,15 @@
1
+ require "spec_helper"
2
+
3
+ describe TestLab::Provisioner do
4
+
5
+ subject { TestLab::Provisioner.new }
6
+
7
+ describe "class" do
8
+
9
+ it "should be an instance of TestLab::Provisioner" do
10
+ subject.should be_an_instance_of TestLab::Provisioner
11
+ end
12
+
13
+ end
14
+
15
+ end
@@ -0,0 +1,23 @@
1
+ ################################################################################
2
+ #
3
+ # Author: Zachary Patten <zachary@jovelabs.net>
4
+ # Copyright: Copyright (c) Zachary Patten
5
+ # License: Apache License, Version 2.0
6
+ #
7
+ # Licensed under the Apache License, Version 2.0 (the "License");
8
+ # you may not use this file except in compliance with the License.
9
+ # You may obtain a copy of the License at
10
+ #
11
+ # http://www.apache.org/licenses/LICENSE-2.0
12
+ #
13
+ # Unless required by applicable law or agreed to in writing, software
14
+ # distributed under the License is distributed on an "AS IS" BASIS,
15
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
+ # See the License for the specific language governing permissions and
17
+ # limitations under the License.
18
+ #
19
+ ################################################################################
20
+ require 'coveralls'
21
+ Coveralls.wear!
22
+ ################################################################################
23
+ require 'testlab'
@@ -0,0 +1,36 @@
1
+ #!/usr/bin/env ruby
2
+ #^syntax detection
3
+
4
+ host :vagrant do
5
+ provider TestLab::Provider::Vagrant
6
+ config ({
7
+ :vagrant => {
8
+ :ip => "192.168.33.10",
9
+ :cpus => 4,
10
+ :memory => 4096
11
+ }
12
+ })
13
+
14
+ network "west-1" do
15
+ end
16
+
17
+ container "devop-test-1" do
18
+ provisioner TestLab::Provisioner::Chef
19
+ distro "ubuntu"
20
+ release "lucid"
21
+ persist true
22
+ ip "192.168.0.1"
23
+ mac "00:00:5e:35:ea:d5"
24
+
25
+ config ({
26
+ :chef => {
27
+ :environment => "test",
28
+ :run_list => [
29
+ "role[base]",
30
+ "role[chef-client]"
31
+ ]
32
+ }
33
+ })
34
+ end
35
+
36
+ end
@@ -0,0 +1,16 @@
1
+ require "spec_helper"
2
+
3
+ describe TestLab do
4
+
5
+ subject { TestLab.new(File.join(File.dirname(__FILE__), 'support', 'Labfile')) }
6
+
7
+ describe "class" do
8
+
9
+ it "should be an instance of TestLab" do
10
+ subject.should be_an_instance_of TestLab
11
+ end
12
+
13
+ end
14
+
15
+
16
+ end
data/testlab.gemspec CHANGED
@@ -1,19 +1,47 @@
1
- # -*- encoding: utf-8 -*-
1
+ ################################################################################
2
+ #
3
+ # Author: Zachary Patten <zachary@jovelabs.net>
4
+ # Copyright: Copyright (c) Zachary Patten
5
+ # License: Apache License, Version 2.0
6
+ #
7
+ # Licensed under the Apache License, Version 2.0 (the "License");
8
+ # you may not use this file except in compliance with the License.
9
+ # You may obtain a copy of the License at
10
+ #
11
+ # http://www.apache.org/licenses/LICENSE-2.0
12
+ #
13
+ # Unless required by applicable law or agreed to in writing, software
14
+ # distributed under the License is distributed on an "AS IS" BASIS,
15
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
+ # See the License for the specific language governing permissions and
17
+ # limitations under the License.
18
+ #
19
+ ################################################################################
2
20
  lib = File.expand_path('../lib', __FILE__)
3
21
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
22
  require 'testlab/version'
5
23
 
6
- Gem::Specification.new do |gem|
7
- gem.name = "testlab"
8
- gem.version = TestLab::VERSION
9
- gem.authors = ["Zachary Patten"]
10
- gem.email = ["zachary@jovelabs.com"]
11
- gem.description = %q{A framework for building virtual testing laboratories}
12
- gem.summary = %q{A framework for building virtual testing laboratories}
13
- gem.homepage = "https://github.com/zpatten"
24
+ Gem::Specification.new do |spec|
25
+ spec.name = "testlab"
26
+ spec.version = TestLab::VERSION
27
+ spec.authors = ["Zachary Patten"]
28
+ spec.email = ["zachary@jovelabs.com"]
29
+ spec.description = %q{A framework for building virtual laboratories}
30
+ spec.summary = %q{A framework for building virtual laboratories}
31
+ spec.homepage = "https://github.com/zpatten/testlab"
32
+ spec.license = "Apache 2.0"
14
33
 
15
- gem.files = `git ls-files`.split($/)
16
- gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
17
- gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
18
- gem.require_paths = ["lib"]
34
+ spec.files = `git ls-files`.split($/)
35
+ spec.executables = spec.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
36
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
37
+ spec.require_paths = ["lib"]
38
+
39
+ spec.add_dependency("ztk")
40
+
41
+ spec.add_development_dependency("bundler")
42
+ spec.add_development_dependency("pry")
43
+ spec.add_development_dependency("rake")
44
+ spec.add_development_dependency("redcarpet")
45
+ spec.add_development_dependency("rspec")
46
+ spec.add_development_dependency("yard")
19
47
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: testlab
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,25 +9,164 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-04-13 00:00:00.000000000 Z
13
- dependencies: []
14
- description: A framework for building virtual testing laboratories
12
+ date: 2013-04-25 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: ztk
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: bundler
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: pry
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ - !ruby/object:Gem::Dependency
63
+ name: rake
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ type: :development
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ - !ruby/object:Gem::Dependency
79
+ name: redcarpet
80
+ requirement: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ! '>='
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ type: :development
87
+ prerelease: false
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ! '>='
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ - !ruby/object:Gem::Dependency
95
+ name: rspec
96
+ requirement: !ruby/object:Gem::Requirement
97
+ none: false
98
+ requirements:
99
+ - - ! '>='
100
+ - !ruby/object:Gem::Version
101
+ version: '0'
102
+ type: :development
103
+ prerelease: false
104
+ version_requirements: !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ! '>='
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ - !ruby/object:Gem::Dependency
111
+ name: yard
112
+ requirement: !ruby/object:Gem::Requirement
113
+ none: false
114
+ requirements:
115
+ - - ! '>='
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ none: false
122
+ requirements:
123
+ - - ! '>='
124
+ - !ruby/object:Gem::Version
125
+ version: '0'
126
+ description: A framework for building virtual laboratories
15
127
  email:
16
128
  - zachary@jovelabs.com
17
- executables: []
129
+ executables:
130
+ - testlab-console
18
131
  extensions: []
19
132
  extra_rdoc_files: []
20
133
  files:
134
+ - .coveralls.yml
21
135
  - .gitignore
136
+ - .rspec
137
+ - .ruby-gemset
138
+ - .ruby-version
139
+ - .travis.yml
22
140
  - Gemfile
23
- - LICENSE.txt
141
+ - LICENSE
24
142
  - README.md
25
143
  - Rakefile
144
+ - bin/testlab-console
26
145
  - lib/testlab.rb
146
+ - lib/testlab/container.rb
147
+ - lib/testlab/labfile.rb
148
+ - lib/testlab/network.rb
149
+ - lib/testlab/node.rb
150
+ - lib/testlab/provider.rb
151
+ - lib/testlab/providers/aws.rb
152
+ - lib/testlab/providers/local.rb
153
+ - lib/testlab/providers/templates/vagrant/Vagrantfile.erb
154
+ - lib/testlab/providers/vagrant.rb
155
+ - lib/testlab/provisioner.rb
156
+ - lib/testlab/provisioners/chef.rb
157
+ - lib/testlab/provisioners/shell.rb
158
+ - lib/testlab/provisioners/templates/chef/bootstrap.erb
159
+ - lib/testlab/router.rb
27
160
  - lib/testlab/version.rb
161
+ - spec/provider_spec.rb
162
+ - spec/provisioner_spec.rb
163
+ - spec/spec_helper.rb
164
+ - spec/support/Labfile
165
+ - spec/testlab_spec.rb
28
166
  - testlab.gemspec
29
- homepage: https://github.com/zpatten
30
- licenses: []
167
+ homepage: https://github.com/zpatten/testlab
168
+ licenses:
169
+ - Apache 2.0
31
170
  post_install_message:
32
171
  rdoc_options: []
33
172
  require_paths:
@@ -38,16 +177,28 @@ required_ruby_version: !ruby/object:Gem::Requirement
38
177
  - - ! '>='
39
178
  - !ruby/object:Gem::Version
40
179
  version: '0'
180
+ segments:
181
+ - 0
182
+ hash: 2080738052269751162
41
183
  required_rubygems_version: !ruby/object:Gem::Requirement
42
184
  none: false
43
185
  requirements:
44
186
  - - ! '>='
45
187
  - !ruby/object:Gem::Version
46
188
  version: '0'
189
+ segments:
190
+ - 0
191
+ hash: 2080738052269751162
47
192
  requirements: []
48
193
  rubyforge_project:
49
- rubygems_version: 1.8.24
194
+ rubygems_version: 1.8.25
50
195
  signing_key:
51
196
  specification_version: 3
52
- summary: A framework for building virtual testing laboratories
53
- test_files: []
197
+ summary: A framework for building virtual laboratories
198
+ test_files:
199
+ - spec/provider_spec.rb
200
+ - spec/provisioner_spec.rb
201
+ - spec/spec_helper.rb
202
+ - spec/support/Labfile
203
+ - spec/testlab_spec.rb
204
+ has_rdoc:
data/LICENSE.txt DELETED
@@ -1,22 +0,0 @@
1
- Copyright (c) 2013 Zachary Patten
2
-
3
- MIT License
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining
6
- a copy of this software and associated documentation files (the
7
- "Software"), to deal in the Software without restriction, including
8
- without limitation the rights to use, copy, modify, merge, publish,
9
- distribute, sublicense, and/or sell copies of the Software, and to
10
- permit persons to whom the Software is furnished to do so, subject to
11
- the following conditions:
12
-
13
- The above copyright notice and this permission notice shall be
14
- included in all copies or substantial portions of the Software.
15
-
16
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
- NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
- LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
- OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
- WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.