Merge lp:~ltrager/maas/lp1655721 into lp:~maas-committers/maas/trunk

Proposed by Lee Trager
Status: Merged
Approved by: Lee Trager
Approved revision: no longer in the source branch.
Merged at revision: 5643
Proposed branch: lp:~ltrager/maas/lp1655721
Merge into: lp:~maas-committers/maas/trunk
Diff against target: 78 lines (+27/-2)
2 files modified
src/provisioningserver/import_images/boot_resources.py (+7/-1)
src/provisioningserver/import_images/tests/test_boot_resources.py (+20/-1)
To merge this branch: bzr merge lp:~ltrager/maas/lp1655721
Reviewer Review Type Date Requested Status
Gavin Panella (community) Approve
Andres Rodriguez Pending
Review via email: mp+314574@code.launchpad.net

Commit message

Only reload TGT config when a TGT config file exists.

Description of the change

From the pastebin in the bug it looks like no images were imported so there was no config file to reload. This patches MAAS to only reload TGT when a config is available.

To post a comment you must log in.
Revision history for this message
Gavin Panella (allenap) wrote :

Looks fine to me. One question, one suggestion, no blockers.

review: Approve
Revision history for this message
Lee Trager (ltrager) :

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/provisioningserver/import_images/boot_resources.py'
2--- src/provisioningserver/import_images/boot_resources.py 2016-12-07 12:46:14 +0000
3+++ src/provisioningserver/import_images/boot_resources.py 2017-01-17 21:00:33 +0000
4@@ -1,4 +1,4 @@
5-# Copyright 2014-2016 Canonical Ltd. This software is licensed under the
6+# Copyright 2014-2017 Canonical Ltd. This software is licensed under the
7 # GNU Affero General Public License version 3 (see the file LICENSE).
8
9 __all__ = [
10@@ -208,6 +208,12 @@
11
12 # Update the tgt config.
13 targets_conf = os.path.join(snapshot, 'maas.tgt')
14+
15+ # The targets_conf may not exist in the event the BootSource is broken
16+ # and images havn't been imported yet. This fixes LP:1655721
17+ if not os.path.exists(targets_conf):
18+ return
19+
20 try:
21 call_and_check(sudo([
22 '/usr/sbin/tgt-admin',
23
24=== modified file 'src/provisioningserver/import_images/tests/test_boot_resources.py'
25--- src/provisioningserver/import_images/tests/test_boot_resources.py 2016-12-07 12:46:14 +0000
26+++ src/provisioningserver/import_images/tests/test_boot_resources.py 2017-01-17 21:00:33 +0000
27@@ -1,4 +1,4 @@
28-# Copyright 2014-2016 Canonical Ltd. This software is licensed under the
29+# Copyright 2014-2017 Canonical Ltd. This software is licensed under the
30 # GNU Affero General Public License version 3 (see the file LICENSE).
31
32 """Tests for the boot_resources module."""
33@@ -25,12 +25,14 @@
34 )
35
36 from maastesting.factory import factory
37+from maastesting.fixtures import TempDirectory
38 from maastesting.matchers import (
39 MockAnyCall,
40 MockCalledOnce,
41 MockCalledOnceWith,
42 MockCalledWith,
43 MockCallsMatch,
44+ MockNotCalled,
45 )
46 from maastesting.testcase import MAASTestCase
47 from maastesting.utils import age_file
48@@ -599,6 +601,7 @@
49 mock_try_send_rack_event = self.patch(
50 boot_resources, 'try_send_rack_event')
51 mock_maaslog = self.patch(boot_resources.maaslog, 'warning')
52+ self.patch(boot_resources.os.path, 'exists').return_value = True
53 self.patch(boot_resources, 'call_and_check').side_effect = (
54 ExternalProcessError(
55 returncode=2, cmd=('tgt-admin',), output='error'))
56@@ -606,6 +609,22 @@
57 self.assertThat(mock_try_send_rack_event, MockCalledOnce())
58 self.assertThat(mock_maaslog, MockCalledOnce())
59
60+ def test_update_targets_only_runs_when_conf_exists(self):
61+ # Regression test for LP:1655721
62+ temp_dir = self.useFixture(TempDirectory()).path
63+ self.useFixture(ClusterConfigurationFixture(tftp_root=temp_dir))
64+ mock_ensureService = self.patch(
65+ boot_resources.service_monitor, "ensureService")
66+ mock_call_and_check = self.patch(boot_resources, "call_and_check")
67+ mock_path_exists = self.patch(boot_resources.os.path, 'exists')
68+ mock_path_exists.return_value = False
69+ boot_resources.update_targets_conf(temp_dir)
70+ self.assertThat(mock_ensureService, MockCalledOnceWith("tgt"))
71+ self.assertThat(
72+ mock_path_exists,
73+ MockCalledOnceWith(os.path.join(temp_dir, 'maas.tgt')))
74+ self.assertThat(mock_call_and_check, MockNotCalled())
75+
76
77 class TestMetaContains(MAASTestCase):
78 """Tests for the `meta_contains` function."""