testlab 0.3.1 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +17 -1
- data/bin/tl +124 -8
- data/lib/testlab/container/lxc.rb +25 -0
- data/lib/testlab/container.rb +5 -5
- data/lib/testlab/interface.rb +2 -2
- data/lib/testlab/labfile.rb +2 -2
- data/lib/testlab/node/ssh.rb +2 -2
- data/lib/testlab/node/templates/node-setup.erb +1 -1
- data/lib/testlab/node.rb +2 -2
- data/lib/testlab/provisioner.rb +3 -2
- data/lib/testlab/provisioners/omnibus.rb +48 -0
- data/lib/testlab/provisioners/omnitruck.rb +115 -0
- data/lib/testlab/provisioners/shell.rb +18 -11
- data/lib/testlab/provisioners/templates/chef/omnibus.erb +6 -0
- data/lib/testlab/provisioners/templates/chef/omnitruck.erb +102 -0
- data/lib/testlab/version.rb +1 -1
- data/lib/testlab.rb +2 -4
- data/spec/container_spec.rb +55 -20
- data/spec/network_spec.rb +5 -1
- data/spec/node_spec.rb +51 -1
- data/spec/provisioners/shell_spec.rb +66 -0
- data/spec/support/Labfile +32 -4
- data/spec/testlab_spec.rb +4 -1
- data/spec/utility_spec.rb +114 -0
- metadata +12 -6
- data/lib/testlab/provisioners/chef.rb +0 -27
- data/lib/testlab/provisioners/templates/chef/bootstrap.erb +0 -0
@@ -0,0 +1,102 @@
|
|
1
|
+
#!/bin/env bash
|
2
|
+
<%= ZTK::Template.do_not_edit_notice(:message => "OmniTruck Bootstrap") %>
|
3
|
+
set -x
|
4
|
+
|
5
|
+
DEBIAN_FRONTEND="noninteractive"
|
6
|
+
CHEF_SOLO_ROOT="/tmp/chef-solo"
|
7
|
+
KNIFE_CONFIG_EXP_FILE="/tmp/knife-config.exp"
|
8
|
+
export DEBIAN_FRONTEND CHEF_SOLO_ROOT KNIFE_CONFIG_EXP_FILE
|
9
|
+
|
10
|
+
mkdir -p /tmp/chef-solo/
|
11
|
+
cd ${CHEF_SOLO_ROOT}
|
12
|
+
|
13
|
+
apt-get -y --force-yes update
|
14
|
+
apt-get -y --force-yes install build-essential expect wget curl
|
15
|
+
|
16
|
+
mkdir -pv /etc/chef /var/log/chef ${HOME}/.chef
|
17
|
+
|
18
|
+
cat <<EOF | tee /etc/chef/solo.rb
|
19
|
+
file_cache_path "${CHEF_SOLO_ROOT}/"
|
20
|
+
cookbook_path %w(${CHEF_SOLO_ROOT}/cookbooks/ ${CHEF_SOLO_ROOT}/site-cookbooks/)
|
21
|
+
role_path "${CHEF_SOLO_ROOT}/roles/"
|
22
|
+
EOF
|
23
|
+
|
24
|
+
cat <<EOF | tee ${CHEF_SOLO_ROOT}/attributes.json
|
25
|
+
<%= @chef_solo_attributes.to_json %>
|
26
|
+
EOF
|
27
|
+
|
28
|
+
curl -L https://www.opscode.com/chef/install.sh | bash
|
29
|
+
# bash install.sh -v <%= @version %>
|
30
|
+
<% if (@chef_pre_11 == false) -%>
|
31
|
+
|
32
|
+
mkdir -pv /var/chef/cache ${CHEF_SOLO_ROOT}/cookbooks/chef-server
|
33
|
+
wget -qO- https://github.com/opscode-cookbooks/chef-server/archive/master.tar.gz | tar xvzC ${CHEF_SOLO_ROOT}/cookbooks/chef-server --strip-components=1
|
34
|
+
<% else -%>
|
35
|
+
|
36
|
+
export PATH=/opt/chef/embedded/bin:$PATH
|
37
|
+
|
38
|
+
cat <<EOF | tee ${CHEF_SOLO_ROOT}/Gemfile
|
39
|
+
source 'https://rubygems.org'
|
40
|
+
gem 'chef', '<%= @version %>'
|
41
|
+
gem 'berkshelf'
|
42
|
+
gem 'moneta', '< 0.7.0'
|
43
|
+
EOF
|
44
|
+
|
45
|
+
cat <<EOF | tee ${CHEF_SOLO_ROOT}/Berksfile
|
46
|
+
site :opscode
|
47
|
+
cookbook 'chef-server'
|
48
|
+
EOF
|
49
|
+
|
50
|
+
gem install bundler --no-ri --no-rdoc
|
51
|
+
bundle install --standalone --path vendor/bundle --binstubs
|
52
|
+
mv -v ${CHEF_SOLO_ROOT}/cookbooks ${CHEF_SOLO_ROOT}/site-cookbooks
|
53
|
+
bin/berks install --path ${CHEF_SOLO_ROOT}/cookbooks/
|
54
|
+
<% end -%>
|
55
|
+
|
56
|
+
chef-solo --config /etc/chef/solo.rb --json-attributes ${CHEF_SOLO_ROOT}/attributes.json --logfile /var/log/chef/chef-solo.log --log_level debug
|
57
|
+
<% if (@chef_pre_11 == false) -%>
|
58
|
+
|
59
|
+
cat << EOF | tee /etc/chef-server/chef-server.rb
|
60
|
+
<%= ZTK::Template.do_not_edit_notice(:message => "OmniTruck Bootstrap") %>
|
61
|
+
server_name = "<%= @server_name %>"
|
62
|
+
#
|
63
|
+
topology "standalone"
|
64
|
+
api_fqdn server_name
|
65
|
+
nginx['url'] = "https://#{server_name}"
|
66
|
+
nginx['server_name'] = server_name
|
67
|
+
lb['fqdn'] = server_name
|
68
|
+
bookshelf['vip'] = server_name
|
69
|
+
EOF
|
70
|
+
sudo chef-server-ctl reconfigure
|
71
|
+
<% end -%>
|
72
|
+
|
73
|
+
echo -n "Waiting on <%= File.basename(@chef_validator) %> and <%= File.basename(@chef_webui) %> to appear..."
|
74
|
+
until [ -f <%= @chef_validator %> ] && [ -f <%= @chef_webui %> ]; do
|
75
|
+
echo -n "."
|
76
|
+
sleep 1
|
77
|
+
done
|
78
|
+
echo "done."
|
79
|
+
|
80
|
+
cp -v <%= @chef_validator %> <%= @chef_webui %> ~/.chef
|
81
|
+
<% if (@chef_pre_11 == false) -%>
|
82
|
+
|
83
|
+
ln -sv <%= @chef_validator %> /etc/chef/validation.pem
|
84
|
+
ln -sv <%= @chef_admin %> /etc/chef/admin.pem
|
85
|
+
<% end -%>
|
86
|
+
|
87
|
+
cat <<EOF | tee ${KNIFE_CONFIG_EXP_FILE}
|
88
|
+
#!/usr/bin/expect -f
|
89
|
+
set timeout 10
|
90
|
+
<% if (@chef_pre_11 == false) -%>
|
91
|
+
spawn knife configure -i --server-url https://127.0.0.1 --admin-client-key <%= @chef_admin %> -u ${SUDO_USER} -r '' --defaults --yes -VV
|
92
|
+
<% else -%>
|
93
|
+
spawn knife configure -i --server-url https://127.0.0.1 -u ${SUDO_USER} -r '' --defaults --yes -VV
|
94
|
+
<% end -%>
|
95
|
+
expect "Please enter a password for the new user:" { send "<%= @default_password %>\n" }
|
96
|
+
interact
|
97
|
+
EOF
|
98
|
+
chmod +x ${KNIFE_CONFIG_EXP_FILE}
|
99
|
+
${KNIFE_CONFIG_EXP_FILE}
|
100
|
+
|
101
|
+
knife client create <%= @user %> -a -f ${HOME}/.chef/<%= @user %>.pem --disable-editing --yes -VV
|
102
|
+
chown -Rv ${SUDO_USER}:${SUDO_USER} ${HOME}
|
data/lib/testlab/version.rb
CHANGED
data/lib/testlab.rb
CHANGED
@@ -27,6 +27,7 @@ require 'testlab/monkeys'
|
|
27
27
|
#
|
28
28
|
# node :localhost do
|
29
29
|
# components %w(resolv bind)
|
30
|
+
# route true
|
30
31
|
#
|
31
32
|
# provider TestLab::Provider::Vagrant
|
32
33
|
# config Hash[
|
@@ -54,10 +55,7 @@ require 'testlab/monkeys'
|
|
54
55
|
# release "precise"
|
55
56
|
#
|
56
57
|
# provisioner TestLab::Provisioner::Shell
|
57
|
-
# config Hash[
|
58
|
-
# :shell => "/bin/bash",
|
59
|
-
# :setup => shell_provision_script
|
60
|
-
# ]
|
58
|
+
# config Hash[:setup => shell_provision_script]
|
61
59
|
#
|
62
60
|
# interface do
|
63
61
|
# name :eth0
|
data/spec/container_spec.rb
CHANGED
@@ -21,7 +21,11 @@ require "spec_helper"
|
|
21
21
|
|
22
22
|
describe TestLab::Container do
|
23
23
|
|
24
|
-
subject {
|
24
|
+
subject {
|
25
|
+
@ui = ZTK::UI.new(:stdout => StringIO.new, :stderr => StringIO.new)
|
26
|
+
@testlab = TestLab.new(:labfile => LABFILE, :ui => @ui)
|
27
|
+
@testlab.containers.first
|
28
|
+
}
|
25
29
|
|
26
30
|
describe "class" do
|
27
31
|
|
@@ -29,18 +33,22 @@ describe TestLab::Container do
|
|
29
33
|
subject.should be_an_instance_of TestLab::Container
|
30
34
|
end
|
31
35
|
|
32
|
-
|
33
|
-
|
34
|
-
describe "methods" do
|
36
|
+
describe "methods" do
|
35
37
|
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
38
|
+
describe "domains" do
|
39
|
+
it "should return the domains for all defined containers" do
|
40
|
+
subject.class.domains.should be_kind_of(Array)
|
41
|
+
subject.class.domains.should_not be_empty
|
42
|
+
subject.class.domains.should == ["default.zone"]
|
43
|
+
end
|
41
44
|
end
|
45
|
+
|
42
46
|
end
|
43
47
|
|
48
|
+
end
|
49
|
+
|
50
|
+
describe "methods" do
|
51
|
+
|
44
52
|
describe "#status" do
|
45
53
|
it "should return a hash of status information about the container" do
|
46
54
|
subject.lxc.stub(:state) { :not_created }
|
@@ -58,7 +66,7 @@ describe TestLab::Container do
|
|
58
66
|
|
59
67
|
describe "#fqdn" do
|
60
68
|
it "should return the FQDN for the container" do
|
61
|
-
subject.fqdn.should == "server-
|
69
|
+
subject.fqdn.should == "server-dual-nic.default.zone"
|
62
70
|
end
|
63
71
|
end
|
64
72
|
|
@@ -169,23 +177,50 @@ describe TestLab::Container do
|
|
169
177
|
end
|
170
178
|
|
171
179
|
describe "#setup" do
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
180
|
+
context "with no provisioner" do
|
181
|
+
it "should create and online the container" do
|
182
|
+
subject.stub(:create) { true }
|
183
|
+
subject.stub(:up) { true }
|
184
|
+
subject.instance_variable_get(:@provisioner) and subject.instance_variable_get(:@provisioner).stub(:setup) { true }
|
176
185
|
|
177
|
-
|
186
|
+
subject.setup
|
187
|
+
end
|
188
|
+
end
|
189
|
+
|
190
|
+
context "with the shell provisioner" do
|
191
|
+
it "should create and online the container" do
|
192
|
+
subject = TestLab::Container.first('server-shell')
|
193
|
+
subject.stub(:create) { true }
|
194
|
+
subject.stub(:up) { true }
|
195
|
+
subject.instance_variable_get(:@provisioner) and subject.instance_variable_get(:@provisioner).stub(:setup) { true }
|
196
|
+
|
197
|
+
subject.setup
|
198
|
+
end
|
178
199
|
end
|
179
200
|
end
|
180
201
|
|
181
202
|
describe "#teardown" do
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
203
|
+
context "with no provisioner" do
|
204
|
+
it "should create and online the container" do
|
205
|
+
subject.stub(:down) { true }
|
206
|
+
subject.stub(:destroy) { true }
|
207
|
+
subject.instance_variable_get(:@provisioner) and subject.instance_variable_get(:@provisioner).stub(:teardown) { true }
|
186
208
|
|
187
|
-
|
209
|
+
subject.teardown
|
210
|
+
end
|
188
211
|
end
|
212
|
+
|
213
|
+
context "with the shell provisioner" do
|
214
|
+
it "should create and online the container" do
|
215
|
+
subject = TestLab::Container.first('server-shell')
|
216
|
+
subject.stub(:down) { true }
|
217
|
+
subject.stub(:destroy) { true }
|
218
|
+
subject.instance_variable_get(:@provisioner) and subject.instance_variable_get(:@provisioner).stub(:teardown) { true }
|
219
|
+
|
220
|
+
subject.teardown
|
221
|
+
end
|
222
|
+
end
|
223
|
+
|
189
224
|
end
|
190
225
|
|
191
226
|
end
|
data/spec/network_spec.rb
CHANGED
@@ -21,7 +21,11 @@ require "spec_helper"
|
|
21
21
|
|
22
22
|
describe TestLab::Network do
|
23
23
|
|
24
|
-
subject {
|
24
|
+
subject {
|
25
|
+
@ui = ZTK::UI.new(:stdout => StringIO.new, :stderr => StringIO.new)
|
26
|
+
@testlab = TestLab.new(:labfile => LABFILE, :ui => @ui)
|
27
|
+
@testlab.networks.first
|
28
|
+
}
|
25
29
|
|
26
30
|
describe "class" do
|
27
31
|
|
data/spec/node_spec.rb
CHANGED
@@ -21,7 +21,11 @@ require "spec_helper"
|
|
21
21
|
|
22
22
|
describe TestLab::Node do
|
23
23
|
|
24
|
-
subject {
|
24
|
+
subject {
|
25
|
+
@ui = ZTK::UI.new(:stdout => StringIO.new, :stderr => StringIO.new)
|
26
|
+
@testlab = TestLab.new(:labfile => LABFILE, :ui => @ui)
|
27
|
+
@testlab.nodes.first
|
28
|
+
}
|
25
29
|
|
26
30
|
describe "class" do
|
27
31
|
|
@@ -39,6 +43,22 @@ describe TestLab::Node do
|
|
39
43
|
end
|
40
44
|
end
|
41
45
|
|
46
|
+
describe "#bind_setup" do
|
47
|
+
it "should setup bind" do
|
48
|
+
subject.ssh.stub(:exec) { true }
|
49
|
+
subject.ssh.stub(:file).and_yield(StringIO.new)
|
50
|
+
subject.bind_setup
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
describe "#build_resolv_conf" do
|
55
|
+
it "should build resolv.conf" do
|
56
|
+
subject.ssh.stub(:exec) { true }
|
57
|
+
subject.ssh.stub(:file).and_yield(StringIO.new)
|
58
|
+
subject.build_resolv_conf
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
42
62
|
describe "#status" do
|
43
63
|
it "should return a hash of status information about the node" do
|
44
64
|
subject.instance_variable_get(:@provider).stub(:state) { :not_created }
|
@@ -90,6 +110,36 @@ describe TestLab::Node do
|
|
90
110
|
end
|
91
111
|
end
|
92
112
|
|
113
|
+
describe "setup" do
|
114
|
+
it "should setup the node" do
|
115
|
+
subject.ssh.stub(:bootstrap) { true }
|
116
|
+
subject.stub(:route_setup) { true }
|
117
|
+
subject.stub(:build_resolv_conf) { true }
|
118
|
+
subject.stub(:bind_setup) { true }
|
119
|
+
subject.stub(:bind_reload) { true }
|
120
|
+
subject.containers.each do |container|
|
121
|
+
container.stub(:setup) { true }
|
122
|
+
end
|
123
|
+
subject.networks.each do |network|
|
124
|
+
network.stub(:setup) { true }
|
125
|
+
end
|
126
|
+
subject.setup
|
127
|
+
end
|
128
|
+
end
|
129
|
+
|
130
|
+
describe "teardown" do
|
131
|
+
it "should teardown the node" do
|
132
|
+
subject.stub(:route_setup) { true }
|
133
|
+
subject.containers.each do |container|
|
134
|
+
container.stub(:teardown) { true }
|
135
|
+
end
|
136
|
+
subject.networks.each do |network|
|
137
|
+
network.stub(:teardown) { true }
|
138
|
+
end
|
139
|
+
subject.teardown
|
140
|
+
end
|
141
|
+
end
|
142
|
+
|
93
143
|
end
|
94
144
|
|
95
145
|
end
|
@@ -0,0 +1,66 @@
|
|
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::Provisioner::Shell do
|
23
|
+
|
24
|
+
subject {
|
25
|
+
@ui = ZTK::UI.new(:stdout => StringIO.new, :stderr => StringIO.new)
|
26
|
+
@testlab = TestLab.new(:labfile => LABFILE, :ui => @ui)
|
27
|
+
TestLab::Container.first('server-shell')
|
28
|
+
}
|
29
|
+
|
30
|
+
describe "class" do
|
31
|
+
|
32
|
+
it "should be an instance of TestLab::Provisioner::Shell" do
|
33
|
+
subject.instance_variable_get(:@provisioner).should be_an_instance_of TestLab::Provisioner::Shell
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
37
|
+
|
38
|
+
describe "methods" do
|
39
|
+
|
40
|
+
describe "setup" do
|
41
|
+
context "bootstrap successful" do
|
42
|
+
it "should provision the container" do
|
43
|
+
subject.node.ssh.stub(:file).and_yield(StringIO.new)
|
44
|
+
subject.lxc.stub(:attach) { "" }
|
45
|
+
subject.instance_variable_get(:@provisioner).setup(subject)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
context "bootstrap fails" do
|
50
|
+
it "should raise an exception" do
|
51
|
+
subject.node.ssh.stub(:file).and_yield(StringIO.new)
|
52
|
+
subject.lxc.stub(:attach) { "No such file or directory" }
|
53
|
+
lambda{ subject.instance_variable_get(:@provisioner).setup(subject) }.should raise_error TestLab::ContainerError
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
describe "teardown" do
|
59
|
+
it "should decomission the container" do
|
60
|
+
subject.instance_variable_get(:@provisioner).teardown(subject)
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
end
|
65
|
+
|
66
|
+
end
|
data/spec/support/Labfile
CHANGED
@@ -1,12 +1,21 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
#^syntax detection
|
3
3
|
|
4
|
+
shell_provision_script = <<-EOF
|
5
|
+
set -x
|
6
|
+
apt-get -y update
|
7
|
+
apt-get -y install dnsutils
|
8
|
+
EOF
|
9
|
+
|
4
10
|
config Hash[
|
5
11
|
:domain => "default.zone"
|
6
12
|
]
|
7
13
|
|
8
14
|
node :localhost do
|
9
15
|
|
16
|
+
components %w(resolv bind)
|
17
|
+
route true
|
18
|
+
|
10
19
|
provider TestLab::Provider::Vagrant
|
11
20
|
config Hash[
|
12
21
|
:vagrant => {
|
@@ -20,14 +29,13 @@ node :localhost do
|
|
20
29
|
:repo => File.dirname(__FILE__)
|
21
30
|
]
|
22
31
|
|
23
|
-
route false
|
24
|
-
|
25
32
|
network :testnet do
|
26
33
|
address '192.168.255.254/16'
|
27
34
|
bridge :br0
|
28
35
|
end
|
29
36
|
|
30
|
-
|
37
|
+
# DUAL NICs
|
38
|
+
container "server-dual-nic" do
|
31
39
|
distro "ubuntu"
|
32
40
|
release "precise"
|
33
41
|
|
@@ -45,7 +53,8 @@ node :localhost do
|
|
45
53
|
end
|
46
54
|
end
|
47
55
|
|
48
|
-
|
56
|
+
# SINGLE NIC
|
57
|
+
container "server-single-nic" do
|
49
58
|
distro "ubuntu"
|
50
59
|
release "precise"
|
51
60
|
|
@@ -56,4 +65,23 @@ node :localhost do
|
|
56
65
|
end
|
57
66
|
end
|
58
67
|
|
68
|
+
# SHELL PROVISIONER
|
69
|
+
container "server-shell" do
|
70
|
+
distro "ubuntu"
|
71
|
+
release "precise"
|
72
|
+
|
73
|
+
provisioner TestLab::Provisioner::Shell
|
74
|
+
config Hash[
|
75
|
+
:shell => "/bin/bash",
|
76
|
+
:setup => shell_provision_script
|
77
|
+
]
|
78
|
+
|
79
|
+
interface do
|
80
|
+
name :eth0
|
81
|
+
network_id :testnet
|
82
|
+
address '192.168.0.200/16'
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
|
59
87
|
end
|
data/spec/testlab_spec.rb
CHANGED
@@ -21,7 +21,10 @@ require "spec_helper"
|
|
21
21
|
|
22
22
|
describe TestLab do
|
23
23
|
|
24
|
-
subject {
|
24
|
+
subject {
|
25
|
+
@ui = ZTK::UI.new(:stdout => StringIO.new, :stderr => StringIO.new)
|
26
|
+
@testlab = TestLab.new(:labfile => LABFILE, :ui => @ui)
|
27
|
+
}
|
25
28
|
|
26
29
|
describe "class" do
|
27
30
|
|
@@ -0,0 +1,114 @@
|
|
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::Utility do
|
23
|
+
|
24
|
+
subject { TestLab::Utility }
|
25
|
+
|
26
|
+
describe "class" do
|
27
|
+
|
28
|
+
it "should be TestLab::Utility" do
|
29
|
+
subject.should be TestLab::Utility
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
33
|
+
|
34
|
+
describe "methods" do
|
35
|
+
|
36
|
+
describe "#cidr_octets" do
|
37
|
+
context "with CIDR 0" do
|
38
|
+
it "should return the correct number of octets based on our CIDR" do
|
39
|
+
address = "192.168.0.254/0"
|
40
|
+
subject.cidr_octets(address).should be_kind_of(Array)
|
41
|
+
subject.cidr_octets(address).should_not be_empty
|
42
|
+
subject.cidr_octets(address).should == ["192", "168", "0", "254"]
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
context "with CIDR 8" do
|
47
|
+
it "should return the correct number of octets based on our CIDR" do
|
48
|
+
address = "192.168.0.254/8"
|
49
|
+
subject.cidr_octets(address).should be_kind_of(Array)
|
50
|
+
subject.cidr_octets(address).should_not be_empty
|
51
|
+
subject.cidr_octets(address).should == ["168", "0", "254"]
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
context "with CIDR 16" do
|
56
|
+
it "should return the correct number of octets based on our CIDR" do
|
57
|
+
address = "192.168.0.254/16"
|
58
|
+
subject.cidr_octets(address).should be_kind_of(Array)
|
59
|
+
subject.cidr_octets(address).should_not be_empty
|
60
|
+
subject.cidr_octets(address).should == ["0", "254"]
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
context "with CIDR 24" do
|
65
|
+
it "should return the correct number of octets based on our CIDR" do
|
66
|
+
address = "192.168.0.254/24"
|
67
|
+
subject.cidr_octets(address).should be_kind_of(Array)
|
68
|
+
subject.cidr_octets(address).should_not be_empty
|
69
|
+
subject.cidr_octets(address).should == ["254"]
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
describe "#arpa_octets" do
|
75
|
+
context "with CIDR 0" do
|
76
|
+
it "should return the correct number of octets based on our CIDR" do
|
77
|
+
address = "192.168.0.254/0"
|
78
|
+
subject.arpa_octets(address).should be_kind_of(Array)
|
79
|
+
subject.arpa_octets(address).should be_empty
|
80
|
+
subject.arpa_octets(address).should == []
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
context "with CIDR 8" do
|
85
|
+
it "should return the correct number of octets based on our CIDR" do
|
86
|
+
address = "192.168.0.254/8"
|
87
|
+
subject.arpa_octets(address).should be_kind_of(Array)
|
88
|
+
subject.arpa_octets(address).should_not be_empty
|
89
|
+
subject.arpa_octets(address).should == ["192"]
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
context "with CIDR 16" do
|
94
|
+
it "should return the correct number of octets based on our CIDR" do
|
95
|
+
address = "192.168.0.254/16"
|
96
|
+
subject.arpa_octets(address).should be_kind_of(Array)
|
97
|
+
subject.arpa_octets(address).should_not be_empty
|
98
|
+
subject.arpa_octets(address).should == ["168", "192"]
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
context "with CIDR 24" do
|
103
|
+
it "should return the correct number of octets based on our CIDR" do
|
104
|
+
address = "192.168.0.254/24"
|
105
|
+
subject.arpa_octets(address).should be_kind_of(Array)
|
106
|
+
subject.arpa_octets(address).should_not be_empty
|
107
|
+
subject.arpa_octets(address).should == ["0", "168", "192"]
|
108
|
+
end
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
112
|
+
end
|
113
|
+
|
114
|
+
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.
|
4
|
+
version: 0.4.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-05-
|
12
|
+
date: 2013-05-06 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: gli
|
@@ -246,9 +246,11 @@ files:
|
|
246
246
|
- lib/testlab/providers/templates/vagrant/Vagrantfile.erb
|
247
247
|
- lib/testlab/providers/vagrant.rb
|
248
248
|
- lib/testlab/provisioner.rb
|
249
|
-
- lib/testlab/provisioners/
|
249
|
+
- lib/testlab/provisioners/omnibus.rb
|
250
|
+
- lib/testlab/provisioners/omnitruck.rb
|
250
251
|
- lib/testlab/provisioners/shell.rb
|
251
|
-
- lib/testlab/provisioners/templates/chef/
|
252
|
+
- lib/testlab/provisioners/templates/chef/omnibus.erb
|
253
|
+
- lib/testlab/provisioners/templates/chef/omnitruck.erb
|
252
254
|
- lib/testlab/utility.rb
|
253
255
|
- lib/testlab/utility/cidr.rb
|
254
256
|
- lib/testlab/utility/misc.rb
|
@@ -258,9 +260,11 @@ files:
|
|
258
260
|
- spec/node_spec.rb
|
259
261
|
- spec/provider_spec.rb
|
260
262
|
- spec/provisioner_spec.rb
|
263
|
+
- spec/provisioners/shell_spec.rb
|
261
264
|
- spec/spec_helper.rb
|
262
265
|
- spec/support/Labfile
|
263
266
|
- spec/testlab_spec.rb
|
267
|
+
- spec/utility_spec.rb
|
264
268
|
- testlab.gemspec
|
265
269
|
homepage: https://github.com/zpatten/testlab
|
266
270
|
licenses:
|
@@ -277,7 +281,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
277
281
|
version: '0'
|
278
282
|
segments:
|
279
283
|
- 0
|
280
|
-
hash:
|
284
|
+
hash: 2598342112570301025
|
281
285
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
282
286
|
none: false
|
283
287
|
requirements:
|
@@ -286,7 +290,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
286
290
|
version: '0'
|
287
291
|
segments:
|
288
292
|
- 0
|
289
|
-
hash:
|
293
|
+
hash: 2598342112570301025
|
290
294
|
requirements: []
|
291
295
|
rubyforge_project:
|
292
296
|
rubygems_version: 1.8.25
|
@@ -299,7 +303,9 @@ test_files:
|
|
299
303
|
- spec/node_spec.rb
|
300
304
|
- spec/provider_spec.rb
|
301
305
|
- spec/provisioner_spec.rb
|
306
|
+
- spec/provisioners/shell_spec.rb
|
302
307
|
- spec/spec_helper.rb
|
303
308
|
- spec/support/Labfile
|
304
309
|
- spec/testlab_spec.rb
|
310
|
+
- spec/utility_spec.rb
|
305
311
|
has_rdoc:
|