lib/nexussw/lxd/driver/mixins/rest.rb in lxd-common-0.5.0 vs lib/nexussw/lxd/driver/mixins/rest.rb in lxd-common-0.6.0

- old
+ new

@@ -84,18 +84,23 @@ wait_for_status container_id, 'stopped' end def delete_container(container_id) return unless container_exists? container_id - stop_container container_id, force: true + stop_container container_id, force: true - # overcome a race condition where the host is busy doing 'something' async causing the delete command to pop an error - # https://github.com/lxc/lxd/issues/4063 - # sleep 1 - - id = @hk.delete_container(container_id, sync: false)[:id] - @hk.wait_for_operation id + # ISSUE 17: something upstream is causing a double-tap on the REST endpoint + begin + @hk.delete_container container_id + rescue ::Faraday::ConnectionFailed, ::Hyperkit::BadRequest + LXD.with_timeout_and_retries timeout: 120 do + loop do + return unless container_exists? container_id + sleep 0.3 + end + end + end end def container_status(container_id) STATUS_CODES[container(container_id)[:status_code].to_i] end @@ -108,13 +113,10 @@ def container(container_id) @hk.container container_id end def container_exists?(container_id) - return true if container_status(container_id) - return false - rescue - false + hk.containers.include? container_id end protected def wait_for_status(container_id, newstatus)