Beispiel #1
0
 def process_update(self, stream_name: str, updates: List[DataUpdate],
                    resync: bool):
     logging.info('Processing %d SID -> policy updates', len(updates))
     for update in updates:
         policies = AssignedPolicies()
         policies.ParseFromString(update.value)
         self._handle_update(update.key, policies)
Beispiel #2
0
    def test_MultiUpdate(self):
        """
        Test consecutive updates
        """
        assignments_dict = {}
        apn_rules_dict = {}  # type: Dict[str, SubscriberPolicySet]
        basenames_dict = {}
        callback = RuleMappingsStreamerCallback(
            ReAuthHandler(assignments_dict, MockSessionProxyResponderStub3()),
            basenames_dict,
            assignments_dict,
            apn_rules_dict,
        )

        # Construct a set of updates, keyed by subscriber ID
        updates = [
            DataUpdate(
                key="s1",
                value=AssignedPolicies(
                    assigned_policies=["p1", "p2"], ).SerializeToString(),
            ),
            DataUpdate(
                key="s2",
                value=AssignedPolicies(
                    assigned_policies=["p2", "p3"], ).SerializeToString(),
            ),
        ]
        callback.process_update("stream", updates, False)

        updates = [
            DataUpdate(
                key="s1",
                value=AssignedPolicies(
                    assigned_policies=["p4", "p5"], ).SerializeToString(),
            ),
            DataUpdate(
                key="s2",
                value=AssignedPolicies(
                    assigned_policies=["p4", "p5"], ).SerializeToString(),
            ),
        ]
        callback.process_update("stream", updates, False)

        s1_policies = assignments_dict["s1"].installed_policies
        expected = 2
        self.assertEqual(len(s1_policies), expected,
                         'There should be 2 active policies for s1')
        self.assertTrue("p5" in s1_policies,
                        'Policy p5 should be active for subscriber s1')
        self.assertTrue("p4" in s1_policies,
                        'Policy p4 should be active for subscriber s1')

        s2_policies = assignments_dict["s2"].installed_policies
        expected = 2
        self.assertEqual(len(s2_policies), expected,
                         'There should be 2 active policies for s2')
        self.assertTrue("p5" in s2_policies,
                        'Policy p5 should be active for subscriber s2')
        self.assertTrue("p4" in s2_policies,
                        'Policy p4 should be active for subscriber s2')
Beispiel #3
0
    def test_SuccessfulUpdate(self):
        """
        Test the happy path where updates come in for added rules, and sessiond
        accepts the RAR without issue.
        """
        assignments_dict = {}
        basenames_dict = {
            'bn1': ChargingRuleNameSet(RuleNames=['p5']),
            'bn2': ChargingRuleNameSet(RuleNames=['p6']),
        }
        callback = RuleMappingsStreamerCallback(
            ReAuthHandler(assignments_dict, MockSessionProxyResponderStub1()),
            basenames_dict,
            assignments_dict,
        )

        # Construct a set of updates, keyed by subscriber ID
        updates = [
            DataUpdate(
                key="s1",
                value=AssignedPolicies(
                    assigned_policies=["p1", "p2"],
                    assigned_base_names=["bn1"],
                ).SerializeToString(),
            ),
            DataUpdate(
                key="s2",
                value=AssignedPolicies(
                    assigned_policies=["p2", "p3"], ).SerializeToString(),
            ),
        ]

        callback.process_update("stream", updates, False)

        # Since we used a stub which always succeeds when a RAR is made,
        # We should expect the assignments_dict to be updated

        s1_policies = assignments_dict["s1"].installed_policies
        expected = 3
        self.assertEqual(len(s1_policies), expected,
                         'There should be 3 active '
                         'policies for s1')
        self.assertTrue("p1" in s1_policies, 'Policy p1 should be active for '
                        'subscriber s1')
        self.assertTrue("p5" in s1_policies, 'Policy p5 should be active for '
                        'subscriber s1')

        s2_policies = assignments_dict["s2"].installed_policies
        expected = 2
        self.assertEqual(len(s2_policies), expected,
                         'There should be 2 active '
                         'policies for s2')
        self.assertTrue("p3" in s2_policies, 'Policy p3 should be active for '
                        'subscriber s2')
    def test_FailedOnePolicy(self):
        """
        Test when sessiond answers to the RAR with a failure for installing p2.
        """
        assignments_dict = {}
        apn_rules_dict = {} # type: Dict[str, SubscriberPolicySet]
        basenames_dict = {}
        callback = RuleMappingsStreamerCallback(
            ReAuthHandler(assignments_dict, MockSessionProxyResponderStub3()),
            basenames_dict,
            assignments_dict,
            apn_rules_dict,
        )

        # Construct a set of updates, keyed by subscriber ID
        updates = [
            DataUpdate(
                key="s1",
                value=AssignedPolicies(
                    assigned_policies=["p1", "p2"],
                ).SerializeToString(),
            ),
            DataUpdate(
                key="s2",
                value=AssignedPolicies(
                    assigned_policies=["p2", "p3"],
                ).SerializeToString(),
            ),
        ]

        callback.process_update("stream", updates, False)

        s1_policies = assignments_dict["s1"].installed_policies
        expected = 1
        self.assertEqual(len(s1_policies), expected, 'There should be 1 active '
                                                     'policies for s1')
        self.assertTrue("p1" in s1_policies, 'Policy p1 should be active for '
                                             'subscriber s1')

        s2_policies = assignments_dict["s2"].installed_policies
        expected = 1
        self.assertEqual(len(s2_policies), expected, 'There should be 1 active '
                                                     'policies for s2')
        self.assertTrue("p3" in s2_policies, 'Policy p3 should be active for '
                                             'subscriber s2')
    def test_FailedUpdate(self):
        """
        Test when sessiond answers to the RAR with a failure for any re-auth.
        """
        assignments_dict = {}
        apn_rules_dict = {} # type: Dict[str, SubscriberPolicySet]
        basenames_dict = {}
        callback = RuleMappingsStreamerCallback(
            ReAuthHandler(assignments_dict, MockSessionProxyResponderStub2()),
            basenames_dict,
            assignments_dict,
            apn_rules_dict,
        )

        # Construct a set of updates, keyed by subscriber ID
        updates = [
            DataUpdate(
                key="s1",
                value=AssignedPolicies(
                    assigned_policies=["p1", "p2"],
                ).SerializeToString(),
            ),
            DataUpdate(
                key="s2",
                value=AssignedPolicies(
                    assigned_policies=["p2", "p3"],
                ).SerializeToString(),
            ),
        ]

        callback.process_update("stream", updates, False)

        # Since we used a stub which always succeeds when a RAR is made,
        # We should expect the assignments_dict to be updated

        self.assertFalse("s1" in assignments_dict, 'There should be no entry '
                         'for subscriber s1 since update failed')
        self.assertFalse("s2" in assignments_dict, 'There should be no entry '
                         'for subscriber s2 since update failed')