testlab 0.4.8 → 0.4.9

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/bin/tl CHANGED
@@ -336,6 +336,44 @@ EOF
336
336
  end
337
337
  end
338
338
 
339
+ # CONTAINER UP
340
+ ###############
341
+ c.desc 'Up a container'
342
+ c.long_desc <<-EOF
343
+ Up a container. The container is started and brought online.
344
+ EOF
345
+ c.command :up do |up|
346
+ up.action do |global_options, options, args|
347
+ if options[:id].nil?
348
+ help_now!('id is required') if options[:id].nil?
349
+ else
350
+ container = @testlab.containers.select{ |c| c.id.to_sym == options[:id].to_sym }.first
351
+ container.nil? and raise TestLab::TestLabError, "We could not find the container you supplied!"
352
+
353
+ container.up
354
+ end
355
+ end
356
+ end
357
+
358
+ # CONTAINER DOWN
359
+ #################
360
+ c.desc 'Down a container'
361
+ c.long_desc <<-EOF
362
+ Down a container. The container is stopped taking it offline.
363
+ EOF
364
+ c.command :down do |down|
365
+ down.action do |global_options, options, args|
366
+ if options[:id].nil?
367
+ help_now!('id is required') if options[:id].nil?
368
+ else
369
+ container = @testlab.containers.select{ |c| c.id.to_sym == options[:id].to_sym }.first
370
+ container.nil? and raise TestLab::TestLabError, "We could not find the container you supplied!"
371
+
372
+ container.down
373
+ end
374
+ end
375
+ end
376
+
339
377
  # CONTAINER SETUP
340
378
  ####################
341
379
  c.desc 'Setup a container'
@@ -58,7 +58,7 @@ class TestLab
58
58
  # An array of symbols of the various keys in our status hash.
59
59
  #
60
60
  # @see TestLab::Container::Status
61
- STATUS_KEYS = %w(node_id id fqdn state distro release interfaces provisioner).map(&:to_sym)
61
+ STATUS_KEYS = %w(node_id id clone fqdn state distro release interfaces provisioner).map(&:to_sym)
62
62
 
63
63
  # Sub-Modules
64
64
  autoload :Actions, 'testlab/container/actions'
@@ -16,11 +16,7 @@ class TestLab
16
16
  self.domain ||= self.node.labfile.config[:domain]
17
17
  self.arch ||= detect_arch
18
18
 
19
- self.lxc.config.clear
20
- self.lxc.config['lxc.utsname'] = self.fqdn
21
- self.lxc.config['lxc.arch'] = self.arch
22
- self.lxc.config.networks = build_lxc_network_conf(self.interfaces)
23
- self.lxc.config.save
19
+ build_lxc_config(self.lxc.config)
24
20
 
25
21
  self.lxc.create(*create_args)
26
22
 
@@ -75,7 +71,14 @@ class TestLab
75
71
  (self.lxc.state == :not_created) and return false #raise ContainerError, "We can not online a non-existant container!"
76
72
 
77
73
  please_wait(:ui => @ui, :message => format_object_action(self, 'Up', :green)) do
78
- self.lxc.lxc.exec(%(lxc-stop), %(-n #{self.id}-clone))
74
+ if self.lxc_clone.exists?
75
+ self.lxc.stop
76
+ self.lxc_clone.stop
77
+ self.lxc_clone.clone(%(-o #{self.id}-master), %(-n #{self.id}))
78
+ build_lxc_config(self.lxc.config)
79
+ self.lxc_clone.destroy(%(-f))
80
+ end
81
+
79
82
  self.lxc.start
80
83
  self.lxc.wait(:running)
81
84
 
@@ -99,25 +102,37 @@ class TestLab
99
102
  (self.lxc.state == :not_created) and return false # raise ContainerError, "We can not offline a non-existant container!"
100
103
 
101
104
  please_wait(:ui => @ui, :message => format_object_action(self, 'Down', :red)) do
102
- self.lxc.lxc.exec(%(lxc-stop), %(-n #{self.id}-clone))
103
105
  self.lxc.stop
104
106
  self.lxc.wait(:stopped)
105
107
 
106
- (self.lxc.state != :stopped) and raise ContainerError, "The container failed to offline!"
108
+ (self.lxc.state == :running) and raise ContainerError, "The container failed to offline!"
107
109
  end
108
110
 
109
111
  true
110
112
  end
111
113
 
114
+ # Clone the contaienr
115
+ #
116
+ # Prepares the container, if needed, for ephemeral cloning and clones it.
117
+ #
118
+ # @return [Boolean] True if successful.
112
119
  def clone
113
120
  @ui.logger.debug { "Container Clone: #{self.id}" }
114
121
 
115
122
  self.down
116
123
 
117
124
  please_wait(:ui => @ui, :message => format_object_action(self, 'Clone', :yellow)) do
118
- self.lxc.start_ephemeral(%(-o #{self.id} -n #{self.id}-clone), %(-d))
125
+ if self.lxc.exists?
126
+ self.lxc.stop
127
+ self.lxc.clone(%(-o #{self.id}), %(-n #{self.id}-master))
128
+ build_lxc_config(self.lxc_clone.config)
129
+ self.lxc.destroy(%(-f))
130
+ end
131
+
132
+ self.lxc_clone.start_ephemeral(%(-o #{self.id}-master -n #{self.id}), %(-d))
119
133
  end
120
134
 
135
+ true
121
136
  end
122
137
 
123
138
  end
@@ -39,6 +39,17 @@ class TestLab
39
39
  @lxc ||= self.node.lxc.container(self.id)
40
40
  end
41
41
 
42
+ # LXC::Container object
43
+ #
44
+ # Returns a *LXC::Container* class instance configured for the clone of
45
+ # this container.
46
+ #
47
+ # @return [LXC] An instance of LXC::Container configured for the clone of
48
+ # this container.
49
+ def lxc_clone
50
+ @lxc_clone ||= self.node.lxc.container("#{self.id}-master")
51
+ end
52
+
42
53
  # ZTK:SSH object
43
54
  #
44
55
  # Returns a *ZTK:SSH* class instance configured for this container.
@@ -84,6 +95,21 @@ class TestLab
84
95
  end
85
96
  end
86
97
 
98
+ # LXC Container Configuration
99
+ #
100
+ # Builds the LXC container configuration data.
101
+ #
102
+ # @return [Boolean] True if successful.
103
+ def build_lxc_config(lxc_config)
104
+ lxc_config.clear
105
+ lxc_config['lxc.utsname'] = self.fqdn
106
+ lxc_config['lxc.arch'] = self.arch
107
+ lxc_config.networks = build_lxc_network_conf(self.interfaces)
108
+ lxc_config.save
109
+
110
+ true
111
+ end
112
+
87
113
  # LXC Network Configuration
88
114
  #
89
115
  # Builds an array of hashes containing the lxc configuration options for
@@ -53,6 +53,7 @@ class TestLab
53
53
 
54
54
  {
55
55
  :id => self.id,
56
+ :clone => self.lxc_clone.exists?,
56
57
  :fqdn => self.fqdn,
57
58
  :state => self.state,
58
59
  :distro => self.distro,
@@ -1,6 +1,6 @@
1
1
  class TestLab
2
2
  unless const_defined?(:VERSION)
3
3
  # TestLab Gem Version
4
- VERSION = "0.4.8"
4
+ VERSION = "0.4.9"
5
5
  end
6
6
  end
@@ -52,6 +52,7 @@ describe TestLab::Container do
52
52
  describe "#status" do
53
53
  it "should return a hash of status information about the container" do
54
54
  subject.lxc.stub(:state) { :not_created }
55
+ subject.lxc_clone.stub(:exists?) { false }
55
56
  subject.status.should be_kind_of(Hash)
56
57
  subject.status.should_not be_empty
57
58
  end
@@ -165,6 +166,9 @@ describe TestLab::Container do
165
166
  subject.lxc.stub(:wait) { true }
166
167
  subject.lxc.stub(:state) { :running }
167
168
  subject.lxc.stub(:attach)
169
+
170
+ subject.lxc_clone.stub(:exists?) { false }
171
+
168
172
  subject.up
169
173
  end
170
174
  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.8
4
+ version: 0.4.9
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-18 00:00:00.000000000 Z
12
+ date: 2013-05-21 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: gli
@@ -279,12 +279,18 @@ required_ruby_version: !ruby/object:Gem::Requirement
279
279
  - - ! '>='
280
280
  - !ruby/object:Gem::Version
281
281
  version: '0'
282
+ segments:
283
+ - 0
284
+ hash: 1069287922281155445
282
285
  required_rubygems_version: !ruby/object:Gem::Requirement
283
286
  none: false
284
287
  requirements:
285
288
  - - ! '>='
286
289
  - !ruby/object:Gem::Version
287
290
  version: '0'
291
+ segments:
292
+ - 0
293
+ hash: 1069287922281155445
288
294
  requirements: []
289
295
  rubyforge_project:
290
296
  rubygems_version: 1.8.25