~mpontillo/maas/unmanaged-subnets

« back to all changes in this revision

Viewing changes to src/provisioningserver/import_images/tests/test_boot_resources.py

  • Committer: MAAS Lander
  • Author(s): Lee Trager
  • Date: 2016-11-28 23:27:31 UTC
  • mfrom: (5542.4.6 boot_import_events)
  • Revision ID: maas_lander-20161128232731-y13i2h3guxks0g02
[r=allenap][bug=1571031,1629982][author=ltrager] Add NodeEvents for boot import and tgt update errors.

Show diffs side-by-side

added added

removed removed

Lines of Context:
32
32
    MockCalledWith,
33
33
    MockCallsMatch,
34
34
)
35
 
from maastesting.testcase import (
36
 
    MAASTestCase,
37
 
    MAASTwistedRunTest,
38
 
)
 
35
from maastesting.testcase import MAASTestCase
39
36
from maastesting.utils import age_file
40
37
from provisioningserver.boot import BootMethodRegistry
41
38
from provisioningserver.config import (
55
52
    tempdir,
56
53
    write_text_file,
57
54
)
 
55
from provisioningserver.utils.shell import ExternalProcessError
58
56
from testtools.content import Content
59
57
from testtools.content_type import UTF8_TEXT
60
58
from testtools.matchers import (
596
594
        boot_resources.update_targets_conf(factory.make_name("snapshot"))
597
595
        self.assertThat(mock_ensureService, MockCalledOnceWith("tgt"))
598
596
 
 
597
    def test_update_targets_conf_logs_error(self):
 
598
        self.patch(boot_resources.service_monitor, "ensureService")
 
599
        mock_try_send_rack_event = self.patch(
 
600
            boot_resources, 'try_send_rack_event')
 
601
        mock_maaslog = self.patch(boot_resources.maaslog, 'warning')
 
602
        self.patch(boot_resources, 'call_and_check').side_effect = (
 
603
            ExternalProcessError(
 
604
                returncode=2, cmd=('tgt-admin',), output='error'))
 
605
        boot_resources.update_targets_conf(factory.make_name("snapshot"))
 
606
        self.assertThat(mock_try_send_rack_event, MockCalledOnce())
 
607
        self.assertThat(mock_maaslog, MockCalledOnce())
 
608
 
599
609
 
600
610
class TestMetaContains(MAASTestCase):
601
611
    """Tests for the `meta_contains` function."""
662
672
class TestImportImages(MAASTestCase):
663
673
    """Tests for the `import_images`() function."""
664
674
 
665
 
    run_tests_with = MAASTwistedRunTest.make_factory(timeout=5)
666
 
 
667
675
    def test_writes_source_keyrings(self):
668
676
        # Stop import_images() from actually doing anything.
669
677
        self.patch(boot_resources, 'maaslog')
 
678
        self.patch(boot_resources, 'try_send_rack_event')
670
679
        self.patch(boot_resources, 'call_and_check')
671
680
        self.patch(boot_resources, 'download_all_boot_resources')
672
681
        self.patch(boot_resources, 'download_all_image_descriptions')