Permalink
Browse files

expose new elements in VCAP_SERVICES

Exposes label, plan, provider, and version.

The expectation is that the cc sends the label in the legacy label format,
which is used as the key to the hash.  Label is set to the true raw label.

Change-Id: I2ee15cec5d431043a282f63fe62e6f123f57406a
  • Loading branch information...
1 parent f968481 commit 29ee69709bbb9488390266e5d696447ac5193389 @pbozeman pbozeman committed Sep 13, 2012
Showing with 59 additions and 1 deletion.
  1. +3 −1 lib/dea/agent.rb
  2. +56 −0 spec/unit/agent_spec.rb
View
@@ -1138,11 +1138,13 @@ def stage_app_dir(bits_file, bits_uri, sha1, tgz_file, instance_dir, runtime)
# The format used by VCAP_SERVICES
def create_services_for_env(services=[])
- whitelist = ['name', 'label', 'plan', 'tags', 'plan_option', 'credentials']
+ whitelist = ['name', 'plan', 'tags', 'plan_option', 'credentials', 'version', 'provider']
svcs_hash = {}
services.each do |svc|
svcs_hash[svc['label']] ||= []
svc_hash = {}
+ (raw_label, _) = svc['label'].split("-")
+ svc_hash['label'] = raw_label
whitelist.each {|k| svc_hash[k] = svc[k] if svc[k]}
svcs_hash[svc['label']] << svc_hash
end
View
@@ -150,6 +150,54 @@
end
end
+ describe '#setup_instance_env' do
+ before do
+ @instance = {
+ :droplet_id => "some_droplet_id",
+ :instance_id => "some_instance_id",
+ :instance_index => 9,
+ :name => "some_app_name",
+ :dir => "/some/dir",
+ :uris => ["http://app.apps.com"],
+ :version => "some_version",
+ :mem_quota => 1 * (1024*1024),
+ :disk_quota => 2 * (1024*1024),
+ :fds_quota => 11,
+ :state => :STARTING,
+ :start => Time.now,
+ :state_timestamp => Time.now.to_i,
+ :flapping => false,
+ :cc_partition => "some_partition"
+ }
+
+ @app_env = []
+
+ @services = [{ 'name' => "my-mongo",
+ 'label' => "mongodb-2.0",
+ 'vendor' => "my-mongo",
+ 'version' => "2.0",
+ 'plan' => "D100",
+ 'provider' => "core",
+ 'credentials' => { "a" => "b" }
+ }]
+ end
+
+ it 'should export the VCAP_SERVICES to the environment' do
+ agent = make_test_agent
+ env = agent.setup_instance_env(@instance, @app_env, @services)
+ v = find_env_var(env, "VCAP_SERVICES")
+ v.should_not be_nil
+ hash = Yajl::Parser.parse(eval(v))
+ hash.should have_key('mongodb-2.0')
+ svc = hash['mongodb-2.0'].first
+ svc['label'].should == 'mongodb'
+ svc['provider'].should == 'core'
+ svc['version'].should == '2.0'
+ svc['name'].should == 'my-mongo'
+ svc['plan'].should == 'D100'
+ end
+ end
+
def create_crashed_app(base_dir)
apps_dir = create_apps_dir(base_dir)
File.directory?(apps_dir).should be_true
@@ -189,4 +237,12 @@ def make_test_agent(overrides={})
config.update(overrides)
DEA::Agent.new(config)
end
+
+ def find_env_var(env, key)
+ env.each do |e|
+ (k, v) = e.split("=", 2)
+ return v if k == key
+ end
+ nil
+ end
end

0 comments on commit 29ee697

Please sign in to comment.