示例#1
0
 def test_translate_event(self):
     # (expected event, pvm state, power_state)
     tests = [(event.EVENT_LIFECYCLE_STARTED,
               "running", power_state.SHUTDOWN),
              (None, "running", power_state.RUNNING)]
     for t in tests:
         self.assertEqual(t[0], vm.translate_event(t[1], t[2]))
示例#2
0
    def _emit_event(self, pvm_state, inst, is_immed):
        if is_immed:
            # Cancel out any delayed events
            cancel_thread = self._delayed_event_threads.get(inst.uuid)
            if cancel_thread:
                cancel_thread.cancel()
                del self._delayed_event_threads[inst.uuid]
        else:
            # Make sure you're still in the thread.  If not (thread was started
            # but the is_immed _emit_event had run the del), then just bail
            inst_queue = self._delayed_event_threads.get(inst.uuid)
            if not inst_queue:
                return

        # See if it's really a change of state from what OpenStack knows
        transition = vm.translate_event(pvm_state, inst.power_state)
        if transition is None:
            return

        # Log as if normal event
        lce = event.LifecycleEvent(inst.uuid, transition)
        LOG.info(_LI('Sending life cycle event for instance state '
                     'change to: %s'),
                 pvm_state,
                 instance=inst)
        self._driver.emit_event(lce)

        if not is_immed:
            # Delete out the queue
            del self._delayed_event_threads[inst.uuid]
示例#3
0
 def test_translate_event(self):
     # (expected event, pvm state, power_state)
     tests = [
         (event.EVENT_LIFECYCLE_STARTED, "running", power_state.SHUTDOWN),
         (None, "running", power_state.RUNNING)
     ]
     for t in tests:
         self.assertEqual(t[0], vm.translate_event(t[1], t[2]))
示例#4
0
    def _emit_event(self, pvm_uuid, inst):
        # Get the current state
        try:
            pvm_state = vm.get_vm_qp(self._driver.adapter, pvm_uuid,
                                     'PartitionState')
        except exception.InstanceNotFound:
            LOG.debug("LPAR %s was deleted while event was delayed.",
                      pvm_uuid,
                      instance=inst)
            return

        LOG.debug('New state %s for partition %s',
                  pvm_state,
                  pvm_uuid,
                  instance=inst)

        inst = _get_instance(inst, pvm_uuid)
        if inst is None:
            LOG.debug("Not emitting LifecycleEvent: no instance for LPAR %s",
                      pvm_uuid)
            return

        # If we're in the middle of a nova-driven operation, no event necessary
        if inst.task_state in _NO_EVENT_TASK_STATES:
            LOG.debug("Not emitting LifecycleEvent: instance task_state is %s",
                      inst.task_state,
                      instance=inst)
            return

        # See if it's really a change of state from what OpenStack knows
        transition = vm.translate_event(pvm_state, inst.power_state)
        if transition is None:
            LOG.debug(
                "No LifecycleEvent necessary for pvm_state(%s) and "
                "power_state(%s).",
                pvm_state,
                power_state.STATE_MAP[inst.power_state],
                instance=inst)
            return

        # Log as if normal event
        lce = event.LifecycleEvent(inst.uuid, transition)
        LOG.info('Sending LifecycleEvent for instance state change to: %s',
                 pvm_state,
                 instance=inst)
        self._driver.emit_event(lce)

        # Delete out the queue
        del self._delayed_event_threads[pvm_uuid]