예제 #1
0
 def test_fully_dehydrated_controller_contains_essential_fields(self):
     user = factory.make_User()
     controller = self.make_controller()
     handler = ControllerHandler(user, {}, None)
     data = handler.full_dehydrate(controller, for_list=False)
     self.assertThat(
         data,
         ContainsDict(
             {
                 handler._meta.pk: Equals(
                     getattr(controller, handler._meta.pk)
                 ),
                 handler._meta.batch_key: Equals(
                     getattr(controller, handler._meta.batch_key)
                 ),
             }
         ),
     )
예제 #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,
            5,
            "Number of queries has changed; make sure this is expected.",
        )
        self.assertEqual(
            queries_total,
            5,
            "Number of queries has changed; make sure this is expected.",
        )
예제 #3
0
 def test_dehydrate_not_up_to_date_no_update(self):
     owner = factory.make_admin()
     handler = ControllerHandler(owner, {}, None)
     rack = factory.make_RackController()
     versions = SnapVersionsInfo(
         current={
             "revision": "1234",
             "version": "3.0.0~alpha1-111-g.deadbeef",
         },
         channel={"track": "3.0", "risk": "stable"},
     )
     ControllerInfo.objects.set_versions_info(rack, versions)
     # another rack as a higher version
     ControllerInfo.objects.set_versions_info(
         factory.make_RackController(),
         SnapVersionsInfo(
             current={
                 "revision": "1234",
                 "version": "3.0.0-222-g.cafecafe",
             },
             channel={"track": "3.0", "risk": "stable"},
         ),
     )
     result = handler.list({})
     self.assertEqual(
         result[0]["versions"],
         {
             "install_type": "snap",
             "current": {
                 "version": "3.0.0~alpha1-111-g.deadbeef",
                 "snap_revision": "1234",
             },
             "origin": "3.0/stable",
             "up_to_date": False,
             "issues": [],
         },
     )
예제 #4
0
    def test_vlan_counts_list(self):
        owner = factory.make_admin()
        rack1 = factory.make_RackController(owner=owner)
        rack2 = factory.make_RackController(owner=owner)
        vlan1, vlan2 = VLAN.objects.order_by("id")
        # attach the first rack to both VLANs
        iface = factory.make_Interface(node=rack1, vlan=vlan2)
        factory.make_StaticIPAddress(interface=iface)
        vlan1.primary_rack = rack1
        vlan1.save()
        # make the second VLAN HA
        vlan2.primary_rack = rack2
        vlan2.secondary_rack = rack1
        vlan2.save()

        handler = ControllerHandler(owner, {}, None)
        result = {entry["id"]: entry["vlans_ha"] for entry in handler.list({})}
        self.assertEqual(
            result,
            {
                rack1.id: {"true": 1, "false": 1},
                rack2.id: {"true": 1, "false": 0},
            },
        )
예제 #5
0
 def test_dehydrate_show_os_info_returns_true(self):
     owner = factory.make_admin()
     rack = factory.make_RackController()
     handler = ControllerHandler(owner, {}, None)
     self.assertTrue(handler.dehydrate_show_os_info(rack))
예제 #6
0
 def test_get_form_class_for_update(self):
     user = factory.make_admin()
     handler = ControllerHandler(user, {}, None)
     self.assertEqual(ControllerForm, handler.get_form_class("update"))
예제 #7
0
 def test_register_info_non_admin(self):
     user = factory.make_User()
     handler = ControllerHandler(user, {}, None)
     self.assertRaises(HandlerPermissionError, handler.register_info, {})
예제 #8
0
 def test_dehydrate_empty_versions(self):
     owner = factory.make_admin()
     handler = ControllerHandler(owner, {}, None)
     factory.make_RackController()
     result = handler.list({})
     self.assertEqual(result[0]["versions"], {})