47
47
:return: Full absolute path to the directory holding the requisite files
48
48
for this archive, arch, and release.
51
archive, 'dists', release, 'main', 'installer-%s' % arch, 'current',
52
'images', 'netboot', 'ubuntu-installer', arch)
50
if arch[0] in {'amd64', 'i386'}:
52
archive, 'dists', release, 'main', 'installer-%s' % arch[0],
53
'current', 'images', 'netboot', 'ubuntu-installer', arch[0])
54
elif arch[0] == 'armhf':
56
archive, 'dists', '%s-updates' % release, 'main',
57
'installer-%s' % arch[0], 'current', 'images', arch[1], 'netboot')
59
raise NotImplementedError('Unknown architecture: %r' % arch)
62
def compose_download_kernel_name(arch, release):
63
"""Name the kernel file expected to be found in a netboot archive.
65
:param archive: Archive directory (corresponding to the script's ARCHIVE
66
setting, except here it's a filesystem path not a URL).
67
:param arch: Architecture.
68
:return: the kernel name string, eg. "vmlinuz" or "linux" as appropriate
70
if arch[0] in {'amd64', 'i386'}:
72
elif arch[0] == 'armhf':
75
raise NotImplementedError('Unknown architecture: %r' % arch)
78
def compose_download_filenames(arch, release):
79
"""Name files expected to be found in the directory of a netboot archive.
81
:param archive: Archive directory (corresponding to the script's ARCHIVE
82
setting, except here it's a filesystem path not a URL).
83
:param arch: Architecture.
84
:return: list of names to be found in the netboot directory for this
85
particular arch and release. Eg: ['vmlinuz', 'initrd.gz'] or
86
['linux', 'initrd.gz'] as appropriate.
88
return [compose_download_kernel_name(arch, release), 'initrd.gz']
55
91
def compose_tftp_bootloader_path(tftproot):
131
174
check_call(script, env=env, stdout=dev_null)
133
176
def test_procures_pre_boot_loader(self):
134
arch = factory.make_name('arch')
135
177
release = 'precise'
136
archive = self.make_downloads(arch=arch, release=release)
137
self.call_script(archive, self.tftproot, arch=arch, release=release)
178
archive = self.make_downloads(arch=self.arch, release=release)
180
archive, self.tftproot, arch=self.arch, release=release)
138
181
tftp_path = compose_tftp_bootloader_path(self.tftproot)
139
182
expected_contents = read_file('/usr/lib/syslinux', 'pxelinux.0')
140
183
self.assertThat(tftp_path, FileContains(expected_contents))
142
185
def test_updates_pre_boot_loader(self):
143
arch = factory.make_name('arch')
144
186
release = 'precise'
145
187
tftp_path = compose_tftp_bootloader_path(self.tftproot)
146
188
with open(tftp_path, 'w') as existing_file:
147
189
existing_file.write(factory.getRandomString())
148
archive = self.make_downloads(arch=arch, release=release)
149
self.call_script(archive, self.tftproot, arch=arch, release=release)
190
archive = self.make_downloads(arch=self.arch, release=release)
192
archive, self.tftproot, arch=self.arch, release=release)
150
193
expected_contents = read_file('/usr/lib/syslinux', 'pxelinux.0')
151
194
self.assertThat(tftp_path, FileContains(expected_contents))
153
196
def test_procures_install_image(self):
154
arch = factory.make_name('arch')
155
197
release = 'precise'
156
archive = self.make_downloads(arch=arch, release=release)
157
self.call_script(archive, self.tftproot, arch=arch, release=release)
198
archive = self.make_downloads(arch=self.arch, release=release)
200
archive, self.tftproot, arch=self.arch, release=release)
158
201
tftp_path = compose_tftp_path(
159
self.tftproot, arch, release, 'install', 'linux')
160
download_path = compose_download_dir(archive, arch, release)
161
expected_contents = read_file(download_path, 'linux')
202
self.tftproot, self.arch, release, 'install', 'linux')
203
download_path = compose_download_dir(archive, self.arch, release)
204
expected_contents = read_file(download_path,
205
compose_download_kernel_name(self.arch, release))
162
206
self.assertThat(tftp_path, FileContains(expected_contents))
164
208
def test_updates_install_image(self):
165
arch = factory.make_name('arch')
166
209
release = 'precise'
167
210
tftp_path = compose_tftp_path(
168
self.tftproot, arch, release, 'install', 'linux')
211
self.tftproot, self.arch, release, 'install', 'linux')
169
212
os.makedirs(os.path.dirname(tftp_path))
170
213
with open(tftp_path, 'w') as existing_file:
171
214
existing_file.write(factory.getRandomString())
172
archive = self.make_downloads(arch=arch, release=release)
173
self.call_script(archive, self.tftproot, arch=arch, release=release)
174
download_path = compose_download_dir(archive, arch, release)
175
expected_contents = read_file(download_path, 'linux')
215
archive = self.make_downloads(arch=self.arch, release=release)
217
archive, self.tftproot, arch=self.arch, release=release)
218
download_path = compose_download_dir(archive, self.arch, release)
219
expected_contents = read_file(download_path,
220
compose_download_kernel_name(self.arch, release))
176
221
self.assertThat(tftp_path, FileContains(expected_contents))
178
223
def test_leaves_install_image_untouched_if_unchanged(self):
179
arch = factory.make_name('arch')
180
224
release = 'precise'
181
archive = self.make_downloads(arch=arch, release=release)
182
self.call_script(archive, self.tftproot, arch=arch, release=release)
225
archive = self.make_downloads(arch=self.arch, release=release)
227
archive, self.tftproot, arch=self.arch, release=release)
183
228
tftp_path = compose_tftp_path(
184
self.tftproot, arch, release, 'install', 'linux')
229
self.tftproot, self.arch, release, 'install', 'linux')
185
230
backdate(tftp_path)
186
231
original_timestamp = get_write_time(tftp_path)
187
self.call_script(archive, self.tftproot, arch=arch, release=release)
233
archive, self.tftproot, arch=self.arch, release=release)
188
234
self.assertEqual(original_timestamp, get_write_time(tftp_path))