コード例 #1
0
    def test_EnableStaticRules(self):
        """
        Check the happy path where everything succeeds.
        """
        rules_by_sid = {}
        rules_by_basename = {
            "bn1": ChargingRuleNameSet(RuleNames=["p4", "p5"], ),
        }
        reauth_handler = ReAuthHandler(
            rules_by_sid,
            MockSessionProxyResponderStub(),
        )

        servicer = PolicyRpcServicer(
            reauth_handler,
            rules_by_basename,
            MockPolicyAssignmentControllerStub(),
        )

        # Bind the rpc server to a free port
        thread_pool = futures.ThreadPoolExecutor(max_workers=10)
        rpc_server = grpc.server(thread_pool)
        port = rpc_server.add_insecure_port('0.0.0.0:0')

        # Create a mock "mconfig" for the servicer to use
        mconfig = unittest.mock.Mock()
        mconfig.ip_block = None

        # Add the servicer
        servicer.add_to_server(rpc_server)
        rpc_server.start()

        # Create a rpc stub
        channel = grpc.insecure_channel('0.0.0.0:{}'.format(port))
        stub = PolicyDBStub(channel)
        rules_by_basename["bn1"] = ChargingRuleNameSet(RuleNames=["p4",
                                                                  "p5"], )
        req = EnableStaticRuleRequest(
            imsi="s1",
            rule_ids=["p1", "p2", "p3"],
            base_names=["bn1"],
        )
        stub.EnableStaticRules(req)
        self.assertEqual(
            len(rules_by_sid["s1"].installed_policies),
            5,
            'After a successful update, Redis should be tracking '
            '5 active rules.',
        )
コード例 #2
0
    def test_FailOrc8r(self):
        """ Check that nothing is updated if orc8r is unreachable """
        rules_by_sid = {}
        rules_by_basename = {
            "bn1": ChargingRuleNameSet(RuleNames=["p4", "p5"], ),
        }
        reauth_handler = ReAuthHandler(
            rules_by_sid,
            MockSessionProxyResponderStub(),
        )

        servicer = PolicyRpcServicer(
            reauth_handler,
            rules_by_basename,
            MockPolicyAssignmentControllerStub2(),
        )

        # Bind the rpc server to a free port
        thread_pool = futures.ThreadPoolExecutor(max_workers=10)
        rpc_server = grpc.server(thread_pool)
        port = rpc_server.add_insecure_port('0.0.0.0:0')

        # Create a mock "mconfig" for the servicer to use
        mconfig = unittest.mock.Mock()
        mconfig.ip_block = None

        # Add the servicer
        servicer.add_to_server(rpc_server)
        rpc_server.start()

        # Create a rpc stub
        channel = grpc.insecure_channel('0.0.0.0:{}'.format(port))
        stub = PolicyDBStub(channel)
        req = EnableStaticRuleRequest(
            imsi="s1",
            rule_ids=["p1", "p2", "p3"],
            base_names=["bn1"],
        )
        with self.assertRaises(grpc.RpcError):
            stub.EnableStaticRules(req)

        self.assertFalse(
            "s1" in rules_by_sid,
            "There should be no installed policies for s1",
        )
コード例 #3
0
ファイル: policydb_cli.py プロジェクト: maniacs-ops/magma-1
def uninstall_rules(client: PolicyDBStub, args):
    """
    Uninstalls the specified static rules for the session.
    Also unassociates the static rules from the subscriber.
    """
    message = DisableStaticRuleRequest(
        imsi=args.imsi,
        rule_ids=args.rules,
        base_names=args.basenames,
    )
    try:
        client.DisableStaticRules(message)
    except grpc.RpcError as err:
        print('Failed to disable static rules and/or base names: %s' % str(err))
        print(DEBUG_MSG)