File 07_Unpause_the_container_before_stopping.patch of Package openstack-nova-docker

commit 3ad7cdac563a8c49f945882f756d97773455caf5
Author: Davanum Srinivas <dims@linux.vnet.ibm.com>
Date:   Tue Jan 13 07:57:32 2015 -0500

    Unpause the container before stopping
    
    If we get an error from Docker API when we issue a stop,
    then we should call pause followed by a stop. We were doing
    this in one scenario. This commit ensures that all docker.stop(s)
    are called from one place with the try/except to ensure
    pause gets called. This hopefully reduces failures related to
    unmounting in aufs / devicemapper etc.
    
    Change-Id: I95fa7a5af58f0587a8b72f4652a3e5636bff39a9

Index: nova-docker-0.0.0.post141/novadocker/virt/docker/driver.py
===================================================================
--- nova-docker-0.0.0.post141.orig/novadocker/virt/docker/driver.py
+++ nova-docker-0.0.0.post141/novadocker/virt/docker/driver.py
@@ -478,19 +478,22 @@ class DockerDriver(driver.ComputeDriver)
 
         self._start_container(container_id, instance)
 
-    def soft_delete(self, instance):
-        container_id = self._get_container_id(instance)
-        if not container_id:
-            return
+    def _stop(self, container_id, instance, timeout=0):
         try:
-            self.docker.stop(container_id)
+            self.docker.stop(container_id, timeout)
         except errors.APIError as e:
             if 'Unpause the container before stopping' not in e.explanation:
                 LOG.warning(_('Cannot stop container: %s'),
                             e, instance=instance, exc_info=True)
                 raise
             self.docker.unpause(container_id)
-            self.docker.stop(container_id)
+            self.docker.stop(container_id, timeout)
+
+    def soft_delete(self, instance):
+        container_id = self._get_container_id(instance)
+        if not container_id:
+            return
+        self._stop(container_id, instance)
 
     def destroy(self, context, instance, network_info, block_device_info=None,
                 destroy_disks=True, migrate_data=None):
@@ -515,7 +518,7 @@ class DockerDriver(driver.ComputeDriver)
         container_id = self._get_container_id(instance)
         if not container_id:
             return
-        self.docker.stop(container_id)
+        self._stop(container_id, instance)
         try:
             network.teardown_network(container_id)
             if network_info:
@@ -563,7 +566,7 @@ class DockerDriver(driver.ComputeDriver)
         container_id = self._get_container_id(instance)
         if not container_id:
             return
-        self.docker.stop(container_id, timeout)
+        self._stop(container_id, instance, timeout)
 
     def pause(self, instance):
         """Pause the specified instance.
openSUSE Build Service is sponsored by