blob: b7b6aece956274aa441cad25ecf0fbfe3a9b200c [file] [log] [blame]
Mike Frysingerf1ba7ad2022-09-12 05:42:57 -04001# Copyright 2019 The ChromiumOS Authors
Evan Hernandezd437b4e2019-03-25 13:48:30 -06002# Use of this source code is governed by a BSD-style license that can be
3# found in the LICENSE file.
4
5"""Unittests for Binhost operations."""
6
Michael Mortensenfc823882019-08-27 14:38:07 -06007import os
Mike Frysinger166fea02021-02-12 05:30:33 -05008from unittest import mock
Mike Frysingeref94e4c2020-02-10 23:59:54 -05009
Alex Klein231d2da2019-07-22 16:44:45 -060010from chromite.api import api_config
Evan Hernandezd437b4e2019-03-25 13:48:30 -060011from chromite.api.controller import binhost
12from chromite.api.gen.chromite.api import binhost_pb2
LaMont Jonesc64ae212019-04-15 15:41:28 -060013from chromite.lib import cros_build_lib
Evan Hernandezd437b4e2019-03-25 13:48:30 -060014from chromite.lib import cros_test_lib
Michael Mortensenfc823882019-08-27 14:38:07 -060015from chromite.lib import osutils
Evan Hernandezd437b4e2019-03-25 13:48:30 -060016from chromite.service import binhost as binhost_service
17
Alex Klein231d2da2019-07-22 16:44:45 -060018
Michael Mortensena0af77b2019-11-13 11:15:15 -070019class GetBinhostsTest(cros_test_lib.MockTestCase, api_config.ApiConfigMixin):
Alex Klein1699fab2022-09-08 08:46:06 -060020 """Unittests for GetBinhosts."""
Michael Mortensena0af77b2019-11-13 11:15:15 -070021
Alex Klein1699fab2022-09-08 08:46:06 -060022 def setUp(self):
23 self.response = binhost_pb2.BinhostGetResponse()
Michael Mortensena0af77b2019-11-13 11:15:15 -070024
Alex Klein1699fab2022-09-08 08:46:06 -060025 def testValidateOnly(self):
26 """Check that a validate only call does not execute any logic."""
27 patch = self.PatchObject(binhost_service, "GetBinhosts")
Michael Mortensena0af77b2019-11-13 11:15:15 -070028
Alex Klein1699fab2022-09-08 08:46:06 -060029 request = binhost_pb2.BinhostGetRequest()
30 request.build_target.name = "target"
31 binhost.GetBinhosts(request, self.response, self.validate_only_config)
32 patch.assert_not_called()
Michael Mortensena0af77b2019-11-13 11:15:15 -070033
Alex Klein1699fab2022-09-08 08:46:06 -060034 def testMockCall(self):
35 """Test that a mock call does not execute logic, returns mocked value."""
36 patch = self.PatchObject(binhost_service, "GetBinhosts")
Michael Mortensena0af77b2019-11-13 11:15:15 -070037
Alex Klein1699fab2022-09-08 08:46:06 -060038 input_proto = binhost_pb2.BinhostGetRequest()
39 input_proto.build_target.name = "target"
Michael Mortensena0af77b2019-11-13 11:15:15 -070040
Alex Klein1699fab2022-09-08 08:46:06 -060041 binhost.GetBinhosts(input_proto, self.response, self.mock_call_config)
Michael Mortensena0af77b2019-11-13 11:15:15 -070042
Alex Klein1699fab2022-09-08 08:46:06 -060043 self.assertEqual(len(self.response.binhosts), 1)
44 self.assertEqual(self.response.binhosts[0].package_index, "Packages")
45 patch.assert_not_called()
Michael Mortensena0af77b2019-11-13 11:15:15 -070046
Alex Klein1699fab2022-09-08 08:46:06 -060047 def testGetBinhosts(self):
48 """GetBinhosts calls service with correct args."""
49 binhost_list = [
50 "gs://cr-prebuilt/board/amd64-generic/paladin-R66-17.0.0-rc2/packages/",
51 "gs://cr-prebuilt/board/eve/paladin-R66-17.0.0-rc2/packages/",
52 ]
53 get_binhost = self.PatchObject(
54 binhost_service, "GetBinhosts", return_value=binhost_list
55 )
Michael Mortensena0af77b2019-11-13 11:15:15 -070056
Alex Klein1699fab2022-09-08 08:46:06 -060057 input_proto = binhost_pb2.BinhostGetRequest()
58 input_proto.build_target.name = "target"
Michael Mortensena0af77b2019-11-13 11:15:15 -070059
Alex Klein1699fab2022-09-08 08:46:06 -060060 binhost.GetBinhosts(input_proto, self.response, self.api_config)
Michael Mortensena0af77b2019-11-13 11:15:15 -070061
Alex Klein1699fab2022-09-08 08:46:06 -060062 self.assertEqual(len(self.response.binhosts), 2)
63 self.assertEqual(self.response.binhosts[0].package_index, "Packages")
64 get_binhost.assert_called_once_with(mock.ANY)
Michael Mortensena0af77b2019-11-13 11:15:15 -070065
66
Alex Klein1699fab2022-09-08 08:46:06 -060067class GetPrivatePrebuiltAclArgsTest(
68 cros_test_lib.MockTestCase, api_config.ApiConfigMixin
69):
70 """Unittests for GetPrivatePrebuiltAclArgs."""
Michael Mortensen42251f92019-11-14 11:01:43 -070071
Alex Klein1699fab2022-09-08 08:46:06 -060072 def setUp(self):
73 self.response = binhost_pb2.AclArgsResponse()
Michael Mortensen42251f92019-11-14 11:01:43 -070074
Alex Klein1699fab2022-09-08 08:46:06 -060075 def testValidateOnly(self):
76 """Check that a validate only call does not execute any logic."""
77 patch = self.PatchObject(binhost_service, "GetPrebuiltAclArgs")
Michael Mortensen42251f92019-11-14 11:01:43 -070078
Alex Klein1699fab2022-09-08 08:46:06 -060079 request = binhost_pb2.AclArgsRequest()
80 request.build_target.name = "target"
81 binhost.GetPrivatePrebuiltAclArgs(
82 request, self.response, self.validate_only_config
83 )
84 patch.assert_not_called()
Michael Mortensen42251f92019-11-14 11:01:43 -070085
Alex Klein1699fab2022-09-08 08:46:06 -060086 def testMockCall(self):
87 """Test that a mock call does not execute logic, returns mocked value."""
88 patch = self.PatchObject(binhost_service, "GetPrebuiltAclArgs")
Michael Mortensen42251f92019-11-14 11:01:43 -070089
Alex Klein1699fab2022-09-08 08:46:06 -060090 input_proto = binhost_pb2.AclArgsRequest()
91 input_proto.build_target.name = "target"
Michael Mortensen42251f92019-11-14 11:01:43 -070092
Alex Klein1699fab2022-09-08 08:46:06 -060093 binhost.GetPrivatePrebuiltAclArgs(
94 input_proto, self.response, self.mock_call_config
95 )
Michael Mortensen42251f92019-11-14 11:01:43 -070096
Alex Klein1699fab2022-09-08 08:46:06 -060097 self.assertEqual(len(self.response.args), 1)
98 self.assertEqual(self.response.args[0].arg, "-g")
99 self.assertEqual(self.response.args[0].value, "group1:READ")
100 patch.assert_not_called()
Michael Mortensen42251f92019-11-14 11:01:43 -0700101
Alex Klein1699fab2022-09-08 08:46:06 -0600102 def testGetPrivatePrebuiltAclArgs(self):
103 """GetPrivatePrebuildAclsArgs calls service with correct args."""
104 argvalue_list = [["-g", "group1:READ"]]
105 get_binhost = self.PatchObject(
106 binhost_service, "GetPrebuiltAclArgs", return_value=argvalue_list
107 )
Michael Mortensen42251f92019-11-14 11:01:43 -0700108
Alex Klein1699fab2022-09-08 08:46:06 -0600109 input_proto = binhost_pb2.AclArgsRequest()
110 input_proto.build_target.name = "target"
Michael Mortensen42251f92019-11-14 11:01:43 -0700111
Alex Klein1699fab2022-09-08 08:46:06 -0600112 binhost.GetPrivatePrebuiltAclArgs(
113 input_proto, self.response, self.api_config
114 )
Michael Mortensen42251f92019-11-14 11:01:43 -0700115
Alex Klein1699fab2022-09-08 08:46:06 -0600116 self.assertEqual(len(self.response.args), 1)
117 self.assertEqual(self.response.args[0].arg, "-g")
118 self.assertEqual(self.response.args[0].value, "group1:READ")
119 get_binhost.assert_called_once_with(mock.ANY)
Michael Mortensen42251f92019-11-14 11:01:43 -0700120
121
Alex Klein1699fab2022-09-08 08:46:06 -0600122class PrepareBinhostUploadsTest(
123 cros_test_lib.MockTestCase, api_config.ApiConfigMixin
124):
125 """Unittests for PrepareBinhostUploads."""
Evan Hernandezd437b4e2019-03-25 13:48:30 -0600126
Alex Klein1699fab2022-09-08 08:46:06 -0600127 def setUp(self):
128 self.PatchObject(
129 binhost_service,
130 "GetPrebuiltsRoot",
131 return_value="/build/target/packages",
132 )
133 self.PatchObject(
134 binhost_service,
135 "GetPrebuiltsFiles",
136 return_value=["foo.tbz2", "bar.tbz2"],
137 )
138 self.PatchObject(
139 binhost_service,
140 "UpdatePackageIndex",
141 return_value="/build/target/packages/Packages",
142 )
Evan Hernandezd437b4e2019-03-25 13:48:30 -0600143
Alex Klein1699fab2022-09-08 08:46:06 -0600144 self.response = binhost_pb2.PrepareBinhostUploadsResponse()
Alex Klein231d2da2019-07-22 16:44:45 -0600145
Alex Klein1699fab2022-09-08 08:46:06 -0600146 def testValidateOnly(self):
147 """Check that a validate only call does not execute any logic."""
148 patch = self.PatchObject(binhost_service, "GetPrebuiltsRoot")
Alex Klein231d2da2019-07-22 16:44:45 -0600149
Alex Klein1699fab2022-09-08 08:46:06 -0600150 request = binhost_pb2.PrepareBinhostUploadsRequest()
151 request.build_target.name = "target"
152 request.uri = "gs://chromeos-prebuilt/target"
153 rc = binhost.PrepareBinhostUploads(
154 request, self.response, self.validate_only_config
155 )
156 patch.assert_not_called()
157 self.assertEqual(rc, 0)
Alex Klein231d2da2019-07-22 16:44:45 -0600158
Alex Klein1699fab2022-09-08 08:46:06 -0600159 def testMockCall(self):
160 """Test that a mock call does not execute logic, returns mocked value."""
161 patch = self.PatchObject(binhost_service, "GetPrebuiltsRoot")
Michael Mortensen42251f92019-11-14 11:01:43 -0700162
Alex Klein1699fab2022-09-08 08:46:06 -0600163 request = binhost_pb2.PrepareBinhostUploadsRequest()
164 request.build_target.name = "target"
165 request.uri = "gs://chromeos-prebuilt/target"
166 rc = binhost.PrepareBinhostUploads(
167 request, self.response, self.mock_call_config
168 )
169 self.assertEqual(self.response.uploads_dir, "/upload/directory")
170 self.assertEqual(self.response.upload_targets[0].path, "upload_target")
171 patch.assert_not_called()
172 self.assertEqual(rc, 0)
Michael Mortensen42251f92019-11-14 11:01:43 -0700173
Alex Klein1699fab2022-09-08 08:46:06 -0600174 def testPrepareBinhostUploads(self):
175 """PrepareBinhostUploads returns Packages and tar files."""
176 input_proto = binhost_pb2.PrepareBinhostUploadsRequest()
177 input_proto.build_target.name = "target"
178 input_proto.uri = "gs://chromeos-prebuilt/target"
179 binhost.PrepareBinhostUploads(
180 input_proto, self.response, self.api_config
181 )
182 self.assertEqual(self.response.uploads_dir, "/build/target/packages")
183 self.assertCountEqual(
184 [ut.path for ut in self.response.upload_targets],
185 ["Packages", "foo.tbz2", "bar.tbz2"],
186 )
Evan Hernandezd437b4e2019-03-25 13:48:30 -0600187
Alex Klein1699fab2022-09-08 08:46:06 -0600188 def testPrepareBinhostUploadsNonGsUri(self):
189 """PrepareBinhostUploads dies when URI does not point to GS."""
190 input_proto = binhost_pb2.PrepareBinhostUploadsRequest()
191 input_proto.build_target.name = "target"
192 input_proto.uri = "https://foo.bar"
193 with self.assertRaises(ValueError):
194 binhost.PrepareBinhostUploads(
195 input_proto, self.response, self.api_config
196 )
Evan Hernandezd437b4e2019-03-25 13:48:30 -0600197
198
Alex Klein231d2da2019-07-22 16:44:45 -0600199class SetBinhostTest(cros_test_lib.MockTestCase, api_config.ApiConfigMixin):
Alex Klein1699fab2022-09-08 08:46:06 -0600200 """Unittests for SetBinhost."""
Evan Hernandezd437b4e2019-03-25 13:48:30 -0600201
Alex Klein1699fab2022-09-08 08:46:06 -0600202 def setUp(self):
203 self.response = binhost_pb2.SetBinhostResponse()
Alex Klein231d2da2019-07-22 16:44:45 -0600204
Alex Klein1699fab2022-09-08 08:46:06 -0600205 def testValidateOnly(self):
206 """Check that a validate only call does not execute any logic."""
207 patch = self.PatchObject(binhost_service, "SetBinhost")
Alex Klein231d2da2019-07-22 16:44:45 -0600208
Alex Klein1699fab2022-09-08 08:46:06 -0600209 request = binhost_pb2.SetBinhostRequest()
210 request.build_target.name = "target"
211 request.key = binhost_pb2.POSTSUBMIT_BINHOST
212 request.uri = "gs://chromeos-prebuilt/target"
213 binhost.SetBinhost(request, self.response, self.validate_only_config)
214 patch.assert_not_called()
Alex Klein231d2da2019-07-22 16:44:45 -0600215
Alex Klein1699fab2022-09-08 08:46:06 -0600216 def testMockCall(self):
217 """Test that a mock call does not execute logic, returns mocked value."""
218 patch = self.PatchObject(binhost_service, "SetBinhost")
Michael Mortensen42251f92019-11-14 11:01:43 -0700219
Alex Klein1699fab2022-09-08 08:46:06 -0600220 request = binhost_pb2.SetBinhostRequest()
221 request.build_target.name = "target"
222 request.key = binhost_pb2.POSTSUBMIT_BINHOST
223 request.uri = "gs://chromeos-prebuilt/target"
Arif Kasim6242cdd2022-10-19 17:51:00 +0000224 request.max_uris = 4
Alex Klein1699fab2022-09-08 08:46:06 -0600225 binhost.SetBinhost(request, self.response, self.mock_call_config)
226 patch.assert_not_called()
227 self.assertEqual(self.response.output_file, "/path/to/BINHOST.conf")
Michael Mortensen42251f92019-11-14 11:01:43 -0700228
Alex Klein1699fab2022-09-08 08:46:06 -0600229 def testSetBinhost(self):
230 """SetBinhost calls service with correct args."""
231 set_binhost = self.PatchObject(
232 binhost_service, "SetBinhost", return_value="/path/to/BINHOST.conf"
233 )
Evan Hernandezd437b4e2019-03-25 13:48:30 -0600234
Alex Klein1699fab2022-09-08 08:46:06 -0600235 input_proto = binhost_pb2.SetBinhostRequest()
236 input_proto.build_target.name = "target"
237 input_proto.private = True
238 input_proto.key = binhost_pb2.POSTSUBMIT_BINHOST
239 input_proto.uri = "gs://chromeos-prebuilt/target"
Arif Kasim6242cdd2022-10-19 17:51:00 +0000240 input_proto.max_uris = 4
Alex Klein1699fab2022-09-08 08:46:06 -0600241 binhost.SetBinhost(input_proto, self.response, self.api_config)
Evan Hernandezd437b4e2019-03-25 13:48:30 -0600242
Alex Klein1699fab2022-09-08 08:46:06 -0600243 self.assertEqual(self.response.output_file, "/path/to/BINHOST.conf")
244 set_binhost.assert_called_once_with(
245 "target",
246 "POSTSUBMIT_BINHOST",
247 "gs://chromeos-prebuilt/target",
248 private=True,
Arif Kasim6242cdd2022-10-19 17:51:00 +0000249 max_uris=4,
Alex Klein1699fab2022-09-08 08:46:06 -0600250 )
LaMont Jonesc64ae212019-04-15 15:41:28 -0600251
Alex Klein231d2da2019-07-22 16:44:45 -0600252
Alex Klein1699fab2022-09-08 08:46:06 -0600253class RegenBuildCacheTest(
254 cros_test_lib.MockTestCase, api_config.ApiConfigMixin
255):
256 """Unittests for RegenBuildCache."""
LaMont Jonesc64ae212019-04-15 15:41:28 -0600257
Alex Klein1699fab2022-09-08 08:46:06 -0600258 def setUp(self):
259 self.response = binhost_pb2.RegenBuildCacheResponse()
Alex Klein231d2da2019-07-22 16:44:45 -0600260
Alex Klein1699fab2022-09-08 08:46:06 -0600261 def testValidateOnly(self):
262 """Check that a validate only call does not execute any logic."""
263 patch = self.PatchObject(binhost_service, "RegenBuildCache")
Alex Klein231d2da2019-07-22 16:44:45 -0600264
Alex Klein1699fab2022-09-08 08:46:06 -0600265 request = binhost_pb2.RegenBuildCacheRequest()
266 request.overlay_type = binhost_pb2.OVERLAYTYPE_BOTH
267 binhost.RegenBuildCache(
268 request, self.response, self.validate_only_config
269 )
270 patch.assert_not_called()
Alex Klein231d2da2019-07-22 16:44:45 -0600271
Alex Klein1699fab2022-09-08 08:46:06 -0600272 def testMockCall(self):
273 """Test that a mock call does not execute logic, returns mocked value."""
274 patch = self.PatchObject(binhost_service, "RegenBuildCache")
Michael Mortensen42251f92019-11-14 11:01:43 -0700275
Alex Klein1699fab2022-09-08 08:46:06 -0600276 request = binhost_pb2.RegenBuildCacheRequest()
277 request.overlay_type = binhost_pb2.OVERLAYTYPE_BOTH
278 binhost.RegenBuildCache(request, self.response, self.mock_call_config)
279 patch.assert_not_called()
280 self.assertEqual(len(self.response.modified_overlays), 1)
281 self.assertEqual(
282 self.response.modified_overlays[0].path, "/path/to/BuildCache"
283 )
284
285 def testRegenBuildCache(self):
286 """RegenBuildCache calls service with the correct args."""
287 regen_cache = self.PatchObject(binhost_service, "RegenBuildCache")
288
289 input_proto = binhost_pb2.RegenBuildCacheRequest()
290 input_proto.overlay_type = binhost_pb2.OVERLAYTYPE_BOTH
291
292 binhost.RegenBuildCache(input_proto, self.response, self.api_config)
293 regen_cache.assert_called_once_with(mock.ANY, "both")
294
295 def testRequiresOverlayType(self):
296 """RegenBuildCache dies if overlay_type not specified."""
297 regen_cache = self.PatchObject(binhost_service, "RegenBuildCache")
298
299 input_proto = binhost_pb2.RegenBuildCacheRequest()
300 input_proto.overlay_type = binhost_pb2.OVERLAYTYPE_UNSPECIFIED
301
302 with self.assertRaises(cros_build_lib.DieSystemExit):
303 binhost.RegenBuildCache(input_proto, self.response, self.api_config)
304 regen_cache.assert_not_called()
Michael Mortensen42251f92019-11-14 11:01:43 -0700305
306
Alex Klein1699fab2022-09-08 08:46:06 -0600307class PrepareDevInstallerBinhostUploadsTest(
308 cros_test_lib.MockTempDirTestCase, api_config.ApiConfigMixin
309):
310 """Tests for the UploadDevInstallerPrebuilts stage."""
LaMont Jonesc64ae212019-04-15 15:41:28 -0600311
Alex Klein1699fab2022-09-08 08:46:06 -0600312 def setUp(self):
313 self.PatchObject(cros_build_lib, "IsInsideChroot", return_value=False)
314 # target packages dir
315 self.chroot_path = os.path.join(self.tempdir, "chroot")
316 self.sysroot_path = "/build/target"
317 self.chroot_path = os.path.join(self.tempdir, "chroot")
318 full_sysroot_path = os.path.join(
319 self.chroot_path, self.sysroot_path.lstrip(os.sep)
320 )
321 self.full_sysroot_package_path = os.path.join(
322 full_sysroot_path, "packages"
323 )
324 osutils.SafeMakedirs(self.full_sysroot_package_path)
325 self.uploads_dir = os.path.join(self.tempdir, "uploads_dir")
326 osutils.SafeMakedirs(self.uploads_dir)
327 # Create packages/Packages file
328 packages_file = os.path.join(self.full_sysroot_package_path, "Packages")
329 packages_content = """\
Michael Mortensenfc823882019-08-27 14:38:07 -0600330USE: test
331
332CPV: app-arch/brotli-1.0.6
333
334CPV: app-arch/zip-3.0-r3
335
336CPV: chromeos-base/shill-0.0.1-r1
337
338CPV: chromeos-base/test-0.0.1-r1
339
340CPV: virtual/chromium-os-printing-1-r4
341
342CPV: virtual/python-enum34-1
343
344"""
Alex Klein1699fab2022-09-08 08:46:06 -0600345 osutils.WriteFile(packages_file, packages_content)
Michael Mortensenfc823882019-08-27 14:38:07 -0600346
Alex Klein1699fab2022-09-08 08:46:06 -0600347 # Create package.installable file
348 self.dev_install_packages = [
349 "app-arch/zip-3.0-r3",
350 "virtual/chromium-os-printing-1-r4",
351 "virtual/python-enum34-1",
352 ]
353 package_installable_dir = os.path.join(
354 full_sysroot_path, "build/dev-install"
355 )
356 osutils.SafeMakedirs(package_installable_dir)
357 package_installable_filename = os.path.join(
358 package_installable_dir, "package.installable"
359 )
Michael Mortensenfc823882019-08-27 14:38:07 -0600360
Alex Klein1699fab2022-09-08 08:46:06 -0600361 # Create path to the dev_install_packages
362 packages_dir = os.path.join(full_sysroot_path, "packages")
363 osutils.SafeMakedirs(packages_dir)
364 for package in self.dev_install_packages:
365 # Since a package has a category, such as app-arch/zip-3.0-r3, we need
366 # to create the packages_dir / category dir as needed.
367 category = package.split(os.sep)[0]
368 osutils.SafeMakedirs(os.path.join(packages_dir, category))
369 package_tbz2_file = os.path.join(packages_dir, package) + ".tbz2"
370 osutils.Touch(package_tbz2_file)
371 with open(
372 package_installable_filename, "w"
373 ) as package_installable_file:
374 for package in self.dev_install_packages:
375 package_installable_file.write(package + "\n")
376 self.response = binhost_pb2.PrepareDevInstallBinhostUploadsResponse()
Michael Mortensenfc823882019-08-27 14:38:07 -0600377
Alex Klein1699fab2022-09-08 08:46:06 -0600378 def testValidateOnly(self):
379 """Check that a validate only call does not execute any logic."""
380 patch = self.PatchObject(
381 binhost_service, "ReadDevInstallFilesToCreatePackageIndex"
382 )
Michael Mortensenfc823882019-08-27 14:38:07 -0600383
Alex Klein1699fab2022-09-08 08:46:06 -0600384 input_proto = binhost_pb2.PrepareDevInstallBinhostUploadsRequest()
385 input_proto.uri = "gs://chromeos-prebuilt/target"
386 input_proto.chroot.path = self.chroot_path
387 input_proto.sysroot.path = self.sysroot_path
388 input_proto.uploads_dir = self.uploads_dir
389 binhost.PrepareDevInstallBinhostUploads(
390 input_proto, self.response, self.validate_only_config
391 )
392 patch.assert_not_called()
Michael Mortensen42251f92019-11-14 11:01:43 -0700393
Alex Klein1699fab2022-09-08 08:46:06 -0600394 def testMockCall(self):
395 """Test that a mock call does not execute logic, returns mocked value."""
396 patch = self.PatchObject(
397 binhost_service, "ReadDevInstallFilesToCreatePackageIndex"
398 )
Michael Mortensen42251f92019-11-14 11:01:43 -0700399
Alex Klein1699fab2022-09-08 08:46:06 -0600400 input_proto = binhost_pb2.PrepareDevInstallBinhostUploadsRequest()
401 input_proto.uri = "gs://chromeos-prebuilt/target"
402 input_proto.chroot.path = self.chroot_path
403 input_proto.sysroot.path = self.sysroot_path
404 input_proto.uploads_dir = self.uploads_dir
405 binhost.PrepareDevInstallBinhostUploads(
406 input_proto, self.response, self.mock_call_config
407 )
408 self.assertEqual(len(self.response.upload_targets), 3)
409 self.assertEqual(self.response.upload_targets[2].path, "Packages")
410 patch.assert_not_called()
Michael Mortensen42251f92019-11-14 11:01:43 -0700411
Alex Klein1699fab2022-09-08 08:46:06 -0600412 def testDevInstallerUpload(self):
413 """Test uploads of dev installer prebuilts."""
414 # self.RunStage()
415 input_proto = binhost_pb2.PrepareDevInstallBinhostUploadsRequest()
416 input_proto.uri = "gs://chromeos-prebuilt/target"
417 input_proto.chroot.path = self.chroot_path
418 input_proto.sysroot.path = self.sysroot_path
419 input_proto.uploads_dir = self.uploads_dir
420 # Call method under test
421 binhost.PrepareDevInstallBinhostUploads(
422 input_proto, self.response, self.api_config
423 )
424 # Verify results
425 expected_upload_targets = [
426 "app-arch/zip-3.0-r3.tbz2",
427 "virtual/chromium-os-printing-1-r4.tbz2",
428 "virtual/python-enum34-1.tbz2",
429 "Packages",
430 ]
431 self.assertCountEqual(
432 [ut.path for ut in self.response.upload_targets],
433 expected_upload_targets,
434 )
435 # All of the upload_targets should also be in the uploads_directory
436 for target in self.response.upload_targets:
437 self.assertExists(
438 os.path.join(input_proto.uploads_dir, target.path)
439 )
Michael Mortensen42251f92019-11-14 11:01:43 -0700440
Alex Klein1699fab2022-09-08 08:46:06 -0600441 def testPrepareBinhostUploadsNonGsUri(self):
442 """PrepareBinhostUploads dies when URI does not point to GS."""
443 input_proto = binhost_pb2.PrepareDevInstallBinhostUploadsRequest()
444 input_proto.chroot.path = self.chroot_path
445 input_proto.sysroot.path = self.sysroot_path
446 input_proto.uploads_dir = self.uploads_dir
447 input_proto.uri = "https://foo.bar"
448 with self.assertRaises(ValueError):
449 binhost.PrepareDevInstallBinhostUploads(
450 input_proto, self.response, self.api_config
451 )