Example #1
0
    def _stop_jobs(self, element):
        pending_jobs = self._get_pending_jobs_affecting_element(element)
        for job in pending_jobs:
            job_details = self._get_job_details(job, extended=True)
            try:
                if not job.Cancellable:
                    LOG.debug(
                        "Got request to terminate "
                        "non-cancelable job: %s.", job_details)
                    continue

                job.RequestStateChange(self._KILL_JOB_STATE_CHANGE_REQUEST)
            except exceptions.x_wmi as ex:
                # The job may had been completed right before we've
                # attempted to kill it.
                if not _utils._is_not_found_exc(ex):
                    LOG.debug(
                        "Failed to stop job. Exception: %s. "
                        "Job details: %s.", ex, job_details)

        pending_jobs = self._get_pending_jobs_affecting_element(element)
        if pending_jobs:
            pending_job_details = [
                self._get_job_details(job, extended=True)
                for job in pending_jobs
            ]
            LOG.debug(
                "Attempted to terminate jobs "
                "affecting element %(element)s but "
                "%(pending_count)s jobs are still pending: "
                "%(pending_jobs)s.",
                dict(element=element,
                     pending_count=len(pending_jobs),
                     pending_jobs=pending_job_details))
            raise exceptions.JobTerminateFailed()
    def test_is_not_found_exc(self, hresult):
        exc = test_base.FakeWMIExc(hresult=hresult)

        result = _utils._is_not_found_exc(exc)

        expected = hresult == _utils._WBEM_E_NOT_FOUND
        self.assertEqual(expected, result)
Example #3
0
    def _stop_jobs(self, element):
        pending_jobs = self._get_pending_jobs_affecting_element(
            element, ignore_error_state=False)
        for job in pending_jobs:
            try:
                if not job.Cancellable:
                    LOG.debug("Got request to terminate "
                              "non-cancelable job.")
                    continue
                elif job.JobState == constants.JOB_STATE_EXCEPTION:
                    LOG.debug("Attempting to terminate exception state job.")

                job.RequestStateChange(self._KILL_JOB_STATE_CHANGE_REQUEST)
            except exceptions.x_wmi as ex:
                # The job may had been completed right before we've
                # attempted to kill it.
                if not _utils._is_not_found_exc(ex):
                    LOG.debug("Failed to stop job. Exception: %s", ex)

        pending_jobs = self._get_pending_jobs_affecting_element(element)
        if pending_jobs:
            LOG.debug(
                "Attempted to terminate jobs "
                "affecting element %(element)s but "
                "%(pending_count)s jobs are still pending.",
                dict(element=element, pending_count=len(pending_jobs)))
            raise exceptions.JobTerminateFailed()
Example #4
0
    def test_is_not_found_exc(self, hresult, mock_get_com_error_hresult):
        mock_get_com_error_hresult.return_value = hresult
        exc = mock.MagicMock()

        result = _utils._is_not_found_exc(exc)

        expected = hresult == _utils._WBEM_E_NOT_FOUND
        self.assertEqual(expected, result)
        mock_get_com_error_hresult.assert_called_once_with(exc.com_error)
Example #5
0
    def _get_pending_jobs_affecting_element(self, element):
        # Msvm_AffectedJobElement is in fact an association between
        # the affected element and the affecting job.
        mappings = self._conn.Msvm_AffectedJobElement(
            AffectedElement=element.path_())
        pending_jobs = []
        for mapping in mappings:
            try:
                if mapping.AffectingElement and not self._is_job_completed(
                        mapping.AffectingElement):
                    pending_jobs.append(mapping.AffectingElement)

            except exceptions.x_wmi as ex:
                # NOTE(claudiub): we can ignore "Not found" type exceptions.
                if not _utils._is_not_found_exc(ex):
                    raise

        return pending_jobs