Exemplo n.º 1
0
def _stop_vpn_in_subnet(context, neutron, cleaner, subnet):
    os_vpnservice_id = subnet.get("os_vpnservice_id")
    if not os_vpnservice_id:
        return
    for vpn in db_api.get_items(context, "vpn"):
        vpn_connection_api._delete_subnet_vpn(context, neutron, cleaner, subnet, vpn)
    _safe_delete_vpnservice(neutron, os_vpnservice_id, subnet["id"])
Exemplo n.º 2
0
def _stop_vpn_in_subnet(context, neutron, cleaner, subnet):
    os_vpnservice_id = subnet.get('os_vpnservice_id')
    if not os_vpnservice_id:
        return
    for vpn in db_api.get_items(context, 'vpn'):
        vpn_connection_api._delete_subnet_vpn(context, neutron, cleaner,
                                              subnet, vpn)
    _safe_delete_vpnservice(neutron, os_vpnservice_id, subnet['id'])
Exemplo n.º 3
0
    def test_delete_subnet_vpn(self):
        context = base.create_context()
        cleaner = common.OnCrashCleaner()

        # subnet is not connected to the vpn
        vpn_connection_api._delete_subnet_vpn(context, self.neutron, cleaner,
                                              fakes.DB_SUBNET_1,
                                              fakes.DB_VPN_CONNECTION_1)
        self.assertFalse(self.db_api.update_item.called)
        self.assertFalse(self.neutron.delete_ipsec_site_connection.called)

        # delete subnet vpn connection
        vpn_connection_api._delete_subnet_vpn(
            context, self.neutron, cleaner, fakes.DB_SUBNET_2,
            copy.deepcopy(fakes.DB_VPN_CONNECTION_1))
        self.db_api.update_item.assert_called_once_with(
            mock.ANY,
            tools.update_dict(fakes.DB_VPN_CONNECTION_1,
                              {'os_ipsec_site_connections': {}}))
        self.neutron.delete_ipsec_site_connection.assert_called_once_with(
            fakes.ID_OS_IPSEC_SITE_CONNECTION_2)

        # delete subnet vpn connection, leave connections of other subnets
        self.db_api.reset_mock()
        self.neutron.reset_mock()
        id_os_connection = fakes.random_os_id()
        vpn_connection_1 = copy.deepcopy(fakes.DB_VPN_CONNECTION_1)
        (vpn_connection_1['os_ipsec_site_connections'][fakes.ID_EC2_SUBNET_1]
         ) = id_os_connection
        vpn_connection_api._delete_subnet_vpn(context, self.neutron, cleaner,
                                              fakes.DB_SUBNET_1,
                                              vpn_connection_1)
        self.db_api.update_item.assert_called_once_with(
            mock.ANY, fakes.DB_VPN_CONNECTION_1)
        self.neutron.delete_ipsec_site_connection.assert_called_once_with(
            id_os_connection)

        # rollback of deleting subnet vpn connection
        self.db_api.reset_mock()
        self.neutron.reset_mock()
        try:
            with common.OnCrashCleaner() as cleaner:
                vpn_connection_api._delete_subnet_vpn(
                    context, self.neutron, cleaner, fakes.DB_SUBNET_2,
                    copy.deepcopy(fakes.DB_VPN_CONNECTION_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)
        self.assertFalse(self.neutron.create_ipsec_site_connection.called)
    def test_delete_subnet_vpn(self):
        context = base.create_context()
        cleaner = common.OnCrashCleaner()

        # subnet is not connected to the vpn
        vpn_connection_api._delete_subnet_vpn(
            context, self.neutron, cleaner, fakes.DB_SUBNET_1,
            fakes.DB_VPN_CONNECTION_1)
        self.assertFalse(self.db_api.update_item.called)
        self.assertFalse(self.neutron.delete_ipsec_site_connection.called)

        # delete subnet vpn connection
        vpn_connection_api._delete_subnet_vpn(
            context, self.neutron, cleaner, fakes.DB_SUBNET_2,
            copy.deepcopy(fakes.DB_VPN_CONNECTION_1))
        self.db_api.update_item.assert_called_once_with(
            mock.ANY, tools.update_dict(fakes.DB_VPN_CONNECTION_1,
                                        {'os_ipsec_site_connections': {}}))
        self.neutron.delete_ipsec_site_connection.assert_called_once_with(
            fakes.ID_OS_IPSEC_SITE_CONNECTION_2)

        # delete subnet vpn connection, leave connections of other subnets
        self.db_api.reset_mock()
        self.neutron.reset_mock()
        id_os_connection = fakes.random_os_id()
        vpn_connection_1 = copy.deepcopy(fakes.DB_VPN_CONNECTION_1)
        (vpn_connection_1['os_ipsec_site_connections']
         [fakes.ID_EC2_SUBNET_1]) = id_os_connection
        vpn_connection_api._delete_subnet_vpn(
            context, self.neutron, cleaner, fakes.DB_SUBNET_1,
            vpn_connection_1)
        self.db_api.update_item.assert_called_once_with(
            mock.ANY, fakes.DB_VPN_CONNECTION_1)
        self.neutron.delete_ipsec_site_connection.assert_called_once_with(
            id_os_connection)

        # rollback of deleting subnet vpn connection
        self.db_api.reset_mock()
        self.neutron.reset_mock()
        try:
            with common.OnCrashCleaner() as cleaner:
                vpn_connection_api._delete_subnet_vpn(
                    context, self.neutron, cleaner, fakes.DB_SUBNET_2,
                    copy.deepcopy(fakes.DB_VPN_CONNECTION_1))
                raise Exception('fake-exception')
        except Exception as ex:
            if str(ex) != 'fake-exception':
                raise
        self.db_api.update_item.assert_called_with(
            mock.ANY, fakes.DB_VPN_CONNECTION_1)
        self.assertFalse(self.neutron.create_ipsec_site_connection.called)