Skip to content
This repository
tree: c9836cff2c
Fetching contributors…

Cannot retrieve contributors at this time

file 61 lines (50 sloc) 2.416 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
# Copyright (c) 2009-2012 VMware, Inc.

require File.dirname(__FILE__) + '/../../../spec_helper'

Bosh::Agent::Infrastructure.new("aws").infrastructure

describe Bosh::Agent::Infrastructure::Aws::Settings do
  before(:all) do
    @test_authorized_dir = Dir.mktmpdir
    @test_authorized_keys = File.join(@test_authorized_dir, "test_auth")
  end

  before(:each) do
    Bosh::Agent::Config.settings_file = File.join(base_dir, 'settings.json')
    @settings = {"vm" => "test_vm", "disks" => "test_disks"}
  end

  it 'should load settings' do
    Bosh::Agent::Infrastructure::Aws::Registry.stub(:get_settings).and_return(@settings)
    Bosh::Agent::Infrastructure::Aws::Registry.stub(:get_openssh_key).and_return("test_key")
    settings_wrapper = Bosh::Agent::Infrastructure::Aws::Settings.new
    settings_wrapper.stub(:authorized_keys).and_return(@test_authorized_keys)
    settings = settings_wrapper.load_settings
    settings.should == @settings
  end

  it 'should get network settings for dhcp network' do
    settings_wrapper = Bosh::Agent::Infrastructure::Aws::Settings.new
    network_properties = {"type" => "dynamic"}
    properties = settings_wrapper.get_network_settings("test", network_properties)

    properties.should have_key("ip")
    properties.should have_key("netmask")
    properties.should have_key("dns")
    properties.should have_key("gateway")
  end

  it 'should get nothing for vip network' do
    settings_wrapper = Bosh::Agent::Infrastructure::Aws::Settings.new
    network_properties = {"type" => "vip"}
    properties = settings_wrapper.get_network_settings("test", network_properties)
    properties.should be_nil
  end

  it 'should raise unsupported network exception for manual network' do
    settings_wrapper = Bosh::Agent::Infrastructure::Aws::Settings.new
    network_properties = {}
    lambda {
      properties = settings_wrapper.get_network_settings("test", network_properties)
    }.should raise_error(Bosh::Agent::StateError, /Unsupported network/)
  end

  it 'should setup the ssh public key' do
    Bosh::Agent::Infrastructure::Aws::Registry.stub!(:get_openssh_key).and_return("test_key")
    settings_wrapper = Bosh::Agent::Infrastructure::Aws::Settings.new
    settings_wrapper.stub(:authorized_keys).and_return(@test_authorized_keys)
    settings_wrapper.setup_openssh_key
    File.open(@test_authorized_keys, "r") { |f| f.read.should == "test_key" }
  end

end
Something went wrong with that request. Please try again.