ACK.
On Apr 3, 2012, at 2:28 PM, [email protected] wrote: > From: marios <[email protected]> > > > Signed-off-by: marios <[email protected]> > --- > server/tests/drivers/openstack/api_test.rb | 4 +- > .../drivers/openstack/hardware_profiles_test.rb | 20 ++++-- > server/tests/drivers/openstack/images_test.rb | 5 +- > server/tests/drivers/openstack/instances_test.rb | 64 ++++++++++++++++---- > server/tests/drivers/openstack/realms_test.rb | 9 +-- > server/tests/drivers/openstack/setup.rb | 6 +- > 6 files changed, 77 insertions(+), 31 deletions(-) > > diff --git a/server/tests/drivers/openstack/api_test.rb > b/server/tests/drivers/openstack/api_test.rb > index 4ec0ac6..14861b0 100644 > --- a/server/tests/drivers/openstack/api_test.rb > +++ b/server/tests/drivers/openstack/api_test.rb > @@ -31,10 +31,10 @@ module OpenstackTest > collections.include?('instance_states').should == true > collections.include?('instances').should == true > collections.include?('images').should == true > - collections.include?('buckets').should == true > +# collections.include?('buckets').should == true # NOT YET IMPLEMENTED > FOR V2 driver > collections.include?('realms').should == true > collections.include?('hardware_profiles').should == true > - collections.length.should == 7 > + collections.length.should == 6 #7 > end > > end > diff --git a/server/tests/drivers/openstack/hardware_profiles_test.rb > b/server/tests/drivers/openstack/hardware_profiles_test.rb > index ed0cd16..0744011 100644 > --- a/server/tests/drivers/openstack/hardware_profiles_test.rb > +++ b/server/tests/drivers/openstack/hardware_profiles_test.rb > @@ -12,7 +12,7 @@ module OpenstackTest > > def test_01_it_returns_hardware_profiles > get_auth_url '/api;driver=openstack/hardware_profiles' > - (last_xml_response/'hardware_profiles/hardware_profile').length.should > == 5 > + (last_xml_response/'hardware_profiles/hardware_profile').length.should > > 0 > end > > def test_02_each_hardware_profile_has_a_name > @@ -32,21 +32,27 @@ module OpenstackTest > (profile/'property[@name="storage"]').first[:unit].should == 'GB' > (profile/'property[@name="storage"]').first[:kind].should == 'fixed' > end > + hwp = ((last_xml_response/'hardware_profiles/hardware_profile').first) > + @@hwp = { :id => hwp[:id], > + :arch => > (hwp/'property[@name="architecture"]').first[:value], > + :mem => (hwp/'property[@name="memory"]').first[:value], > + :disk => (hwp/'property[@name="storage"]').first[:value] } > + @@no_of_profiles = > (last_xml_response/'hardware_profiles/hardware_profile').length > end > > def test_04_it_returns_single_hardware_profile > - get_auth_url '/api;driver=openstack/hardware_profiles/1' > - (last_xml_response/'hardware_profile/name').first.text.should == '1' > - > (last_xml_response/'hardware_profile/property[@name="architecture"]').first[:value].should > == 'x86_64' > - > (last_xml_response/'hardware_profile/property[@name="memory"]').first[:value].should > == '512' > - > (last_xml_response/'hardware_profile/property[@name="storage"]').first[:value].should > == '0' > + get_auth_url "/api;driver=openstack/hardware_profiles/#{@@hwp[:id]}" > + (last_xml_response/'hardware_profile/name').first.text.should == > @@hwp[:id] > + > (last_xml_response/'hardware_profile/property[@name="architecture"]').first[:value].should > == @@hwp[:arch] > + > (last_xml_response/'hardware_profile/property[@name="memory"]').first[:value].should > == @@hwp[:mem] > + > (last_xml_response/'hardware_profile/property[@name="storage"]').first[:value].should > == @@hwp[:disk] > end > > def test_05_it_filter_hardware_profiles > get_auth_url '/api;driver=openstack/hardware_profiles?architecture=i386' > (last_xml_response/'hardware_profiles/hardware_profile').length.should > == 0 > get_auth_url > '/api;driver=openstack/hardware_profiles?architecture=x86_64' > - (last_xml_response/'hardware_profiles/hardware_profile').length.should > == 5 > + (last_xml_response/'hardware_profiles/hardware_profile').length.should > == @@no_of_profiles > end > > end > diff --git a/server/tests/drivers/openstack/images_test.rb > b/server/tests/drivers/openstack/images_test.rb > index 8b16f93..9b71653 100644 > --- a/server/tests/drivers/openstack/images_test.rb > +++ b/server/tests/drivers/openstack/images_test.rb > @@ -25,14 +25,15 @@ module OpenstackTest > (image/'architecture').should_not == nil > (image/'architecture').should_not == '' > (image/'state').text.should == 'ACTIVE' > - (image/'owner_id').text.should == ENV['API_USER'] > + ENV['API_USER'].include?((image/'owner_id').text).should == true > (image/'actions/link').length.should == 1 > (image/'actions/link').first[:rel].should == 'create_instance' > end > + @@image_id = ((last_xml_response/'images/image').first)[:id] > end > > def test_03_it_returns_single_image > - get_auth_url '/api;driver=openstack/images/1' > + get_auth_url "/api;driver=openstack/images/#{@@image_id}" > (last_xml_response/'image').length.should == 1 > end > > diff --git a/server/tests/drivers/openstack/instances_test.rb > b/server/tests/drivers/openstack/instances_test.rb > index 8020092..c2e2b76 100644 > --- a/server/tests/drivers/openstack/instances_test.rb > +++ b/server/tests/drivers/openstack/instances_test.rb > @@ -11,35 +11,43 @@ module OpenstackTest > end > > def test_01_01_it_can_create_instance_without_hardware_profile > + get_auth_url '/api;driver=openstack/images' > + @@image_id = ((last_xml_response/'images/image').first)[:id] > params = { > - :image_id => '4', > + :image_id => @@image_id, > :'api[driver]' => 'openstack', > } > - post_url '/api/instances', params > + uri = '/api/instances' > + vcr_cassette = stable_vcr_cassette_name('post', uri, params) > + post_url uri, params, {'vcr_cassette'=>vcr_cassette} > last_response.status.should == 201 # Created > @@instance = last_xml_response > (@@instance/'instance').length.should > 0 > (@@instance/'instance/name').first.text.should_not == nil > (@@instance/'instance/name').first.text.should_not == nil > (@@instance/'instance/owner_id').first.text.should_not == '' > - (@@instance/'instance/owner_id').first.text.should == ENV['API_USER'] > + > ENV['API_USER'].include?((@@instance/'instance/owner_id').first.text).should > == true > (@@instance/'instance/state').first.text.should == 'PENDING' > end > > def test_01_02_it_can_create_instance_with_hardware_profile > + get_auth_url '/api;driver=openstack/hardware_profiles' > + @@hwp_id = > ((last_xml_response/'hardware_profiles/hardware_profile').first)[:id] > params = { > - :image_id => '4', > - :hwp_id => '2', > + :image_id => @@image_id, > + :hwp_id => @@hwp_id, > :'api[driver]' => 'openstack', > } > - post_url '/api/instances', params > + uri = '/api/instances' > + vcr_cassette = stable_vcr_cassette_name('post', uri, params) > + post_url uri, params, {'vcr_cassette'=>vcr_cassette} > last_response.status.should == 201 # Created > @@instance2 = last_xml_response > (@@instance2/'instance').length.should > 0 > (@@instance2/'instance/name').first.text.should_not == nil > (@@instance2/'instance/name').first.text.should_not == nil > (@@instance2/'instance/owner_id').first.text.should_not == '' > - (@@instance2/'instance/owner_id').first.text.should == ENV['API_USER'] > + > ENV['API_USER'].include?((@@instance2/'instance/owner_id').first.text).should > == true > (@@instance2/'instance/state').first.text.should == 'PENDING' > end > > @@ -58,6 +66,7 @@ module OpenstackTest > > (@@instance2/'instance/authentication/login/password').first.text.should_not > == nil > > (@@instance2/'instance/authentication/login/password').first.text.should_not > == '' > end > + > =begin > TODO: Disabled since our testing setup doesn't return IP addresses yet ;-) > def test_03_01_created_instance_has_correct_addresses > @@ -75,7 +84,7 @@ module OpenstackTest > > def test_03_02_created_instance_has_correct_hardware_profile > (@@instance2/'instance/hardware_profile').length.should == 1 > - (@@instance2/'instance/hardware_profile').first[:id].should == "2" > + (@@instance2/'instance/hardware_profile').first[:id].should == @@hwp_id > (@@instance2/'instance/hardware_profile').first[:href].should_not == nil > end > > @@ -94,7 +103,6 @@ module OpenstackTest > > (last_xml_response/'instance/actions/link[@rel="reboot"]').first.should_not > == nil > > (last_xml_response/'instance/actions/link[@rel="stop"]').first.should_not == > nil > > (last_xml_response/'instance/actions/link[@rel="create_image"]').first.should_not > == nil > - > (last_xml_response/'instance/actions/link[@rel="run"]').first.should_not == > nil > end > > def test_04_02_created_instance_goes_to_running_state > @@ -112,7 +120,6 @@ module OpenstackTest > > (last_xml_response/'instance/actions/link[@rel="reboot"]').first.should_not > == nil > > (last_xml_response/'instance/actions/link[@rel="stop"]').first.should_not == > nil > > (last_xml_response/'instance/actions/link[@rel="create_image"]').first.should_not > == nil > - > (last_xml_response/'instance/actions/link[@rel="run"]').first.should_not == > nil > end > > def test_05_01_created_instance_can_be_rebooted > @@ -120,7 +127,7 @@ module OpenstackTest > :'api[driver]' => 'openstack', > } > post_url "/api/instances/#{(@@instance/'instance').first[:id]}/reboot", > params > - last_response.status.should == 200 > + last_response.status.should == 202 > 20.times do |tick| > get_auth_url > "/api;driver=openstack/instances/#{(@@instance/'instance').first[:id]}", { > :tick => tick} > last_response.status.should_not == 500 > @@ -130,7 +137,31 @@ module OpenstackTest > end > end > > + def test_05_02_created_instance_can_be_rebooted > + params = { > + :'api[driver]' => 'openstack', > + } > + post_url > "/api/instances/#{(@@instance2/'instance').first[:id]}/reboot", params > + last_response.status.should == 202 > + 20.times do |tick| > + get_auth_url > "/api;driver=openstack/instances/#{(@@instance2/'instance').first[:id]}", { > :tick => tick} > + last_response.status.should_not == 500 > + state = (last_xml_response/'instance/state').first.text > + break if state=='RUNNING' > + sleep(5) > + end > + end > + > def test_06_01_created_instance_can_be_destroyed > + #first make sure we recovered from the reboot > + 20.times do |tick| > + get_auth_url > "/api;driver=openstack/instances/#{(@@instance/'instance').first[:id]}", { > :tick => tick} > + last_response.status.should_not == 500 > + state = (last_xml_response/'instance/state').first.text > + break if state=='RUNNING' > + sleep(5) > + end > + #now destroy > params = { > :'api[driver]' => 'openstack', > } > @@ -146,10 +177,19 @@ module OpenstackTest > end > > def test_06_02_created_instance_can_be_destroyed > + #first make sure we recovered from the reboot > + 20.times do |tick| > + get_auth_url > "/api;driver=openstack/instances/#{(@@instance2/'instance').first[:id]}", { > :tick => tick} > + last_response.status.should_not == 500 > + state = (last_xml_response/'instance/state').first.text > + break if state=='RUNNING' > + sleep(5) > + end > + #now destroy > params = { > :'api[driver]' => 'openstack', > } > - post_url "/api/instances/#{(@@instance2/'instance').first[:id]}/stop", > params, authenticate > + post_url "/api/instances/#{(@@instance2/'instance').first[:id]}/stop", > params > last_response.status.should == 200 > 20.times do |tick| > get_auth_url > "/api;driver=openstack/instances/#{(@@instance2/'instance').first[:id]}", { > :tick => tick} > diff --git a/server/tests/drivers/openstack/realms_test.rb > b/server/tests/drivers/openstack/realms_test.rb > index 7929099..f62a6f9 100644 > --- a/server/tests/drivers/openstack/realms_test.rb > +++ b/server/tests/drivers/openstack/realms_test.rb > @@ -12,7 +12,7 @@ module OpenstackTest > > def test_01_it_returns_realms > get_auth_url '/api;driver=openstack/realms' > - (last_xml_response/'realms/realm').length.should == 1 > + (last_xml_response/'realms/realm').length.should > 0 > end > > def test_02_each_realm_has_a_name > @@ -20,16 +20,15 @@ module OpenstackTest > (last_xml_response/'realms/realm').each do |profile| > (profile/'name').text.should_not == nil > (profile/'name').text.should_not == '' > - (profile/'name').text.should == 'United States' > + (profile/'name').text.should == 'default' > end > end > > def test_03_it_returns_single_realm > get_auth_url '/api;driver=openstack/realms/us' > - (last_xml_response/'realm').first[:id].should == 'us' > - (last_xml_response/'realm/name').first.text.should == 'United States' > + (last_xml_response/'realm').first[:id].should == 'default' > + (last_xml_response/'realm/name').first.text.should == 'default' > (last_xml_response/'realm/state').first.text.should == 'AVAILABLE' > - (last_xml_response/'realm/limit').first.text.should == '' > end > > end > diff --git a/server/tests/drivers/openstack/setup.rb > b/server/tests/drivers/openstack/setup.rb > index 3e3645a..b9e1ca0 100644 > --- a/server/tests/drivers/openstack/setup.rb > +++ b/server/tests/drivers/openstack/setup.rb > @@ -1,8 +1,8 @@ > ENV.delete 'API_VERBOSE' > ENV['API_DRIVER'] = "openstack" > -ENV['API_USER'] = 'mfojtik' > -ENV['API_PASSWORD'] = 'test' > -ENV['API_PROVIDER'] = 'http://mfojtik-2.brq.redhat.com:8774/auth/1.1' > +ENV['API_USER'] = '[email protected][email protected]' > +ENV['API_PASSWORD'] = 'Not_a_real_password!1' > +ENV['API_PROVIDER'] = > 'https://region-a.geo-1.identity.hpcloudsvc.com:35357/v2.0/' > > require 'vcr' > DeltacloudTestCommon::record! > -- > 1.7.6.5 >
