<html>
  <head>

    <meta http-equiv="content-type" content="text/html; charset=utf-8">
  </head>
  <body bgcolor="#FFFFFF" text="#000000">
    Hi,<br>
    <br>
    In sampling.py, remove() is being called without calling add()
    before, which throws:<br>
    <blockquote>JsonRpc (StompReactor)::DEBUG::2015-04-28
      17:35:55,061::stompReactor::94::Broker.StompAdapter::(handle_frame)
      Handling message &lt;StompFrame command=u'SEND'&gt;<br>
      Thread-37401::DEBUG::2015-04-28
      17:35:55,062::__init__::445::jsonrpc.JsonRpcServer::(_serveRequest)
      Calling 'VM.destroy' in bridge with {u'vmID':
      u'6ec9c0a0-2879-4bfe-9a79-92471881ebfe'}<br>
      JsonRpcServer::DEBUG::2015-04-28
      17:35:55,062::__init__::482::jsonrpc.JsonRpcServer::(serve_requests)
      Waiting for request<br>
      Thread-37401::INFO::2015-04-28
      17:35:55,062::API::334::vds::(destroy) vmContainerLock acquired by
      vm 6ec9c0a0-2879-4bfe-9a79-92471881ebfe<br>
      Thread-37401::DEBUG::2015-04-28
      17:35:55,062::vm::3513::vm.Vm::(destroy)
      vmId=`6ec9c0a0-2879-4bfe-9a79-92471881ebfe`::destroy Called<br>
      Thread-37401::INFO::2015-04-28
      17:35:55,062::vm::3444::vm.Vm::(releaseVm)
      vmId=`6ec9c0a0-2879-4bfe-9a79-92471881ebfe`::Release VM resources<br>
      Thread-37401::WARNING::2015-04-28
      17:35:55,062::vm::375::vm.Vm::(_set_lastStatus)
      vmId=`6ec9c0a0-2879-4bfe-9a79-92471881ebfe`::trying to set state
      to Powering down when already Down<br>
      Thread-37401::ERROR::2015-04-28
      17:35:55,063::__init__::469::jsonrpc.JsonRpcServer::(_serveRequest)
      Internal server error<br>
      Traceback (most recent call last):<br>
        File "/usr/lib/python2.7/site-packages/yajsonrpc/__init__.py",
      line 464, in _serveRequest<br>
          res = method(**params)<br>
        File "/usr/share/vdsm/rpc/Bridge.py", line 273, in
      _dynamicMethod<br>
          result = fn(*methodArgs)<br>
        File "/usr/share/vdsm/API.py", line 339, in destroy<br>
          res = v.destroy()<br>
        File "/usr/share/vdsm/virt/vm.py", line 3515, in destroy<br>
          result = self.doDestroy()<br>
        File "/usr/share/vdsm/virt/vm.py", line 3533, in doDestroy<br>
          return self.releaseVm()<br>
        File "/usr/share/vdsm/virt/vm.py", line 3448, in releaseVm<br>
          sampling.stats_cache.remove(self.id)<br>
        File "/usr/share/vdsm/virt/sampling.py", line 428, in remove<br>
          if vmid in self._vm_last_timestamp.keys():<br>
      KeyError: u'6ec9c0a0-2879-4bfe-9a79-92471881ebfe'<br>
      Thread-37401::DEBUG::2015-04-28
      17:35:55,063::stompReactor::158::yajsonrpc.StompServer::(send)
      Sending response<br>
    </blockquote>
    In file '/usr/share/vdsm/virt/sampling.py':<br>
    <br>
        def add(self, vmid):<br>
            """<br>
            Warm up the cache for the given VM.<br>
            This is to avoid races during the first sampling and the
    first<br>
            reporting, which may result in a VM wrongly reported as
    unresponsive.<br>
            """<br>
            with self._lock:<br>
                self._vm_last_timestamp[vmid] = self._clock()<br>
    <br>
        def remove(self, vmid):<br>
            """<br>
            Remove any data from the cache related to the given VM.<br>
            """<br>
            with self._lock:<br>
    <b>            if vmid in self._vm_last_timestamp.keys():</b><b>
      &lt;----------------- I patched here as a workarround<br>
    </b><b>                del self._vm_last_timestamp[vmid]</b><br>
    <br>
  </body>
</html>