Exemplo n.º 1
0
 def testCommitStagedCIPD(self, update_mock):
     with tempfile_ext.NamedTemporaryDirectory() as workDir,\
          tempfile_ext.NamedTemporaryDirectory() as repoRoot,\
          cts_utils.chdir(workDir):
         cts_utils_test.setup_fake_repo(repoRoot)
         cts_updater = update_cts.UpdateCTS('.', repoRoot)
         with self.assertRaises(update_cts.MissingDirError):
             cts_updater.commit_staged_cipd()
         cts_utils_test.writefile(CIPD_DATA['yaml'],
                                  os.path.join('staged', 'cipd.yaml'))
         with cts_utils.chdir('staged'):
             generate_zip_file(CONFIG_DATA['file11'], CONFIG_DATA['apk1'])
             generate_zip_file(CONFIG_DATA['file12'], CONFIG_DATA['apk1'])
             generate_zip_file(CONFIG_DATA['file21'], CONFIG_DATA['apk2a'],
                               CONFIG_DATA['apk2b'])
             with self.assertRaises(update_cts.MissingFileError):
                 cts_updater.commit_staged_cipd()
             generate_zip_file(CONFIG_DATA['file22'], CONFIG_DATA['apk2a'],
                               CONFIG_DATA['apk2b'])
         update_mock.return_value = 'newcipdversion'
         cts_updater.commit_staged_cipd()
         update_mock.assert_called_with(
             os.path.join(workDir, 'staged', 'cipd.yaml'))
         self.assertEqual('newcipdversion',
                          cts_utils_test.readfile('cipd_version.txt'))
Exemplo n.º 2
0
    def testUpdateRepository(self, cmd_mock, run_mock):
        with tempfile_ext.NamedTemporaryDirectory() as workDir,\
             tempfile_ext.NamedTemporaryDirectory() as repoRoot,\
             cts_utils.chdir(workDir):
            cts_utils_test.setup_fake_repo(repoRoot)
            cts_updater = update_cts.UpdateCTS('.', repoRoot)
            cts_utils_test.writefile('newversion', 'cipd_version.txt')
            cts_utils_test.writefile(CIPD_DATA['yaml'],
                                     os.path.join('staged', 'cipd.yaml'))

            cts_utils_test.writefile(
                CIPD_DATA['yaml'],
                os.path.join(os.path.join('staged', 'cipd.yaml')))

            cmd_mock.return_value = ''
            run_mock.return_value = 0

            cts_updater.update_repository()

            self._assertCIPDVersionUpdated(repoRoot, 'newversion')

            repo_cipd_yaml = os.path.join(repoRoot, cts_utils.TOOLS_DIR,
                                          cts_utils.CIPD_FILE)
            run_mock.assert_any_call([
                'cp',
                os.path.join(workDir, 'staged', 'cipd.yaml'), repo_cipd_yaml
            ])

            run_mock.assert_any_call([
                'cipd', 'ensure', '-root',
                os.path.dirname(repo_cipd_yaml), '-ensure-file', mock.ANY
            ])
            run_mock.assert_any_call(['python', GENERATE_BUILDBOT_JSON])
Exemplo n.º 3
0
 def testStageCIPDUpdate(self):
     with tempfile_ext.NamedTemporaryDirectory() as workDir,\
          tempfile_ext.NamedTemporaryDirectory() as repoRoot,\
          cts_utils.chdir(workDir):
         cts_utils_test.setup_fake_repo(repoRoot)
         cts_utils_test.writefile(
             'n1', os.path.join('filtered', CONFIG_DATA['base11']))
         cts_utils_test.writefile(
             'n3', os.path.join('filtered', CONFIG_DATA['base12']))
         for i in [str(i) for i in range(1, 5)]:
             cts_utils_test.writefile(
                 'o' + i, os.path.join('cipd', CIPD_DATA['file' + i]))
         cts_updater = update_cts.UpdateCTS('.', repoRoot)
         cts_updater.stage_cipd_update()
         self.assertTrue(os.path.isdir('staged'))
         with cts_utils.chdir('staged'):
             self.assertEqual(
                 'n1', cts_utils_test.readfile(CONFIG_DATA['file11']))
             self.assertEqual(
                 'n3', cts_utils_test.readfile(CONFIG_DATA['file12']))
             self.assertEqual(
                 'o2', cts_utils_test.readfile(CONFIG_DATA['file21']))
             self.assertEqual(
                 'o4', cts_utils_test.readfile(CONFIG_DATA['file22']))
             self.assertEqual(CIPD_DATA['yaml'],
                              cts_utils_test.readfile('cipd.yaml'))
Exemplo n.º 4
0
    def testDownloadCTS_allPlatforms(self, download_mock):
        with tempfile_ext.NamedTemporaryDirectory() as workDir,\
             tempfile_ext.NamedTemporaryDirectory() as repoRoot:
            cts_utils_test.setup_fake_repo(repoRoot)
            cts_updater = update_cts.UpdateCTS(workDir, repoRoot)

            cts_updater.download_cts()
            download_mock.assert_has_calls([
                call(
                    CONFIG_DATA['origin11'],
                    os.path.join(cts_updater.download_dir,
                                 CONFIG_DATA['base11'])),
                call(
                    CONFIG_DATA['origin12'],
                    os.path.join(cts_updater.download_dir,
                                 CONFIG_DATA['base12'])),
                call(
                    CONFIG_DATA['origin21'],
                    os.path.join(cts_updater.download_dir,
                                 CONFIG_DATA['base21'])),
                call(
                    CONFIG_DATA['origin22'],
                    os.path.join(cts_updater.download_dir,
                                 CONFIG_DATA['base22']))
            ])
            self.assertEqual(4, download_mock.call_count)
Exemplo n.º 5
0
    def testDownloadCIPD_dirExists(self):
        with tempfile_ext.NamedTemporaryDirectory() as workDir,\
             tempfile_ext.NamedTemporaryDirectory() as repoRoot,\
             cts_utils.chdir(workDir):
            cts_utils_test.setup_fake_repo(repoRoot)

            cts_updater = update_cts.UpdateCTS('.', repoRoot)

            os.makedirs('cipd')
            with self.assertRaises(update_cts.DirExistsError):
                cts_updater.download_cipd()
Exemplo n.º 6
0
 def testUpdateRepository_buildbotUpdateError(self, cmd_mock, run_mock):
     with tempfile_ext.NamedTemporaryDirectory() as workDir,\
          tempfile_ext.NamedTemporaryDirectory() as repoRoot,\
          cts_utils.chdir(workDir):
         cts_utils_test.setup_fake_repo(repoRoot)
         cts_updater = update_cts.UpdateCTS('.', repoRoot)
         cts_utils_test.writefile('newversion', 'cipd_version.txt')
         cts_utils_test.writefile(CIPD_DATA['yaml'],
                                  os.path.join('staged', 'cipd.yaml'))
         cmd_mock.return_value = ''
         run_mock.return_value = 1
         with self.assertRaises(IOError):
             cts_updater.update_repository()
Exemplo n.º 7
0
    def testUpdateRepository_inconsistentFiles(self, cmd_mock, run_mock):
        with tempfile_ext.NamedTemporaryDirectory() as workDir,\
             tempfile_ext.NamedTemporaryDirectory() as repoRoot,\
             cts_utils.chdir(workDir):
            cts_utils_test.setup_fake_repo(repoRoot)
            cts_updater = update_cts.UpdateCTS('.', repoRoot)
            cts_utils_test.writefile('newversion', 'cipd_version.txt')
            cts_utils_test.writefile(CIPD_DATA['yaml'],
                                     os.path.join('staged', 'cipd.yaml'))

            cmd_mock.return_value = ''
            run_mock.return_value = 0
            cts_utils_test.writefile(
                CIPD_DATA['template'] %
                ('wrong/package/name', CIPD_DATA['file1'], CIPD_DATA['file2'],
                 CIPD_DATA['file3'], CIPD_DATA['file4']),
                os.path.join(os.path.join('staged', 'cipd.yaml')))
            with self.assertRaises(update_cts.InconsistentFilesException):
                cts_updater.update_repository()
Exemplo n.º 8
0
 def testFilterCTS(self):
     with tempfile_ext.NamedTemporaryDirectory() as workDir,\
          tempfile_ext.NamedTemporaryDirectory() as repoRoot,\
          cts_utils.chdir(workDir):
         cts_utils_test.setup_fake_repo(repoRoot)
         cts_updater = update_cts.UpdateCTS('.', repoRoot)
         expected_download_dir = os.path.abspath('downloaded')
         self.assertEqual(expected_download_dir, cts_updater.download_dir)
         os.makedirs(expected_download_dir)
         with cts_utils.chdir('downloaded'):
             generate_zip_file(CONFIG_DATA['base11'], CONFIG_DATA['apk1'],
                               'not/a/webview/apk')
             generate_zip_file(CONFIG_DATA['base12'], CONFIG_DATA['apk1'],
                               'not/a/webview/apk')
         cts_updater.filter_downloaded_cts()
         with cts_utils.chdir('filtered'):
             self.assertEqual(2, len(os.listdir('.')))
             verify_zip_file(CONFIG_DATA['base11'], CONFIG_DATA['apk1'])
             verify_zip_file(CONFIG_DATA['base12'], CONFIG_DATA['apk1'])
Exemplo n.º 9
0
    def testDownloadCIPD(self, run_mock):
        with tempfile_ext.NamedTemporaryDirectory() as workDir,\
             tempfile_ext.NamedTemporaryDirectory() as repoRoot,\
             cts_utils.chdir(workDir):
            cts_utils_test.setup_fake_repo(repoRoot)
            fake_cipd = cts_utils_test.FakeCIPD()
            fake_cipd.add_package(
                os.path.join(repoRoot, cts_utils.TOOLS_DIR,
                             cts_utils.CIPD_FILE), DEPS_DATA['revision'])
            fake_run_cmd = cts_utils_test.FakeRunCmd(fake_cipd)
            run_mock.side_effect = fake_run_cmd.run_cmd

            cts_updater = update_cts.UpdateCTS('.', repoRoot)
            cts_updater.download_cipd()
            self.assertTrue(os.path.isdir('cipd'))
            for i in [str(x) for x in range(1, 5)]:
                self.assertEqual(
                    CIPD_DATA['file' + i],
                    cts_utils_test.readfile(
                        os.path.join(workDir, 'cipd', CIPD_DATA['file' + i])))
Exemplo n.º 10
0
    def testCompleteUpdate(self, retrieve_mock, update_json_mock, cmd_mock,
                           run_mock):
        with tempfile_ext.NamedTemporaryDirectory() as workDir,\
             tempfile_ext.NamedTemporaryDirectory() as repoRoot,\
             cts_utils.chdir(workDir):
            cts_utils_test.setup_fake_repo(repoRoot)
            fake_cipd = cts_utils_test.FakeCIPD()
            fake_cipd.add_package(
                os.path.join(repoRoot, cts_utils.TOOLS_DIR,
                             cts_utils.CIPD_FILE), DEPS_DATA['revision'])
            fake_download = FakeDownload()
            fake_download.add_fake_zip_files(CONFIG_DATA['json'])
            fake_run_cmd = cts_utils_test.FakeRunCmd(fake_cipd)

            retrieve_mock.side_effect = fake_download.download
            run_mock.side_effect = fake_run_cmd.run_cmd
            update_json_mock.return_value = 0
            cmd_mock.return_value = ''

            cts_updater = update_cts.UpdateCTS('.', repoRoot)
            cts_updater.download_cts_cmd()
            cts_updater.create_cipd_cmd()
            cts_updater.update_repository_cmd()

            latest_version = fake_cipd.get_latest_version(
                'chromium/android_webview/tools/cts_archive')
            self.assertNotEqual(DEPS_DATA['revision'], latest_version)
            self._assertCIPDVersionUpdated(repoRoot, latest_version)

            repo_cipd_yaml = os.path.join(repoRoot, cts_utils.TOOLS_DIR,
                                          cts_utils.CIPD_FILE)
            run_mock.assert_any_call([
                'cp',
                os.path.join(workDir, 'staged', 'cipd.yaml'), repo_cipd_yaml
            ])

            run_mock.assert_any_call([
                'cipd', 'ensure', '-root',
                os.path.dirname(repo_cipd_yaml), '-ensure-file', mock.ANY
            ])
            update_json_mock.assert_called_with()