testlab 1.8.3 → 1.8.4

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.
data/lib/testlab.rb CHANGED
@@ -1,3 +1,4 @@
1
+ require 'zlib'
1
2
  require 'socket'
2
3
 
3
4
  require 'ztk'
@@ -79,7 +79,6 @@ class TestLab
79
79
  autoload :ClassMethods, 'testlab/container/class_methods'
80
80
  autoload :Clone, 'testlab/container/clone'
81
81
  autoload :Configuration, 'testlab/container/configuration'
82
- autoload :Generators, 'testlab/container/generators'
83
82
  autoload :Interface, 'testlab/container/interface'
84
83
  autoload :IO, 'testlab/container/io'
85
84
  autoload :LXC, 'testlab/container/lxc'
@@ -93,7 +92,6 @@ class TestLab
93
92
  include TestLab::Container::Actions
94
93
  include TestLab::Container::Clone
95
94
  include TestLab::Container::Configuration
96
- include TestLab::Container::Generators
97
95
  include TestLab::Container::Interface
98
96
  include TestLab::Container::IO
99
97
  include TestLab::Container::LXC
@@ -23,25 +23,83 @@ class TestLab
23
23
 
24
24
  @ui.logger.debug { "Loading Interface" }
25
25
  super(*args)
26
+
27
+ self.address ||= generate_ip
28
+ self.mac ||= generate_mac
29
+
26
30
  @ui.logger.debug { "Interface '#{self.id}' Loaded" }
27
31
  end
28
32
 
33
+ # IP address for the interface
29
34
  def ip
30
35
  TestLab::Utility.ip(self.address)
31
36
  end
32
37
 
38
+ # CIDR mask for the interface
33
39
  def cidr
34
40
  TestLab::Utility.cidr(self.address)
35
41
  end
36
42
 
43
+ # Netmask for the interface
37
44
  def netmask
38
45
  TestLab::Utility.netmask(self.address)
39
46
  end
40
47
 
48
+ # PTR record for the interface
41
49
  def ptr
42
50
  TestLab::Utility.ptr(self.address)
43
51
  end
44
52
 
53
+ # Generate IP address
54
+ #
55
+ # Generates an RFC compliant private IP address.
56
+ #
57
+ # @return [String] A random, private IP address in the 192.168.0.1/24
58
+ # range.
59
+ def generate_ip
60
+ crc32 = Zlib.crc32(self.id.to_s)
61
+ offset = crc32.modulo(255)
62
+
63
+ octets = [ 192..192,
64
+ 168..168,
65
+ 0..254,
66
+ 1..254 ]
67
+ ip = Array.new
68
+ for x in 1..4 do
69
+ ip << octets[x-1].to_a[offset.modulo(octets[x-1].count)].to_s
70
+ end
71
+ "#{ip.join(".")}/24"
72
+ end
73
+
74
+ # Generate MAC address
75
+ #
76
+ # Generates an RFC compliant private MAC address.
77
+ #
78
+ # @return [String] A random, private MAC address.
79
+ def generate_mac
80
+ crc32 = Zlib.crc32(self.id.to_s)
81
+ offset = crc32.modulo(255)
82
+
83
+ digits = [ %w(0),
84
+ %w(0),
85
+ %w(0),
86
+ %w(0),
87
+ %w(5),
88
+ %w(e),
89
+ %w(0 1 2 3 4 5 6 7 8 9 a b c d e f),
90
+ %w(0 1 2 3 4 5 6 7 8 9 a b c d e f),
91
+ %w(5 6 7 8 9 a b c d e f),
92
+ %w(3 4 5 6 7 8 9 a b c d e f),
93
+ %w(0 1 2 3 4 5 6 7 8 9 a b c d e f),
94
+ %w(0 1 2 3 4 5 6 7 8 9 a b c d e f) ]
95
+ mac = ""
96
+ for x in 1..12 do
97
+ mac += digits[x-1][offset.modulo(digits[x-1].count)]
98
+ mac += ":" if (x.modulo(2) == 0) && (x != 12)
99
+ end
100
+ mac
101
+ end
102
+
45
103
  end
46
104
 
47
105
  end
@@ -9,7 +9,6 @@ class TestLab
9
9
  #
10
10
  # @author Zachary Patten <zachary AT jovelabs DOT com>
11
11
  class Vagrant
12
- require 'zlib'
13
12
 
14
13
  # States which indicate the VM is running
15
14
  RUNNING_STATES = %w(running).map(&:to_sym)
@@ -1,6 +1,6 @@
1
1
  class TestLab
2
2
  unless const_defined?(:VERSION)
3
3
  # TestLab Gem Version
4
- VERSION = "1.8.3"
4
+ VERSION = "1.8.4"
5
5
  end
6
6
  end
@@ -138,20 +138,6 @@ describe TestLab::Container do
138
138
  end
139
139
  end
140
140
 
141
- describe "#generate_ip" do
142
- it "should generate a random RFC compliant private IP address" do
143
- subject.generate_ip.should_not be_nil
144
- subject.generate_ip.should be_kind_of(String)
145
- end
146
- end
147
-
148
- describe "#generate_mac" do
149
- it "should generate a random RFC compliant private MAC address" do
150
- subject.generate_mac.should_not be_nil
151
- subject.generate_mac.should be_kind_of(String)
152
- end
153
- end
154
-
155
141
  describe "#create" do
156
142
  it "should create the container" do
157
143
  subject.node.stub(:alive?) { true }
@@ -0,0 +1,62 @@
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::Interface do
23
+
24
+ subject {
25
+ @logger = ZTK::Logger.new('/tmp/test.log')
26
+ @ui = ZTK::UI.new(:stdout => StringIO.new, :stderr => StringIO.new, :logger => @logger)
27
+ @testlab = TestLab.new(:repo_dir => REPO_DIR, :labfile_path => LABFILE_PATH, :ui => @ui)
28
+ @testlab.boot
29
+ @testlab.containers.first.interfaces.first
30
+ }
31
+
32
+ describe "class" do
33
+
34
+ it "should be an instance of TestLab::Interface" do
35
+ subject.should be_an_instance_of TestLab::Interface
36
+ end
37
+
38
+ describe "methods" do
39
+
40
+ end
41
+
42
+ end
43
+
44
+ describe "methods" do
45
+
46
+ describe "#generate_ip" do
47
+ it "should generate a random RFC compliant private IP address" do
48
+ subject.generate_ip.should_not be_nil
49
+ subject.generate_ip.should be_kind_of(String)
50
+ end
51
+ end
52
+
53
+ describe "#generate_mac" do
54
+ it "should generate a random RFC compliant private MAC address" do
55
+ subject.generate_mac.should_not be_nil
56
+ subject.generate_mac.should be_kind_of(String)
57
+ end
58
+ end
59
+
60
+ end
61
+
62
+ 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: 1.8.3
4
+ version: 1.8.4
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-09-17 00:00:00.000000000 Z
12
+ date: 2013-09-18 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: gli
@@ -244,7 +244,6 @@ files:
244
244
  - lib/testlab/container/class_methods.rb
245
245
  - lib/testlab/container/clone.rb
246
246
  - lib/testlab/container/configuration.rb
247
- - lib/testlab/container/generators.rb
248
247
  - lib/testlab/container/interface.rb
249
248
  - lib/testlab/container/io.rb
250
249
  - lib/testlab/container/lxc.rb
@@ -318,6 +317,7 @@ files:
318
317
  - lib/testlab/utility/misc.rb
319
318
  - lib/testlab/version.rb
320
319
  - spec/container_spec.rb
320
+ - spec/interface_spec.rb
321
321
  - spec/network_spec.rb
322
322
  - spec/node_spec.rb
323
323
  - spec/provider_spec.rb
@@ -344,7 +344,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
344
344
  version: '0'
345
345
  segments:
346
346
  - 0
347
- hash: 2852140378552631871
347
+ hash: -284786399860132132
348
348
  required_rubygems_version: !ruby/object:Gem::Requirement
349
349
  none: false
350
350
  requirements:
@@ -353,7 +353,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
353
353
  version: '0'
354
354
  segments:
355
355
  - 0
356
- hash: 2852140378552631871
356
+ hash: -284786399860132132
357
357
  requirements: []
358
358
  rubyforge_project:
359
359
  rubygems_version: 1.8.25
@@ -370,6 +370,7 @@ test_files:
370
370
  - features/support/env.rb
371
371
  - features/testlab.feature
372
372
  - spec/container_spec.rb
373
+ - spec/interface_spec.rb
373
374
  - spec/network_spec.rb
374
375
  - spec/node_spec.rb
375
376
  - spec/provider_spec.rb
@@ -1,53 +0,0 @@
1
- class TestLab
2
- class Container
3
-
4
- module Generators
5
-
6
- # Generate IP address
7
- #
8
- # Generates an RFC compliant private IP address.
9
- #
10
- # @return [String] A random, private IP address in the 192.168.0.1/24
11
- # range.
12
- def generate_ip
13
- octets = [ 192..192,
14
- 168..168,
15
- 0..254,
16
- 1..254 ]
17
- ip = Array.new
18
- for x in 1..4 do
19
- ip << octets[x-1].to_a[rand(octets[x-1].count)].to_s
20
- end
21
- ip.join(".")
22
- end
23
-
24
- # Generate MAC address
25
- #
26
- # Generates an RFC compliant private MAC address.
27
- #
28
- # @return [String] A random, private MAC address.
29
- def generate_mac
30
- digits = [ %w(0),
31
- %w(0),
32
- %w(0),
33
- %w(0),
34
- %w(5),
35
- %w(e),
36
- %w(0 1 2 3 4 5 6 7 8 9 a b c d e f),
37
- %w(0 1 2 3 4 5 6 7 8 9 a b c d e f),
38
- %w(5 6 7 8 9 a b c d e f),
39
- %w(3 4 5 6 7 8 9 a b c d e f),
40
- %w(0 1 2 3 4 5 6 7 8 9 a b c d e f),
41
- %w(0 1 2 3 4 5 6 7 8 9 a b c d e f) ]
42
- mac = ""
43
- for x in 1..12 do
44
- mac += digits[x-1][rand(digits[x-1].count)]
45
- mac += ":" if (x.modulo(2) == 0) && (x != 12)
46
- end
47
- mac
48
- end
49
-
50
- end
51
-
52
- end
53
- end