2015-05-19 05:02:59 -04:00
Shindo . tests ( 'Fog::Compute[:aws] | describe_instance_attribute request' , [ 'aws' ] ) do
@instance_attributes = [
'instanceType' ,
'kernel' ,
'ramdisk' ,
'userData' ,
'disableApiTermination' ,
'instanceInitiatedShutdownBehavior' ,
'rootDeviceName' ,
'blockDeviceMapping' ,
'productCodes' ,
'groupSet' ,
'ebsOptimized' ,
'sourceDestCheck' ,
'sriovNetSupport'
]
@instance_attribute_common_format = {
" requestId " = > String ,
" instanceId " = > String
}
@instance_attribute_format = {
" instanceType " = > Fog :: Nullable :: String ,
" kernelId " = > Fog :: Nullable :: String ,
" ramdiskId " = > Fog :: Nullable :: String ,
" userData " = > Fog :: Nullable :: String ,
" disableApiTermination " = > Fog :: Nullable :: Boolean ,
" instanceInitiatedShutdownBehavior " = > Fog :: Nullable :: String ,
" rootDeviceName " = > Fog :: Nullable :: String ,
" blockDeviceMapping " = > [ Fog :: Nullable :: Hash ] ,
" productCodes " = > Fog :: Nullable :: Array ,
" ebsOptimized " = > Fog :: Nullable :: Boolean ,
" sriovNetSupport " = > Fog :: Nullable :: String ,
" sourceDestCheck " = > Fog :: Nullable :: Boolean ,
" groupSet " = > [ Fog :: Nullable :: Hash ]
}
tests ( 'success' ) do
2015-05-20 03:51:52 -04:00
# In mocking the groupSet attribute is returned as nil
2015-05-19 11:35:39 -04:00
if Fog . mocking?
@instance_attribute_format [ " groupSet " ] = Fog :: Nullable :: Array
end
2015-05-20 03:51:52 -04:00
# Setting up the environment
@instance_id = nil
@ami = 'ami-79c0ae10'
2015-05-21 11:39:32 -04:00
key_name = uniq_id ( 'fog-test-key' )
2015-05-19 05:02:59 -04:00
@key = Fog :: Compute [ :aws ] . key_pairs . create ( :name = > key_name )
instance_type = " t1.micro "
@az = " us-east-1a "
vpc = Fog :: Compute [ :aws ] . vpcs . create ( 'cidr_block' = > '10.0.10.0/16' )
subnet = Fog :: Compute [ :aws ] . subnets . create ( 'vpc_id' = > vpc . id , 'cidr_block' = > '10.0.10.0/16' , " availability_zone " = > @az )
security_groups = Fog :: Compute [ :aws ] . security_groups . all
@launch_config = {
:image_id = > @ami ,
:flavor_id = > instance_type ,
:key_name = > key_name ,
2015-05-19 11:35:39 -04:00
:subnet_id = > subnet . subnet_id ,
:disable_api_termination = > false
2015-05-19 05:02:59 -04:00
}
2015-05-19 11:35:39 -04:00
if ! Fog . mocking?
security_group = security_groups . select { | group | group . vpc_id == vpc . id }
security_group_ids = security_group . collect { | group | group . group_id }
@launch_config [ :security_group_ids ] = security_group_ids
block_device_mapping = [ { " DeviceName " = > " /dev/sdp1 " , " VirtualName " = > nil , " Ebs.VolumeSize " = > 15 } ]
@launch_config [ :block_device_mapping ] = block_device_mapping
else
security_group_ids = [ nil ]
2015-05-20 03:51:52 -04:00
# In mocking the first device provided in block_device_mapping is set as the root device. There is no root device by default. So setting the root device here so that the tests for rootDeviceName and blockDeviceMapping attribute get passed
2015-05-19 11:35:39 -04:00
block_device_mapping = [ { " DeviceName " = > " /dev/sda1 " , " VirtualName " = > nil , " Ebs.VolumeSize " = > 15 } , { " DeviceName " = > " /dev/sdp1 " , " VirtualName " = > nil , " Ebs.VolumeSize " = > 15 } ]
@launch_config [ :block_device_mapping ] = block_device_mapping
end
2015-05-19 05:02:59 -04:00
server = Fog :: Compute [ :aws ] . servers . create ( @launch_config )
server . wait_for { ready? }
server . reload
@instance_id = server . id
2015-05-20 03:51:52 -04:00
################
# BEGIN TESTS #
################
2015-05-19 05:02:59 -04:00
@instance_attributes . each do | attrib |
2015-05-20 03:51:52 -04:00
# Creating format schema for each attribute
2015-05-19 05:02:59 -04:00
describe_instance_attribute_format = @instance_attribute_common_format . clone
if attrib == " kernel "
key = " kernelId "
elsif attrib == " ramdisk "
key = " ramdiskId "
else
key = attrib
end
describe_instance_attribute_format [ key ] = @instance_attribute_format [ key ]
2015-05-20 03:51:52 -04:00
# Running format check
2015-05-19 05:02:59 -04:00
tests ( " # describe_instance_attribute(' #{ @instance_id } ', #{ attrib } ) " ) . formats ( describe_instance_attribute_format , false ) do
Fog :: Compute [ :aws ] . describe_instance_attribute ( @instance_id , attrib ) . body
end
2015-05-20 03:51:52 -04:00
# Running test to see proper instance Id is get in each response
2015-05-19 05:02:59 -04:00
tests ( " # describe_instance_attribute(' #{ @instance_id } ', #{ attrib } ) " ) . returns ( @instance_id ) do
Fog :: Compute [ :aws ] . describe_instance_attribute ( @instance_id , attrib ) . body [ 'instanceId' ]
end
end
2015-05-19 11:35:39 -04:00
2015-05-20 03:51:52 -04:00
# Test for instanceType attribute
2015-05-19 05:02:59 -04:00
tests ( " # describe_instance_attribute( #{ @instance_id } , 'instanceType') " ) . returns ( instance_type ) do
Fog :: Compute [ :aws ] . describe_instance_attribute ( @instance_id , 'instanceType' ) . body [ " instanceType " ]
end
2015-05-20 03:51:52 -04:00
# Test for disableApiTermination attribute
2015-05-19 05:02:59 -04:00
tests ( " # describe_instance_attribute( #{ @instance_id } , 'disableApiTermination') " ) . returns ( false ) do
Fog :: Compute [ :aws ] . describe_instance_attribute ( @instance_id , 'disableApiTermination' ) . body [ " disableApiTermination " ]
end
2015-05-20 03:51:52 -04:00
# Test for instanceInitiatedShutdownBehavior attribute
2015-05-19 05:02:59 -04:00
tests ( " # describe_instance_attribute( #{ @instance_id } , 'instanceInitiatedShutdownBehavior') " ) . returns ( 'stop' ) do
Fog :: Compute [ :aws ] . describe_instance_attribute ( @instance_id , 'instanceInitiatedShutdownBehavior' ) . body [ " instanceInitiatedShutdownBehavior " ]
end
2015-05-20 03:51:52 -04:00
# Test for rootDeviceName attribute
2015-05-19 05:02:59 -04:00
tests ( " # describe_instance_attribute( #{ @instance_id } , 'rootDeviceName') " ) . returns ( '/dev/sda1' ) do
Fog :: Compute [ :aws ] . describe_instance_attribute ( @instance_id , 'rootDeviceName' ) . body [ " rootDeviceName " ]
end
2015-05-20 03:51:52 -04:00
# Test to see there are two devices for blockDeviceMapping attribute
2015-05-19 05:02:59 -04:00
tests ( " # describe_instance_attribute( #{ @instance_id } , 'blockDeviceMapping') " ) . returns ( 2 ) do
Fog :: Compute [ :aws ] . describe_instance_attribute ( @instance_id , 'blockDeviceMapping' ) . body [ " blockDeviceMapping " ] . count
end
2015-05-20 03:51:52 -04:00
# Test to check the device name /dev/sdp1 passed in block_device_mapping is returned correctly
2015-05-19 05:02:59 -04:00
tests ( " # describe_instance_attribute( #{ @instance_id } , 'blockDeviceMapping') " ) . returns ( " /dev/sdp1 " ) do
Fog :: Compute [ :aws ] . describe_instance_attribute ( @instance_id , 'blockDeviceMapping' ) . body [ " blockDeviceMapping " ] . last [ " deviceName " ]
end
2015-05-20 03:51:52 -04:00
# Test for groupSet attribute
2015-05-19 05:02:59 -04:00
tests ( " # describe_instance_attribute( #{ @instance_id } , 'groupSet') " ) . returns ( security_group_ids ) do
group_set = Fog :: Compute [ :aws ] . describe_instance_attribute ( @instance_id , 'groupSet' ) . body [ " groupSet " ]
group_set . collect { | g | g [ " groupId " ] }
end
2015-05-20 03:51:52 -04:00
# Test for sourceDestCheck attribute (This attribute is set only for VPC instances. So created the instance in a VPC during setup process)
2015-05-19 05:02:59 -04:00
tests ( " # describe_instance_attribute( #{ @instance_id } , 'sourceDestCheck') " ) . returns ( true ) do
Fog :: Compute [ :aws ] . describe_instance_attribute ( @instance_id , 'sourceDestCheck' ) . body [ " sourceDestCheck " ]
end
2015-05-20 03:51:52 -04:00
# Test for ebsOptimized attribute
2015-05-19 05:02:59 -04:00
tests ( " # describe_instance_attribute( #{ @instance_id } , 'ebsOptimized') " ) . returns ( false ) do
Fog :: Compute [ :aws ] . describe_instance_attribute ( @instance_id , 'ebsOptimized' ) . body [ " ebsOptimized " ]
end
2015-05-20 03:51:52 -04:00
###############
# END OF TEST #
###############
2015-05-19 05:02:59 -04:00
2015-05-20 03:51:52 -04:00
# Tear down
2015-05-19 11:35:39 -04:00
if ! Fog . mocking?
@key . destroy
server . destroy
until server . state == " terminated "
sleep 5 #Wait for the server to be terminated
server . reload
end
subnet . destroy
vpc . destroy
2015-05-19 05:02:59 -04:00
end
end
tests ( 'failure' ) do
@instance_attributes . each do | attrib |
2018-09-12 05:35:01 -04:00
tests ( " # describe_instance_attribute('i-00000000', #{ attrib } ) " ) . raises ( Fog :: AWS :: Compute :: NotFound ) do
2015-05-19 05:02:59 -04:00
Fog :: Compute [ :aws ] . describe_instance_attribute ( 'i-00000000' , attrib )
end
end
end
end