From eaff8be1811226c31a6f315c5a2998d63d5b85b5 Mon Sep 17 00:00:00 2001 From: geemus Date: Wed, 5 May 2010 13:39:41 -0700 Subject: [PATCH] update xml parsing to be more consistent, return nil instead of '' --- benchs/parse_vs_push.rb | 2 +- lib/fog/aws/parsers/ec2/describe_images.rb | 2 +- lib/fog/aws/parsers/ec2/describe_instances.rb | 2 +- lib/fog/aws/parsers/ec2/describe_security_groups.rb | 2 +- lib/fog/aws/parsers/ec2/describe_volumes.rb | 2 +- lib/fog/aws/parsers/ec2/get_console_output.rb | 4 +++- lib/fog/aws/parsers/ec2/run_instances.rb | 2 +- lib/fog/aws/parsers/ec2/terminate_instances.rb | 2 +- lib/fog/aws/parsers/elb/describe_load_balancers.rb | 2 +- lib/fog/parser.rb | 3 ++- lib/fog/terremark/parsers/shared/get_catalog.rb | 2 +- lib/fog/terremark/parsers/shared/get_catalog_item.rb | 2 +- .../parsers/shared/get_internet_services.rb | 2 +- lib/fog/terremark/parsers/shared/get_network_ips.rb | 4 ---- lib/fog/terremark/parsers/shared/get_organization.rb | 2 +- .../terremark/parsers/shared/get_organizations.rb | 2 +- lib/fog/terremark/parsers/shared/get_tasks_list.rb | 2 +- .../terremark/parsers/shared/get_vapp_template.rb | 2 +- lib/fog/terremark/parsers/shared/get_vdc.rb | 2 +- .../parsers/shared/instantiate_vapp_template.rb | 2 +- lib/fog/terremark/parsers/shared/internet_service.rb | 2 +- lib/fog/terremark/parsers/shared/network.rb | 2 +- lib/fog/terremark/parsers/shared/task.rb | 2 +- lib/fog/terremark/parsers/shared/vapp.rb | 2 +- spec/aws/requests/ec2/create_snapshot_spec.rb | 2 +- spec/aws/requests/ec2/create_volume_spec.rb | 2 +- spec/aws/requests/ec2/describe_instances_spec.rb | 9 +++++++-- spec/aws/requests/ec2/describe_volumes_spec.rb | 4 ++-- spec/aws/requests/ec2/get_console_output_spec.rb | 12 +++++++----- spec/aws/requests/ec2/run_instances_spec.rb | 6 +++--- 30 files changed, 47 insertions(+), 41 deletions(-) diff --git a/benchs/parse_vs_push.rb b/benchs/parse_vs_push.rb index eebfbd33fc..37d85e4754 100644 --- a/benchs/parse_vs_push.rb +++ b/benchs/parse_vs_push.rb @@ -20,7 +20,7 @@ def characters(string) end def start_element(name, attrs = []) - @value = '' + @value = nil end def end_element(name) diff --git a/lib/fog/aws/parsers/ec2/describe_images.rb b/lib/fog/aws/parsers/ec2/describe_images.rb index 38219e0de5..cf548a8f68 100644 --- a/lib/fog/aws/parsers/ec2/describe_images.rb +++ b/lib/fog/aws/parsers/ec2/describe_images.rb @@ -11,10 +11,10 @@ def reset end def start_element(name, attrs = []) + super if name == 'productCodes' @in_product_codes = true end - @value = '' end def end_element(name) diff --git a/lib/fog/aws/parsers/ec2/describe_instances.rb b/lib/fog/aws/parsers/ec2/describe_instances.rb index 7780eae1fd..d5ba7fa2a6 100644 --- a/lib/fog/aws/parsers/ec2/describe_instances.rb +++ b/lib/fog/aws/parsers/ec2/describe_instances.rb @@ -13,6 +13,7 @@ def reset end def start_element(name, attrs = []) + super case name when 'blockDeviceMapping' @in_block_device_mapping = true @@ -21,7 +22,6 @@ def start_element(name, attrs = []) when 'instancesSet' @in_instances_set = true end - @value = '' end def end_element(name) diff --git a/lib/fog/aws/parsers/ec2/describe_security_groups.rb b/lib/fog/aws/parsers/ec2/describe_security_groups.rb index 06163bb8dd..8e243d00b9 100644 --- a/lib/fog/aws/parsers/ec2/describe_security_groups.rb +++ b/lib/fog/aws/parsers/ec2/describe_security_groups.rb @@ -14,6 +14,7 @@ def reset end def start_element(name, attrs = []) + super if name == 'groups' @in_groups = true elsif name == 'ipPermissions' @@ -21,7 +22,6 @@ def start_element(name, attrs = []) elsif name == 'ipRanges' @in_ip_ranges = true end - @value = '' end def end_element(name) diff --git a/lib/fog/aws/parsers/ec2/describe_volumes.rb b/lib/fog/aws/parsers/ec2/describe_volumes.rb index 80d53122b5..998d603ceb 100644 --- a/lib/fog/aws/parsers/ec2/describe_volumes.rb +++ b/lib/fog/aws/parsers/ec2/describe_volumes.rb @@ -13,10 +13,10 @@ def reset end def start_element(name, attrs = []) + super if name == 'attachmentSet' @in_attachment_set = true end - @value = '' end def end_element(name) diff --git a/lib/fog/aws/parsers/ec2/get_console_output.rb b/lib/fog/aws/parsers/ec2/get_console_output.rb index 5366e919fb..2097fbe12c 100644 --- a/lib/fog/aws/parsers/ec2/get_console_output.rb +++ b/lib/fog/aws/parsers/ec2/get_console_output.rb @@ -14,7 +14,9 @@ def end_element(name) when 'instanceId', 'requestId' @response[name] = @value when 'output' - @response[name] = Base64.decode64(@value) + if @value + @response[name] = Base64.decode64(@value) + end when 'timestamp' @response[name] = Time.parse(@value) end diff --git a/lib/fog/aws/parsers/ec2/run_instances.rb b/lib/fog/aws/parsers/ec2/run_instances.rb index 2d6356ceb3..95de3c27fa 100644 --- a/lib/fog/aws/parsers/ec2/run_instances.rb +++ b/lib/fog/aws/parsers/ec2/run_instances.rb @@ -12,6 +12,7 @@ def reset end def start_element(name, attrs = []) + super case name when 'blockDeviceMapping' @in_block_device_mapping = true @@ -20,7 +21,6 @@ def start_element(name, attrs = []) when 'productCodes' @in_product_codes = true end - @value = '' end def end_element(name) diff --git a/lib/fog/aws/parsers/ec2/terminate_instances.rb b/lib/fog/aws/parsers/ec2/terminate_instances.rb index 584433d466..458392adec 100644 --- a/lib/fog/aws/parsers/ec2/terminate_instances.rb +++ b/lib/fog/aws/parsers/ec2/terminate_instances.rb @@ -11,12 +11,12 @@ def reset end def start_element(name, attrs = []) + super if name == 'previousState' @in_previous_state = true elsif name == 'currentState' @in_current_state = true end - @value = '' end def end_element(name) diff --git a/lib/fog/aws/parsers/elb/describe_load_balancers.rb b/lib/fog/aws/parsers/elb/describe_load_balancers.rb index 7814aee224..7778a6a087 100644 --- a/lib/fog/aws/parsers/elb/describe_load_balancers.rb +++ b/lib/fog/aws/parsers/elb/describe_load_balancers.rb @@ -13,6 +13,7 @@ def reset end def start_element(name, attrs = []) + super case name when 'ListenerDescriptions' @in_listeners = true @@ -29,7 +30,6 @@ def start_element(name, attrs = []) when 'AppCookieStickinessPolicies' @in_app_cookies = true end - @value = '' end def end_element(name) diff --git a/lib/fog/parser.rb b/lib/fog/parser.rb index eaaa4d96f6..f7cb154748 100644 --- a/lib/fog/parser.rb +++ b/lib/fog/parser.rb @@ -13,11 +13,12 @@ def reset end def characters(string) + @value ||= '' @value << string.strip end def start_element(name, attrs = []) - @value = '' + @value = nil end end diff --git a/lib/fog/terremark/parsers/shared/get_catalog.rb b/lib/fog/terremark/parsers/shared/get_catalog.rb index 4c6316b941..f426c31803 100644 --- a/lib/fog/terremark/parsers/shared/get_catalog.rb +++ b/lib/fog/terremark/parsers/shared/get_catalog.rb @@ -10,7 +10,7 @@ def reset end def start_element(name, attributes) - @value = '' + super case name when 'CatalogItem' catalog_item = {} diff --git a/lib/fog/terremark/parsers/shared/get_catalog_item.rb b/lib/fog/terremark/parsers/shared/get_catalog_item.rb index 6ff2d41d7f..b6effc249c 100644 --- a/lib/fog/terremark/parsers/shared/get_catalog_item.rb +++ b/lib/fog/terremark/parsers/shared/get_catalog_item.rb @@ -10,7 +10,7 @@ def reset end def start_element(name, attributes) - @value = '' + super case name when 'Entity' until attributes.empty? diff --git a/lib/fog/terremark/parsers/shared/get_internet_services.rb b/lib/fog/terremark/parsers/shared/get_internet_services.rb index 74f26f9473..1a03c61360 100644 --- a/lib/fog/terremark/parsers/shared/get_internet_services.rb +++ b/lib/fog/terremark/parsers/shared/get_internet_services.rb @@ -12,7 +12,7 @@ def reset end def start_element(name, attributes) - @value = '' + super case name when 'PublicIPAddress' @in_public_ip_address = true diff --git a/lib/fog/terremark/parsers/shared/get_network_ips.rb b/lib/fog/terremark/parsers/shared/get_network_ips.rb index 4ffaaf20ff..12e5970bf5 100644 --- a/lib/fog/terremark/parsers/shared/get_network_ips.rb +++ b/lib/fog/terremark/parsers/shared/get_network_ips.rb @@ -10,10 +10,6 @@ def reset @response = { 'IpAddresses' => [] } end - def start_element(name,attributes=[]) - @value = '' - end - def end_element(name) case name when 'Name', 'Status', 'Server' diff --git a/lib/fog/terremark/parsers/shared/get_organization.rb b/lib/fog/terremark/parsers/shared/get_organization.rb index 1a0d3875ee..33cf14c772 100644 --- a/lib/fog/terremark/parsers/shared/get_organization.rb +++ b/lib/fog/terremark/parsers/shared/get_organization.rb @@ -10,7 +10,7 @@ def reset end def start_element(name, attributes) - @value = '' + super case name when 'Link' link = {} diff --git a/lib/fog/terremark/parsers/shared/get_organizations.rb b/lib/fog/terremark/parsers/shared/get_organizations.rb index b71774f1ba..b0426f3d4c 100644 --- a/lib/fog/terremark/parsers/shared/get_organizations.rb +++ b/lib/fog/terremark/parsers/shared/get_organizations.rb @@ -10,7 +10,7 @@ def reset end def start_element(name, attributes) - @value = '' + super if name == 'Org' organization = {} until attributes.empty? diff --git a/lib/fog/terremark/parsers/shared/get_tasks_list.rb b/lib/fog/terremark/parsers/shared/get_tasks_list.rb index 9031bf9b96..4cffd45676 100644 --- a/lib/fog/terremark/parsers/shared/get_tasks_list.rb +++ b/lib/fog/terremark/parsers/shared/get_tasks_list.rb @@ -11,7 +11,7 @@ def reset end def start_element(name, attributes) - @value = '' + super case name when 'Owner', 'Result' data = {} diff --git a/lib/fog/terremark/parsers/shared/get_vapp_template.rb b/lib/fog/terremark/parsers/shared/get_vapp_template.rb index a5ccbcc085..0bda28b07b 100644 --- a/lib/fog/terremark/parsers/shared/get_vapp_template.rb +++ b/lib/fog/terremark/parsers/shared/get_vapp_template.rb @@ -10,7 +10,7 @@ def reset end def start_element(name, attributes) - @value = '' + super case name when 'Link' link = {} diff --git a/lib/fog/terremark/parsers/shared/get_vdc.rb b/lib/fog/terremark/parsers/shared/get_vdc.rb index 9ea29711af..f05d6a230d 100644 --- a/lib/fog/terremark/parsers/shared/get_vdc.rb +++ b/lib/fog/terremark/parsers/shared/get_vdc.rb @@ -26,7 +26,7 @@ def reset end def start_element(name, attributes) - @value = '' + super case name when 'Cpu' @in_cpu = true diff --git a/lib/fog/terremark/parsers/shared/instantiate_vapp_template.rb b/lib/fog/terremark/parsers/shared/instantiate_vapp_template.rb index 79b9ec7af9..1f27a600fc 100644 --- a/lib/fog/terremark/parsers/shared/instantiate_vapp_template.rb +++ b/lib/fog/terremark/parsers/shared/instantiate_vapp_template.rb @@ -11,7 +11,7 @@ def reset end def start_element(name, attributes) - @value = '' + super case name when 'Link' link = {} diff --git a/lib/fog/terremark/parsers/shared/internet_service.rb b/lib/fog/terremark/parsers/shared/internet_service.rb index 2e106baffe..86bc25f938 100644 --- a/lib/fog/terremark/parsers/shared/internet_service.rb +++ b/lib/fog/terremark/parsers/shared/internet_service.rb @@ -11,7 +11,7 @@ def reset end def start_element(name, attributes) - @value = '' + super case name when 'Href' data = {} diff --git a/lib/fog/terremark/parsers/shared/network.rb b/lib/fog/terremark/parsers/shared/network.rb index 575385a8c2..24f548156b 100644 --- a/lib/fog/terremark/parsers/shared/network.rb +++ b/lib/fog/terremark/parsers/shared/network.rb @@ -12,7 +12,7 @@ def reset end def start_element(name,attributes=[]) - @value = '' + super case name when "Network" until attributes.empty? diff --git a/lib/fog/terremark/parsers/shared/task.rb b/lib/fog/terremark/parsers/shared/task.rb index 74c0e7283c..464cdb5a27 100644 --- a/lib/fog/terremark/parsers/shared/task.rb +++ b/lib/fog/terremark/parsers/shared/task.rb @@ -10,7 +10,7 @@ def reset end def start_element(name, attributes) - @value = '' + super case name when 'Owner', 'Result' data = {} diff --git a/lib/fog/terremark/parsers/shared/vapp.rb b/lib/fog/terremark/parsers/shared/vapp.rb index bfe20a0855..aee6af9dbd 100644 --- a/lib/fog/terremark/parsers/shared/vapp.rb +++ b/lib/fog/terremark/parsers/shared/vapp.rb @@ -10,7 +10,7 @@ def reset end def start_element(name, attributes) - @value = '' + super case name when 'Link' link = {} diff --git a/spec/aws/requests/ec2/create_snapshot_spec.rb b/spec/aws/requests/ec2/create_snapshot_spec.rb index b46c5d26b4..4d21f97113 100644 --- a/spec/aws/requests/ec2/create_snapshot_spec.rb +++ b/spec/aws/requests/ec2/create_snapshot_spec.rb @@ -15,7 +15,7 @@ it "should return proper attributes" do actual = AWS[:ec2].create_snapshot(@volume_id) - actual.body['progress'].should be_a(String) + actual.body['progress'].should be_nil @snapshot_id = actual.body['snapshotId'] actual.body['snapshotId'].should be_a(String) actual.body['startTime'].should be_a(Time) diff --git a/spec/aws/requests/ec2/create_volume_spec.rb b/spec/aws/requests/ec2/create_volume_spec.rb index c40a99591a..0c633fa197 100644 --- a/spec/aws/requests/ec2/create_volume_spec.rb +++ b/spec/aws/requests/ec2/create_volume_spec.rb @@ -13,7 +13,7 @@ actual.body['createTime'].should be_a(Time) actual.body['requestId'].should be_a(String) actual.body['size'].should == 1 - actual.body['snapshotId'].should == '' + actual.body['snapshotId'].should be_nil actual.body['status'].should be_a(String) actual.body['volumeId'].should be_a(String) @volume_id = actual.body['volumeId'] diff --git a/spec/aws/requests/ec2/describe_instances_spec.rb b/spec/aws/requests/ec2/describe_instances_spec.rb index e7acdd620f..822bd294c7 100644 --- a/spec/aws/requests/ec2/describe_instances_spec.rb +++ b/spec/aws/requests/ec2/describe_instances_spec.rb @@ -7,6 +7,7 @@ run_instances = AWS[:ec2].run_instances(GENTOO_AMI, 1, 1).body @instance_id = run_instances['instancesSet'].first['instanceId'] @reservation_id = run_instances['reservationId'] + Fog.wait_for { AWS[:ec2].servers.get(@instance_id) } AWS[:ec2].servers.get(@instance_id).wait_for { ready? } end @@ -45,7 +46,9 @@ instance['productCodes'].should be_an(Array) instance['productCodes'].first.should be_a(String) if instance['productCodes'].first instance['ramdiskId'].should be_a(String) - instance['reason'].should be_a(String) + if instance['reason'] + instance['reason'].should be_a(String) + end # instance['rootDeviceName'].should be_a(String) instance['rootDeviceType'].should be_a(String) end @@ -81,7 +84,9 @@ instance['productCodes'].should be_an(Array) instance['productCodes'].first.should be_a(String) if instance['productCodes'].first instance['ramdiskId'].should be_a(String) - instance['reason'].should be_a(String) + if instance['reason'] + instance['reason'].should be_a(String) + end # instance['rootDeviceName'].should be_a(String) instance['rootDeviceType'].should be_a(String) end diff --git a/spec/aws/requests/ec2/describe_volumes_spec.rb b/spec/aws/requests/ec2/describe_volumes_spec.rb index 4af9a21ef6..178198d771 100644 --- a/spec/aws/requests/ec2/describe_volumes_spec.rb +++ b/spec/aws/requests/ec2/describe_volumes_spec.rb @@ -18,7 +18,7 @@ volume['availabilityZone'].should be_a(String) volume['createTime'].should be_a(Time) volume['size'].should == 1 - volume['snapshotId'].should == '' + volume['snapshotId'].should be_nil volume['status'].should be_a(String) volume['volumeId'].should == @volume_id volume['attachmentSet'].should == [] @@ -31,7 +31,7 @@ volume['availabilityZone'].should be_a(String) volume['createTime'].should be_a(Time) volume['size'].should == 1 - volume['snapshotId'].should == '' + volume['snapshotId'].should be_nil volume['status'].should be_a(String) volume['volumeId'].should == @volume_id volume['attachmentSet'].should == [] diff --git a/spec/aws/requests/ec2/get_console_output_spec.rb b/spec/aws/requests/ec2/get_console_output_spec.rb index 99eff2cac9..d5f8c688cb 100644 --- a/spec/aws/requests/ec2/get_console_output_spec.rb +++ b/spec/aws/requests/ec2/get_console_output_spec.rb @@ -13,11 +13,13 @@ end it "should return proper attributes" do - actual = AWS[:ec2].get_console_output(@instance_id) - actual.body['instanceId'].should be_a(String) - actual.body['output'].should be_a(String) - actual.body['requestId'].should be_a(String) - actual.body['timestamp'].should be_a(Time) + actual = AWS[:ec2].get_console_output(@instance_id).body + actual['instanceId'].should be_a(String) + if actual['output'] + actual['output'].should be_a(String) + end + actual['requestId'].should be_a(String) + actual['timestamp'].should be_a(Time) end end diff --git a/spec/aws/requests/ec2/run_instances_spec.rb b/spec/aws/requests/ec2/run_instances_spec.rb index 99d9633241..b4870b5799 100644 --- a/spec/aws/requests/ec2/run_instances_spec.rb +++ b/spec/aws/requests/ec2/run_instances_spec.rb @@ -18,7 +18,7 @@ instance['amiLaunchIndex'].should be_a(Integer) # instance['architecture'].should be_a(String) instance['blockDeviceMapping'].should be_an(Array) - instance['dnsName'].should be_a(String) + instance['dnsName'].should be_nil instance['imageId'].should be_a(String) instance['instanceId'].should be_a(String) instance['instanceState'].should be_an(Hash) @@ -33,10 +33,10 @@ [false, true].should include(instance['monitoring']['state']) instance['placement'].should be_a(Hash) instance['placement']['availabilityZone'].should be_a(String) - instance['privateDnsName'].should be_a(String) + instance['privateDnsName'].should be_nil # instance['privateIpAddress'].should be_a(String) instance['ramdiskId'].should be_a(String) - instance['reason'].should be_a(String) + instance['reason'].should be_nil actual.body['ownerId'].should be_a(String) actual.body['requestId'].should be_a(String) actual.body['reservationId'].should be_a(String)