Skip to content
Browse files

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

- Added tests to already existing requests.
  • Loading branch information...
1 parent b7370d6 commit e99450ec1f8cf83c0519ccd68af9ba88203734e5 Alfonso Juan Dillera committed with Keoven
View
31 lib/fog/openstack/requests/compute/create_key_pair.rb
@@ -24,11 +24,26 @@ def create_key_pair(key_name, public_key = nil)
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
20 lib/fog/openstack/requests/compute/delete_key_pair.rb
@@ -14,8 +14,18 @@ def delete_key_pair(key_name)
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
29 lib/fog/openstack/requests/compute/list_key_pairs.rb
@@ -14,10 +14,25 @@ def list_key_pairs
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
30 tests/openstack/requests/compute/keypair_tests.rb
@@ -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

0 comments on commit e99450e

Please sign in to comment.
Something went wrong with that request. Please try again.