This repository has been archived by the owner on Nov 23, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #91 from alphagov/storage-profile-href
[#62454712] Storage profile should be provisioned using name only
- Loading branch information
Showing
8 changed files
with
257 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
module Vcloud | ||
VERSION = '0.6.0' | ||
VERSION = '0.7.0' | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
--- | ||
vapps: | ||
- name: <%= vapp_name_1 %> | ||
vdc_name: <%= vdc_name_1 %> | ||
catalog: <%= catalog %> | ||
catalog_item: <%= vapp_template %> | ||
vm: | ||
hardware_config: &hardware_config | ||
memory: 4096 | ||
cpu: 2 | ||
bootstrap: &bootstrap | ||
script_path: <%= bootstrap_script %> | ||
vars: | ||
message: hello world | ||
storage_profile: <%= storage_profile %> | ||
- name: <%= vapp_name_2 %> | ||
vdc_name: <%= vdc_name_2 %> | ||
catalog: <%= catalog %> | ||
catalog_item: <%= vapp_template %> | ||
vm: | ||
hardware_config: | ||
<<: *hardware_config | ||
bootstrap: | ||
<<: *bootstrap | ||
storage_profile: <%= storage_profile %> | ||
- name: <%= vapp_name_3 %> | ||
vdc_name: <%= vdc_name_1 %> | ||
catalog: <%= catalog %> | ||
catalog_item: <%= vapp_template %> | ||
vm: | ||
hardware_config: | ||
<<: *hardware_config | ||
metadata: | ||
storage_profile_test_vm: true | ||
bootstrap: | ||
<<: *bootstrap | ||
- name: <%= vapp_name_4 %> | ||
vdc_name: <%= vdc_name_1 %> | ||
catalog: <%= catalog %> | ||
catalog_item: <%= vapp_template %> | ||
vm: | ||
hardware_config: | ||
<<: *hardware_config | ||
metadata: | ||
storage_profile_test_vm: true | ||
bootstrap: | ||
<<: *bootstrap | ||
storage_profile: <%= nonsense_storage_profile %> |
113 changes: 113 additions & 0 deletions
113
spec/integration/launcher/storage_profile_integration_test.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
require 'spec_helper' | ||
|
||
describe Vcloud::Launch do | ||
context "storage profile" do | ||
before(:all) do | ||
@test_data = define_test_data | ||
@config_yaml = generate_input_yaml_config(@test_data, File.join(File.dirname(__FILE__), 'data/storage_profile.yaml.erb')) | ||
@fog_interface = Vcloud::Fog::ServiceInterface.new | ||
Vcloud::Launch.new.run(@config_yaml, {:no_power_on => true}) | ||
|
||
@vapp_query_result_1 = @fog_interface.get_vapp_by_name_and_vdc_name(@test_data[:vapp_name_1], @test_data[:vdc_name_1]) | ||
@vapp_id_1 = @vapp_query_result_1[:href].split('/').last | ||
@vapp_1 = @fog_interface.get_vapp @vapp_id_1 | ||
@vm_1 = @vapp_1[:Children][:Vm].first | ||
|
||
@vapp_query_result_2 = @fog_interface.get_vapp_by_name_and_vdc_name(@test_data[:vapp_name_2], @test_data[:vdc_name_2]) | ||
@vapp_id_2 = @vapp_query_result_2[:href].split('/').last | ||
@vapp_2 = @fog_interface.get_vapp @vapp_id_2 | ||
@vm_2 = @vapp_2[:Children][:Vm].first | ||
|
||
@vapp_query_result_3 = @fog_interface.get_vapp_by_name_and_vdc_name(@test_data[:vapp_name_3], @test_data[:vdc_name_1]) | ||
@vapp_id_3 = @vapp_query_result_3[:href].split('/').last | ||
@vapp_3 = @fog_interface.get_vapp @vapp_id_3 | ||
@vm_3 = @vapp_3[:Children][:Vm].first | ||
|
||
@vapp_query_result_4 = @fog_interface.get_vapp_by_name_and_vdc_name(@test_data[:vapp_name_4], @test_data[:vdc_name_1]) | ||
@vapp_id_4 = @vapp_query_result_4[:href].split('/').last | ||
@vapp_4 = @fog_interface.get_vapp @vapp_id_4 | ||
@vm_4 = @vapp_4[:Children][:Vm].first | ||
end | ||
|
||
it "vdc 1 should have a storage profile without the href being specified" do | ||
@vm_1[:StorageProfile][:name].should == @test_data[:storage_profile] | ||
end | ||
|
||
it "vdc 1's storage profile should have the expected href" do | ||
@vm_1[:StorageProfile][:href].should == @test_data[:vdc_1_sp_href] | ||
end | ||
|
||
it "vdc 2 should have the same named storage profile as vdc 1" do | ||
@vm_2[:StorageProfile][:name].should == @test_data[:storage_profile] | ||
end | ||
|
||
it "the storage profile in vdc 2 should have a different href to the storage profile in vdc 1" do | ||
@vm_2[:StorageProfile][:href].should == @test_data[:vdc_2_sp_href] | ||
end | ||
|
||
it "when a storage profile is not specified, vm uses the default and continues" do | ||
@vm_3[:StorageProfile][:name].should == @test_data[:default_storage_profile_name] | ||
@vm_3[:StorageProfile][:href].should == @test_data[:default_storage_profile_href] | ||
end | ||
|
||
it "when a storage profile is not specified, customize continues with other customizations" do | ||
@vm_3_id = @vm_3[:href].split('/').last | ||
@vm_3_metadata = Vcloud::Core::Vm.get_metadata @vm_3_id | ||
@vm_3_metadata[:storage_profile_test_vm].should == true | ||
end | ||
|
||
it "when a storage profile specified does not exist, vm uses the default" do | ||
@vm_4[:StorageProfile][:name].should == @test_data[:default_storage_profile_name] | ||
@vm_4[:StorageProfile][:href].should == @test_data[:default_storage_profile_href] | ||
end | ||
|
||
# This is a bug - if it has failed customization it should let the user know | ||
it "when storage profile specified doesn't exist, it errors and continues" do | ||
@vm_4_id = @vm_4[:href].split('/').last | ||
@vm_4_metadata = Vcloud::Core::Vm.get_metadata @vm_4_id | ||
@vm_4_metadata[:storage_profile_test_vm].should be_nil | ||
end | ||
|
||
after(:all) do | ||
unless ENV['VCLOUD_TOOLS_RSPEC_NO_DELETE_VAPP'] | ||
File.delete @config_yaml | ||
@fog_interface.delete_vapp(@vapp_id_1).should == true | ||
@fog_interface.delete_vapp(@vapp_id_2).should == true | ||
@fog_interface.delete_vapp(@vapp_id_3).should == true | ||
@fog_interface.delete_vapp(@vapp_id_4).should == true | ||
end | ||
end | ||
|
||
end | ||
|
||
end | ||
|
||
def generate_input_yaml_config test_namespace, input_erb_config | ||
input_erb_config = input_erb_config | ||
e = ERB.new(File.open(input_erb_config).read) | ||
output_yaml_config = File.join(File.dirname(input_erb_config), "output_#{Time.now.strftime('%s')}.yaml") | ||
File.open(output_yaml_config, 'w') { |f| | ||
f.write e.result(OpenStruct.new(test_namespace).instance_eval { binding }) | ||
} | ||
output_yaml_config | ||
end | ||
|
||
def define_test_data | ||
{ | ||
vapp_name_1: "vdc-1-sp-#{Time.now.strftime('%s')}", | ||
vapp_name_2: "vdc-2-sp-#{Time.now.strftime('%s')}", | ||
vapp_name_3: "vdc-3-sp-#{Time.now.strftime('%s')}", | ||
vapp_name_4: "vdc-4-sp-#{Time.now.strftime('%s')}", | ||
vdc_name_1: ENV['VDC_NAME_1'], | ||
vdc_name_2: ENV['VDC_NAME_2'], | ||
catalog: ENV['VCLOUD_CATALOG_NAME'], | ||
vapp_template: ENV['VCLOUD_TEMPLATE_NAME'], | ||
storage_profile: ENV['VCLOUD_STORAGE_PROFILE_NAME'], | ||
vdc_1_sp_href: ENV['VDC_1_STORAGE_PROFILE_HREF'], | ||
vdc_2_sp_href: ENV['VDC_2_STORAGE_PROFILE_HREF'], | ||
default_storage_profile_name: ENV['DEFAULT_STORAGE_PROFILE_NAME'], | ||
default_storage_profile_href: ENV['DEFAULT_STORAGE_PROFILE_HREF'], | ||
nonsense_storage_profile: "nonsense-storage-profile-name", | ||
bootstrap_script: File.join(File.dirname(__FILE__), "data/basic_preamble_test.erb"), | ||
} | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters