예제 #1
0
    def testImagePresentOnlyVgSetup(self):
        # Mount an image that is present, attached to a loopback device, and has a
        # VG, but doesn't have anything else set up.  This can't arise in normal
        # usage, but could happen if cros_sdk crashes in the middle of setup.
        # Should call losetup, vgs, vgchange, lvs, lvcreate, mke2fs, mount
        self._makeImageFile(self.chroot_img)

        m = self._mockFindVolumeGroupForDevice()
        m2 = self._mockDeviceFromFile('/dev/loop0')

        with cros_test_lib.RunCommandMock() as rc_mock:
            rc_mock.AddCmdResult(self._VGS_LOOKUP,
                                 returncode=self._LVM_SUCCESS_CODE)
            rc_mock.AddCmdResult(self._VGCHANGE)
            rc_mock.AddCmdResult(self._LVS_LOOKUP,
                                 returncode=self._LVM_FAILURE_CODE)
            rc_mock.AddCmdResult(self._LVCREATE)
            rc_mock.AddCmdResult(self._MKE2FS)
            rc_mock.AddCmdResult(self._MOUNT)

            success = cros_sdk_lib.MountChroot(self.chroot_path)
            self.assertTrue(success)

        m.assert_called_with(self.chroot_path, '/dev/loop0')
        m2.assert_called_with(self.chroot_img)
예제 #2
0
    def setUp(self):
        self.rc_mock = cros_test_lib.RunCommandMock()
        self.rc_mock.SetDefaultCmdResult()
        self.StartPatcher(self.rc_mock)

        self.sdk_mock = self.StartPatcher(
            SDKFetcherMock(external_mocks=[self.rc_mock]))

        # This needs to occur before initializing MockChromeSDKCommand.
        self.bashrc = os.path.join(self.tempdir, 'bashrc')
        self.PatchObject(constants, 'CHROME_SDK_BASHRC', new=self.bashrc)

        self.PatchObject(osutils,
                         'SourceEnvironment',
                         autospec=True,
                         side_effect=self.SourceEnvironmentMock)
        self.rc_mock.AddCmdResult(
            cros_chrome_sdk.ChromeSDKCommand.GOMACC_PORT_CMD, output='8088')

        # Initialized by SetupCommandMock.
        self.cmd_mock = None

        # Set up a fake Chrome src/ directory
        self.chrome_root = os.path.join(self.tempdir, 'chrome_root')
        self.chrome_src_dir = os.path.join(self.chrome_root, 'src')
        osutils.SafeMakedirs(self.chrome_src_dir)
        osutils.Touch(os.path.join(self.chrome_root, '.gclient'))
예제 #3
0
    def testMountedCleanupWithDelete(self):
        m = self.PatchObject(osutils, 'UmountTree')
        m2 = self.PatchObject(osutils, 'SafeUnlink')
        m3 = self.PatchObject(osutils, 'RmDir')
        m4 = self.PatchObject(cros_sdk_lib, '_RescanDeviceLvmMetadata')

        proc_mounts = os.path.join(self.tempdir, 'proc_mounts')
        with open(proc_mounts, 'w') as f:
            f.write('/dev/mapper/cros_vg_name-chroot %s ext4 rw 0 0\n' %
                    self.chroot_path)

        with cros_test_lib.RunCommandMock() as rc_mock:
            rc_mock.AddCmdResult(self._VGS_DEV_LOOKUP, output='  /dev/loop0')
            rc_mock.AddCmdResult(self._VGCHANGE_N)
            rc_mock.AddCmdResult(self._LOSETUP_DETACH)

            cros_sdk_lib.CleanupChrootMount(self.chroot_path,
                                            None,
                                            delete=True,
                                            proc_mounts=proc_mounts)

        m.assert_called_with(self.chroot_path)
        m2.assert_called_with(self.chroot_img)
        m3.assert_called_with(self.chroot_path, ignore_missing=True, sudo=True)
        m4.assert_called_with('/dev/loop0')
예제 #4
0
    def testBlockDevice(self):
        """Test block device info when there is no record or a record is stale."""
        disk = self._CreateDisk(1)

        mock_device = '/dev/sda1'
        mock_size = 12345678987654321
        mock_ids = ['ata-ST1000DM003-1ER162_Z4Y3WQDB-part1']
        mock_labels = ['BOOT-PARTITION']
        mock_lsblk = 'NAME="sda1" RM="0" TYPE="part" SIZE="%s"' % mock_size

        self.StartPatcher(mock.patch('chromite.lib.osutils.ResolveSymlink'))
        osutils.ResolveSymlink.return_value = '/dev/sda1'

        with cros_test_lib.RunCommandMock() as rc_mock:
            rc_mock.AddCmdResult(partial_mock.In(
                systeminfo.SYSTEMFILE_DEV_DISKBY['ids']),
                                 output='\n'.join(mock_ids))
            rc_mock.AddCmdResult(partial_mock.In(
                systeminfo.SYSTEMFILE_DEV_DISKBY['labels']),
                                 output='\n'.join(mock_labels))
            rc_mock.AddCmdResult(partial_mock.In('lsblk'), output=mock_lsblk)

            mock_blockdevice = [
                systeminfo.RESOURCE_BLOCKDEVICE(mock_device, mock_size,
                                                mock_ids, mock_labels)
            ]

            self.assertEquals(disk.BlockDevices(mock_device), mock_blockdevice)
 def testCleanupChrootNormal(self):
   """Check normal CleanupChroot."""
   osutils.SafeMakedirs(self.chroot)
   osutils.Touch(self.chroot + '.img')
   self.StartPatcher(cros_test_lib.RunCommandMock())
   with mock.patch.object(cros_sdk_lib, 'CleanupChrootMount'):
     cbuildbot_launch.CleanupChroot(self.buildroot)
예제 #6
0
    def setUp(self):
        self.rc_mock = self.StartPatcher(cros_test_lib.RunCommandMock())
        self.email_mock = self.PatchObject(alerts, 'SendEmail')

        self.user = '******'
        self.email = '*****@*****.**'
        self.loas = loas.Loas(self.user, self.email)
  def testEvaluateFromHost(self):
    """Tests Evaluate() which runs test from host."""
    # Mock RunTestFromDut fail.
    command_mock = self.StartPatcher(cros_test_lib.RunCommandMock())
    command_mock.AddCmdResult(
        partial_mock.InOrder(['rm', '-f', self.REMOTE_REPORT_FILE]),
        returncode=0)
    command_mock.AddCmdResult(
        partial_mock.InOrder([self.AUTOTEST_CLIENT, self.TEST_TARGET]),
        returncode=1)

    self.SkipMaySetupBoard()

    # Mock RunTestFromHost success.
    command_mock.AddCmdResult(self.TEST_THAT_COMMAND, returncode=0)

    # Mock 'find' and returns a result file for verify.
    score = 59.9
    report_file_in_chroot, _ = self.WriteTestResult(self.evaluator, score)
    command_mock.AddCmdResult(
        ['find', '.', '-name', 'results-chart.json'],
        output=report_file_in_chroot)

    eval_score = self.evaluator.Evaluate(self.DUT, self.BUILD_LABEL)
    self.assertEqual(1, len(eval_score.values))
    self.assertEqual(score, eval_score.values[0])
    self.assertEqual(score, eval_score.mean)
    self.assertEqual(0.0, eval_score.variance)
    self.assertEqual(0.0, eval_score.std)
예제 #8
0
 def testNonFFPush(self):
     """Non fast-forward push error propagates to the caller."""
     with cros_test_lib.RunCommandMock() as rc_mock:
         rc_mock.AddCmdResult(partial_mock.In('push'),
                              returncode=128,
                              error=self.NON_FF_PUSH_ERROR)
         self.assertRaises(cros_build_lib.RunCommandError, self._RunGitPush)
예제 #9
0
    def testImagePresentNotSetup(self):
        # Mount an image that is present but doesn't have anything set up.  This
        # can't arise in normal usage, but could happen if cros_sdk crashes in the
        # middle of setup.
        # Should call losetup -j, losetup -f, vgs, vgcreate, lvs, lvcreate, mke2fs,
        # mount
        self._makeImageFile(self.chroot_img)

        m = self._mockFindVolumeGroupForDevice()
        m2 = self._mockAttachDeviceToFile()
        m3 = self._mockDeviceFromFile('')

        with cros_test_lib.RunCommandMock() as rc_mock:
            rc_mock.AddCmdResult(self._VGS_LOOKUP,
                                 returncode=self._LVM_FAILURE_CODE)
            rc_mock.AddCmdResult(self._VGCREATE)
            rc_mock.AddCmdResult(self._LVS_LOOKUP,
                                 returncode=self._LVM_FAILURE_CODE)
            rc_mock.AddCmdResult(self._LVCREATE)
            rc_mock.AddCmdResult(self._MKE2FS)
            rc_mock.AddCmdResult(self._MOUNT)

            success = cros_sdk_lib.MountChroot(self.chroot_path)
            self.assertTrue(success)

        m.assert_called_with(self.chroot_path, '/dev/loop0')
        m2.assert_called_with(self.chroot_img)
        m3.assert_called_with(self.chroot_img)
예제 #10
0
    def testNothingCleanupWithDelete(self):
        m = self.PatchObject(osutils, 'UmountTree')
        m2 = self.PatchObject(cros_sdk_lib, 'FindVolumeGroupForDevice')
        m2.return_value = 'cros_chroot_001'
        m3 = self.PatchObject(osutils, 'SafeUnlink')
        m4 = self.PatchObject(osutils, 'RmDir')

        proc_mounts = os.path.join(self.tempdir, 'proc_mounts')
        with open(proc_mounts, 'w') as f:
            f.write('sysfs /sys sysfs rw 0 0\n')

        with cros_test_lib.RunCommandMock() as rc_mock:
            rc_mock.AddCmdResult(self._LOSETUP_FIND, returncode=1)
            rc_mock.AddCmdResult(self._VGS_VG_LOOKUP,
                                 returncode=self._LVM_FAILURE_CODE)

            cros_sdk_lib.CleanupChrootMount(self.chroot_path,
                                            None,
                                            delete=True,
                                            proc_mounts=proc_mounts)

        m.assert_called_with(self.chroot_path)
        m2.assert_called_with(self.chroot_path, None)
        m3.assert_called_with(self.chroot_img)
        m4.assert_called_with(self.chroot_path, ignore_missing=True, sudo=True)
예제 #11
0
    def testPhysicalVolumeWithoutVolumeGroup(self):
        with cros_test_lib.RunCommandMock() as rc_mock:
            rc_mock.SetDefaultCmdResult(output="""
  wrong_vg1\t/dev/sda1
  \t/dev/loop0
""")
            vg = cros_sdk_lib.FindVolumeGroupForDevice('/chroot', '/dev/loop0')
            self.assertEqual(vg, 'cros_chroot_000')
 def setUp(self):
     self._Prepare()
     self.rc_mock = self.StartPatcher(cros_test_lib.RunCommandMock())
     self.rc_mock.SetDefaultCmdResult()
     self.buildstore = FakeBuildStore()
     # Prepare the directories
     chroot_tmp = os.path.join(self.build_root, 'chroot', 'tmp')
     osutils.SafeMakedirs(chroot_tmp)
예제 #13
0
    def testNoMatchingVolumeGroup(self):
        with cros_test_lib.RunCommandMock() as rc_mock:
            rc_mock.SetDefaultCmdResult(output='''
  wrong_vg1\t/dev/sda1
  wrong_vg2\t/dev/loop0
''')
            vg = cros_sdk_lib.FindVolumeGroupForDevice('/chroot', '')
            self.assertEqual(vg, 'cros_chroot_000')
예제 #14
0
 def testBuildAndArchiveDeltaSysroot(self):
     """Test tarball is added to upload queue."""
     stage = self.ConstructStageForArchiveStep()
     with cros_test_lib.RunCommandMock() as rc:
         rc.SetDefaultCmdResult()
         stage.BuildAndArchiveDeltaSysroot()
     stage._upload_queue.put.assert_called_with(
         [constants.DELTA_SYSROOT_TAR])
예제 #15
0
    def setUp(self):
        self.StartPatcher(generic_stages_unittest.ArchivingStageMixinMock())
        self.StartPatcher(parallel_unittest.ParallelMock())

        self.rc_mock = self.StartPatcher(cros_test_lib.RunCommandMock())
        self.rc_mock.SetDefaultCmdResult(output='')

        self.stage = None
예제 #16
0
    def testExistingDevice(self):
        with cros_test_lib.RunCommandMock() as rc_mock:
            rc_mock.SetDefaultCmdResult(output="""
  wrong_vg1\t/dev/sda1
  test_vg\t/dev/loop1
  wrong_vg2\t/dev/loop0
""")
            vg = cros_sdk_lib.FindVolumeGroupForDevice('/chroot', '/dev/loop1')
            self.assertEqual(vg, 'test_vg')
예제 #17
0
    def setUp(self):
        self.rc_mock = cros_test_lib.RunCommandMock()
        self.rc_mock.SetDefaultCmdResult()
        self.StartPatcher(self.rc_mock)

        self.cmd_mock = MockChromeSDKCommand(
            ['--board', SDKFetcherMock.BOARD, 'true'],
            base_args=['--cache-dir', self.tempdir])
        self.StartPatcher(self.cmd_mock)
예제 #18
0
    def testTooManyVolumeGroups(self):
        with cros_test_lib.RunCommandMock() as rc_mock:
            rc_mock.SetDefaultCmdResult(output="""
  wrong_vg1\t/dev/sda1
%s
  wrong_vg2\t/dev/loop0
""" % '\n'.join(['  cros_chroot_%03d\t/dev/any' % i for i in range(1000)]))
            vg = cros_sdk_lib.FindVolumeGroupForDevice('/chroot', '')
            self.assertIsNone(vg)
 def testCleanupChrootTimeout(self):
   """Check timeouts in CleanupChroot."""
   osutils.SafeMakedirs(self.chroot)
   osutils.Touch(self.chroot + '.img')
   rc_mock = self.StartPatcher(cros_test_lib.RunCommandMock())
   rc_mock.SetDefaultCmdResult()
   with mock.patch.object(cros_sdk_lib, 'CleanupChrootMount',
                          side_effect=timeout_util.TimeoutError):
     cbuildbot_launch.CleanupChroot(self.buildroot)
예제 #20
0
    def testInvalidLines(self):
        with cros_test_lib.RunCommandMock() as rc_mock:
            rc_mock.SetDefaultCmdResult(output="""
  \t/dev/sda1

  wrong_vg2\t/dev/loop0\t
""")
            vg = cros_sdk_lib.FindVolumeGroupForDevice('/chroot', '')
            self.assertEqual(vg, 'cros_chroot_000')
예제 #21
0
 def testPersistentTransientError(self):
     """GitPush fails if transient error occurs multiple times."""
     for error in self.TRANSIENT_ERRORS:
         with cros_test_lib.RunCommandMock() as rc_mock:
             rc_mock.AddCmdResult(partial_mock.In('push'),
                                  returncode=128,
                                  error=error)
             self.assertRaises(cros_build_lib.RunCommandError,
                               self._RunGitPush)
예제 #22
0
  def setUp(self):
    self.rc_mock = cros_test_lib.RunCommandMock()
    self.StartPatcher(self.rc_mock)
    self.rc_mock.SetDefaultCmdResult()

    self.PatchObject(glob, 'glob', return_value=LOOP_PARTS_LIST)
    def fake_which(val, *_arg, **_kwargs):
      return val
    self.PatchObject(osutils, 'Which', side_effect=fake_which)
  def testRunTestFromHostTestThatFailWithEvalPassingOnly(self):
    """Tests TestFromHost() with failed autotest and --eval-passing-only."""
    self.UpdateOptionsAndEvaluator(dict(eval_passing_only=True))

    command_mock = self.StartPatcher(cros_test_lib.RunCommandMock())
    self.SkipMaySetupBoard()
    command_mock.AddCmdResult(self.TEST_THAT_COMMAND, returncode=1)

    self.assertFalse(self.evaluator.RunTestFromHost(self.DUT, self.REPORT_FILE))
  def testRunTestFromHostReportFileMissing(self):
    """Tests TestFromHost() when test report file does not exist."""
    command_mock = self.StartPatcher(cros_test_lib.RunCommandMock())
    self.SkipMaySetupBoard()
    command_mock.AddCmdResult(self.TEST_THAT_COMMAND, returncode=0)
    command_mock.AddCmdResult(
        ['find', '.', '-name', 'results-chart.json'], output='')

    self.assertFalse(self.evaluator.RunTestFromHost(self.DUT, self.REPORT_FILE))
  def testLookupReportFileMissing(self):
    """Tests LookupReportFile() when the report does not exist."""
    command_mock = self.StartPatcher(cros_test_lib.RunCommandMock())
    results_base_path = self.GetTestResultPath(self.evaluator)
    command_mock.AddCmdResult(
        ['find', '.', '-name', 'results-chart.json'],
        kwargs={'cwd': results_base_path, 'capture_output': True},
        output='')

    self.assertIsNone(self.evaluator.LookupReportFile())
예제 #26
0
    def testInvalidChars(self):
        with cros_test_lib.RunCommandMock() as rc_mock:
            rc_mock.SetDefaultCmdResult(output="""
  wrong_vg1\t/dev/sda1
  cros_chroot_000\t/dev/loop1
  wrong_vg2\t/dev/loop0
""")
            vg = cros_sdk_lib.FindVolumeGroupForDevice(
                '//full path /to& "my" /chroot', '')
            self.assertEqual(vg, 'cros_full+path++to+++my+++chroot_000')
예제 #27
0
 def testBuildAndArchiveDeltaSysrootFailure(self):
     """Test tarball not added to upload queue on command exception."""
     stage = self.ConstructStageForArchiveStep()
     with cros_test_lib.RunCommandMock() as rc:
         rc.AddCmdResult(partial_mock.In('generate_delta_sysroot'),
                         returncode=1,
                         error='generate_delta_sysroot: error')
         self.assertRaises2(cros_build_lib.RunCommandError,
                            stage.BuildAndArchiveDeltaSysroot)
     self.assertFalse(stage._upload_queue.put.called)
예제 #28
0
    def setUp(self):
        self.CreateMockOverlay('amd64-generic')

        self.StartPatcher(generic_stages_unittest.ArchivingStageMixinMock())
        self.StartPatcher(parallel_unittest.ParallelMock())

        self.rc_mock = self.StartPatcher(cros_test_lib.RunCommandMock())
        self.rc_mock.SetDefaultCmdResult(output='')

        self.stage = None
        self.buildstore = FakeBuildStore()
예제 #29
0
 def testGetInstallArgsList(self):
     """Check GetInstallArgsList behavior."""
     stdout = (
         'sys-apps/which-2.21 gs://bucket/board/which-2.21.debug.tbz2\n'
         'dev-libs/foo-1-r1 gs://bucket/board/foo-1-r1.debug.tbz2\n')
     rc = self.StartPatcher(cros_test_lib.RunCommandMock())
     rc.AddCmdResult(cmd=['foo', '--list'], stdout=stdout)
     self.assertEqual([[
         'sys-apps/which-2.21', 'gs://bucket/board/which-2.21.debug.tbz2'
     ], ['dev-libs/foo-1-r1', 'gs://bucket/board/foo-1-r1.debug.tbz2']],
                      cros_install_debug_syms.GetInstallArgsList(['foo']))
  def testRunTestFromHostTestThatFailReportMissing(self):
    """Tests TestFromHost() with failed autotest and without report."""
    command_mock = self.StartPatcher(cros_test_lib.RunCommandMock())
    self.SkipMaySetupBoard()
    # test_that failed.
    command_mock.AddCmdResult(self.TEST_THAT_COMMAND, returncode=1)

    # And report file is missing.
    command_mock.AddCmdResult(
        ['find', '.', '-name', 'results-chart.json'], output='')

    self.assertFalse(self.evaluator.RunTestFromHost(self.DUT, self.REPORT_FILE))