Commit e9a5da45 authored by Colin Obyrne's avatar Colin Obyrne

Adds unit coverage for deployments with cloud configs

- DeploymentSpecParser specs use cloud configs and have less of their
  constructed objects mocked
- Adds machinist blueprint for CloudConfig to enable testing with real
  CloudConfig objects.
[#91451310]
Signed-off-by: default avatarJonathan Barnes <jbarnes@pivotal.io>
parent ca371f1d
......@@ -6,6 +6,10 @@ module Bosh
self.created_at ||= Time.now
end
def manifest=(cloud_config_hash)
self.properties = Psych.dump(cloud_config_hash)
end
def manifest
Psych.load properties
end
......
# Copyright (c) 2009-2012 VMware, Inc.
require_relative '../../spec/support/deployments'
Sham.define do
name { |index| "name-#{index}" }
......@@ -131,27 +132,29 @@ module Bosh::Director::Models
content_sha1 { Sham.sha1 }
created_at { Time.now }
end
end
module Bosh::Director::Models::Dns
Domain.blueprint do
name { Sham.name }
type { "NATIVE" }
CloudConfig.blueprint do
manifest { Bosh::Spec::Deployments.simple_cloud_config }
end
Record.blueprint do
domain { Domain.make }
name { Sham.name }
type { "A" }
content { Sham.ip }
end
module Dns
Domain.blueprint do
name { Sham.name }
type { "NATIVE" }
end
Record.blueprint(:PTR) do
domain { Domain.make }
name { Sham.ptr }
type { "PTR" }
content { Sham.name }
end
Record.blueprint do
domain { Domain.make }
name { Sham.name }
type { "A" }
content { Sham.ip }
end
Record.blueprint(:PTR) do
domain { Domain.make }
name { Sham.ptr }
type { "PTR" }
content { Sham.name }
end
end
end
......@@ -143,9 +143,8 @@ module Bosh::Director
stemcell_1_2 = Models::Stemcell.create(name: "stemcell-1", version: 2, cid: 123)
stemcell_2_1 = Models::Stemcell.create(name: "stemcell-2", version: 1, cid: 124)
old_cloud_config = Models::CloudConfig.create(properties: "", created_at: Time.now - 60)
new_cloud_config = Models::CloudConfig.create(properties: "", created_at: Time.now)
old_cloud_config = Models::CloudConfig.make(manifest: {}, created_at: Time.now - 60)
new_cloud_config = Models::CloudConfig.make(manifest: {})
deployment_3 = Models::Deployment.create(
name: "deployment-3",
......@@ -422,7 +421,7 @@ module Bosh::Director
cloud_config: cloud_config
)
end
let(:cloud_config) { Models::CloudConfig.create }
let(:cloud_config) { Models::CloudConfig.make }
before { allow(Config).to receive(:event_log).with(no_args).and_return(event_log) }
let(:event_log) { instance_double('Bosh::Director::EventLog::Log') }
......
......@@ -180,7 +180,7 @@ module Bosh::Director
end
describe '#bind_idle_vm' do
let(:cloud_config){ Models::CloudConfig.create }
let(:cloud_config){ Models::CloudConfig.make }
let(:deployment_plan) { Planner.new('fake-deployment', '{"fake-manifest-text": true}', cloud_config) }
let(:state) { { 'state' => 'foo' } }
let(:network) { Network.new(deployment_plan, {'name' => resource_pool_manifest['network']}) }
......
......@@ -2,12 +2,13 @@ require 'spec_helper'
module Bosh::Director::Jobs
describe UpdateDeployment do
subject(:job) { UpdateDeployment.new(manifest_path, nil) }
subject(:job) { UpdateDeployment.new(manifest_path, cloud_config_id) }
let(:config) { Bosh::Director::Config.load_file(asset('test-director-config.yml'))}
let(:directory) { Support::FileHelpers::DeploymentDirectory.new }
let(:manifest_path) { directory.add_file('deployment.yml', manifest_content) }
let(:manifest_content) { Psych.dump ManifestHelper.default_legacy_manifest }
let(:cloud_config_id) { nil }
before do
allow(Bosh::Director::Config).to receive(:cloud) { instance_double(Bosh::Cloud) }
......@@ -41,6 +42,13 @@ module Bosh::Director::Jobs
expect(notifier).to receive(:send_end_event).ordered
end
context 'when a cloud_config is passed in' do
let(:cloud_config_id) { Bosh::Director::Models::CloudConfig.make.id }
it 'uses the cloud config' do
expect(job.perform).to eq("/deployments/deployment-name")
end
end
it 'performs an update' do
expect(job.perform).to eq("/deployments/deployment-name")
end
......@@ -51,8 +59,6 @@ module Bosh::Director::Jobs
end
end
it 'works with a cloud_config object passed in'
context 'when the first step fails' do
before do
expect(job).to receive(:with_deployment_lock).and_yield.ordered
......
......@@ -33,19 +33,30 @@ module Bosh::Spec
}],
}],
'resource_pools' => [{
'name' => 'a',
'size' => 3,
'cloud_properties' => {},
'network' => 'a',
'stemcell' => {
'name' => 'ubuntu-stemcell',
'version' => '1',
},
}]
'resource_pools' => [resource_pool]
})
end
def self.resource_pool
{
'name' => 'a',
'size' => 3,
'cloud_properties' => {},
'network' => 'a',
'stemcell' => {
'name' => 'ubuntu-stemcell',
'version' => '1',
},
}
end
def self.disk_pool
{
'name' => 'disk_a',
'disk_size' => 123
}
end
def self.minimal_manifest
{
'name' => 'minimal',
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment