From a2adff395f193a77e5329c7a37ea819d8f11f1e4 Mon Sep 17 00:00:00 2001
From: "Le'Sage, Oded (ol7435)" <ol7435@att.com>
Date: Thu, 4 Mar 2021 15:31:18 -0600
Subject: [PATCH] fix shaker-spot execution

A previous commit introduced a feature to specify the directory the
agent uses for shell class execution via a cfg entry, agent_dir.

However this addition introduced an error when using shaker-spot:
  oslo_config.cfg.NoSuchOptError: no such option agent_dir in group
  [DEFAULT]

This commit fixes shaker-spot while still supporting the agent_dir
feature

Change-Id: I7cfb87ba406e177121e7914225857937a19502e4
---
 shaker/agent/agent.py | 7 ++-----
 1 file changed, 2 insertions(+), 5 deletions(-)

diff --git a/shaker/agent/agent.py b/shaker/agent/agent.py
index 3b86c74..322fb60 100644
--- a/shaker/agent/agent.py
+++ b/shaker/agent/agent.py
@@ -61,10 +61,6 @@ def send_reply(socket, agent_id, result):
 def run_command(command):
     command_stdout, command_stderr = None, None
     start = time.time()
-    agent_dir = cfg.CONF.agent_dir
-
-    if agent_dir:
-        utils.mkdir_tree(agent_dir)
 
     if command['type'] == 'program':
         command_stdout, command_stderr = processutils.execute(
@@ -72,7 +68,8 @@ def run_command(command):
 
     elif command['type'] == 'script':
         if 'agent_dir' in cfg.CONF:
-            file_name = tempfile.mktemp(dir="%s" % agent_dir)
+            utils.mkdir_tree(cfg.CONF.agent_dir)
+            file_name = tempfile.mktemp(dir="%s" % cfg.CONF.agent_dir)
         else:
             file_name = tempfile.mktemp()