Exemplo n.º 1
0
 def test_catches_connection_errors_and_sets_component_error(self):
     sources = [
         factory.make_BootSource(keyring_data=b"1234") for _ in range(3)
     ]
     download_image_descriptions = self.patch(
         download_descriptions_module, "download_image_descriptions"
     )
     error_text_one = factory.make_name("<error1>")
     error_text_two = factory.make_name("<error2>")
     # Make two of the downloads fail.
     download_image_descriptions.side_effect = [
         ConnectionError(error_text_one),
         BootImageMapping(),
         IOError(error_text_two),
     ]
     cache_boot_sources()
     base_error = "Failed to import images from {url}: {err}"
     error_part_one = base_error.format(
         url=sources[0].url, err=html.escape(error_text_one)
     )
     error_part_two = base_error.format(
         url=sources[2].url, err=html.escape(error_text_two)
     )
     expected_error = error_part_one + "<br>" + error_part_two
     actual_error = get_persistent_error(COMPONENT.REGION_IMAGE_IMPORT)
     self.assertEqual(expected_error, actual_error)
Exemplo n.º 2
0
 def test_clears_component_error_when_successful(self):
     register_persistent_error(COMPONENT.REGION_IMAGE_IMPORT,
                               factory.make_string())
     [factory.make_BootSource(keyring_data=b"1234") for _ in range(3)]
     download_image_descriptions = self.patch(
         download_descriptions_module, "download_image_descriptions")
     # Make all of the downloads successful.
     download_image_descriptions.return_value = BootImageMapping()
     cache_boot_sources()
     self.assertIsNone(get_persistent_error(COMPONENT.REGION_IMAGE_IMPORT))
Exemplo n.º 3
0
def update_import_script_error():
    import_script = COMPONENT.IMPORT_PXE_FILES
    have_boot_images = BootImage.objects.all().exists()
    if not have_boot_images and get_persistent_error(import_script) is None:
        warning = dedent("""\
            The region controller does not know whether any boot images have
            been imported yet.  If this message does not disappear in 5
            minutes, there may be a communication problem between the region
            worker process and the region controller.  Check the region
            worker's logs for signs that it was unable to report to the MAAS
            API.
            """)
        register_persistent_error(import_script, warning)
Exemplo n.º 4
0
def update_import_script_error():
    import_script = COMPONENT.IMPORT_PXE_FILES
    have_boot_images = BootImage.objects.all().exists()
    if not have_boot_images and get_persistent_error(import_script) is None:
        warning = dedent("""\
            The region controller does not know whether any boot images have
            been imported yet.  If this message does not disappear in 5
            minutes, there may be a communication problem between the region
            worker process and the region controller.  Check the region
            worker's logs for signs that it was unable to report to the MAAS
            API.
            """)
        register_persistent_error(import_script, warning)
Exemplo n.º 5
0
    def test__registers_error_if_all_rack_controllers_are_disconnected(self):
        factory.make_RackController()

        getAllClients = self.patch(middleware_module, 'getAllClients')
        getAllClients.return_value = []

        self.quick_process()

        error = get_persistent_error(COMPONENT.RACK_CONTROLLERS)
        self.assertEqual(
            "One rack controller is not yet connected to the region. Visit "
            "the <a href=\"%s#/controllers\">"
            "rack controllers page</a> for more "
            "information." % (reverse('index')), error)
Exemplo n.º 6
0
    def test_registers_error_if_all_rack_controllers_are_disconnected(self):
        factory.make_RackController()

        getAllClients = self.patch(middleware_module, "getAllClients")
        getAllClients.return_value = []

        self.quick_process()

        error = get_persistent_error(COMPONENT.RACK_CONTROLLERS)
        self.assertEqual(
            "One rack controller is not yet connected to the region. Visit "
            'the <a href="/MAAS/l/controllers">'
            "rack controllers page</a> for more "
            "information.",
            error,
        )
Exemplo n.º 7
0
    def test__registers_error_if_all_rack_controllers_are_disconnected(self):
        factory.make_RackController()

        getAllClients = self.patch(middleware_module, 'getAllClients')
        getAllClients.return_value = []

        request = factory.make_fake_request(factory.make_string(), 'GET')
        middleware = ExternalComponentsMiddleware()
        middleware.process_request(request)

        error = get_persistent_error(COMPONENT.RACK_CONTROLLERS)
        self.assertEqual(
            "One rack controller is not yet connected to the region. Visit "
            "the <a href=\"%s#/nodes?tab=controllers\">"
            "rack controllers page</a> for more "
            "information." % (reverse('index')), error)
Exemplo n.º 8
0
    def test__removes_error_once_all_clusters_are_connected(self):
        rack_controllers = [
            factory.make_RackController(),
            factory.make_RackController(),
        ]

        getAllClients = self.patch(middleware_module, 'getAllClients')
        getAllClients.return_value = [
            Mock(ident=rack.system_id) for rack in rack_controllers
        ]

        register_persistent_error(COMPONENT.RACK_CONTROLLERS,
                                  "Who flung that batter pudding?")

        self.quick_process()

        error = get_persistent_error(COMPONENT.RACK_CONTROLLERS)
        self.assertIsNone(error)
Exemplo n.º 9
0
    def test__registers_error_if_any_clusters_are_disconnected(self):
        rack_controllers = [
            factory.make_RackController(),
            factory.make_RackController(),
            factory.make_RackController(),
        ]

        getAllClients = self.patch(middleware_module, 'getAllClients')
        getAllClients.return_value = [
            Mock(ident=rack_controllers[0].system_id)
        ]

        self.quick_process()

        error = get_persistent_error(COMPONENT.RACK_CONTROLLERS)
        self.assertEqual(
            "2 rack controllers are not yet connected to the region. Visit "
            "the <a href=\"%s#/controllers\">"
            "rack controllers page</a> for more "
            "information." % reverse('index'), error)
Exemplo n.º 10
0
 def test_get_persistent_error_returns_component_error(self):
     component = factory.make_name('component')
     error = factory.make_name('error')
     register_persistent_error(component, error)
     self.assertEqual(error, get_persistent_error(component))
Exemplo n.º 11
0
 def test_get_persistent_error_returns_None_if_no_error(self):
     self.assertIsNone(get_persistent_error(factory.make_name('component')))
Exemplo n.º 12
0
 def test_get_persistent_error_returns_component_error(self):
     component = factory.make_name('component')
     error = factory.make_name('error')
     register_persistent_error(component, error)
     self.assertEqual(error, get_persistent_error(component))
Exemplo n.º 13
0
 def test_get_persistent_error_returns_None_if_no_error(self):
     self.assertIsNone(get_persistent_error(factory.make_name('component')))