Hi Chip, fun ! The fact that you don't have a provider at the point where you print it, isn't an issue; what you pass into Deltacloud::new (defined on line 127 in lib/deltacloud/api.rb) is an options hash, which contains user/password for credentials, but also the provider.
The provider does not wind up in the credentials, but in Thread.current[:provider], which you should access within your driver by calling api_provider (lib/deltacloud/drivers/base_driver.rb:278) It seems this needs slightly better docs :( Also, to keep credentials and the like out of the code that will get checked in, you should create a file ${HOME}/.deltacloud/config and put the following in it (it's a YAML file): cloudstack: user: USERNAME password: PASSWORD provider: SOME_URL mock: user: mockuser password: mockpassword provider: compute (you can put more credentials in there for ec2 etc.) In your test, load the credentials for your driver with Deltacloud::Test::config.credentials("cloudstack") (tests/test_helper.rb:81) - actually, I see it doesn't pull out the provider from the config file; it would actually be a good idea to add a method driver to Deltacloud::Test::Config: def driver(name) params = @hash[name.to_s] raise "No config for driver #{name}" unless params Deltacloud::new(name, params) end so that you can just say 'driver = Deltacloud::Test::config.driver(:cloudstack)' in your tests and get a driver that is setup according to your ~/.deltacloud/config. David On Fri, 2013-02-08 at 16:15 -0500, Chip Childers wrote: > Hi all, > > I'm getting through some of the basic plumbing for the CloudStack > driver, and have been battling something that's probably dead simple for > those of you in the know. It's also possible that my lack of ruby experience > is a contributing factor in this... ;-) > > Within my unit tests, I need to be able to set the API URL to talk to (I > know this isn't the right way to do a pure unit test, but I need to > bootstrap my work). > > Here's the test code: > > require 'rubygems' > > require 'require_relative' if RUBY_VERSION < '1.9' > > > > require_relative 'common' > > > > describe 'CloudStack Instances' do > > > > def credentials > > { > > :user => > 'yy0sfCPpyKnvREhgpeIWzXORIIvyteq_iCgFpKXnqpdbnHuoYiK78nprSggG4hcx-hxwW897nU-XvGB0Tq8YFw', > > :password => > 'Pse4fqYNnr1xvoRXlAe8NQKCSXeK_VGdwUxUzyLEPVQ7B3cI1Q7B8jmZ42FQpz2jIICFax1foIzg2716lJFZVw' > , > > :provider => 'http://192.168.56.10:8080/client/api/' > > } > > end > > > > before do > > @driver = Deltacloud::new(:cloudstack, credentials) > > end > > > > it 'must return list of instances' do > > @driver.instances.wont_be_empty > > @driver.instances.first.must_be_kind_of Instance > > end > > > > end > > And here's the relevant method of the driver where I'm attempting to access > credentials.provider: > > > > def new_client(credentials) > > safely do > > if credentials.user.empty? > > raise AuthenticationFailure.new(Exception.new("Error: you must supply > your CloudStack API key as your username")) > end > > if credentials.password.empty? > > raise AuthenticationFailure.new(Exception.new("Error: you must supply > your CloudStack Secret key as your password")) > end > > puts credentials.to_s > > return CloudstackRubyClient::Client.new(credentials.provider, > credentials.user, credentials.password, false) > end > > end > > When I run the tests, I get the following exception: > > CloudStack Instances > #<OpenStruct > user="yy0sfCPpyKnvREhgpeIWzXORIIvyteq_iCgFpKXnqpdbnHuoYiK78nprSggG4hcx-hxwW897nU-XvGB0Tq8YFw > ", > password="Pse4fqYNnr1xvoRXlAe8NQKCSXeK_VGdwUxUzyLEPVQ7B3cI1Q7B8jmZ42FQpz2jIICFax1foIzg2716lJFZVw"> > ERROR (0:00:00.238) test_0001_must return list of instances > undefined method `request_uri' for #<URI::Generic:0x007ffbca4316b0> > @ > /Users/chip.childers/.rvm/gems/ruby-1.9.2-p320/gems/cloudstack_ruby_client-0.0.2/lib/cloudstack > _ruby_client/base_client.rb:37:in `request' > > /Users/chip.childers/.rvm/gems/ruby-1.9.2-p320/gems/cloudstack_ruby_client-0.0.2/lib/cloudstack > _ruby_client/client.rb:1242:in `listVirtualMachines' > lib/deltacloud/drivers/cloudstack/cloudstack_driver.rb:140:in > `instances' > lib/deltacloud/api.rb:118:in `method_missing' > tests/drivers/cloudstack/instances_test.rb:21:in `block (2 levels) > in <top (required)>' > > > Note the output of the puts debug statement before the ERROR report. > credentials.provider seems to be lost. > > Any advice? > > Thanks in advance for any help you can provide. > > -chip > >