Esempio n. 1
0
    def test_stop_gateway_vpn_connections(self, stop_vpn_connection):
        context = base.create_context()
        cleaner = common.OnCrashCleaner()
        vpn_connection_3 = tools.update_dict(
            fakes.DB_VPN_CONNECTION_1, {"id": fakes.random_ec2_id("vpn"), "os_ipsec_site_connections": {}}
        )

        self.set_mock_db_items(fakes.DB_VPN_CONNECTION_1, vpn_connection_3, fakes.DB_VPN_CONNECTION_2)
        vpn_connection_api._stop_gateway_vpn_connections(context, self.neutron, cleaner, fakes.DB_VPN_GATEWAY_1)
        self.assertEqual(2, stop_vpn_connection.call_count)
        stop_vpn_connection.assert_any_call(self.neutron, fakes.DB_VPN_CONNECTION_1)
        stop_vpn_connection.assert_any_call(self.neutron, vpn_connection_3)
        self.assertEqual(2, self.db_api.update_item.call_count)
        self.db_api.update_item.assert_any_call(
            mock.ANY, tools.update_dict(fakes.DB_VPN_CONNECTION_1, {"os_ipsec_site_connections": {}})
        )
        self.db_api.update_item.assert_any_call(mock.ANY, vpn_connection_3)

        self.db_api.reset_mock()
        self.neutron.reset_mock()
        stop_vpn_connection.reset_mock()
        self.set_mock_db_items(fakes.DB_VPN_CONNECTION_1)
        try:
            with common.OnCrashCleaner() as cleaner:
                vpn_connection_api._stop_gateway_vpn_connections(context, self.neutron, cleaner, fakes.DB_VPN_GATEWAY_1)
                raise Exception("fake-exception")
        except Exception as ex:
            if ex.message != "fake-exception":
                raise
        self.db_api.update_item.assert_called_with(mock.ANY, fakes.DB_VPN_CONNECTION_1)
Esempio n. 2
0
def detach_vpn_gateway(context, vpc_id, vpn_gateway_id):
    vpn_gateway = ec2utils.get_db_item(context, vpn_gateway_id)
    if vpn_gateway['vpc_id'] != vpc_id:
        raise exception.InvalidVpnGatewayAttachmentNotFound(
            vgw_id=vpn_gateway_id, vpc_id=vpc_id)

    vpc = db_api.get_item_by_id(context, vpc_id)
    neutron = clients.neutron(context)
    remove_os_gateway_router = (
        ec2utils.get_attached_gateway(context, vpc_id, 'igw') is None)
    subnets = [subnet for subnet in db_api.get_items(context, 'subnet')
               if subnet['vpc_id'] == vpc['id']]
    with common.OnCrashCleaner() as cleaner:
        _detach_vpn_gateway_item(context, vpn_gateway)
        cleaner.addCleanup(_attach_vpn_gateway_item, context, vpn_gateway,
                           vpc_id)
        vpn_connection_api._stop_gateway_vpn_connections(
            context, neutron, cleaner, vpn_gateway)
        for subnet in subnets:
            _delete_subnet_vpnservice(context, neutron, cleaner, subnet)

        if remove_os_gateway_router:
            try:
                neutron.remove_gateway_router(vpc['os_id'])
            except neutron_exception.NotFound:
                pass

    return True
Esempio n. 3
0
    def test_stop_gateway_vpn_connections(self, stop_vpn_connection):
        context = base.create_context()
        cleaner = common.OnCrashCleaner()
        vpn_connection_3 = tools.update_dict(fakes.DB_VPN_CONNECTION_1, {
            'id': fakes.random_ec2_id('vpn'),
            'os_ipsec_site_connections': {}
        })

        self.set_mock_db_items(fakes.DB_VPN_CONNECTION_1, vpn_connection_3,
                               fakes.DB_VPN_CONNECTION_2)
        vpn_connection_api._stop_gateway_vpn_connections(
            context, self.neutron, cleaner, fakes.DB_VPN_GATEWAY_1)
        self.assertEqual(2, stop_vpn_connection.call_count)
        stop_vpn_connection.assert_any_call(self.neutron,
                                            fakes.DB_VPN_CONNECTION_1)
        stop_vpn_connection.assert_any_call(self.neutron, vpn_connection_3)
        self.assertEqual(2, self.db_api.update_item.call_count)
        self.db_api.update_item.assert_any_call(
            mock.ANY,
            tools.update_dict(fakes.DB_VPN_CONNECTION_1,
                              {'os_ipsec_site_connections': {}}))
        self.db_api.update_item.assert_any_call(mock.ANY, vpn_connection_3)

        self.db_api.reset_mock()
        self.neutron.reset_mock()
        stop_vpn_connection.reset_mock()
        self.set_mock_db_items(fakes.DB_VPN_CONNECTION_1)
        try:
            with common.OnCrashCleaner() as cleaner:
                vpn_connection_api._stop_gateway_vpn_connections(
                    context, self.neutron, cleaner, fakes.DB_VPN_GATEWAY_1)
                raise Exception('fake-exception')
        except Exception as ex:
            if ex.message != 'fake-exception':
                raise
        self.db_api.update_item.assert_called_with(mock.ANY,
                                                   fakes.DB_VPN_CONNECTION_1)