From 48eec8b324f6deb78fdaa9fae6c9b2ffeb3cf7af Mon Sep 17 00:00:00 2001 From: Miguel Caballer Date: Tue, 26 Nov 2024 13:01:45 +0100 Subject: [PATCH] Fix ctxt dist path --- IM/ConfManager.py | 5 +++-- IM/CtxtAgentBase.py | 5 +++-- contextualization/ctxt_agent_dist.py | 3 ++- test/unit/test_ctxt_agent.py | 4 ++-- 4 files changed, 10 insertions(+), 7 deletions(-) diff --git a/IM/ConfManager.py b/IM/ConfManager.py index fd2997b4..ff3125d1 100644 --- a/IM/ConfManager.py +++ b/IM/ConfManager.py @@ -56,6 +56,7 @@ from IM.recipe import Recipe from IM.config import Config from radl.radl import system, contextualize_item +from IM.CtxtAgentBase import CtxtAgentBase class ConfManager(LoggerMixin, threading.Thread): @@ -397,8 +398,8 @@ def launch_ctxt_agent(self, vm, tasks): vault_password = vm.info.systems[0].getValue("vault.password") if vault_password: vault_export = "export VAULT_PASS='%s' && " % vault_password - (pid, _, _) = ssh.execute("nohup sh -c \"" + vault_export + "/var/tmp/.ansible/bin/python3 " + - Config.REMOTE_CONF_DIR + + (pid, _, _) = ssh.execute("nohup sh -c \"" + vault_export + CtxtAgentBase.VENV_DIR + + "/bin/python3 " + Config.REMOTE_CONF_DIR + "/" + str(self.inf.id) + "/" + ctxt_agent_command + Config.REMOTE_CONF_DIR + "/" + str(self.inf.id) + "/" + "/general_info.cfg " + remote_dir + "/" + os.path.basename(conf_file) + diff --git a/IM/CtxtAgentBase.py b/IM/CtxtAgentBase.py index 486789b1..a88b0953 100644 --- a/IM/CtxtAgentBase.py +++ b/IM/CtxtAgentBase.py @@ -37,6 +37,7 @@ class CtxtAgentBase: # the ConfManager PLAYBOOK_RETRIES = 1 INTERNAL_PLAYBOOK_RETRIES = 1 + VENV_DIR = "/var/tmp/.ansible" def __init__(self, conf_data_filename): self.logger = None @@ -508,7 +509,7 @@ def install_ansible_roles(self, general_conf_data, playbook): task["name"] = "Create YAML file to install the collections with ansible-galaxy" yaml_data[0]['tasks'].append(task) - task = {"command": "/var/tmp/.ansible/bin/ansible-galaxy collection install -c -r %s" % filename} + task = {"command": self.VENV_DIR + "/bin/ansible-galaxy collection install -c -r %s" % filename} task["name"] = "Install galaxy collections" task["become"] = "yes" task["register"] = "collections_install" @@ -562,7 +563,7 @@ def install_ansible_roles(self, general_conf_data, playbook): task["name"] = "Create YAML file to install the roles with ansible-galaxy" yaml_data[0]['tasks'].append(task) - task = {"command": "/var/tmp/.ansible/bin/ansible-galaxy install -c -r %s" % filename} + task = {"command": self.VENV_DIR + "/bin/ansible-galaxy install -c -r %s" % filename} task["name"] = "Install galaxy roles" task["become"] = "yes" task["register"] = "roles_install" diff --git a/contextualization/ctxt_agent_dist.py b/contextualization/ctxt_agent_dist.py index f96a8a01..ac5c1e77 100755 --- a/contextualization/ctxt_agent_dist.py +++ b/contextualization/ctxt_agent_dist.py @@ -162,7 +162,8 @@ def LaunchRemoteAgent(self, vm, vault_pass, pk_file, changed_pass_ok): vm_dir = os.path.abspath(os.path.dirname(self.vm_conf_data_filename)) remote_dir = os.path.abspath(os.path.dirname(self.conf_data_filename)) try: - (pid, _, _) = ssh_client.execute(vault_export + "nohup python3 " + remote_dir + "/ctxt_agent_dist.py " + + (pid, _, _) = ssh_client.execute(vault_export + "nohup " + CtxtAgentBase.VENV_DIR + "/bin/python3 " + + remote_dir + "/ctxt_agent_dist.py " + self.conf_data_filename + " " + self.vm_conf_data_filename + " 1 > " + vm_dir + "/stdout 2> " + vm_dir + "/stderr < /dev/null & echo -n $!") diff --git a/test/unit/test_ctxt_agent.py b/test/unit/test_ctxt_agent.py index 7354646f..3f9dac14 100755 --- a/test/unit/test_ctxt_agent.py +++ b/test/unit/test_ctxt_agent.py @@ -278,7 +278,7 @@ def test_95_install_ansible_roles(self): self.assertEqual(copy_content, "[{src: ansible_role}, {name: hadoop, src: " "'git+https://github.com/micafer/ansible-role-hadoop'}]") self.assertEqual(yaml_data[0]['tasks'][2]['command'][:69], - "/var/tmp/.ansible/bin/ansible-galaxy install -c -r /tmp/galaxy_roles_") + ctxt_agent.VENV_DIR + "/bin/ansible-galaxy install -c -r /tmp/galaxy_roles_") os.unlink(res) @@ -302,7 +302,7 @@ def test_99_install_ansible_collections(self): copy_content = yaml_data[0]['tasks'][0]['copy'][pos + 9:-2] self.assertEqual(copy_content, "{collections: [{name: ns.collection, version: '1.0'}]}") self.assertEqual(yaml_data[0]['tasks'][1]['command'][:86], - "/var/tmp/.ansible/bin/ansible-galaxy collection install -c -r /tmp/galaxy_collections_") + ctxt_agent.VENV_DIR + "/bin/ansible-galaxy collection install -c -r /tmp/galaxy_collections_") os.unlink(res)