autoupdater_unittest.py revision 73aa2908e457c64ede3597cc78451cca5fba85be
1#!/usr/bin/python 2# Copyright (c) 2013 The Chromium OS Authors. All rights reserved. 3# Use of this source code is governed by a BSD-style license that can be 4# found in the LICENSE file. 5 6import mox 7import unittest 8 9import common 10 11import autoupdater 12 13 14class TestAutoUpdater(mox.MoxTestBase): 15 """Test autoupdater module.""" 16 17 18 def testParseBuildFromUpdateUrlwithUpdate(self): 19 """Test that we properly parse the build from an update_url.""" 20 update_url = ('http://172.22.50.205:8082/update/lumpy-release/' 21 'R27-3837.0.0') 22 expected_value = 'lumpy-release/R27-3837.0.0' 23 self.assertEqual(autoupdater.url_to_image_name(update_url), 24 expected_value) 25 26 27 def testCheckVersion_1(self): 28 """Test version check methods work for any build. 29 30 Test two methods used to check version, check_version and 31 check_version_to_confirm_install, for: 32 1. trybot paladin build. 33 update version: trybot-lumpy-paladin/R27-3837.0.0-b123 34 booted version: 3837.0.2013_03_21_1340 35 36 """ 37 update_url = ('http://172.22.50.205:8082/update/trybot-lumpy-paladin/' 38 'R27-1111.0.0-b123') 39 updater = autoupdater.ChromiumOSUpdater(update_url) 40 41 self.mox.UnsetStubs() 42 self.mox.StubOutWithMock(updater, 'get_build_id') 43 updater.get_build_id().MultipleTimes().AndReturn( 44 '1111.0.2013_03_21_1340') 45 self.mox.ReplayAll() 46 47 self.assertFalse(updater.check_version()) 48 self.assertTrue(updater.check_version_to_confirm_install()) 49 50 self.mox.UnsetStubs() 51 self.mox.StubOutWithMock(updater, 'get_build_id') 52 updater.get_build_id().MultipleTimes().AndReturn('1111.0.0-rc1') 53 self.mox.ReplayAll() 54 55 self.assertFalse(updater.check_version()) 56 self.assertFalse(updater.check_version_to_confirm_install()) 57 58 self.mox.UnsetStubs() 59 self.mox.StubOutWithMock(updater, 'get_build_id') 60 updater.get_build_id().MultipleTimes().AndReturn('1111.0.0') 61 self.mox.ReplayAll() 62 63 self.assertFalse(updater.check_version()) 64 self.assertFalse(updater.check_version_to_confirm_install()) 65 66 self.mox.UnsetStubs() 67 self.mox.StubOutWithMock(updater, 'get_build_id') 68 updater.get_build_id().MultipleTimes().AndReturn( 69 '4444.0.0-pgo-generate') 70 self.mox.ReplayAll() 71 72 self.assertFalse(updater.check_version()) 73 self.assertFalse(updater.check_version_to_confirm_install()) 74 75 76 def testCheckVersion_2(self): 77 """Test version check methods work for any build. 78 79 Test two methods used to check version, check_version and 80 check_version_to_confirm_install, for: 81 2. trybot release build. 82 update version: trybot-lumpy-release/R27-3837.0.0-b456 83 booted version: 3837.0.0 84 85 """ 86 update_url = ('http://172.22.50.205:8082/update/trybot-lumpy-release/' 87 'R27-2222.0.0-b456') 88 updater = autoupdater.ChromiumOSUpdater(update_url) 89 90 self.mox.UnsetStubs() 91 self.mox.StubOutWithMock(updater, 'get_build_id') 92 updater.get_build_id().MultipleTimes().AndReturn( 93 '2222.0.2013_03_21_1340') 94 self.mox.ReplayAll() 95 96 self.assertFalse(updater.check_version()) 97 self.assertFalse(updater.check_version_to_confirm_install()) 98 99 self.mox.UnsetStubs() 100 self.mox.StubOutWithMock(updater, 'get_build_id') 101 updater.get_build_id().MultipleTimes().AndReturn('2222.0.0-rc1') 102 self.mox.ReplayAll() 103 104 self.assertFalse(updater.check_version()) 105 self.assertFalse(updater.check_version_to_confirm_install()) 106 107 self.mox.UnsetStubs() 108 self.mox.StubOutWithMock(updater, 'get_build_id') 109 updater.get_build_id().MultipleTimes().AndReturn('2222.0.0') 110 self.mox.ReplayAll() 111 112 self.assertFalse(updater.check_version()) 113 self.assertTrue(updater.check_version_to_confirm_install()) 114 115 self.mox.UnsetStubs() 116 self.mox.StubOutWithMock(updater, 'get_build_id') 117 updater.get_build_id().MultipleTimes().AndReturn( 118 '4444.0.0-pgo-generate') 119 self.mox.ReplayAll() 120 121 self.assertFalse(updater.check_version()) 122 self.assertFalse(updater.check_version_to_confirm_install()) 123 124 125 def testCheckVersion_3(self): 126 """Test version check methods work for any build. 127 128 Test two methods used to check version, check_version and 129 check_version_to_confirm_install, for: 130 3. buildbot official release build. 131 update version: lumpy-release/R27-3837.0.0 132 booted version: 3837.0.0 133 134 """ 135 update_url = ('http://172.22.50.205:8082/update/lumpy-release/' 136 'R27-3333.0.0') 137 updater = autoupdater.ChromiumOSUpdater(update_url) 138 139 self.mox.UnsetStubs() 140 self.mox.StubOutWithMock(updater, 'get_build_id') 141 updater.get_build_id().MultipleTimes().AndReturn( 142 '3333.0.2013_03_21_1340') 143 self.mox.ReplayAll() 144 145 self.assertFalse(updater.check_version()) 146 self.assertFalse(updater.check_version_to_confirm_install()) 147 148 self.mox.UnsetStubs() 149 self.mox.StubOutWithMock(updater, 'get_build_id') 150 updater.get_build_id().MultipleTimes().AndReturn('3333.0.0-rc1') 151 self.mox.ReplayAll() 152 153 self.assertFalse(updater.check_version()) 154 self.assertFalse(updater.check_version_to_confirm_install()) 155 156 self.mox.UnsetStubs() 157 self.mox.StubOutWithMock(updater, 'get_build_id') 158 updater.get_build_id().MultipleTimes().AndReturn('3333.0.0') 159 self.mox.ReplayAll() 160 161 self.assertTrue(updater.check_version()) 162 self.assertTrue(updater.check_version_to_confirm_install()) 163 164 self.mox.UnsetStubs() 165 self.mox.StubOutWithMock(updater, 'get_build_id') 166 updater.get_build_id().MultipleTimes().AndReturn( 167 '4444.0.0-pgo-generate') 168 self.mox.ReplayAll() 169 170 self.assertFalse(updater.check_version()) 171 self.assertFalse(updater.check_version_to_confirm_install()) 172 173 174 def testCheckVersion_4(self): 175 """Test version check methods work for any build. 176 177 Test two methods used to check version, check_version and 178 check_version_to_confirm_install, for: 179 4. non-official paladin rc build. 180 update version: lumpy-paladin/R27-3837.0.0-rc7 181 booted version: 3837.0.0-rc7 182 183 """ 184 update_url = ('http://172.22.50.205:8082/update/lumpy-paladin/' 185 'R27-4444.0.0-rc7') 186 updater = autoupdater.ChromiumOSUpdater(update_url) 187 188 self.mox.UnsetStubs() 189 self.mox.StubOutWithMock(updater, 'get_build_id') 190 updater.get_build_id().MultipleTimes().AndReturn( 191 '4444.0.2013_03_21_1340') 192 self.mox.ReplayAll() 193 194 self.assertFalse(updater.check_version()) 195 self.assertFalse(updater.check_version_to_confirm_install()) 196 197 self.mox.UnsetStubs() 198 self.mox.StubOutWithMock(updater, 'get_build_id') 199 updater.get_build_id().MultipleTimes().AndReturn('4444.0.0-rc7') 200 self.mox.ReplayAll() 201 202 self.assertTrue(updater.check_version()) 203 self.assertTrue(updater.check_version_to_confirm_install()) 204 205 self.mox.UnsetStubs() 206 self.mox.StubOutWithMock(updater, 'get_build_id') 207 updater.get_build_id().MultipleTimes().AndReturn('4444.0.0') 208 self.mox.ReplayAll() 209 210 self.assertFalse(updater.check_version()) 211 self.assertFalse(updater.check_version_to_confirm_install()) 212 213 self.mox.UnsetStubs() 214 self.mox.StubOutWithMock(updater, 'get_build_id') 215 updater.get_build_id().MultipleTimes().AndReturn( 216 '4444.0.0-pgo-generate') 217 self.mox.ReplayAll() 218 219 self.assertFalse(updater.check_version()) 220 self.assertFalse(updater.check_version_to_confirm_install()) 221 222 223 def testCheckVersion_5(self): 224 """Test version check methods work for any build. 225 226 Test two methods used to check version, check_version and 227 check_version_to_confirm_install, for: 228 5. chrome-perf build. 229 update version: lumpy-chrome-perf/R28-3837.0.0-b2996 230 booted version: 3837.0.0 231 232 """ 233 update_url = ('http://172.22.50.205:8082/update/lumpy-chrome-perf/' 234 'R28-4444.0.0-b2996') 235 updater = autoupdater.ChromiumOSUpdater(update_url) 236 237 self.mox.UnsetStubs() 238 self.mox.StubOutWithMock(updater, 'get_build_id') 239 updater.get_build_id().MultipleTimes().AndReturn( 240 '4444.0.2013_03_21_1340') 241 self.mox.ReplayAll() 242 243 self.assertFalse(updater.check_version()) 244 self.assertFalse(updater.check_version_to_confirm_install()) 245 246 self.mox.UnsetStubs() 247 self.mox.StubOutWithMock(updater, 'get_build_id') 248 updater.get_build_id().MultipleTimes().AndReturn('4444.0.0-rc7') 249 self.mox.ReplayAll() 250 251 self.assertFalse(updater.check_version()) 252 self.assertFalse(updater.check_version_to_confirm_install()) 253 254 self.mox.UnsetStubs() 255 self.mox.StubOutWithMock(updater, 'get_build_id') 256 updater.get_build_id().MultipleTimes().AndReturn('4444.0.0') 257 self.mox.ReplayAll() 258 259 self.assertFalse(updater.check_version()) 260 self.assertTrue(updater.check_version_to_confirm_install()) 261 262 self.mox.UnsetStubs() 263 self.mox.StubOutWithMock(updater, 'get_build_id') 264 updater.get_build_id().MultipleTimes().AndReturn( 265 '4444.0.0-pgo-generate') 266 self.mox.ReplayAll() 267 268 self.assertFalse(updater.check_version()) 269 self.assertFalse(updater.check_version_to_confirm_install()) 270 271 272 def testCheckVersion_6(self): 273 """Test version check methods work for any build. 274 275 Test two methods used to check version, check_version and 276 check_version_to_confirm_install, for: 277 6. pgo-generate build. 278 update version: lumpy-release-pgo-generate/R28-3837.0.0-b2996 279 booted version: 3837.0.0-pgo-generate 280 281 """ 282 update_url = ('http://172.22.50.205:8082/update/lumpy-release-pgo-' 283 'generate/R28-4444.0.0-b2996') 284 updater = autoupdater.ChromiumOSUpdater(update_url) 285 286 self.mox.UnsetStubs() 287 self.mox.StubOutWithMock(updater, 'get_build_id') 288 updater.get_build_id().MultipleTimes().AndReturn( 289 '4444.0.0-2013_03_21_1340') 290 self.mox.ReplayAll() 291 292 self.assertFalse(updater.check_version()) 293 self.assertFalse(updater.check_version_to_confirm_install()) 294 295 self.mox.UnsetStubs() 296 self.mox.StubOutWithMock(updater, 'get_build_id') 297 updater.get_build_id().MultipleTimes().AndReturn('4444.0.0-rc7') 298 self.mox.ReplayAll() 299 300 self.assertFalse(updater.check_version()) 301 self.assertFalse(updater.check_version_to_confirm_install()) 302 303 self.mox.UnsetStubs() 304 self.mox.StubOutWithMock(updater, 'get_build_id') 305 updater.get_build_id().MultipleTimes().AndReturn('4444.0.0') 306 self.mox.ReplayAll() 307 308 self.assertFalse(updater.check_version()) 309 self.assertFalse(updater.check_version_to_confirm_install()) 310 311 self.mox.UnsetStubs() 312 self.mox.StubOutWithMock(updater, 'get_build_id') 313 updater.get_build_id().MultipleTimes().AndReturn( 314 '4444.0.0-pgo-generate') 315 self.mox.ReplayAll() 316 317 self.assertFalse(updater.check_version()) 318 self.assertTrue(updater.check_version_to_confirm_install()) 319 320 321 def testUpdateStateful(self): 322 """Tests that we call the stateful update script with the correct args. 323 """ 324 self.mox.StubOutWithMock(autoupdater.ChromiumOSUpdater, '_run') 325 update_url = ('http://172.22.50.205:8082/update/lumpy-chrome-perf/' 326 'R28-4444.0.0-b2996') 327 static_update_url = ('http://172.22.50.205:8082/static/archive/' 328 'lumpy-chrome-perf/R28-4444.0.0-b2996') 329 330 # Test with clobber=False. 331 autoupdater.ChromiumOSUpdater._run( 332 mox.And( 333 mox.StrContains(autoupdater.REMOTE_STATEUL_UPDATE_PATH), 334 mox.StrContains(static_update_url), 335 mox.Not(mox.StrContains('--stateful_change=clean'))), 336 timeout=600) 337 338 self.mox.ReplayAll() 339 updater = autoupdater.ChromiumOSUpdater(update_url) 340 updater.update_stateful(clobber=False) 341 self.mox.VerifyAll() 342 343 # Test with clobber=True. 344 self.mox.ResetAll() 345 autoupdater.ChromiumOSUpdater._run( 346 mox.And( 347 mox.StrContains(autoupdater.REMOTE_STATEUL_UPDATE_PATH), 348 mox.StrContains(static_update_url), 349 mox.StrContains('--stateful_change=clean')), 350 timeout=600) 351 self.mox.ReplayAll() 352 updater = autoupdater.ChromiumOSUpdater(update_url) 353 updater.update_stateful(clobber=True) 354 self.mox.VerifyAll() 355 356 357if __name__ == '__main__': 358 unittest.main() 359