diff --git a/lib/aviator/core/session.rb b/lib/aviator/core/session.rb index baa81e6..0774112 100644 --- a/lib/aviator/core/session.rb +++ b/lib/aviator/core/session.rb @@ -83,6 +83,13 @@ module Aviator end + def load(session_dump) + initialize_with_dump(session_dump) + update_services_session_data + self + end + + def method_missing(name, *args, &block) service_name_parts = name.to_s.match(/^(\w+)_service$/) diff --git a/test/aviator/core/session_test.rb b/test/aviator/core/session_test.rb index 26914de..c1954cd 100644 --- a/test/aviator/core/session_test.rb +++ b/test/aviator/core/session_test.rb @@ -99,6 +99,35 @@ class Aviator::Test end end + + + describe '#load' do + + it 'returns itself' do + session = new_session + session.authenticate + + str = session.dump + session.load(str).must_equal session + end + + + it 'updates the session data of its service objects' do + session1 = new_session + session1.authenticate + keystone1 = session1.identity_service + + session2 = new_session + session2.authenticate + keystone2 = session2.identity_service + + session1.load(session2.dump) + + keystone1.wont_equal keystone2 + keystone1.default_session_data.must_equal keystone2.default_session_data + end + + end # describe '#load' describe '::load' do diff --git a/test/cassettes/core/session/i_load/returns_itself.yml b/test/cassettes/core/session/i_load/returns_itself.yml new file mode 100644 index 0000000..3e8f221 --- /dev/null +++ b/test/cassettes/core/session/i_load/returns_itself.yml @@ -0,0 +1,63 @@ +--- +http_interactions: +- request: + method: post + uri: :5000/v2.0/tokens + body: + encoding: UTF-8 + string: ! '{"auth":{"passwordCredentials":{"username":"admin","password":""},"tenantName":"admin"}}' + headers: + Content-Type: + - application/json + User-Agent: + - Faraday v0.8.8 + response: + status: + code: 200 + message: + headers: + vary: + - X-Auth-Token + content-type: + - application/json + content-length: + - '2648' + date: + - Mon, 02 Sep 2013 17:53:35 GMT + connection: + - close + body: + encoding: US-ASCII + string: ! '{"access": {"token": {"issued_at": "2013-09-02T17:53:35.649618", + "expires": "2013-09-03T17:53:35Z", "id": "3a562100f8d448d39d7a18142bcb9d31", + "tenant": {"description": null, "enabled": true, "id": "3cab25130620477b8b03f1bfa8741603", + "name": "admin"}}, "serviceCatalog": [{"endpoints": [{"adminURL": "http://192.168.56.11:8774/v2/3cab25130620477b8b03f1bfa8741603", + "region": "RegionOne", "internalURL": "http://192.168.56.11:8774/v2/3cab25130620477b8b03f1bfa8741603", + "id": "3b72a66bf2f0491bb8dba827cade0d48", "publicURL": "http://192.168.56.11:8774/v2/3cab25130620477b8b03f1bfa8741603"}], + "endpoints_links": [], "type": "compute", "name": "nova"}, {"endpoints": [{"adminURL": + "http://192.168.56.11:3333", "region": "RegionOne", "internalURL": "http://192.168.56.11:3333", + "id": "482f749b370c40eab8788d6d0bc47f48", "publicURL": "http://192.168.56.11:3333"}], + "endpoints_links": [], "type": "s3", "name": "s3"}, {"endpoints": [{"adminURL": + "http://192.168.56.11:9292", "region": "RegionOne", "internalURL": "http://192.168.56.11:9292", + "id": "0cd5d5d5a0c24721a0392b47c89e3640", "publicURL": "http://192.168.56.11:9292"}], + "endpoints_links": [], "type": "image", "name": "glance"}, {"endpoints": [{"adminURL": + "http://192.168.56.11:8777", "region": "RegionOne", "internalURL": "http://192.168.56.11:8777", + "id": "4eb4edec1d2647bfb8ba4f9a5757169d", "publicURL": "http://192.168.56.11:8777"}], + "endpoints_links": [], "type": "metering", "name": "ceilometer"}, {"endpoints": + [{"adminURL": "http://192.168.56.11:8776/v1/3cab25130620477b8b03f1bfa8741603", + "region": "RegionOne", "internalURL": "http://192.168.56.11:8776/v1/3cab25130620477b8b03f1bfa8741603", + "id": "009e8a41953d439f845b2a0c0dc28b73", "publicURL": "http://192.168.56.11:8776/v1/3cab25130620477b8b03f1bfa8741603"}], + "endpoints_links": [], "type": "volume", "name": "cinder"}, {"endpoints": + [{"adminURL": "http://192.168.56.11:8773/services/Admin", "region": "RegionOne", + "internalURL": "http://192.168.56.11:8773/services/Cloud", "id": "6820836ec6834548bf7b54da0271dded", + "publicURL": "http://192.168.56.11:8773/services/Cloud"}], "endpoints_links": + [], "type": "ec2", "name": "ec2"}, {"endpoints": [{"adminURL": "http://192.168.56.11:35357/v2.0", + "region": "RegionOne", "internalURL": "http://192.168.56.11:5000/v2.0", "id": + "24a95f51f67949e784971e97463ee4d8", "publicURL": "http://192.168.56.11:5000/v2.0"}], + "endpoints_links": [], "type": "identity", "name": "keystone"}], "user": {"username": + "admin", "roles_links": [], "id": "cbbcc4f7aef6435fa2da7e5f0b2f1e97", "roles": + [{"name": "admin"}], "name": "admin"}, "metadata": {"is_admin": 0, "roles": + ["01a81f2dbb3441f1aaa8fe68a7c6f546"]}}}' + http_version: + recorded_at: Tue, 03 Sep 2013 07:59:33 GMT +recorded_with: VCR 2.5.0 diff --git a/test/cassettes/core/session/i_load/updates_the_session_data_of_its_service_objects.yml b/test/cassettes/core/session/i_load/updates_the_session_data_of_its_service_objects.yml new file mode 100644 index 0000000..f96408a --- /dev/null +++ b/test/cassettes/core/session/i_load/updates_the_session_data_of_its_service_objects.yml @@ -0,0 +1,123 @@ +--- +http_interactions: +- request: + method: post + uri: :5000/v2.0/tokens + body: + encoding: UTF-8 + string: ! '{"auth":{"passwordCredentials":{"username":"admin","password":""},"tenantName":"admin"}}' + headers: + Content-Type: + - application/json + User-Agent: + - Faraday v0.8.8 + response: + status: + code: 200 + message: + headers: + vary: + - X-Auth-Token + content-type: + - application/json + content-length: + - '2648' + date: + - Mon, 02 Sep 2013 18:02:17 GMT + connection: + - close + body: + encoding: US-ASCII + string: ! '{"access": {"token": {"issued_at": "2013-09-02T18:02:17.103202", + "expires": "2013-09-03T18:02:17Z", "id": "368a64a148714e9fbe618f39dbbca105", + "tenant": {"description": null, "enabled": true, "id": "3cab25130620477b8b03f1bfa8741603", + "name": "admin"}}, "serviceCatalog": [{"endpoints": [{"adminURL": "http://192.168.56.11:8774/v2/3cab25130620477b8b03f1bfa8741603", + "region": "RegionOne", "internalURL": "http://192.168.56.11:8774/v2/3cab25130620477b8b03f1bfa8741603", + "id": "3b72a66bf2f0491bb8dba827cade0d48", "publicURL": "http://192.168.56.11:8774/v2/3cab25130620477b8b03f1bfa8741603"}], + "endpoints_links": [], "type": "compute", "name": "nova"}, {"endpoints": [{"adminURL": + "http://192.168.56.11:3333", "region": "RegionOne", "internalURL": "http://192.168.56.11:3333", + "id": "482f749b370c40eab8788d6d0bc47f48", "publicURL": "http://192.168.56.11:3333"}], + "endpoints_links": [], "type": "s3", "name": "s3"}, {"endpoints": [{"adminURL": + "http://192.168.56.11:9292", "region": "RegionOne", "internalURL": "http://192.168.56.11:9292", + "id": "0cd5d5d5a0c24721a0392b47c89e3640", "publicURL": "http://192.168.56.11:9292"}], + "endpoints_links": [], "type": "image", "name": "glance"}, {"endpoints": [{"adminURL": + "http://192.168.56.11:8777", "region": "RegionOne", "internalURL": "http://192.168.56.11:8777", + "id": "4eb4edec1d2647bfb8ba4f9a5757169d", "publicURL": "http://192.168.56.11:8777"}], + "endpoints_links": [], "type": "metering", "name": "ceilometer"}, {"endpoints": + [{"adminURL": "http://192.168.56.11:8776/v1/3cab25130620477b8b03f1bfa8741603", + "region": "RegionOne", "internalURL": "http://192.168.56.11:8776/v1/3cab25130620477b8b03f1bfa8741603", + "id": "009e8a41953d439f845b2a0c0dc28b73", "publicURL": "http://192.168.56.11:8776/v1/3cab25130620477b8b03f1bfa8741603"}], + "endpoints_links": [], "type": "volume", "name": "cinder"}, {"endpoints": + [{"adminURL": "http://192.168.56.11:8773/services/Admin", "region": "RegionOne", + "internalURL": "http://192.168.56.11:8773/services/Cloud", "id": "6820836ec6834548bf7b54da0271dded", + "publicURL": "http://192.168.56.11:8773/services/Cloud"}], "endpoints_links": + [], "type": "ec2", "name": "ec2"}, {"endpoints": [{"adminURL": "http://192.168.56.11:35357/v2.0", + "region": "RegionOne", "internalURL": "http://192.168.56.11:5000/v2.0", "id": + "24a95f51f67949e784971e97463ee4d8", "publicURL": "http://192.168.56.11:5000/v2.0"}], + "endpoints_links": [], "type": "identity", "name": "keystone"}], "user": {"username": + "admin", "roles_links": [], "id": "cbbcc4f7aef6435fa2da7e5f0b2f1e97", "roles": + [{"name": "admin"}], "name": "admin"}, "metadata": {"is_admin": 0, "roles": + ["01a81f2dbb3441f1aaa8fe68a7c6f546"]}}}' + http_version: + recorded_at: Tue, 03 Sep 2013 08:08:07 GMT +- request: + method: post + uri: :5000/v2.0/tokens + body: + encoding: UTF-8 + string: ! '{"auth":{"passwordCredentials":{"username":"admin","password":""},"tenantName":"admin"}}' + headers: + Content-Type: + - application/json + User-Agent: + - Faraday v0.8.8 + response: + status: + code: 200 + message: + headers: + vary: + - X-Auth-Token + content-type: + - application/json + content-length: + - '2648' + date: + - Mon, 02 Sep 2013 18:02:17 GMT + connection: + - close + body: + encoding: US-ASCII + string: ! '{"access": {"token": {"issued_at": "2013-09-02T18:02:17.395539", + "expires": "2013-09-03T18:02:17Z", "id": "8b4101a55c99402a9f2cb154b2975391", + "tenant": {"description": null, "enabled": true, "id": "3cab25130620477b8b03f1bfa8741603", + "name": "admin"}}, "serviceCatalog": [{"endpoints": [{"adminURL": "http://192.168.56.11:8774/v2/3cab25130620477b8b03f1bfa8741603", + "region": "RegionOne", "internalURL": "http://192.168.56.11:8774/v2/3cab25130620477b8b03f1bfa8741603", + "id": "3b72a66bf2f0491bb8dba827cade0d48", "publicURL": "http://192.168.56.11:8774/v2/3cab25130620477b8b03f1bfa8741603"}], + "endpoints_links": [], "type": "compute", "name": "nova"}, {"endpoints": [{"adminURL": + "http://192.168.56.11:3333", "region": "RegionOne", "internalURL": "http://192.168.56.11:3333", + "id": "482f749b370c40eab8788d6d0bc47f48", "publicURL": "http://192.168.56.11:3333"}], + "endpoints_links": [], "type": "s3", "name": "s3"}, {"endpoints": [{"adminURL": + "http://192.168.56.11:9292", "region": "RegionOne", "internalURL": "http://192.168.56.11:9292", + "id": "0cd5d5d5a0c24721a0392b47c89e3640", "publicURL": "http://192.168.56.11:9292"}], + "endpoints_links": [], "type": "image", "name": "glance"}, {"endpoints": [{"adminURL": + "http://192.168.56.11:8777", "region": "RegionOne", "internalURL": "http://192.168.56.11:8777", + "id": "4eb4edec1d2647bfb8ba4f9a5757169d", "publicURL": "http://192.168.56.11:8777"}], + "endpoints_links": [], "type": "metering", "name": "ceilometer"}, {"endpoints": + [{"adminURL": "http://192.168.56.11:8776/v1/3cab25130620477b8b03f1bfa8741603", + "region": "RegionOne", "internalURL": "http://192.168.56.11:8776/v1/3cab25130620477b8b03f1bfa8741603", + "id": "009e8a41953d439f845b2a0c0dc28b73", "publicURL": "http://192.168.56.11:8776/v1/3cab25130620477b8b03f1bfa8741603"}], + "endpoints_links": [], "type": "volume", "name": "cinder"}, {"endpoints": + [{"adminURL": "http://192.168.56.11:8773/services/Admin", "region": "RegionOne", + "internalURL": "http://192.168.56.11:8773/services/Cloud", "id": "6820836ec6834548bf7b54da0271dded", + "publicURL": "http://192.168.56.11:8773/services/Cloud"}], "endpoints_links": + [], "type": "ec2", "name": "ec2"}, {"endpoints": [{"adminURL": "http://192.168.56.11:35357/v2.0", + "region": "RegionOne", "internalURL": "http://192.168.56.11:5000/v2.0", "id": + "24a95f51f67949e784971e97463ee4d8", "publicURL": "http://192.168.56.11:5000/v2.0"}], + "endpoints_links": [], "type": "identity", "name": "keystone"}], "user": {"username": + "admin", "roles_links": [], "id": "cbbcc4f7aef6435fa2da7e5f0b2f1e97", "roles": + [{"name": "admin"}], "name": "admin"}, "metadata": {"is_admin": 0, "roles": + ["01a81f2dbb3441f1aaa8fe68a7c6f546"]}}}' + http_version: + recorded_at: Tue, 03 Sep 2013 08:08:07 GMT +recorded_with: VCR 2.5.0