def test_discard_persistent_error_can_be_called_many_times(self): error_message = factory.getRandomString() component = get_random_component() register_persistent_error(component, error_message) discard_persistent_error(component) discard_persistent_error(component) self.assertItemsEqual([], get_persistent_errors())
def test_permanent_error_displayed(self): fault_codes = [ randint(1, 100), randint(101, 200), ] errors = [] for fault in fault_codes: # Create component with getRandomString to be sure # to display all the errors. component = factory.make_name('component') error_message = factory.make_name('error') error = Fault(fault, error_message) errors.append(error) register_persistent_error(component, error_message) links = [ reverse('index'), reverse('node-list'), reverse('prefs'), ] for link in links: response = self.client.get(link) self.assertThat( response.content, ContainsAll( [escape(error.faultString) for error in errors]))
def test_register_persistent_error_stores_last_error(self): error_message = factory.make_string() error_message2 = factory.make_string() component = get_random_component() register_persistent_error(component, error_message) register_persistent_error(component, error_message2) self.assertItemsEqual([error_message2], get_persistent_errors())
def _check_rack_controller_connectivity(self): """Check each rack controller to see if it's connected. If any rack controllers are disconnected, add a persistent error. """ controllers = RackController.objects.all() connected_ids = {client.ident for client in getAllClients()} disconnected_controllers = { controller for controller in controllers if controller.system_id not in connected_ids } if len(disconnected_controllers) == 0: discard_persistent_error(COMPONENT.RACK_CONTROLLERS) else: if len(disconnected_controllers) == 1: message = ( "One rack controller is not yet connected to the region") else: message = ( "%d rack controllers are not yet connected to the region" % len(disconnected_controllers)) message = ('%s. Visit the <a href="/MAAS/#/controllers">' "rack controllers page</a> for " "more information." % message) register_persistent_error(COMPONENT.RACK_CONTROLLERS, message)
def test_discard_persistent_error_can_be_called_many_times(self): error_message = factory.make_string() component = get_random_component() register_persistent_error(component, error_message) discard_persistent_error(component) discard_persistent_error(component) self.assertItemsEqual([], get_persistent_errors())
def test_register_persistent_error_stores_last_error(self): error_message = factory.getRandomString() error_message2 = factory.getRandomString() component = get_random_component() register_persistent_error(component, error_message) register_persistent_error(component, error_message2) self.assertItemsEqual( [error_message2], get_persistent_errors())
def get_persistent_errors_returns_text_for_error_codes(self): errors, components = [], [] for _ in range(3): error_message = factory.make_string() component = get_random_component() register_persistent_error(component, error_message) errors.append(error_message) components.append(component) self.assertItemsEqual(errors, get_persistent_errors())
def get_persistent_errors_returns_text_for_error_codes(self): errors, components = [], [] for i in range(3): error_message = factory.getRandomString() component = get_random_component() register_persistent_error(component, error_message) errors.append(error_message) components.append(component) self.assertItemsEqual(errors, get_persistent_errors())
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))
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)
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)
def test_start_up_does_not_warn_if_already_warning(self): # If there already is a warning about missing boot images, it is # based on more precise knowledge of whether we ever heard from # the region worker at all. It will not be replaced by a less # knowledgeable warning. BootImage.objects.all().delete() register_persistent_error(COMPONENT.IMPORT_PXE_FILES, factory.getRandomString()) recorder = self.patch(start_up, 'register_persistent_error') start_up.start_up() self.assertNotIn(COMPONENT.IMPORT_PXE_FILES, [args[0][0] for args in recorder.call_args_list])
def test_start_up_does_not_warn_if_already_warning(self): # If there already is a warning about missing boot images, it is # based on more precise knowledge of whether we ever heard from # the region worker at all. It will not be replaced by a less # knowledgeable warning. BootImage.objects.all().delete() register_persistent_error( COMPONENT.IMPORT_PXE_FILES, factory.getRandomString()) recorder = self.patch(start_up, 'register_persistent_error') start_up.start_up() self.assertNotIn( COMPONENT.IMPORT_PXE_FILES, [args[0][0] for args in recorder.call_args_list])
def test_register_persistent_error_reuses_component_errors(self): """When registering a persistent error that already has an error recorded for that component, reuse the error instead of deleting and recreating it.""" component = factory.make_name("component") error1 = factory.make_name("error") error2 = factory.make_name("error") register_persistent_error(component, error1) notification = Notification.objects.get(ident=component) self.assertEqual(notification.render(), error1) notification_id = notification.id register_persistent_error(component, error2) notification = Notification.objects.get(ident=component) # The message is updated. self.assertEqual(notification.render(), error2) # The same notification row is used. self.assertEqual(notification.id, notification_id)
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)
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))
def test_discard_persistent_error_discards_error(self): error_message = factory.getRandomString() component = get_random_component() register_persistent_error(component, error_message) discard_persistent_error(component) self.assertItemsEqual([], get_persistent_errors())
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))