Exemplo n.º 1
0
    def _detach_subscribers_by_ids(self, deleted_sub_ids: List[str]):
        """
        Sends grpc DeleteSubscriber request to mme to detach all subscribers
        given as args.

        Args:
            deleted_sub_ids: a list of old subscriber ids in the store,
                             prefixed by subscriber type

        Returns:
            None

        """
        # send detach request to mme for all deleted subscribers.
        chan = ServiceRegistry.get_rpc_channel(
            's6a_service',
            ServiceRegistry.LOCAL,
        )
        client = S6aServiceStub(chan)
        req = DeleteSubscriberRequest()

        # mme expects a list of IMSIs without "IMSI" prefix
        imsis_to_delete_without_prefix = [sub[4:] for sub in deleted_sub_ids]

        req.imsi_list.extend(imsis_to_delete_without_prefix)
        future = client.DeleteSubscriber.future(req)
        future.add_done_callback(
            lambda future: self._loop.call_soon_threadsafe(
                self._detach_deleted_subscribers_done,
                future,
            ), )
Exemplo n.º 2
0
    def test_detach_deleted_subscribers(self, s6a_service_mock_stub):
        """
        Test if the streamer_callback detach deleted subscribers.
        """
        # Mock out DeleteSubscriber.future
        mock = unittest.mock.Mock()
        mock.DeleteSubscriber.future.side_effect = [unittest.mock.Mock()]
        s6a_service_mock_stub.side_effect = [mock]

        # Call with no samples
        old_sub_ids = ["IMSI202", "IMSI101"]
        new_sub_ids = ["IMSI101", "IMSI202"]
        self._streamer_callback.detach_deleted_subscribers(
            old_sub_ids, new_sub_ids)
        s6a_service_mock_stub.DeleteSubscriber.future.assert_not_called()
        self._streamer_callback._loop.stop()

        # Call with one subscriber id deleted
        old_sub_ids = ["IMSI202", "IMSI101", "IMSI303"]
        new_sub_ids = ["IMSI202"]
        self._streamer_callback.detach_deleted_subscribers(
            old_sub_ids, new_sub_ids)

        mock.DeleteSubscriber.future.assert_called_once_with(
            DeleteSubscriberRequest(imsi_list=["101", "303"]))
Exemplo n.º 3
0
    def test_detach_deleted_subscribers(self, s6a_service_mock_stub):
        """
        Test if the subscriberdb cloud client detaches deleted subscribers

        Args:
            s6a_service_mock_stub: mocked s6a stub
        """
        # Mock out DeleteSubscriber.future
        mock = unittest.mock.Mock()
        mock.DeleteSubscriber.future.side_effect = [unittest.mock.Mock()]
        s6a_service_mock_stub.side_effect = [mock]

        # Call with no samples
        old_sub_ids = ["IMSI202", "IMSI101"]
        new_sub_ids = ["IMSI101", "IMSI202"]
        self.subscriberdb_cloud_client._detach_deleted_subscribers(
            old_sub_ids,
            new_sub_ids,
        )
        s6a_service_mock_stub.DeleteSubscriber.future.assert_not_called()
        self.subscriberdb_cloud_client._loop.stop()

        # Call with one subscriber id deleted
        old_sub_ids = ["IMSI202", "IMSI101", "IMSI303"]
        new_sub_ids = ["IMSI202"]
        self.subscriberdb_cloud_client._detach_deleted_subscribers(
            old_sub_ids,
            new_sub_ids,
        )

        mock.DeleteSubscriber.future.assert_called_once_with(
            DeleteSubscriberRequest(imsi_list=["101", "303"]), )
Exemplo n.º 4
0
 def detach_deleted_subscribers(self, old_sub_ids, new_sub_ids):
     """
     Compares current subscriber ids and new subscriber ids list
     just streamed from the cloud to figure out the deleted subscribers.
     Then send grpc DeleteSubscriber request to mme to detach all the
     deleted subscribers.
     :param old_sub_ids: a list of old subscriber ids in the store.
     :param new_sub_ids: a list of new subscriber ids
             just streamed from the cloud
     :return: n/a
     """
     deleted_sub_ids = [
         sub_id for sub_id in old_sub_ids if sub_id not in set(new_sub_ids)
     ]
     if len(deleted_sub_ids) == 0:
         return
     # send detach request to mme for all deleted subscribers.
     chan = ServiceRegistry.get_rpc_channel('s6a_service',
                                            ServiceRegistry.LOCAL)
     client = S6aServiceStub(chan)
     req = DeleteSubscriberRequest()
     req.imsi_list.extend(deleted_sub_ids)
     future = client.DeleteSubscriber.future(req)
     future.add_done_callback(
         lambda future: self._loop.call_soon_threadsafe(
             self.detach_deleted_subscribers_done, future))
Exemplo n.º 5
0
    def _detach_deleted_subscribers(self, old_sub_ids, new_sub_ids):
        """
        Detach deleted subscribers from store and network.

        Compares current subscriber ids and new subscriber ids list
        just streamed from the cloud to figure out the deleted subscribers.
        Then send grpc DeleteSubscriber request to mme to detach all the
        deleted subscribers.

        Args:
            old_sub_ids: a list of old subscriber ids in the store
            new_sub_ids: a list of new active subscriber ids

        Returns:
            None

        """
        # THIS IS A HACK UNTIL WE FIX THIS ON CLOUD
        # We accept IMSIs with or without 'IMSI' prepended on cloud, but we
        # always store IMSIs on local subscriberdb with IMSI prepended. If the
        # cloud streams down subscriber IDs without 'IMSI' prepended,
        # subscriberdb will try to delete all of the subscribers from MME every
        # time it streams from cloud because the set membership will fail
        # when comparing '12345' to 'IMSI12345'.
        new_sub_ids = {
            'IMSI{imsiVal}'.format(imsiVal=s) if not s.startswith('IMSI')
            else s
            for s in new_sub_ids
        }
        deleted_sub_ids = [
            sub_id for sub_id in old_sub_ids
            if sub_id not in set(new_sub_ids)
        ]
        if not deleted_sub_ids:
            return
        # send detach request to mme for all deleted subscribers.
        chan = ServiceRegistry.get_rpc_channel(
            's6a_service',
            ServiceRegistry.LOCAL,
        )
        client = S6aServiceStub(chan)
        req = DeleteSubscriberRequest()

        # mme expects a list of IMSIs without "IMSI" prefix
        imsis_to_delete_without_prefix = [sub[4:] for sub in deleted_sub_ids]

        req.imsi_list.extend(imsis_to_delete_without_prefix)
        future = client.DeleteSubscriber.future(req)
        future.add_done_callback(
            lambda future:
            self._loop.call_soon_threadsafe(
                self._detach_deleted_subscribers_done,
                future,
            ),
        )
Exemplo n.º 6
0
 def detach_deleted_subscribers(self, old_sub_ids, new_sub_ids):
     """
     Compares current subscriber ids and new subscriber ids list
     just streamed from the cloud to figure out the deleted subscribers.
     Then send grpc DeleteSubscriber request to mme to detach all the
     deleted subscribers.
     :param old_sub_ids: a list of old subscriber ids in the store.
     :param new_sub_ids: a list of new subscriber ids
             just streamed from the cloud
     :return: n/a
     """
     # THIS IS A HACK UNTIL WE FIX THIS ON CLOUD
     # We accept IMSIs with or without 'IMSI' prepended on cloud, but we
     # always store IMSIs on local subscriberdb with IMSI prepended. If the
     # cloud streams down subscriber IDs without 'IMSI' prepended,
     # subscriberdb will try to delete all of the subscribers from MME every
     # time it streams from cloud because the set membership will fail
     # when comparing '12345' to 'IMSI12345'.
     new_sub_ids = set(
         map(
             lambda s: 'IMSI' + s if not s.startswith('IMSI') else s,
             new_sub_ids,
         ),
     )
     deleted_sub_ids = [sub_id for sub_id in old_sub_ids
                        if sub_id not in set(new_sub_ids)]
     if len(deleted_sub_ids) == 0:
         return
     # send detach request to mme for all deleted subscribers.
     chan = ServiceRegistry.get_rpc_channel('s6a_service',
                                            ServiceRegistry.LOCAL)
     client = S6aServiceStub(chan)
     req = DeleteSubscriberRequest()
     req.imsi_list.extend(deleted_sub_ids)
     future = client.DeleteSubscriber.future(req)
     future.add_done_callback(lambda future:
                              self._loop.call_soon_threadsafe(
                                  self.detach_deleted_subscribers_done,
                                  future)
                              )
Exemplo n.º 7
0
def delete_subscriber(client, args):
    req = DeleteSubscriberRequest()
    req.imsi_list.extend(args.imsi_list)
    print("deleting subs:", req.imsi_list)
    client.DeleteSubscriber(req)