Merge lp:~blake-rouse/maas/fix-1341001 into lp:~maas-committers/maas/trunk

Proposed by Blake Rouse
Status: Merged
Approved by: Blake Rouse
Approved revision: no longer in the source branch.
Merged at revision: 2552
Proposed branch: lp:~blake-rouse/maas/fix-1341001
Merge into: lp:~maas-committers/maas/trunk
Diff against target: 185 lines (+76/-23)
4 files modified
src/provisioningserver/import_images/boot_resources.py (+25/-16)
src/provisioningserver/import_images/tests/test_boot_resources.py (+2/-0)
src/provisioningserver/tests/test_upgrade_cluster.py (+34/-1)
src/provisioningserver/upgrade_cluster.py (+15/-6)
To merge this branch: bzr merge lp:~blake-rouse/maas/fix-1341001
Reviewer Review Type Date Requested Status
Gavin Panella (community) Approve
Review via email: mp+226673@code.launchpad.net

Commit message

Re-write maas.tgt on cluster upgrade, when moving from 1.5 to 1.6.

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

Looks good, one comment in the diff.

Is there a reason to choose this approach rather than running an import? Would the ideal actually be to run this migration *and then* run an import too?

review: Approve
Revision history for this message
Blake Rouse (blake-rouse) wrote :

From 1.5 to 1.6 the removal of bootresources.yaml and hwe kernel imports by default. The import would take a while, making the upgrade a very long process.

This approach allows the user to keep all imported files, and allow them to still work with 1.6.

Revision history for this message
Gavin Panella (allenap) wrote :

> From 1.5 to 1.6 the removal of bootresources.yaml and hwe kernel
> imports by default. The import would take a while, making the upgrade
> a very long process.
>
> This approach allows the user to keep all imported files, and allow
> them to still work with 1.6.

Thanks for the explanations :)

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 2014-06-09 19:58:06 +0000
3+++ src/provisioningserver/import_images/boot_resources.py 2014-07-14 14:30:58 +0000
4@@ -159,14 +159,30 @@
5 os.symlink(latest_snapshot, symlink_path)
6
7
8-def write_snapshot_metadata(snapshot, meta_file_content, targets_conf,
9- targets_conf_content):
10- """Write "meta" file and tgt config for `snapshot`."""
11+def write_snapshot_metadata(snapshot, meta_file_content):
12+ """Write "maas.meta" file."""
13 meta_file = os.path.join(snapshot, 'maas.meta')
14 atomic_write(meta_file_content, meta_file, mode=0644)
15+
16+
17+def write_targets_conf(snapshot):
18+ """Write "maas.tgt" file."""
19+ targets_conf = os.path.join(snapshot, 'maas.tgt')
20+ targets_conf_content = compose_targets_conf(snapshot)
21 atomic_write(targets_conf_content, targets_conf, mode=0644)
22
23
24+def update_targets_conf(snapshot):
25+ """Runs tgt-admin to update the new targets from "maas.tgt"."""
26+ targets_conf = os.path.join(snapshot, 'maas.tgt')
27+ call_and_check([
28+ 'sudo',
29+ '/usr/sbin/tgt-admin',
30+ '--conf', targets_conf,
31+ '--update', 'ALL',
32+ ])
33+
34+
35 def read_sources(sources_yaml):
36 """Read boot resources config file.
37
38@@ -228,25 +244,18 @@
39
40 snapshot_path = download_all_boot_resources(
41 sources, storage, product_mapping)
42- targets_conf = os.path.join(snapshot_path, 'maas.tgt')
43-
44- targets_conf_content = compose_targets_conf(snapshot_path)
45-
46- logger.info("Writing metadata and updating iSCSI targets.")
47- write_snapshot_metadata(
48- snapshot_path, meta_file_content, targets_conf, targets_conf_content)
49- call_and_check([
50- 'sudo',
51- '/usr/sbin/tgt-admin',
52- '--conf', targets_conf,
53- '--update', 'ALL',
54- ])
55+
56+ logger.info("Writing metadata and iSCSI targets.")
57+ write_snapshot_metadata(snapshot_path, meta_file_content)
58+ write_targets_conf(snapshot_path)
59
60 logger.info("Installing boot images snapshot %s.", snapshot_path)
61 install_boot_loaders(snapshot_path)
62
63 # If we got here, all went well. This is now truly the "current" snapshot.
64 update_current_symlink(storage, snapshot_path)
65+ logger.info("Updating iSCSI targets.")
66+ update_targets_conf(snapshot_path)
67 logger.info("Import done.")
68
69
70
71=== modified file 'src/provisioningserver/import_images/tests/test_boot_resources.py'
72--- src/provisioningserver/import_images/tests/test_boot_resources.py 2014-06-20 13:38:39 +0000
73+++ src/provisioningserver/import_images/tests/test_boot_resources.py 2014-07-14 14:30:58 +0000
74@@ -424,6 +424,8 @@
75 self.patch(boot_resources, 'install_boot_loaders')
76 self.patch(boot_resources, 'update_current_symlink')
77 self.patch(boot_resources, 'write_snapshot_metadata')
78+ self.patch(boot_resources, 'write_targets_conf')
79+ self.patch(boot_resources, 'update_targets_conf')
80
81 fake_write_all_keyrings = self.patch(
82 boot_resources, 'write_all_keyrings')
83
84=== modified file 'src/provisioningserver/tests/test_upgrade_cluster.py'
85--- src/provisioningserver/tests/test_upgrade_cluster.py 2014-07-08 13:39:40 +0000
86+++ src/provisioningserver/tests/test_upgrade_cluster.py 2014-07-14 14:30:58 +0000
87@@ -254,6 +254,7 @@
88 os.makedirs(
89 os.path.join(
90 storage_dir, 'current', arch, subarch, release, label))
91+ self.patch(upgrade_cluster, 'update_targets_conf')
92 upgrade_cluster.migrate_architectures_into_ubuntu_directory()
93 self.assertItemsEqual(
94 arches,
95@@ -279,6 +280,7 @@
96 factory.make_name('subarch'),
97 factory.make_name('release'),
98 factory.make_name('label')))
99+ self.patch(upgrade_cluster, 'update_targets_conf')
100 upgrade_cluster.migrate_architectures_into_ubuntu_directory()
101 self.assertItemsEqual(
102 [move_arch],
103@@ -308,8 +310,39 @@
104 factory.make_name('subarch'),
105 factory.make_name('release'),
106 factory.make_name('label')))
107-
108+ self.patch(upgrade_cluster, 'update_targets_conf')
109 upgrade_cluster.migrate_architectures_into_ubuntu_directory()
110 self.assertItemsEqual(
111 [move_arch],
112 list_subdirs(os.path.join(storage_dir, 'current', 'ubuntu')))
113+
114+ def setup_working_migration_scenario(self):
115+ storage_dir = self.make_dir()
116+ self.configure_storage(storage_dir)
117+ arches = [factory.make_name('arch') for _ in range(3)]
118+ subarches = [factory.make_name('subarch') for _ in range(3)]
119+ releases = [factory.make_name('release') for _ in range(3)]
120+ labels = [factory.make_name('label') for _ in range(3)]
121+ for arch, subarch, release, label in product(
122+ arches, subarches, releases, labels):
123+ os.makedirs(
124+ os.path.join(
125+ storage_dir, 'current', arch, subarch, release, label))
126+ return storage_dir
127+
128+ def test__calls_write_targets_conf_with_current_dir(self):
129+ storage_dir = self.setup_working_migration_scenario()
130+ mock_write = self.patch(upgrade_cluster, 'write_targets_conf')
131+ self.patch(upgrade_cluster, 'update_targets_conf')
132+ upgrade_cluster.migrate_architectures_into_ubuntu_directory()
133+ self.assertThat(
134+ mock_write,
135+ MockCalledOnceWith(os.path.join(storage_dir, 'current')))
136+
137+ def test__calls_update_targets_conf_with_current_dir(self):
138+ storage_dir = self.setup_working_migration_scenario()
139+ mock_update = self.patch(upgrade_cluster, 'update_targets_conf')
140+ upgrade_cluster.migrate_architectures_into_ubuntu_directory()
141+ self.assertThat(
142+ mock_update,
143+ MockCalledOnceWith(os.path.join(storage_dir, 'current')))
144
145=== modified file 'src/provisioningserver/upgrade_cluster.py'
146--- src/provisioningserver/upgrade_cluster.py 2014-07-08 13:39:40 +0000
147+++ src/provisioningserver/upgrade_cluster.py 2014-07-14 14:30:58 +0000
148@@ -45,7 +45,10 @@
149 drill_down,
150 list_subdirs,
151 )
152-
153+from provisioningserver.import_images.boot_resources import (
154+ write_targets_conf,
155+ update_targets_conf,
156+ )
157
158 logger = getLogger(__name__)
159
160@@ -184,14 +187,20 @@
161 # Extract the only top directories (arch) from the paths, as we only need
162 # its name to move into the new 'ubuntu' folder.
163 arches = {arch for arch, _, _, _ in paths}
164+ if len(arches) == 0:
165+ return
166
167 # Create the ubuntu directory and move the archiecture folders under that
168 # directory.
169- if len(arches) > 0:
170- ubuntu_dir = os.path.join(current_dir, 'ubuntu')
171- os.mkdir(ubuntu_dir)
172- for arch in arches:
173- shutil.move(os.path.join(current_dir, arch), ubuntu_dir)
174+ ubuntu_dir = os.path.join(current_dir, 'ubuntu')
175+ os.mkdir(ubuntu_dir)
176+ for arch in arches:
177+ shutil.move(os.path.join(current_dir, arch), ubuntu_dir)
178+
179+ # Re-write the maas.tgt to point to the new location for the ubuntu boot
180+ # resources.
181+ write_targets_conf(current_dir)
182+ update_targets_conf(current_dir)
183
184
185 # Upgrade hooks, from oldest to newest. The hooks are callables, taking no