1
0
Fork 0
mirror of https://github.com/fog/fog.git synced 2022-11-09 13:51:43 -05:00

[Vcloud] Bugfixes wrt Internet Service RedirectURL

This commit is contained in:
freeformz 2010-06-30 01:53:09 +08:00 committed by Wesley Beary
parent 69a5140472
commit 721319e07b
8 changed files with 100 additions and 50 deletions

View file

@ -85,16 +85,20 @@ module Fog
:href => extension_url + "/publicIp/51",
:name => "99.1.2.3",
:services => [
{ :id => "71", :port => "80", :protocol => 'HTTP', :enabled => "true", :timeout => "2", :name => 'Web Site', :description => 'Web Servers' },
{ :id => "72", :port => "7000", :protocol => 'HTTP', :enabled => "true", :timeout => "2", :name => 'An SSH Map', :description => 'SSH 1' }
{ :id => "71", :port => "80", :protocol => 'HTTP', :enabled => "true", :timeout => "2", :name => 'Web Site',
:description => 'Web Servers', :redirect_url => 'http://fakey.com' },
{ :id => "72", :port => "7000", :protocol => 'HTTP', :enabled => "true", :timeout => "2", :name => 'An SSH Map',
:description => 'SSH 1', :redirect_url => '' }
]
},
{ :id => "52",
:href => extension_url + "/publicIp/52",
:name => "99.1.2.4",
:services => [
{ :id => "73", :port => "80", :protocol => 'HTTP', :enabled => "true", :timeout => "2", :name => 'Web Site', :description => 'Web Servers' },
{ :id => "74", :port => "7000", :protocol => 'HTTP', :enabled => "true", :timeout => "2", :name => 'An SSH Map', :description => 'SSH 2' }
{ :id => "73", :port => "80", :protocol => 'HTTP', :enabled => "true", :timeout => "2", :name => 'Web Site',
:description => 'Web Servers', :redirect_url => 'http://fakey.com' },
{ :id => "74", :port => "7000", :protocol => 'HTTP', :enabled => "true", :timeout => "2", :name => 'An SSH Map',
:description => 'SSH 2', :redirect_url => '' }
]
},
{ :id => "53",

View file

@ -14,7 +14,7 @@ module Fog
builder.Port(service_data[:port])
builder.Enabled(service_data[:enabled])
builder.Description(service_data[:description])
builder.RedirectUrl(service_data[:redirect_url])
builder.RedirectURL(service_data[:redirect_url])
#builder.Monitor {
# builder.MonitorType {}
# builder.UrlSendString {}

View file

@ -4,7 +4,7 @@ module Fog
module Ecloud
module Real
def generate_configure_internet_service_request(service_data,ip_address_data)
def generate_configure_internet_service_response(service_data,ip_address_data)
builder = Builder::XmlMarkup.new
builder.InternetService(:"xmlns:i" => "http://www.w3.org/2001/XMLSchema-instance",
:xmlns => "urn:tmrk:eCloudExtensions-2.3") {
@ -38,7 +38,7 @@ module Fog
validate_public_ip_address_data(ip_address_data)
request(
:body => generate_configure_internet_service_request(service_data, ip_address_data),
:body => generate_configure_internet_service_response(service_data, ip_address_data),
:expects => 200,
:headers => {'Content-Type' => 'application/vnd.tmrk.ecloud.internetService+xml'},
:method => 'PUT',
@ -62,33 +62,16 @@ module Fog
internet_service_uri = ensure_unparsed(internet_service_uri)
found = false
xml = nil
if ip = ip_from_uri(ip_address_data[:href])
if service = ip[:services].detect { |service| service[:id] == internet_service_uri.split('/')[-1] }
found = true
ip[:services][ip[:services].index(service)] = service_data
builder = Builder::XmlMarkup.new
xml = builder.InternetService(:xmlns => "urn:tmrk:eCloudExtensions-2.0",
:"xmlns:i" => "http://www.w3.org/2001/XMLSchema-instance") {
builder.Id(service_data[:id])
builder.Href(Fog::Vcloud::Terremark::Ecloud::Mock.internet_service_href(service_data))
builder.Name(service_data[:name])
builder.PublicIpAddress {
builder.Id(ip[:id])
builder.Href(Fog::Vcloud::Terremark::Ecloud::Mock.public_ip_href(ip))
builder.Name(ip[:name])
}
builder.Protocol(service_data[:protocol])
builder.Port(service_data[:port])
builder.Enabled(service_data[:enabled])
builder.Description(service_data[:description])
builder.Timeout(service_data[:timeout])
}
xml = generate_configure_internet_service_response(service_data, ip)
end
end
if found
if xml
mock_it 200, xml, {'Content-Type' => 'application/vnd.tmrk.ecloud.internetService+xml'}
else
mock_error 200, "401 Unauthorized"

View file

@ -31,7 +31,7 @@ module Fog
xml.Enabled(service[:enabled])
xml.Timeout(service[:timeout])
xml.Description(service[:description])
xml.RedirectURL
xml.RedirectURL(service[:redirect_url])
xml.Monitor
}
end

View file

@ -226,10 +226,12 @@ Spec::Runner.configure do |config|
config.before(:all, :type => :mock_tmrk_ecloud_request) do
@base_url = Fog::Vcloud::Terremark::Ecloud::Mock.base_url
@mock_data = Fog::Vcloud::Terremark::Ecloud::Mock.data
@mock_version = @mock_data[:versions][0]
@mock_organization = @mock_data[:organizations][0]
@mock_vdc = @mock_organization[:vdcs][0]
@mock_network = @mock_vdc[:networks][0]
@mock_version = @mock_data[:versions].first
@mock_organization = @mock_data[:organizations].first
@mock_vdc = @mock_organization[:vdcs].first
@mock_public_ip = @mock_vdc[:public_ips].first
@mock_service = @mock_public_ip[:services].first
@mock_network = @mock_vdc[:networks].first
end
config.after(:all, :type => :mock_tmrk_ecloud_request) do
Fog::Vcloud::Terremark::Ecloud::Mock.data_reset
@ -237,10 +239,12 @@ Spec::Runner.configure do |config|
config.before(:all, :type => :mock_tmrk_ecloud_model) do
@base_url = Fog::Vcloud::Terremark::Ecloud::Mock.base_url
@mock_data = Fog::Vcloud::Terremark::Ecloud::Mock.data
@mock_version = @mock_data[:versions][0]
@mock_organization = @mock_data[:organizations][0]
@mock_vdc = @mock_organization[:vdcs][0]
@mock_network = @mock_vdc[:networks][0]
@mock_version = @mock_data[:versions].first
@mock_organization = @mock_data[:organizations].first
@mock_vdc = @mock_organization[:vdcs].first
@mock_public_ip = @mock_vdc[:public_ips].first
@mock_service = @mock_public_ip[:services].first
@mock_network = @mock_vdc[:networks].first
end
config.before(:each, :type => :mock_tmrk_ecloud_model) do
@vcloud = Fog::Vcloud.new(:username => "foo", :password => "bar", :versions_uri => "http://fakey.com/api/versions", :module => "Fog::Vcloud::Terremark::Ecloud")

View file

@ -3,8 +3,6 @@ require File.join(File.dirname(__FILE__),'..','..','..','spec_helper')
if Fog.mocking?
describe "Fog::Vcloud::Terremark::Ecloud::InternetService", :type => :mock_tmrk_ecloud_model do
before do
@mock_ip = @mock_vdc[:public_ips].first
@mock_service = @mock_ip[:services].first
@mock_service_uri = "#{@base_url}/extensions/internetService/#{@mock_service[:id]}"
end
@ -41,13 +39,13 @@ if Fog.mocking?
its(:identity) { should == @mock_service_uri }
its(:name) { should == @mock_service[:name] }
its(:id) { should == @mock_service[:id] }
its(:protocol) { should == "HTTP" }
its(:port) { should == "80" }
its(:enabled) { should == "true" }
its(:description) { should == "Web Servers" }
its(:protocol) { should == @mock_service[:protocol] }
its(:port) { should == @mock_service[:port] }
its(:enabled) { should == @mock_service[:enabled] }
its(:description) { should == @mock_service[:description] }
its(:public_ip) { should == public_ip }
its(:timeout) { should == "2" }
its(:redirect_url) { should == "" }
its(:timeout) { should == @mock_service[:timeout] }
its(:redirect_url) { should == @mock_service[:redirect_url] }
its(:monitor) { should == "" }
specify { composed_public_ip_data[:href].should == public_ip[:Href].to_s }

View file

@ -8,7 +8,7 @@ if Fog.mocking?
describe "#configure_internet_service" do
before do
@public_ip = @vcloud.vdcs[0].public_ips[0]
@public_ip = @vcloud.vdcs.first.public_ips.first
@original_service = @vcloud.get_internet_services(@public_ip.href).body[:InternetService].first
@ip_data = { :id => @public_ip.id, :name => @public_ip.name, :href => @public_ip.href.to_s }
@service_data = { :name => @original_service[:Name], :protocol => @original_service[:Protocol],
@ -26,12 +26,23 @@ if Fog.mocking?
context "with some changed data" do
before do
@service_data[:description] = "TEST BOOM"
@service_data[:redirect_url] = "http://google.com"
@service_data[:port] = "80"
end
it "should change data" do
@original_service[:Description].should == "Web Servers"
@original_service[:Description].should == @mock_service[:description]
@original_service[:RedirectURL].should == @mock_service[:redirect_url]
@original_service[:Port].should == @mock_service[:port]
result = subject
result.body[:Description].should == "TEST BOOM"
@vcloud.get_internet_services(@public_ip.href).body[:InternetService].first[:Description].should == "TEST BOOM"
result.body[:Description].should == @service_data[:description]
result.body[:RedirectURL].should == @service_data[:redirect_url]
result.body[:Port].should == @service_data[:port]
new_result = @vcloud.get_internet_services(@public_ip.href).body[:InternetService].first
new_result[:Description].should == @service_data[:description]
new_result[:RedirectURL].should == @service_data[:redirect_url]
new_result[:Port].should == @service_data[:port]
end
end

View file

@ -47,7 +47,57 @@ if Fog.mocking?
specify { service[:Enabled].should == mock_service[:enabled] }
specify { service[:Timeout].should == mock_service[:timeout] }
specify { service[:Description].should == mock_service[:description] }
specify { service[:RedirectURL].should == "" }
specify { service[:RedirectURL].should == mock_service[:redirect_url] }
specify { service[:Monitor].should == "" }
end
end
end
end
context "with a valid Public IP uri" do
before do
@mock_public_ip = @mock_vdc[:public_ips].first
@services = @vcloud.get_internet_services( @mock_public_ip[:href] + "/internetServices" )
end
subject { @services }
it_should_behave_like "all responses"
it { should have_headers_denoting_a_content_type_of "application/vnd.tmrk.ecloud.internetServicesList+xml" }
describe "#body" do
subject { @services.body }
it { should have(3).items }
its(:xmlns) { should == "urn:tmrk:eCloudExtensions-2.3" }
its(:xmlns_i) { should == "http://www.w3.org/2001/XMLSchema-instance" }
context "[:InternetService]" do
subject { @services.body[:InternetService] }
it { should have(2).items }
[0,1].each do |idx|
let(:service) { subject[idx] }
let(:mock_service) { @mock_public_ip[:services][idx] }
let(:mock_ip) { @mock_public_ip }
specify { service.should be_an_instance_of Hash }
specify { service.should have(11).attributes }
specify { service[:Name].should == mock_service[:name] }
specify { service[:Id].should == mock_service[:id] }
specify { service[:Href].should == Fog::Vcloud::Terremark::Ecloud::Mock.internet_service_href(mock_service) }
specify { service[:PublicIpAddress].should be_an_instance_of Hash }
specify { service[:PublicIpAddress].should have(3).attributes }
specify { service[:PublicIpAddress][:Name].should == mock_ip[:name] }
specify { service[:PublicIpAddress][:Id].should == mock_ip[:id] }
specify { service[:Port].should == mock_service[:port] }
specify { service[:Protocol].should == mock_service[:protocol] }
specify { service[:Enabled].should == mock_service[:enabled] }
specify { service[:Timeout].should == mock_service[:timeout] }
specify { service[:Description].should == mock_service[:description] }
specify { service[:RedirectURL].should == mock_service[:redirect_url] }
specify { service[:Monitor].should == "" }
end
end