spec/container_spec.rb in testlab-1.9.2 vs spec/container_spec.rb in testlab-1.10.0
- old
+ new
@@ -21,14 +21,15 @@
describe TestLab::Container do
subject {
@logger = ZTK::Logger.new('/tmp/test.log')
- @ui = ZTK::UI.new(:stdout => StringIO.new, :stderr => StringIO.new, :logger => @logger)
- @testlab = TestLab.new(:repo_dir => REPO_DIR, :labfile_path => LABFILE_PATH, :ui => @ui)
+ @ui = ui_helper(:logger => @logger)
+ @testlab = testlab_helper(:ui => @ui)
@testlab.boot
- @testlab.containers.first
+
+ TestLab::Container.first('master')
}
describe "class" do
it "should be an instance of TestLab::Container" do
@@ -49,56 +50,135 @@
end
describe "methods" do
- describe "#status" do
- it "should return a hash of status information about the container" do
- subject.node.stub(:dead?) { false }
- subject.node.stub(:state) { :running }
- subject.lxc.stub(:state) { :not_created }
- subject.lxc.stub(:memory_usage) { 0 }
- subject.lxc.stub(:cpu_usage) { 0 }
- subject.lxc_clone.stub(:exists?) { false }
+ { :ephemeral => true, :persistent => false }.each do |tag, mode|
+ context tag do
- subject.status.should be_kind_of(Hash)
- subject.status.should_not be_empty
- end
- end
+ before(:each) do
+ subject.node.stub(:dead?) { false }
+ subject.node.stub(:alive?) { true }
+ subject.node.stub(:state) { :running }
- describe "#state" do
- it "should return the state of the container" do
- subject.node.stub(:dead?) { false }
- subject.lxc.stub(:state) { :not_created }
- subject.lxc_clone.stub(:exists?) { false }
- subject.state.should == :not_created
+ subject.lxc_clone.stub(:exists?) { mode }
+ end
+
+ describe "#status" do
+ it "should return a hash of status information about the container" do
+ subject.lxc.stub(:state) { :not_created }
+ subject.lxc.stub(:memory_usage) { 0 }
+ subject.lxc.stub(:cpu_usage) { 0 }
+
+ subject.status.should be_kind_of(Hash)
+ subject.status.should_not be_empty
+ end
+ end
+
+ describe "#state" do
+ it "should return the state of the container" do
+ subject.node.stub(:dead?) { false }
+ subject.node.stub(:alive?) { true }
+ subject.node.stub(:state) { :running }
+
+ subject.state.should == :not_created
+ end
+ end
+
+ describe "#ephemeral" do
+ it "should attempt to convert to a ephemeral container" do
+ subject.ephemeral
+ end
+ end
+
+ describe "#persistent" do
+ it "should attempt to convert to a persistent container" do
+ subject.persistent
+ end
+ end
+
+ # describe "#export" do
+ # it "should attempt to export the container" do
+ # case tag
+ # when :ephemeral
+ # lambda { subject.export }.should raise_error TestLab::ContainerError
+ # when :persistent
+ # subject.stub(:down) { true }
+ # # subject.stub(:destroy) { true }
+ # # subject.stub(:create) { true }
+ # # subject.stub(:up) { true }
+
+ # subject.lxc.config.stub(:save) { true }
+ # subject.lxc.stub(:state) { :running }
+
+ # subject.lxc.stub(:start) { true }
+ # subject.lxc.stub(:stop) { true }
+ # subject.lxc.stub(:create) { true }
+ # subject.lxc.stub(:destroy) { true }
+
+ # subject.lxc.stub(:attach) { "" }
+ # subject.lxc.stub(:exec) { OpenStruct.new(:exit_code => 0) }
+
+ # subject.export
+ # end
+ # end
+ # end
+
+ describe "#copy" do
+ it "should attempt to copy the container" do
+ case tag
+ when :ephemeral
+ lambda { subject.copy("master") }.should raise_error TestLab::ContainerError
+ when :persistent
+ subject.copy("master")
+ end
+ end
+ end
+
+ describe "#up" do
+ it "should up the container" do
+ subject.lxc.config.stub(:save) { true }
+ subject.lxc.stub(:state) { :running }
+ subject.lxc.stub(:start) { true }
+ subject.lxc.stub(:attach) { "" }
+ subject.lxc.stub(:exec) { OpenStruct.new(:exit_code => 0) }
+
+ subject.node.stub(:arch) { "x86_64" }
+ subject.node.stub(:exec) { OpenStruct.new(:exit_code => 1) }
+
+ subject.stub(:provisioners) { Array.new }
+
+ subject.up
+ end
+ end
+
end
end
describe "#fqdn" do
it "should return the FQDN for the container" do
- subject.fqdn.should == "server-dual-nic.default.zone"
+ subject.fqdn.should == "master.default.zone"
end
end
describe "#ip" do
it "should return the IP address of the containers primary interface" do
- subject.ip.should == "192.168.0.254"
+ subject.ip.should == "100.64.0.10"
end
end
describe "#cidr" do
it "should return the CIDR of the containers primary interface" do
- subject.cidr.should == 16
+ subject.cidr.should == 24
end
end
describe "#ptr" do
it "should return a BIND PTR record for the containers primary interface" do
subject.ptr.should be_kind_of(String)
subject.ptr.should_not be_empty
- subject.ptr.should == "254.0"
+ subject.ptr.should == "10"
end
end
describe "#lxc" do
it "should return an instance of LXC::Container configured for this container" do
@@ -112,10 +192,26 @@
subject.ssh.should_not be_nil
subject.ssh.should be_kind_of(ZTK::SSH)
end
end
+ describe "#console" do
+ it "should attempt to open an LXC console via a node SSH console" do
+ subject.node.ssh.stub(:console)
+
+ subject.console
+ end
+ end
+
+ describe "#ssh_config" do
+ it "should return a text blob with our SSH configuration" do
+ subject.ssh_config.should_not be_nil
+ subject.ssh_config.should_not be_empty
+ subject.ssh_config.should be_kind_of(String)
+ end
+ end
+
describe "#exists?" do
it "should return false for a non-existant container" do
subject.lxc.stub(:exists?) { false }
subject.exists?.should == false
end
@@ -173,50 +269,63 @@
subject.destroy
end
end
- describe "#up" do
- it "should up the container" do
+ describe "#down" do
+ it "should down the container" do
subject.node.stub(:dead?) { false }
subject.node.stub(:alive?) { true }
subject.node.stub(:state) { :running }
- subject.node.stub(:arch) { "x86_64" }
- subject.node.stub(:exec) { }
subject.lxc.stub(:exists?) { true }
- subject.lxc.stub(:start) { true }
+ subject.lxc.stub(:stop) { true }
subject.lxc.stub(:wait) { true }
- subject.lxc.stub(:state) { :running }
+ subject.lxc.stub(:state) { :stopped }
subject.lxc_clone.stub(:exists?) { false }
- subject.stub(:exec) { }
- subject.stub(:configure) { }
subject.stub(:provisioners) { Array.new }
- ZTK::TCPSocketCheck.any_instance.stub(:wait) { true }
+ subject.down
+ end
+ end
- subject.up
+ describe "#build" do
+ it "should build the container" do
+ subject.stub(:create) { true }
+ subject.stub(:up) { true }
+ subject.stub(:provision) { true }
+
+ subject.build.should == true
end
end
- describe "#down" do
- it "should down the container" do
- subject.node.stub(:dead?) { false }
- subject.node.stub(:alive?) { true }
- subject.node.stub(:state) { :running }
+ describe "#demolish" do
+ it "should demolish the container" do
+ subject.stub(:destroy) { true }
+ subject.stub(:down) { true }
+ subject.stub(:deprovision) { true }
- subject.lxc.stub(:exists?) { true }
- subject.lxc.stub(:stop) { true }
- subject.lxc.stub(:wait) { true }
- subject.lxc.stub(:state) { :stopped }
+ subject.demolish.should == true
+ end
+ end
- subject.lxc_clone.stub(:exists?) { false }
+ describe "#recycle" do
+ it "should recycle the container" do
+ subject.stub(:demolish) { true }
+ subject.stub(:build) { true }
- subject.stub(:provisioners) { Array.new }
+ subject.recycle.should == true
+ end
+ end
- subject.down
+ describe "#bounce" do
+ it "should bounce the container" do
+ subject.stub(:down) { true }
+ subject.stub(:up) { true }
+
+ subject.bounce.should == true
end
end
describe "#provision" do
context "with no provisioner" do