1
0
Fork 0
mirror of https://github.com/fog/fog.git synced 2022-11-09 13:51:43 -05:00

[openstack|compute] Add requests, models and tests for keypairs

- Added tests to already existing requests.
This commit is contained in:
Alfonso Juan Dillera 2012-02-23 17:38:44 +08:00 committed by Nelvin Driz
parent b7370d640e
commit e99450ec1f
4 changed files with 90 additions and 20 deletions

View file

@ -24,11 +24,26 @@ module Fog
end
class Mock
end
end
end
end
def create_key_pair(key_name, public_key = nil)
response = Excon::Response.new
response.status = 200
response.headers = {
"X-Compute-Request-Id" => "req-c373a42c-2825-4e60-8d34-99416ea850be",
"Content-Type" => "application/json",
"Content-Length" => "1289",
"Date" => Date.new}
response.body = {
"keypair" => {
"public_key" => "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAAAgQDCdAZLjljntJbLVVkNHjWFSoKen2nZbk39ZfqhZJOMdeFdz02GWBS45rcuboeGg/gozKRwsLu4N6NLPlYtbK/NapJIvgO/djBp+FQG1QZNtLPsx7j4hVJac3yISGms+Xtu4cEv6j5sFDzAgTQbWez0Z1+9qOq9ngdaoW+YClfQ== vagrant@nova\n",
"private_key" => "-----BEGIN RSA PRIVATE KEY-----\nMIICXgIBAAKBgQDCdAZLjljn1tJbLVVkNHjWFSoKen2nZbk39ZfqhZJOMdeFdz02\nGWBS45rcuHboeGg/gozKRwsLu4N6NLPlYtbK/NapJIvgO/djBp+FQG1QZNtLPsx7\nj4hVJac3yISGms+Xtu4cEv6j5sFDzAgTQbWez0Z1+9qOq9ngdaoW+YClfQIDAQAB\nAoGBALBoT9m1vuQ82EONQf2RONqHAsfUzi/SMhEZRgOlv9AemXZkcWyl4uPvxmtd\nEcreiTystAtCHjw7lhCExXthipevUjtIAAt+b3pMn6Oyjad3IRvde6atMdjrje43\n/nftYtuXYyJTsvwEvLYqSioLQ0Nn/XDKhOpcM5tejDHOH35lAkEA+H4r7y9X521u\nIABVAezBWaT/wvdMjx5cwfyYEQjnI1bxfRIqkgoY5gDDBdVbT75UTsHHbHLORQcw\nRjRvS2zgewJBAMhT6eyMonJvHHvC5RcchcY+dWkscIKoOzeyUKMb+7tERQa9/UN2\njYb+jdM0VyL0ruLFwYtl2m34gfmhcXgIvGcCQGzKMEnjHEUBr7jq7EyPbobkqeSd\niDMQQ+PZxmmO0EK0ib0L+v881HG926PuKK/cz+Q7Cif8iznFT+ksg50t6YkCQQC9\nwfcAskqieSuS9A9LcCIrojhXctf0e+T0Ij2N89DlF4sHEuqXf/IZ4IB5gsfTfdE3\nUDnAkK9yogaEbu/r0uKbAkEAy5kl71bIqvKTKsY2mES9ziVxfftl/9UIi5LI+QHb\nmC/c6cTrGVCM71fi2GMxGgBeEea4+7xwoWTL4CxA00kmTg==\n-----END RSA PRIVATE KEY-----\n",
"user_id" => "admin",
"name" => key_name,
"fingerprint" => "97:86:f4:15:68:0c:7b:a7:e5:8f:f0:bd:1f:27:65:ad"
}
}
response
end
end # mock
end # openstack
end # compute
end # fog

View file

@ -14,8 +14,18 @@ module Fog
end
class Mock
end
end
end
end
def delete_key_pair(key_name)
response = Excon::Response.new
response.status = 202
response.headers = {
"Content-Type" => "text/html; charset=UTF-8",
"Content-Length" => "0",
"Date" => Date.new
}
response.body = {}
response
end
end # mock
end # openstack
end # compute
end # fog

View file

@ -14,10 +14,25 @@ module Fog
end
class Mock
end
end
end
end
def list_key_pairs
response = Excon::Response.new
response.status = 200
response.headers = {
"X-Compute-Request-Id" => "req-c373a42c-2825-4e60-8d34-99416ea850be",
"Content-Type" => "application/json",
"Content-Length" => "360",
"Date" => Date.new}
response.body = {
"keypairs" => [{
"keypair" => {
"public_key" => "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAAAgQDCdAZLjln1tJbLVVkNHjWFSoKen2nZbk39ZfqhZJOMdeFdz02GWBS4rcuHboeGg/gozKRwsLu4N6NLPlYtbK/NapJIvgO/djBp+FG1QZNtLPsx7j4hVJac3yISGms+Xtu4cEv6j5sFDzAgTQbWz0Z1+9qOq9ngdaoW+YClfQ== vagrant@nova\n",
"name" => "test_key",
"fingerprint" => "97:86:f4:15:68:0c:7b:a7:e5:8f:f0:bd:1f:27:65:ad"
}
}]
}
end
end # mock
end # openstack
end # compute
end # fog

View file

@ -0,0 +1,30 @@
Shindo.tests('Fog::Compute[:openstack] | keypair requests', ['openstack']) do
@keypair_format = {
"public_key" => String,
"private_key" => String,
"user_id" => String,
"name" => String,
"fingerprint" => String
}
@keypair_list_format = {
"public_key" => String,
"name" => String,
"fingerprint" => String
}
tests('success') do
tests('#create_key_pair((key_name, public_key = nil))').formats({"keypair" => @keypair_format}) do
Fog::Compute[:openstack].create_key_pair('from_shindo_test').body
end
tests('#list_key_pairs').formats({"keypairs" => [{"keypair" => @keypair_list_format}]}) do
Fog::Compute[:openstack].list_key_pairs
end
tests('#delete_key_pair(key_name)').succeeds do
Fog::Compute[:openstack].delete_key_pair(1)
end
end
end