testlab 1.9.2 → 1.10.0

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.
@@ -26,7 +26,8 @@ describe TestLab::Interface do
26
26
  @ui = ZTK::UI.new(:stdout => StringIO.new, :stderr => StringIO.new, :logger => @logger)
27
27
  @testlab = TestLab.new(:repo_dir => REPO_DIR, :labfile_path => LABFILE_PATH, :ui => @ui)
28
28
  @testlab.boot
29
- @testlab.containers.first.interfaces.first
29
+
30
+ TestLab::Container.first('master').primary_interface
30
31
  }
31
32
 
32
33
  describe "class" do
@@ -35,17 +36,45 @@ describe TestLab::Interface do
35
36
  subject.should be_an_instance_of TestLab::Interface
36
37
  end
37
38
 
38
- describe "methods" do
39
+ end
40
+
41
+ describe "methods" do
39
42
 
43
+ describe "#ip" do
44
+ it "should return the IP address of the interface" do
45
+ subject.ip.should_not be_nil
46
+ subject.ip.should_not be_empty
47
+ subject.ip.should be_kind_of(String)
48
+ end
40
49
  end
41
50
 
42
- end
51
+ describe "#netmask" do
52
+ it "should return the netmask address of the interface" do
53
+ subject.netmask.should_not be_nil
54
+ subject.netmask.should_not be_empty
55
+ subject.netmask.should be_kind_of(String)
56
+ end
57
+ end
43
58
 
44
- describe "methods" do
59
+ describe "#ptr" do
60
+ it "should return the PTR address of the interface" do
61
+ subject.ptr.should_not be_nil
62
+ subject.ptr.should_not be_empty
63
+ subject.ptr.should be_kind_of(String)
64
+ end
65
+ end
66
+
67
+ describe "#cidr" do
68
+ it "should return the CIDR mask of the interface" do
69
+ subject.cidr.should_not be_nil
70
+ subject.cidr.should be_kind_of(Integer)
71
+ end
72
+ end
45
73
 
46
74
  describe "#generate_ip" do
47
75
  it "should generate a random RFC compliant private IP address" do
48
76
  subject.generate_ip.should_not be_nil
77
+ subject.generate_ip.should_not be_empty
49
78
  subject.generate_ip.should be_kind_of(String)
50
79
  end
51
80
  end
@@ -53,6 +82,7 @@ describe TestLab::Interface do
53
82
  describe "#generate_mac" do
54
83
  it "should generate a random RFC compliant private MAC address" do
55
84
  subject.generate_mac.should_not be_nil
85
+ subject.generate_mac.should_not be_empty
56
86
  subject.generate_mac.should be_kind_of(String)
57
87
  end
58
88
  end
@@ -0,0 +1,57 @@
1
+ ################################################################################
2
+ #
3
+ # Author: Zachary Patten <zachary AT jovelabs DOT com>
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 "spec_helper"
21
+
22
+ describe TestLab::Labfile do
23
+
24
+ subject {
25
+ @ui = ui_helper
26
+ @testlab = testlab_helper(:ui => @ui)
27
+ @testlab.boot
28
+ @testlab.labfile
29
+ }
30
+
31
+ describe "class" do
32
+
33
+ it "should be an instance of TestLab::Labfile" do
34
+ subject.should be_an_instance_of TestLab::Labfile
35
+ end
36
+
37
+ end
38
+
39
+ describe "methods" do
40
+
41
+ describe "config_dir" do
42
+ it "should return the configuration directory for the lab" do
43
+ subject.config_dir.should be_kind_of(String)
44
+ subject.config_dir.should_not be_empty
45
+ end
46
+ end
47
+
48
+ describe "repo_dir" do
49
+ it "should return the configuration directory for the lab" do
50
+ subject.repo_dir.should be_kind_of(String)
51
+ subject.repo_dir.should_not be_empty
52
+ end
53
+ end
54
+
55
+ end
56
+
57
+ end
data/spec/network_spec.rb CHANGED
@@ -42,7 +42,7 @@ describe TestLab::Network do
42
42
  it "should return the ips for all defined containers" do
43
43
  subject.class.ips.should be_kind_of(Array)
44
44
  subject.class.ips.should_not be_empty
45
- subject.class.ips.should == ["192.168.255.254"]
45
+ subject.class.ips.should == ["100.64.0.254"]
46
46
  end
47
47
  end
48
48
 
@@ -50,7 +50,7 @@ describe TestLab::Network do
50
50
  it "should return a BIND PTR record for the networks bridge interface" do
51
51
  subject.ptr.should be_kind_of(String)
52
52
  subject.ptr.should_not be_empty
53
- subject.ptr.should == "254.255"
53
+ subject.ptr.should == "254"
54
54
  end
55
55
  end
56
56
 
@@ -58,37 +58,37 @@ describe TestLab::Network do
58
58
  it "should return the ARPA network calculated from the cidr address" do
59
59
  subject.arpa.should be_kind_of(String)
60
60
  subject.arpa.should_not be_empty
61
- subject.arpa.should == "168.192.in-addr.arpa"
61
+ subject.arpa.should == "0.64.100.in-addr.arpa"
62
62
  end
63
63
  end
64
64
 
65
65
  describe "#ip" do
66
66
  it "should return the IP address of the networks bridge interface" do
67
- subject.ip.should == "192.168.255.254"
67
+ subject.ip.should == "100.64.0.254"
68
68
  end
69
69
  end
70
70
 
71
71
  describe "#cidr" do
72
72
  it "should return the CIDR of the networks bridge interface" do
73
- subject.cidr.should == 16
73
+ subject.cidr.should == 24
74
74
  end
75
75
  end
76
76
 
77
77
  describe "#netmask" do
78
78
  it "should return the netmask of the networks bridge interface" do
79
- subject.netmask.should == "255.255.0.0"
79
+ subject.netmask.should == "255.255.255.0"
80
80
  end
81
81
  end
82
82
 
83
83
  describe "#network" do
84
84
  it "should return the network address of the networks bridge interface" do
85
- subject.network.should == "192.168.0.0"
85
+ subject.network.should == "100.64.0.0"
86
86
  end
87
87
  end
88
88
 
89
89
  describe "#broadcast" do
90
90
  it "should return the broadcast address of the networks bridge interface" do
91
- subject.broadcast.should == "192.168.255.255"
91
+ subject.broadcast.should == "100.64.0.255"
92
92
  end
93
93
  end
94
94
 
@@ -188,6 +188,44 @@ describe TestLab::Network do
188
188
  end
189
189
  end
190
190
 
191
+ describe "#build" do
192
+ it "should build the network" do
193
+ subject.stub(:create) { true }
194
+ subject.stub(:up) { true }
195
+ subject.stub(:provision) { true }
196
+
197
+ subject.build.should == true
198
+ end
199
+ end
200
+
201
+ describe "#demolish" do
202
+ it "should demolish the network" do
203
+ subject.stub(:destroy) { true }
204
+ subject.stub(:down) { true }
205
+ subject.stub(:deprovision) { true }
206
+
207
+ subject.demolish.should == true
208
+ end
209
+ end
210
+
211
+ describe "#recycle" do
212
+ it "should recycle the network" do
213
+ subject.stub(:demolish) { true }
214
+ subject.stub(:build) { true }
215
+
216
+ subject.recycle.should == true
217
+ end
218
+ end
219
+
220
+ describe "#bounce" do
221
+ it "should bounce the network" do
222
+ subject.stub(:down) { true }
223
+ subject.stub(:up) { true }
224
+
225
+ subject.bounce.should == true
226
+ end
227
+ end
228
+
191
229
  end
192
230
 
193
231
  end
data/spec/node_spec.rb CHANGED
@@ -125,6 +125,44 @@ describe TestLab::Node do
125
125
  end
126
126
  end
127
127
 
128
+ describe "#build" do
129
+ it "should build the node" do
130
+ subject.stub(:create) { true }
131
+ subject.stub(:up) { true }
132
+ subject.stub(:provision) { true }
133
+
134
+ subject.build.should == true
135
+ end
136
+ end
137
+
138
+ describe "#demolish" do
139
+ it "should demolish the node" do
140
+ subject.stub(:destroy) { true }
141
+ subject.stub(:down) { true }
142
+ subject.stub(:deprovision) { true }
143
+
144
+ subject.demolish.should == true
145
+ end
146
+ end
147
+
148
+ describe "#recycle" do
149
+ it "should recycle the node" do
150
+ subject.stub(:demolish) { true }
151
+ subject.stub(:build) { true }
152
+
153
+ subject.recycle.should == true
154
+ end
155
+ end
156
+
157
+ describe "#bounce" do
158
+ it "should bounce the node" do
159
+ subject.stub(:down) { true }
160
+ subject.stub(:up) { true }
161
+
162
+ subject.bounce.should == true
163
+ end
164
+ end
165
+
128
166
  end
129
167
 
130
168
  end
@@ -0,0 +1,79 @@
1
+ ################################################################################
2
+ #
3
+ # Author: Zachary Patten <zachary AT jovelabs DOT com>
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 "spec_helper"
21
+
22
+ describe TestLab::Provider::Vagrant do
23
+
24
+ subject {
25
+ @ui = ui_helper
26
+ @testlab = testlab_helper(:ui => @ui)
27
+ @testlab.boot
28
+ @testlab.nodes.first
29
+ }
30
+
31
+ before(:each) do
32
+ ZTK::Command.any_instance.stub(:exec) { OpenStruct.new(:output => "", :exit_code => 0) }
33
+ ZTK::TCPSocketCheck.any_instance.stub(:wait) { true }
34
+ end
35
+
36
+ describe "class" do
37
+
38
+ it "should be an instance of TestLab::Provider::Vagrant" do
39
+ subject.provider.should be TestLab::Provider::Vagrant
40
+ subject.instance_variable_get("@provider").should be_an_instance_of TestLab::Provider::Vagrant
41
+ end
42
+
43
+ end
44
+
45
+ describe "methods" do
46
+
47
+ describe "create" do
48
+ it "should return true" do
49
+ subject.instance_variable_get("@provider").create.should == true
50
+ end
51
+ end
52
+
53
+ describe "destroy" do
54
+ it "should return true" do
55
+ subject.instance_variable_get("@provider").destroy.should == true
56
+ end
57
+ end
58
+
59
+ describe "up" do
60
+ it "should return true" do
61
+ subject.instance_variable_get("@provider").up.should == true
62
+ end
63
+ end
64
+
65
+ describe "down" do
66
+ it "should return true" do
67
+ subject.instance_variable_get("@provider").down.should == true
68
+ end
69
+ end
70
+
71
+ describe "reload" do
72
+ it "should return true" do
73
+ subject.instance_variable_get("@provider").reload.should == true
74
+ end
75
+ end
76
+
77
+ end
78
+
79
+ end
@@ -0,0 +1,93 @@
1
+ ################################################################################
2
+ #
3
+ # Author: Zachary Patten <zachary AT jovelabs DOT com>
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 "spec_helper"
21
+
22
+ include TestLab::Utility::Misc
23
+
24
+ [
25
+ TestLab::Provisioner::Apt,
26
+ TestLab::Provisioner::AptCacherNG,
27
+ TestLab::Provisioner::Bind,
28
+ TestLab::Provisioner::HostsFile,
29
+ TestLab::Provisioner::NFSMount,
30
+ TestLab::Provisioner::Raring,
31
+ TestLab::Provisioner::Resolv,
32
+ TestLab::Provisioner::Route,
33
+ TestLab::Provisioner::Shell
34
+ ].each do |klass|
35
+
36
+ describe klass do
37
+
38
+ subject {
39
+ @ui = ZTK::UI.new(:stdout => StringIO.new, :stderr => StringIO.new)
40
+ @testlab = TestLab.new(:repo_dir => REPO_DIR, :labfile_path => LABFILE_PATH, :ui => @ui)
41
+ @testlab.boot
42
+ TestLab::Container.first("server-#{klass.to_s.split('::').last.downcase}")
43
+ }
44
+
45
+ describe "class" do
46
+
47
+ it "should be an instance of #{klass}" do
48
+ subject.provisioners.last.new(subject.config, @ui).should be_an_instance_of klass
49
+ end
50
+
51
+ end
52
+
53
+ describe "methods" do
54
+
55
+ before(:each) do
56
+ ZTK::SSH.any_instance.stub(:file).and_yield(StringIO.new)
57
+ ZTK::SSH.any_instance.stub(:exec) { OpenStruct.new(:output => "", :exit_code => 0) }
58
+ ZTK::SSH.any_instance.stub(:bootstrap) { "" }
59
+ ZTK::SSH.any_instance.stub(:upload) { true }
60
+ ZTK::SSH.any_instance.stub(:download) { true }
61
+
62
+ ZTK::Command.any_instance.stub(:exec) { OpenStruct.new(:output => "", :exit_code => 0) }
63
+ end
64
+
65
+ %w( create destroy up down provision deprovision import export ).each do |action|
66
+ context action do
67
+
68
+ it "should #{action} a node" do
69
+ sym = "on_node_#{action}".to_sym
70
+ p = klass.new(subject.config, @ui)
71
+ p.respond_to?(sym) and p.send(sym, subject.node)
72
+ end
73
+
74
+ it "should #{action} a network" do
75
+ sym = "on_network_#{action}".to_sym
76
+ p = klass.new(subject.config, @ui)
77
+ p.respond_to?(sym) and p.send(sym, subject.primary_interface.network)
78
+ end
79
+
80
+ it "should #{action} a container" do
81
+ sym = "on_container_#{action}".to_sym
82
+ p = klass.new(subject.config, @ui)
83
+ p.respond_to?(sym) and p.send(sym, subject)
84
+ end
85
+
86
+ end
87
+ end
88
+
89
+ end
90
+
91
+ end
92
+
93
+ end
data/spec/spec_helper.rb CHANGED
@@ -32,5 +32,25 @@ RSpec.configure do |config|
32
32
  TestLab::Network.purge
33
33
  TestLab::Interface.purge
34
34
  TestLab::User.purge
35
+
36
+ ZTK::SSH.any_instance.stub(:file).and_yield(StringIO.new)
37
+ ZTK::SSH.any_instance.stub(:exec) { OpenStruct.new(:output => "", :exit_code => 0) }
38
+ ZTK::SSH.any_instance.stub(:bootstrap) { "" }
39
+ ZTK::SSH.any_instance.stub(:upload) { true }
40
+ ZTK::SSH.any_instance.stub(:download) { true }
41
+
42
+ ZTK::Command.any_instance.stub(:exec) { OpenStruct.new(:output => "", :exit_code => 0) }
43
+
44
+ ZTK::TCPSocketCheck.any_instance.stub(:wait) { true }
45
+
46
+ LXC::Runner::SSH.any_instance.stub(:exec) { "" }
35
47
  end
36
48
  end
49
+
50
+ def ui_helper(options={})
51
+ ZTK::UI.new({:stdout => StringIO.new, :stderr => StringIO.new}.merge(options))
52
+ end
53
+
54
+ def testlab_helper(options={})
55
+ TestLab.new({:repo_dir => REPO_DIR, :labfile_path => LABFILE_PATH}.merge(options))
56
+ end
data/spec/support/Labfile CHANGED
@@ -11,6 +11,13 @@ EOF
11
11
 
12
12
  REPO = File.dirname(__FILE__)
13
13
 
14
+ TestLab::Container.new "simple-template" do
15
+ distro "ubuntu"
16
+ release "precise"
17
+
18
+ template true
19
+ end
20
+
14
21
  node 'vagrant' do
15
22
 
16
23
  provider TestLab::Provider::Vagrant
@@ -32,76 +39,164 @@ node 'vagrant' do
32
39
 
33
40
  network 'testnet' do
34
41
  provisioners [TestLab::Provisioner::Route]
35
- address '192.168.255.254/16'
42
+ address '100.64.0.254/24'
36
43
  bridge :br0
37
44
  end
38
45
 
39
- # DUAL NICs
40
- container "server-dual-nic" do
46
+ container "master" do
41
47
  distro "ubuntu"
42
48
  release "precise"
43
49
 
50
+ aa_profile "unconfined"
51
+ cap_drop "thing"
52
+
44
53
  provisioners [
45
54
  TestLab::Provisioner::Resolv,
46
55
  TestLab::Provisioner::AptCacherNG,
47
56
  TestLab::Provisioner::Apt
48
57
  ]
49
58
 
59
+ user do
60
+ username "deployer"
61
+ password "deployer"
62
+ uid 2600
63
+ gid 2600
64
+ public_identity [File.join(Dir.pwd, 'test')]
65
+ identity [File.join(Dir.pwd, 'test.pub')]
66
+ end
67
+
50
68
  interface do
51
69
  name :eth0
52
70
  network_id 'testnet'
53
- address '192.168.0.254/16'
71
+ address '100.64.0.10/24'
54
72
  primary true
55
73
  end
56
74
 
57
75
  interface do
58
76
  name :eth1
59
77
  network_id 'testnet'
60
- address '192.168.0.253/16'
78
+ address '100.64.0.20/24'
61
79
  end
62
80
  end
63
81
 
64
- # SINGLE NIC
65
- container "server-single-nic" do
66
- distro "ubuntu"
67
- release "precise"
82
+ # SHELL PROVISIONER
83
+ container "server-shell" do
84
+ inherit "simple-template"
68
85
 
69
- provisioners [
70
- TestLab::Provisioner::Resolv,
71
- TestLab::Provisioner::AptCacherNG,
72
- TestLab::Provisioner::Apt
73
- ]
86
+ provisioners [TestLab::Provisioner::Shell]
87
+ config ({:script => "echo 'hello world!'"})
74
88
 
75
89
  interface do
76
90
  name :eth0
77
91
  network_id 'testnet'
78
- address '192.168.0.200/16'
92
+ address '100.64.0.40/24'
79
93
  end
80
94
  end
81
95
 
82
- # SHELL PROVISIONER
83
- container "server-shell" do
84
- distro "ubuntu"
85
- release "precise"
96
+ # BIND PROVISIONER
97
+ container "server-bind" do
98
+ inherit "simple-template"
86
99
 
87
- provisioners [
88
- TestLab::Provisioner::Resolv,
89
- TestLab::Provisioner::AptCacherNG,
90
- TestLab::Provisioner::Apt,
91
- TestLab::Provisioner::Shell
92
- ]
100
+ provisioners [TestLab::Provisioner::Bind]
101
+
102
+ interface do
103
+ name :eth0
104
+ network_id 'testnet'
105
+ address '100.64.0.50/24'
106
+ end
107
+ end
108
+
109
+ # RESOLV PROVISIONER
110
+ container "server-resolv" do
111
+ inherit "simple-template"
93
112
 
94
- config ({
95
- :shell => "/bin/bash",
96
- :script => shell_provision_script
97
- })
113
+ provisioners [TestLab::Provisioner::Resolv]
98
114
 
99
115
  interface do
100
116
  name :eth0
101
117
  network_id 'testnet'
102
- address '192.168.0.200/16'
118
+ address '100.64.0.60/24'
103
119
  end
104
120
  end
105
121
 
122
+ # RARING PROVISIONER
123
+ container "server-raring" do
124
+ inherit "simple-template"
125
+
126
+ provisioners [TestLab::Provisioner::Raring]
127
+
128
+ interface do
129
+ name :eth0
130
+ network_id 'testnet'
131
+ address '100.64.0.70/24'
132
+ end
133
+ end
134
+
135
+ # HOSTSFILE PROVISIONER
136
+ container "server-hostsfile" do
137
+ inherit "simple-template"
138
+
139
+ provisioners [TestLab::Provisioner::HostsFile]
140
+
141
+ interface do
142
+ name :eth0
143
+ network_id 'testnet'
144
+ address '100.64.0.80/24'
145
+ end
146
+ end
147
+
148
+ # APT PROVISIONER
149
+ container "server-apt" do
150
+ inherit "simple-template"
151
+
152
+ provisioners [TestLab::Provisioner::Apt]
153
+
154
+ interface do
155
+ name :eth0
156
+ network_id 'testnet'
157
+ address '100.64.0.80/24'
158
+ end
159
+ end
160
+
161
+ # APTCACHERNG PROVISIONER
162
+ container "server-aptcacherng" do
163
+ inherit "simple-template"
164
+
165
+ provisioners [TestLab::Provisioner::AptCacherNG]
166
+
167
+ interface do
168
+ name :eth0
169
+ network_id 'testnet'
170
+ address '100.64.0.80/24'
171
+ end
172
+ end
173
+
174
+ # ROUTE PROVISIONER
175
+ container "server-route" do
176
+ inherit "simple-template"
177
+
178
+ provisioners [TestLab::Provisioner::Route]
179
+
180
+ interface do
181
+ name :eth0
182
+ network_id 'testnet'
183
+ address '100.64.0.80/24'
184
+ end
185
+ end
186
+
187
+ # NFSMOUNT PROVISIONER
188
+ container "server-nfsmount" do
189
+ inherit "simple-template"
190
+
191
+ provisioners [TestLab::Provisioner::NFSMount]
192
+
193
+ config ({:nfs_mounts => %w( 127.0.0.1 /share /local)})
194
+
195
+ interface do
196
+ name :eth0
197
+ network_id 'testnet'
198
+ address '100.64.0.80/24'
199
+ end
200
+ end
106
201
 
107
202
  end