From 82551a7059663e3018a535cc28154f05a89ee3a9 Mon Sep 17 00:00:00 2001 From: Daniel Clavijo Coca Date: Fri, 21 Dec 2018 13:41:46 -0600 Subject: [PATCH] development: Add 1810 workaround for snap issue --- src/vmm_mad/remotes/lib/lxd/command.rb | 5 ----- src/vmm_mad/remotes/lib/lxd/container.rb | 14 +++++++++++++- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/src/vmm_mad/remotes/lib/lxd/command.rb b/src/vmm_mad/remotes/lib/lxd/command.rb index 6352353f74..4e70c0958b 100644 --- a/src/vmm_mad/remotes/lib/lxd/command.rb +++ b/src/vmm_mad/remotes/lib/lxd/command.rb @@ -53,11 +53,6 @@ module Command execute(cmd, lock) unless running?(cmd.split[0]) end - def self.lxc_execute(lxd_id, cmd) - cmd = "lxc exec #{lxd_id} -- #{cmd}" - execute(cmd, true) - end - # Return true if command is running def self.running?(command) !`ps --noheaders -C #{command}`.empty? diff --git a/src/vmm_mad/remotes/lib/lxd/container.rb b/src/vmm_mad/remotes/lib/lxd/container.rb index 77deee7842..18b6a132cc 100644 --- a/src/vmm_mad/remotes/lib/lxd/container.rb +++ b/src/vmm_mad/remotes/lib/lxd/container.rb @@ -35,6 +35,7 @@ class Container # Class Constants API and Containers Paths #--------------------------------------------------------------------------- CONTAINERS = 'containers'.freeze + LXC_COMMAND = 'lxc' #--------------------------------------------------------------------------- # Methods to access container attributes @@ -161,7 +162,18 @@ class Container # Runs command inside container # @param command [String] to execute through lxc exec def exec(command) - Command.lxc_execute(name, command) + cmd = "#{LXC_COMMAND} exec #{@one.vm_name} -- #{command}" + rc, o, e = Command.execute(cmd, true) + + # TODO this should be removed when Snap bug is fixed + # Snap patch + rc, o, e = Command.execute("sudo #{cmd}", true) if e.include?('cannot create user data directory:') + + return [rc, o, e] unless rc != 0 + + OpenNebula.log_error("#{__method__}: Failed to run command #{cmd}: #{e}") + + [rc, o, e] end #---------------------------------------------------------------------------