mirror of
https://github.com/fog/fog.git
synced 2022-11-09 13:51:43 -05:00
added container commit request and fixed several tests in real mode
This commit is contained in:
parent
803333bc5e
commit
0f220ee618
10 changed files with 58 additions and 12 deletions
|
@ -21,6 +21,7 @@ module Fog
|
|||
request :container_delete
|
||||
request :container_get
|
||||
request :container_action
|
||||
request :container_commit
|
||||
request :image_all
|
||||
request :image_create
|
||||
request :image_delete
|
||||
|
@ -50,7 +51,7 @@ module Fog
|
|||
end
|
||||
|
||||
def camelize_hash_keys(hash)
|
||||
Hash[ hash.map {|k, v| [k.to_s.camelize, v] }]
|
||||
Hash[ hash.map {|k, v| [k.to_s.split('_').map {|w| w.capitalize}.join, v] }]
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -107,6 +107,10 @@ module Fog
|
|||
reload
|
||||
end
|
||||
|
||||
def commit(options = {})
|
||||
service.container_commit({:id=>id}.merge(options))
|
||||
end
|
||||
|
||||
def destroy(options = {})
|
||||
service.container_action(:id =>id, :action => :kill)
|
||||
service.container_delete(:id => id)
|
||||
|
|
|
@ -17,7 +17,7 @@ module Fog
|
|||
def container_action(options = {})
|
||||
raise ArgumentError, "id is a required parameter" unless options.has_key? :id
|
||||
raise ArgumentError, "action is a required parameter" unless options.has_key? :action
|
||||
{'id' => 'a6b02c7ca29a22619f7d0e59062323247739bc0cd375d619f305f0b519af4ef3','State' => {'Running' => false}}
|
||||
{'id' => 'a6b02c7ca29a22619f7d0e59062323247739bc0cd375d619f305f0b519af4ef3','state_running' => false}
|
||||
end
|
||||
|
||||
end
|
||||
|
|
23
lib/fog/fogdocker/requests/compute/container_commit.rb
Normal file
23
lib/fog/fogdocker/requests/compute/container_commit.rb
Normal file
|
@ -0,0 +1,23 @@
|
|||
module Fog
|
||||
module Compute
|
||||
class Fogdocker
|
||||
class Real
|
||||
def container_commit(options)
|
||||
raise ArgumentError, "instance id is a required parameter" unless options.has_key? :id
|
||||
container = Docker::Container.get(options[:id])
|
||||
downcase_hash_keys container.commit(camelize_hash_keys(options)).info
|
||||
end
|
||||
end
|
||||
|
||||
class Mock
|
||||
def container_commit(options)
|
||||
{'id'=>'a6b02c7ca29a22619f7d0e59062323247739bc0cd375d619f305f0b519af4ef3',
|
||||
'repotags' => ['repo/other'],
|
||||
'created' => 1389877693,
|
||||
'size' => 3265536}
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -4,7 +4,7 @@ module Fog
|
|||
|
||||
class Real
|
||||
def image_create(attrs)
|
||||
downcase_hash_keys Docker::Image.create(camelize_hash_keys(attrs)).info
|
||||
downcase_hash_keys Docker::Image.create(attrs).info
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -14,7 +14,7 @@ module Fog
|
|||
class Mock
|
||||
def image_delete(options = {})
|
||||
raise ArgumentError, "instance id is a required parameter" unless options.has_key? :id
|
||||
true
|
||||
"[{'Deleted':'b15c1423ba157d0f7ac83cba178390c421bb8d536e7e7857580fc10f2d53e1b9'}]"
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -6,10 +6,10 @@ Shindo.tests('Fog::Compute[:fogdocker] | server model', ['fogdocker']) do
|
|||
tests('The server model should') do
|
||||
tests('have the action') do
|
||||
test('reload') { server.respond_to? 'reload' }
|
||||
%w{ start restart stop destroy }.each do |action|
|
||||
%w{ start restart stop commit destroy}.each do |action|
|
||||
test(action) { server.respond_to? action }
|
||||
end
|
||||
%w{ start restart stop destroy}.each do |action|
|
||||
%w{ start restart stop commit destroy}.each do |action|
|
||||
test("#{action} returns successfully") {
|
||||
server.send(action.to_sym) ? true : false
|
||||
}
|
||||
|
|
|
@ -6,20 +6,20 @@ Shindo.tests("Fog::Compute[:fogdocker] | container_action request", 'fogdocker')
|
|||
id = response['id']
|
||||
|
||||
|
||||
tests("Run Container") do
|
||||
response = compute.container_action(:id => id, :action => 'run' )
|
||||
tests("Start Container") do
|
||||
response = compute.container_action(:id => id, :action => 'start' )
|
||||
test("should be a kind of Hash") { response.kind_of? Hash}
|
||||
end
|
||||
|
||||
tests("Stop Container") do
|
||||
response = compute.container_action(:id => id, :action => 'stop' )
|
||||
test("should be a kind of Hash") { response.kind_of? Hash}
|
||||
test("should be stopped") { response['State']['Running'] == false}
|
||||
end
|
||||
|
||||
tests("Kill Container") do
|
||||
response = compute.container_action(:id => id, :action => 'kill' )
|
||||
test("should be a kind of Hash") { response.kind_of? Hash}
|
||||
test("should be stopped") { response['state_running'] == false}
|
||||
end
|
||||
|
||||
end
|
||||
|
|
19
tests/fogdocker/requests/compute/container_commit_tests.rb
Normal file
19
tests/fogdocker/requests/compute/container_commit_tests.rb
Normal file
|
@ -0,0 +1,19 @@
|
|||
Shindo.tests("Fog::Compute[:fogdocker] | container_create request", 'fogdocker') do
|
||||
|
||||
compute = Fog::Compute[:fogdocker]
|
||||
name_base = Time.now.to_i
|
||||
hash = compute.container_create(:name => 'fog-'+name_base.to_s, 'image' => 'mattdm/fedora:f19','Cmd' => ['date'] )
|
||||
response = {}
|
||||
|
||||
tests("Commit Container") do
|
||||
response = compute.container_commit(:id=>hash['id'])
|
||||
test("should have Image id") { response.include? 'id'}
|
||||
end
|
||||
|
||||
test("Delete Commited Image") do
|
||||
result = compute.image_delete(:id=>response['id'])
|
||||
test("should have a deleted message") {result.include?('Deleted')}
|
||||
end
|
||||
|
||||
|
||||
end
|
|
@ -1,9 +1,8 @@
|
|||
Shindo.tests('Fog::Compute[:fogdocker] | container_delete request', ['fogdocker']) do
|
||||
|
||||
compute = Fog::Compute[:fogdocker]
|
||||
container = compute.servers.create('name' => 'fog-'+Time.now.to_i.to_s,
|
||||
'Image' => 'mattdm/fedora:f19',
|
||||
'Cmd' => ['/bin/bash'])
|
||||
container = compute.servers.create({'Image' => 'mattdm/fedora:f19',
|
||||
'Cmd' => ['/bin/bash']})
|
||||
|
||||
tests('The response should') do
|
||||
response = compute.container_delete(:id => container.id)
|
||||
|
|
Loading…
Add table
Reference in a new issue