def test_delete_network_interface_with_public_ip(self): detached_network_interface_2 = fakes.gen_db_network_interface( fakes.ID_EC2_NETWORK_INTERFACE_2, fakes.ID_OS_PORT_2, fakes.ID_EC2_VPC_1, fakes.ID_EC2_SUBNET_2, fakes.IP_NETWORK_INTERFACE_2) self.set_mock_db_items(detached_network_interface_2, fakes.DB_ADDRESS_1, fakes.DB_ADDRESS_2) resp = self.execute( 'DeleteNetworkInterface', {'NetworkInterfaceId': fakes.ID_EC2_NETWORK_INTERFACE_2}) self.assertEqual(True, resp['return']) self.db_api.get_item_by_id.assert_any_call( mock.ANY, fakes.ID_EC2_NETWORK_INTERFACE_2) self.db_api.delete_item.assert_called_once_with( mock.ANY, fakes.ID_EC2_NETWORK_INTERFACE_2) self.neutron.delete_port.assert_called_once_with( fakes.ID_OS_PORT_2) self.db_api.update_item.assert_called_once_with( mock.ANY, tools.purge_dict(fakes.DB_ADDRESS_2, ['network_interface_id', 'private_ip_address']))
def test_delete_network_interface_with_public_ip(self): detached_network_interface_2 = fakes.gen_db_network_interface( fakes.ID_EC2_NETWORK_INTERFACE_2, fakes.ID_OS_PORT_2, fakes.ID_EC2_VPC_1, fakes.ID_EC2_SUBNET_2, fakes.IP_NETWORK_INTERFACE_2) self.set_mock_db_items(detached_network_interface_2, fakes.DB_ADDRESS_1, fakes.DB_ADDRESS_2) resp = self.execute( 'DeleteNetworkInterface', {'NetworkInterfaceId': fakes.ID_EC2_NETWORK_INTERFACE_2}) self.assertEqual(True, resp['return']) self.db_api.get_item_by_id.assert_any_call( mock.ANY, fakes.ID_EC2_NETWORK_INTERFACE_2) self.db_api.delete_item.assert_called_once_with( mock.ANY, fakes.ID_EC2_NETWORK_INTERFACE_2) self.neutron.delete_port.assert_called_once_with(fakes.ID_OS_PORT_2) self.db_api.update_item.assert_called_once_with( mock.ANY, tools.purge_dict(fakes.DB_ADDRESS_2, ['network_interface_id', 'private_ip_address']))
def test_associate_address_invalid_vpc_parameters(self): address.address_engine = (address.AddressEngineNeutron()) def do_check(params, error): self.assert_execution_error(error, 'AssociateAddress', params) # NOTE(ft): not registered instance id vs vpc address self.set_mock_db_items() do_check( { 'AllocationId': fakes.ID_EC2_ADDRESS_1, 'InstanceId': fakes.ID_EC2_INSTANCE_1 }, 'InvalidInstanceID.NotFound') # NOTE(ft): vpc instance vs public ip parmeter self.set_mock_db_items(fakes.DB_NETWORK_INTERFACE_2) do_check({ 'PublicIp': '0.0.0.0', 'InstanceId': fakes.ID_EC2_INSTANCE_1 }, 'InvalidParameterCombination') # NOTE(ft): vpc instance vs not registered vpc address do_check( { 'AllocationId': fakes.ID_EC2_ADDRESS_1, 'InstanceId': fakes.ID_EC2_INSTANCE_1 }, 'InvalidAllocationID.NotFound') # NOTE(ft): not registered network interface id vs vpc address do_check( { 'AllocationId': fakes.ID_EC2_ADDRESS_1, 'NetworkInterfaceId': fakes.ID_EC2_NETWORK_INTERFACE_1 }, 'InvalidNetworkInterfaceID.NotFound') # NOTE(ft): vpc instance vs broken vpc address self.set_mock_db_items(fakes.DB_ADDRESS_1, fakes.DB_NETWORK_INTERFACE_2) self.neutron.show_floatingip.side_effect = neutron_exception.NotFound do_check( { 'AllocationId': fakes.ID_EC2_ADDRESS_1, 'InstanceId': fakes.ID_EC2_INSTANCE_1 }, 'InvalidAllocationID.NotFound') self.neutron.show_floatingip.side_effect = None # NOTE(ft): already associated address vs network interface self.set_mock_db_items(fakes.DB_ADDRESS_1, fakes.DB_ADDRESS_2, fakes.DB_NETWORK_INTERFACE_1) self.neutron.show_floatingip.return_value = ({ 'floatingip': fakes.OS_FLOATING_IP_2 }) self.assert_execution_error( 'Resource.AlreadyAssociated', 'AssociateAddress', { 'AllocationId': fakes.ID_EC2_ADDRESS_2, 'NetworkInterfaceId': fakes.ID_EC2_NETWORK_INTERFACE_1 }) # NOTE(ft): already associated address vs vpc instance self.set_mock_db_items( fakes.DB_ADDRESS_2, fakes.gen_db_network_interface( fakes.ID_EC2_NETWORK_INTERFACE_1, fakes.ID_OS_PORT_1, fakes.ID_EC2_VPC_1, fakes.ID_EC2_SUBNET_1, fakes.IP_NETWORK_INTERFACE_1, instance_id=fakes.ID_EC2_INSTANCE_1)) self.assert_execution_error( 'Resource.AlreadyAssociated', 'AssociateAddress', { 'AllocationId': fakes.ID_EC2_ADDRESS_2, 'InstanceId': fakes.ID_EC2_INSTANCE_1 }) # NOTE(ft): multiple network interfaces in vpc instance # w/o network interface selection self.add_mock_db_items(fakes.DB_NETWORK_INTERFACE_2) self.assert_execution_error( 'InvalidInstanceID', 'AssociateAddress', { 'AllocationId': fakes.ID_EC2_ADDRESS_1, 'InstanceId': fakes.ID_EC2_INSTANCE_1 }) # NOTE(ft): internet gateway isn't attached to the vpc self.set_mock_db_items(fakes.DB_ADDRESS_1, fakes.DB_NETWORK_INTERFACE_2) self.assert_execution_error( 'Gateway.NotAttached', 'AssociateAddress', { 'AllocationId': fakes.ID_EC2_ADDRESS_1, 'InstanceId': fakes.ID_EC2_INSTANCE_1 })
def test_create_route_invalid_parameters(self): id_ec2_eni_vpc_2 = fakes.random_ec2_id('eni') eni_vpc_2 = fakes.gen_db_network_interface( id_ec2_eni_vpc_2, fakes.random_os_id(), fakes.ID_EC2_VPC_2, fakes.random_ec2_id('subnet'), '10.20.0.10', instance_id=fakes.ID_EC2_INSTANCE_2) eni_2_in_instance_1 = fakes.gen_db_network_interface( fakes.random_ec2_id('eni'), fakes.random_os_id(), fakes.ID_EC2_VPC_1, fakes.random_ec2_id('subnet'), '10.10.3.15', instance_id=fakes.ID_EC2_INSTANCE_1) self.set_mock_db_items(fakes.DB_ROUTE_TABLE_1, fakes.DB_ROUTE_TABLE_2, fakes.DB_VPC_1, eni_vpc_2, fakes.DB_IGW_1, fakes.DB_IGW_2, fakes.DB_NETWORK_INTERFACE_1, fakes.DB_NETWORK_INTERFACE_2) def do_check(params, error_code): self.assert_execution_error(error_code, 'CreateRoute', params) do_check( { 'RouteTableId': fakes.ID_EC2_ROUTE_TABLE_1, 'DestinationCidrBlock': 'not_a_cidr', 'GatewayId': fakes.ID_EC2_IGW_1 }, 'InvalidParameterValue') do_check( { 'RouteTableId': fakes.random_ec2_id('rtb'), 'DestinationCidrBlock': fakes.CIDR_VPC_1, 'GatewayId': fakes.ID_EC2_IGW_1 }, 'InvalidRouteTableID.NotFound') # NOTE(ft): redefine vpc local route do_check( { 'RouteTableId': fakes.ID_EC2_ROUTE_TABLE_1, 'DestinationCidrBlock': fakes.CIDR_VPC_1, 'GatewayId': fakes.ID_EC2_IGW_1 }, 'InvalidParameterValue') # NOTE(ft): create route for cidr lesser than vpc cidr do_check( { 'RouteTableId': fakes.ID_EC2_ROUTE_TABLE_1, 'DestinationCidrBlock': fakes.IP_NETWORK_INTERFACE_1 + '/24', 'GatewayId': fakes.ID_EC2_IGW_1 }, 'InvalidParameterValue') # NOTE(ft): redefine existed route by route with another attributes do_check( { 'RouteTableId': fakes.ID_EC2_ROUTE_TABLE_2, 'DestinationCidrBlock': '0.0.0.0/0', 'NetworkInterfaceId': fakes.ID_EC2_NETWORK_INTERFACE_1 }, 'RouteAlreadyExists') # NOTE(ft): missed traffic receiver do_check( { 'RouteTableId': fakes.ID_EC2_ROUTE_TABLE_2, 'DestinationCidrBlock': '0.0.0.0/0' }, 'MissingParameter') # NOTE(ft): more than one traffic receiver do_check( { 'RouteTableId': fakes.ID_EC2_ROUTE_TABLE_2, 'DestinationCidrBlock': '0.0.0.0/0', 'NetworkInterfaceId': fakes.ID_EC2_NETWORK_INTERFACE_1, 'GatewayId': fakes.ID_EC2_IGW_1 }, 'InvalidParameterCombination') # NOTE(ft): gateway from different vpc do_check( { 'RouteTableId': fakes.ID_EC2_ROUTE_TABLE_2, 'DestinationCidrBlock': '192.168.100.0/0', 'GatewayId': fakes.ID_EC2_IGW_2 }, 'InvalidParameterValue') # NOTE(ft): network interface from different vpc do_check( { 'RouteTableId': fakes.ID_EC2_ROUTE_TABLE_2, 'DestinationCidrBlock': '192.168.100.0/0', 'NetworkInterfaceId': id_ec2_eni_vpc_2 }, 'InvalidParameterValue') # NOTE(ft): not vpc instance do_check( { 'RouteTableId': fakes.ID_EC2_ROUTE_TABLE_2, 'DestinationCidrBlock': '192.168.100.0/0', 'InstanceId': fakes.ID_EC2_INSTANCE_2 }, 'InvalidParameterValue') # NOTE(ft): multiple network interfaces in instance self.add_mock_db_items(eni_2_in_instance_1) do_check( { 'RouteTableId': fakes.ID_EC2_ROUTE_TABLE_2, 'DestinationCidrBlock': '192.168.100.0/0', 'InstanceId': fakes.ID_EC2_INSTANCE_1 }, 'InvalidInstanceID') # NOTE(ft): different vpc instance do_check( { 'RouteTableId': fakes.ID_EC2_ROUTE_TABLE_2, 'DestinationCidrBlock': '192.168.100.0/0', 'InstanceId': fakes.ID_EC2_INSTANCE_2 }, 'InvalidParameterValue')
def test_associate_address_invalid_vpc_parameters(self): address.address_engine = ( address.AddressEngineNeutron()) def do_check(params, error): self.assert_execution_error(error, 'AssociateAddress', params) # NOTE(ft): not registered instance id vs vpc address self.set_mock_db_items() do_check({'AllocationId': fakes.ID_EC2_ADDRESS_1, 'InstanceId': fakes.ID_EC2_INSTANCE_1}, 'InvalidInstanceID.NotFound') # NOTE(ft): vpc instance vs public ip parmeter self.set_mock_db_items(fakes.DB_NETWORK_INTERFACE_2) do_check({'PublicIp': '0.0.0.0', 'InstanceId': fakes.ID_EC2_INSTANCE_1}, 'InvalidParameterCombination') # NOTE(ft): vpc instance vs not registered vpc address do_check({'AllocationId': fakes.ID_EC2_ADDRESS_1, 'InstanceId': fakes.ID_EC2_INSTANCE_1}, 'InvalidAllocationID.NotFound') # NOTE(ft): not registered network interface id vs vpc address do_check({'AllocationId': fakes.ID_EC2_ADDRESS_1, 'NetworkInterfaceId': fakes.ID_EC2_NETWORK_INTERFACE_1}, 'InvalidNetworkInterfaceID.NotFound') # NOTE(ft): vpc instance vs broken vpc address self.set_mock_db_items(fakes.DB_ADDRESS_1, fakes.DB_NETWORK_INTERFACE_2) self.neutron.show_floatingip.side_effect = neutron_exception.NotFound do_check({'AllocationId': fakes.ID_EC2_ADDRESS_1, 'InstanceId': fakes.ID_EC2_INSTANCE_1}, 'InvalidAllocationID.NotFound') self.neutron.show_floatingip.side_effect = None # NOTE(ft): already associated address vs network interface self.set_mock_db_items(fakes.DB_ADDRESS_1, fakes.DB_ADDRESS_2, fakes.DB_NETWORK_INTERFACE_1) self.neutron.show_floatingip.return_value = ( {'floatingip': fakes.OS_FLOATING_IP_2}) self.assert_execution_error( 'Resource.AlreadyAssociated', 'AssociateAddress', {'AllocationId': fakes.ID_EC2_ADDRESS_2, 'NetworkInterfaceId': fakes.ID_EC2_NETWORK_INTERFACE_1}) # NOTE(ft): already associated address vs vpc instance self.set_mock_db_items( fakes.DB_ADDRESS_2, fakes.gen_db_network_interface( fakes.ID_EC2_NETWORK_INTERFACE_1, fakes.ID_OS_PORT_1, fakes.ID_EC2_VPC_1, fakes.ID_EC2_SUBNET_1, fakes.IP_NETWORK_INTERFACE_1, instance_id=fakes.ID_EC2_INSTANCE_1)) self.assert_execution_error('Resource.AlreadyAssociated', 'AssociateAddress', {'AllocationId': fakes.ID_EC2_ADDRESS_2, 'InstanceId': fakes.ID_EC2_INSTANCE_1}) # NOTE(ft): multiple network interfaces in vpc instance # w/o network interface selection self.add_mock_db_items(fakes.DB_NETWORK_INTERFACE_2) self.assert_execution_error('InvalidInstanceID', 'AssociateAddress', {'AllocationId': fakes.ID_EC2_ADDRESS_1, 'InstanceId': fakes.ID_EC2_INSTANCE_1}) # NOTE(ft): internet gateway isn't attached to the vpc self.set_mock_db_items(fakes.DB_ADDRESS_1, fakes.DB_NETWORK_INTERFACE_2) self.assert_execution_error('Gateway.NotAttached', 'AssociateAddress', {'AllocationId': fakes.ID_EC2_ADDRESS_1, 'InstanceId': fakes.ID_EC2_INSTANCE_1})