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 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341
|
Shindo.tests('Fog::Compute[:aws] | route table requests', ['aws']) do
@route_table_format = {
'routeTable' => [{
'routeSet' => [{
'destinationCidrBlock' => String,
'gatewayId' => String,
'state' => String,
}],
'tagSet' => Hash,
'associationSet' => Array,
'routeTableId' => String,
'vpcId' => String,
}],
'requestId' => String
}
@route_tables_format = {
'routeTableSet' => [{
'associationSet' => [{
'routeTableAssociationId' => Fog::Nullable::String,
'routeTableId' => String,
'subnetId' => Fog::Nullable::String,
'main' => Fog::Boolean
}],
'tagSet' => Hash,
'routeSet' => [{
'destinationCidrBlock' => String,
'gatewayId' => Fog::Nullable::String,
'instanceId' => Fog::Nullable::String,
'instanceOwnerId' => Fog::Nullable::String,
'networkInterfaceId' => Fog::Nullable::String,
'vpcPeeringConnectionId' => Fog::Nullable::String,
'natGatewayId' => Fog::Nullable::String,
'state' => String,
'origin' => String
}],
'routeTableId' => String,
'vpcId' => String,
}],
'requestId' => String
}
Fog::AWS::Compute::Mock.reset if Fog.mocking?
vpc = Fog::Compute[:aws].vpcs.create('cidr_block' => '10.0.10.0/24')
if !Fog.mocking?
vpc.wait_for { state.eql? "available" }
end
@subnet_id = Fog::Compute[:aws].create_subnet(vpc.id, '10.0.10.0/24').body['subnet']['subnetId']
@network_interface = Fog::Compute[:aws].create_network_interface(@subnet_id, {"PrivateIpAddress" => "10.0.10.23"}).body
@internet_gateway_id = Fog::Compute[:aws].create_internet_gateway.body['internetGatewaySet'].first['internetGatewayId']
@alt_internet_gateway_id = Fog::Compute[:aws].create_internet_gateway.body['internetGatewaySet'].first['internetGatewayId']
@network_interface_id = @network_interface['networkInterface']['networkInterfaceId']
key_name = uniq_id('fog-test-key')
key = Fog::Compute[:aws].key_pairs.create(:name => key_name)
@cidr_block = '10.0.10.0/24'
@destination_cidr_block = '10.0.10.0/23'
@ami = 'ami-79c0ae10' # ubuntu 12.04 daily build 20120728
tests('success') do
# Test create_route_table
#
tests("#create_route_table('#{vpc.id}')").formats(@route_table_format) do
data = Fog::Compute[:aws].create_route_table(vpc.id).body
@route_table_id = data['routeTable'].first['routeTableId']
data
end
# Test associate_route_table
#
tests("#associate_route_table('#{@route_table_id}', '#{@subnet_id}')").formats({'requestId'=>String, 'associationId'=>String}) do
data = Fog::Compute[:aws].associate_route_table(@route_table_id, @subnet_id).body
@association_id = data['associationId']
data
end
# Tests create_route
# - using internet gateway
# - using instance id
# - using network interface
#
Fog::Compute[:aws].attach_internet_gateway(@internet_gateway_id, vpc.id).body
tests("#create_route('#{@route_table_id}', '#{@destination_cidr_block}', '#{@internet_gateway_id}', 'nil')").formats(AWS::Compute::Formats::BASIC) do
Fog::Compute[:aws].create_route(@route_table_id, @destination_cidr_block, @internet_gateway_id, nil).body
end
instance = Fog::Compute[:aws].servers.create(:image_id => @ami, :flavor_id => 't1.micro', :key_name => key_name, :subnet_id => @subnet_id)
instance.wait_for { state.eql? "running" }
tests("#create_route('#{@route_table_id}', '10.0.10.0/22', 'nil', '#{instance.id}')").formats(AWS::Compute::Formats::BASIC) do
Fog::Compute[:aws].create_route(@route_table_id, '10.0.10.0/22', nil, instance.id).body
end
tests("#create_route('#{@route_table_id}', '10.0.10.0/21', 'nil', 'nil', '#{@network_interface_id}')").formats(AWS::Compute::Formats::BASIC) do
Fog::Compute[:aws].create_route(@route_table_id, '10.0.10.0/21', nil, nil, @network_interface_id).body
end
# Tests replace_route
# - using internet gateway
# - using instance id
# - using network interface
#
Fog::Compute[:aws].attach_internet_gateway(@alt_internet_gateway_id, vpc.id).body
tests("#replace_route('#{@route_table_id}', '#{@destination_cidr_block}', {'gatewayId' => '#{@alt_internet_gateway_id}'})").formats(AWS::Compute::Formats::BASIC) do
Fog::Compute[:aws].replace_route(@route_table_id, @destination_cidr_block, {'gatewayId' => @alt_internet_gateway_id}).body
end
instance = Fog::Compute[:aws].servers.create(:image_id => @ami, :flavor_id => 't1.micro', :key_name => key_name, :subnet_id => @subnet_id)
instance.wait_for { state.eql? "running" }
tests("#replace_route('#{@route_table_id}', '10.0.10.0/22', {'instanceId' => '#{instance.id}'})").formats(AWS::Compute::Formats::BASIC) do
Fog::Compute[:aws].replace_route(@route_table_id, '10.0.10.0/22', {'instanceId' => instance.id}).body
end
tests("#replace_route('#{@route_table_id}', '10.0.10.0/21', {'networkInterfaceId' => '#{@network_interface_id}'})").formats(AWS::Compute::Formats::BASIC) do
Fog::Compute[:aws].replace_route(@route_table_id, '10.0.10.0/21', {'networkInterfaceId' => @network_interface_id}).body
end
# Tests describe_route_tables
# - no parameters
# - filter: vpc-id => vpc_id
# - filter: vpc-id => ['all']
#
tests('#describe_route_tables').formats(@route_tables_format) do
Fog::Compute[:aws].describe_route_tables.body
end
tests("#describe_route_tables('vpc-id' => #{vpc.id})").formats(@route_tables_format) do
Fog::Compute[:aws].describe_route_tables('vpc-id' => vpc.id).body
end
tests("#describe_route_tables('vpc-id' => ['all'])").formats(@route_tables_format) do
Fog::Compute[:aws].describe_route_tables('vpc-id' => ['all']).body
end
# Test delete_route(route_table_id, cidr_block)
#
tests("#delete_route('#{@route_table_id}', '10.0.10.0/21')").formats(AWS::Compute::Formats::BASIC) do
Fog::Compute[:aws].delete_route(@route_table_id, '10.0.10.0/21').body
end
tests("#delete_route('#{@route_table_id}', '10.0.10.0/22')").formats(AWS::Compute::Formats::BASIC) do
Fog::Compute[:aws].delete_route(@route_table_id, '10.0.10.0/22').body
end
Fog::Compute[:aws].servers.all('instance-id'=>instance.id).first.destroy
if !Fog.mocking?
instance.wait_for { state.eql? "terminated" }
end
tests("#delete_route('#{@route_table_id}', '#{@destination_cidr_block}')").formats(AWS::Compute::Formats::BASIC) do
Fog::Compute[:aws].delete_route(@route_table_id, @destination_cidr_block).body
end
# Test disassociate_route_table(association_id)
#
tests("#disassociate_route_table('#{@association_id}')").formats(AWS::Compute::Formats::BASIC) do
Fog::Compute[:aws].disassociate_route_table(@association_id).body
end
# Test delete_route_table(route_table_id)
#
tests("#delete_route_table('#{@route_table_id}')").formats(AWS::Compute::Formats::BASIC) do
Fog::Compute[:aws].delete_route_table(@route_table_id).body
end
end
tests('failure') do
@route_table_id = Fog::Compute[:aws].create_route_table(vpc.id).body['routeTable'].first['routeTableId']
@association_id = Fog::Compute[:aws].associate_route_table(@route_table_id, @subnet_id).body['associationId']
Fog::Compute[:aws].create_route(@route_table_id, @destination_cidr_block, @internet_gateway_id, nil)
instance = Fog::Compute[:aws].servers.create(:image_id => @ami, :flavor_id => 't1.micro', :key_name => key_name, :subnet_id => @subnet_id)
instance.wait_for { state.eql? "running" }
# Tests create_route_table
# - no parameters
# - passing a nonexisting vpc
#
tests('#create_route_table').raises(ArgumentError) do
Fog::Compute[:aws].create_route_table
end
tests("#create_route_table('vpc-00000000')").raises(Fog::AWS::Compute::NotFound) do
Fog::Compute[:aws].create_route_table('vpc-00000000')
end
# Tests associate_route_table
# - no parameters
# - passing a nonexisiting route table
# - passing a nonexisiting subnet
#
tests('#associate_route_table').raises(ArgumentError) do
Fog::Compute[:aws].associate_route_table
end
tests("#associate_route_table('rtb-00000000', '#{@subnet_id}')").raises(Fog::AWS::Compute::NotFound) do
Fog::Compute[:aws].associate_route_table('rtb-00000000', @subnet_id)
end
tests("#associate_route_table('#{@route_table_id}', 'subnet-00000000')").raises(Fog::AWS::Compute::NotFound) do
Fog::Compute[:aws].associate_route_table(@route_table_id, 'subnet-00000000')
end
# Tests create_route
# - no parameters
# - passing a nonexisiting route table and an existing internet gateway
# - passing a nonexisiting internet gateway
# - passing a nonexisting route table and an existing instance
# - passing a nonexisiting instance
# - passing a nonexsiting route table and an existing network interface
# - passing a nonexisiting network interface
# - attempting to add a route at the same destination cidr block as another
# - attempting to add a route at a less specific destination cidr block
#
tests('#create_route').raises(ArgumentError) do
Fog::Compute[:aws].create_route
end
tests("#create_route('rtb-00000000', '#{@destination_cidr_block}', '#{@internet_gateway_id}')").raises(Fog::AWS::Compute::NotFound) do
Fog::Compute[:aws].create_route('rtb-00000000', @destination_cidr_block, @internet_gateway_id)
end
tests("#create_route('#{@route_table_id}', '#{@destination_cidr_block}', 'igw-00000000')").raises(Fog::AWS::Compute::NotFound) do
Fog::Compute[:aws].create_route(@route_table_id, @destination_cidr_block, 'igw-00000000')
end
tests("#create_route('rtb-00000000', '#{@destination_cidr_block}', 'nil', '#{instance.id}')").raises(Fog::AWS::Compute::NotFound) do
Fog::Compute[:aws].create_route('rtb-00000000', @destination_cidr_block, instance.id)
end
tests("#create_route('#{@route_table_id}', '#{@destination_cidr_block}', 'nil', 'i-00000000')").raises(Fog::AWS::Compute::NotFound) do
Fog::Compute[:aws].create_route(@route_table_id, @destination_cidr_block, nil, 'i-00000000')
end
tests("#create_route('#{@route_table_id}', '#{@destinationCidrBlock}', 'nil', 'nil', 'eni-00000000')").raises(Fog::AWS::Compute::NotFound) do
Fog::Compute[:aws].create_route(@route_table_id, @destination_cidr_block, nil, nil, 'eni-00000000')
end
tests("#create_route('#rtb-00000000', '#{@destination_cidr_block}', 'nil, 'nil', '#{@network_interface_id}')").raises(Fog::AWS::Compute::NotFound) do
Fog::Compute[:aws].create_route('rtb-00000000', @destination_cidr_block, nil, nil, @network_interface_id)
end
tests("#create_route same destination_cidr_block").raises(Fog::AWS::Compute::Error) do
Fog::Compute[:aws].create_route(@route_table_id, @destination_cidr_block, @internet_gateway_id)
Fog::Compute[:aws].create_route(@route_table_id, @destination_cidr_block, nil, nil, @network_interface_id).body
end
if !Fog.mocking?
tests("#create_route less specific destination_cidr_block").raises(Fog::AWS::Compute::Error) do
Fog::Compute[:aws].create_route(@route_table_id, '10.0.10.0/25', @internet_gateway_id)
Fog::Compute[:aws].delete_route(@route_table_id, @destination_cidr_block).body
end
end
# Tests replace_route
# - no parameters
# - passing a nonexisiting route table and an existing internet gateway
# - passing a nonexisiting route table
# - passing a nonexisting route table and an existing instance
# - passing a nonexisiting instance
# - passing a nonexsiting route table and an existing network interface
# - passing a nonexisiting network interface
# - attempting to add a route at a less specific destination cidr block
#
tests('#replace_route').raises(ArgumentError) do
Fog::Compute[:aws].replace_route
end
tests("#replace_route('rtb-00000000', '#{@destination_cidr_block}', {'internetGatewayId' => '#{@internet_gateway_id}'})").raises(Fog::AWS::Compute::NotFound) do
Fog::Compute[:aws].replace_route('rtb-00000000', @destination_cidr_block, {'internetGatewayId' => @internet_gateway_id})
end
tests("#replace_route('rtb-00000000', '#{@destination_cidr_block}')").raises(Fog::AWS::Compute::NotFound) do
Fog::Compute[:aws].replace_route('rtb-00000000', @destination_cidr_block)
end
tests("#replace_route('#{@route_table_id}', '#{@destination_cidr_block}', {'gatewayId' => 'igw-00000000'})").raises(Fog::AWS::Compute::NotFound) do
Fog::Compute[:aws].replace_route(@route_table_id, @destination_cidr_block, {'gatewayId' => 'igw-00000000'})
end
tests("#replace_route('rtb-00000000', '#{@destination_cidr_block}', {'instanceId' => '#{instance.id}'})").raises(Fog::AWS::Compute::NotFound) do
Fog::Compute[:aws].replace_route('rtb-00000000', @destination_cidr_block, {'instanceId' => instance.id})
end
tests("#replace_route('#{@route_table_id}', '#{@destination_cidr_block}', {'instanceId' => 'i-00000000'})").raises(Fog::AWS::Compute::NotFound) do
Fog::Compute[:aws].replace_route(@route_table_id, @destination_cidr_block, {'instanceId' => 'i-00000000'})
end
tests("#replace_route('#{@route_table_id}', '#{@destination_cidr_block}', {'networkInterfaceId' => 'eni-00000000'})").raises(Fog::AWS::Compute::NotFound) do
Fog::Compute[:aws].replace_route(@route_table_id, @destination_cidr_block, {'networkInterfaceId' => 'eni-00000000'})
end
tests("#replace_route('rtb-00000000', '#{@destination_cidr_block}', {'networkInterfaceId' => '#{@network_interface_id}'})").raises(Fog::AWS::Compute::NotFound) do
Fog::Compute[:aws].replace_route('rtb-00000000', @destination_cidr_block, {'networkInterfaceId' => @network_interface_id})
end
if !Fog.mocking?
tests("#replace_route less specific destination_cidr_block").raises(Fog::AWS::Compute::Error) do
Fog::Compute[:aws].replace_route(@route_table_id, '10.0.10.0/25', {'gatewayId' => @internet_gateway_id})
end
end
# Test describe_route_tables
# - passing a nonexisiting vpc
#
tests("#describe_route_tables('vpc-id' => 'vpc-00000000").formats({'routeTableSet'=>Array, 'requestId'=>String}) do
Fog::Compute[:aws].describe_route_tables('vpc-id' => 'vpc-00000000').body
end
# Tests delete_route
# - no parameters
# - passing a nonexisiting route table
#
tests('#delete_route').raises(ArgumentError) do
Fog::Compute[:aws].delete_route
end
tests("#delete_route('rtb-00000000', '#{@destination_cidr_block}')").raises(Fog::AWS::Compute::NotFound) do
Fog::Compute[:aws].delete_route('rtb-00000000', @destination_cidr_block)
end
# Tests disassociate_route_table
# - no parameters
# - passing a nonexisiting route table association id
#
tests('#disassociate_route_table').raises(ArgumentError) do
Fog::Compute[:aws].disassociate_route_table
end
tests("#disassociate_route_table('rtbassoc-00000000')").raises(Fog::AWS::Compute::NotFound) do
Fog::Compute[:aws].disassociate_route_table('rtbassoc-00000000')
end
# Tests delete_route_table
# - no parameters
# - passing a nonexisiting route table
#
tests('#delete_route_table').raises(ArgumentError) do
Fog::Compute[:aws].delete_route_table
end
tests("#delete_route_table('rtb-00000000')").raises(Fog::AWS::Compute::NotFound) do
Fog::Compute[:aws].delete_route_table('rtb-00000000')
end
# Dependency Tests
# - route is depending on route_table, so route_table cannot be deleted
#
tests("#delete_route_table('#{@route_table_id}')").raises(Fog::AWS::Compute::Error) do
Fog::Compute[:aws].delete_route_table(@route_table_id)
end
Fog::Compute[:aws].servers.all('instance-id'=>instance.id).first.destroy
if !Fog.mocking?
instance.wait_for { state.eql? "terminated" }
end
Fog::Compute[:aws].delete_route(@route_table_id, @destination_cidr_block)
Fog::Compute[:aws].disassociate_route_table(@association_id)
Fog::Compute[:aws].delete_route_table(@route_table_id)
end
Fog::Compute[:aws].delete_network_interface(@network_interface_id)
Fog::Compute[:aws].detach_internet_gateway(@internet_gateway_id, vpc.id)
Fog::Compute[:aws].delete_internet_gateway(@internet_gateway_id)
Fog::Compute[:aws].delete_subnet(@subnet_id)
vpc.destroy
key.destroy
end
|