Ejemplo n.º 1
0
    def test_list_num_queries_is_the_expected_number(self):
        # Prevent RBAC from making a query.
        self.useFixture(RBACForceOffFixture())

        admin = factory.make_admin()
        handler = UserHandler(admin, {}, None)
        for _ in range(3):
            factory.make_User()
        queries_one, _ = count_queries(handler.list, {"limit": 1})
        queries_total, _ = count_queries(handler.list, {})
        # This check is to notify the developer that a change was made that
        # affects the number of queries performed when doing a user listing.
        # It is important to keep this number as low as possible. A larger
        # number means regiond has to do more work slowing down its process
        # and slowing down the client waiting for the response.
        self.assertEqual(
            queries_one,
            1,
            "Number of queries has changed; make sure this is expected.",
        )
        self.assertEqual(
            queries_total,
            1,
            "Number of queries has changed; make sure this is expected.",
        )
Ejemplo n.º 2
0
    def test_list_num_queries_is_the_expected_number(self):
        self.useFixture(RBACForceOffFixture())

        owner = factory.make_admin()
        for _ in range(10):
            node = factory.make_RegionRackController(owner=owner)
            commissioning_script_set = factory.make_ScriptSet(
                node=node, result_type=RESULT_TYPE.COMMISSIONING)
            testing_script_set = factory.make_ScriptSet(
                node=node, result_type=RESULT_TYPE.TESTING)
            node.current_commissioning_script_set = commissioning_script_set
            node.current_testing_script_set = testing_script_set
            node.save()
            for __ in range(10):
                factory.make_ScriptResult(status=SCRIPT_STATUS.PASSED,
                                          script_set=commissioning_script_set)
                factory.make_ScriptResult(status=SCRIPT_STATUS.PASSED,
                                          script_set=testing_script_set)

        handler = ControllerHandler(owner, {}, None)
        queries_one, _ = count_queries(handler.list, {'limit': 1})
        queries_total, _ = count_queries(handler.list, {})
        # This check is to notify the developer that a change was made that
        # affects the number of queries performed when doing a node listing.
        # It is important to keep this number as low as possible. A larger
        # number means regiond has to do more work slowing down its process
        # and slowing down the client waiting for the response.
        self.assertEqual(
            queries_one, 3,
            "Number of queries has changed; make sure this is expected.")
        self.assertEqual(
            queries_total, 3,
            "Number of queries has changed; make sure this is expected.")
Ejemplo n.º 3
0
    def test_list_num_queries_is_independent_of_num_devices(self):
        # Prevent RBAC from making a query.
        self.useFixture(RBACForceOffFixture())

        owner = factory.make_User()
        handler = SwitchHandler(owner, {}, None)
        for _ in range(10):
            device = factory.make_Device(owner=owner)
            factory.make_Switch(node=device)
        query_10_count, _ = count_queries(handler.list, {})
        for _ in range(10):
            device = factory.make_Device(owner=owner)
            factory.make_Switch(node=device)
        query_20_count, _ = count_queries(handler.list, {})

        # This check is to notify the developer that a change was made that
        # affects the number of queries performed when doing a node listing.
        # It is important to keep this number as low as possible. A larger
        # number means regiond has to do more work slowing down its process
        # and slowing down the client waiting for the response.
        self.assertEqual(
            query_10_count,
            query_20_count,
            "Number of queries has changed; make sure this is expected.",
        )
Ejemplo n.º 4
0
    def test_query_num_queries_is_independent_of_num_nodes_and_events(self):
        # Prevent RBAC from making a query.
        self.useFixture(RBACForceOffFixture())

        expected_queries = 1
        events_per_node = 5
        num_nodes_per_group = 5
        events_per_group = num_nodes_per_group * events_per_node

        self.make_nodes_in_group_with_events(num_nodes_per_group,
                                             events_per_node)

        handler = events_module.EventsHandler()

        query_1_count, query_1_result = count_queries(
            handler.query,
            RequestFixture({
                "op": "query",
                "level": "DEBUG"
            }, ["op", "level"]),
        )

        self.make_nodes_in_group_with_events(num_nodes_per_group,
                                             events_per_node)

        query_2_count, query_2_result = count_queries(
            handler.query,
            RequestFixture({
                "op": "query",
                "level": "DEBUG"
            }, ["op", "level"]),
        )

        # This check is to notify the developer that a change was made that
        # affects the number of queries performed when doing an event listing.
        # If this happens, consider your prefetching and adjust accordingly.
        self.assertEqual(events_per_group, int(query_1_result["count"]))
        self.assertEqual(
            expected_queries,
            query_1_count,
            "Number of queries has changed; make sure this is expected.",
        )

        self.assertEqual(events_per_group * 2, int(query_2_result["count"]))
        self.assertEqual(
            query_1_count,
            query_2_count,
            "Number of queries is not independent of the number of nodes.",
        )
Ejemplo n.º 5
0
    def test_list_num_queries_is_independent_of_num_devices(self):
        # Prevent RBAC from making a query.
        self.useFixture(RBACForceOffFixture())

        owner = factory.make_User()
        handler = DeviceHandler(owner, {}, None)
        ip_assignment = factory.pick_enum(DEVICE_IP_ASSIGNMENT_TYPE)
        self.make_devices(10, owner=owner, ip_assignment=ip_assignment)
        query_10_count, _ = count_queries(handler.list, {})
        self.make_devices(10, owner=owner, ip_assignment=ip_assignment)
        query_20_count, _ = count_queries(handler.list, {})

        # This check is to notify the developer that a change was made that
        # affects the number of queries performed when doing a node listing.
        # It is important to keep this number as low as possible. A larger
        # number means regiond has to do more work slowing down its process
        # and slowing down the client waiting for the response.
        self.assertEqual(
            query_10_count, query_20_count,
            "Number of queries is not independent to the number of nodes.")