From 5212cf017537838e9c356c3c030f19c75f41d484 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ferenc=20G=C3=A9czi?= Date: Wed, 25 Oct 2023 13:00:00 +0000 Subject: [PATCH] refactor(runtime): Use a constant for the deprecated installation path MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Ferenc Géczi --- instana/collector/helpers/runtime.py | 3 ++- tests/platforms/test_host_collector.py | 8 ++++---- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/instana/collector/helpers/runtime.py b/instana/collector/helpers/runtime.py index d5c2254c..b27a859b 100644 --- a/instana/collector/helpers/runtime.py +++ b/instana/collector/helpers/runtime.py @@ -18,6 +18,7 @@ from .base import BaseHelper +PATH_OF_DEPRECATED_INSTALLATION_VIA_HOST_AGENT = '/tmp/.instana/python' class RuntimeHelper(BaseHelper): """ Helper class to collect snapshot and metrics for this Python runtime """ @@ -181,7 +182,7 @@ def _collect_runtime_snapshot(self, plugin_data): if 'AUTOWRAPT_BOOTSTRAP' in os.environ: snapshot_payload['m'] = 'Autowrapt' - elif '/tmp/.instana/python' in sys.path: + elif PATH_OF_DEPRECATED_INSTALLATION_VIA_HOST_AGENT in sys.path: snapshot_payload['m'] = 'AutoTrace' else: snapshot_payload['m'] = 'Manual' diff --git a/tests/platforms/test_host_collector.py b/tests/platforms/test_host_collector.py index feff844b..1f6b19fa 100644 --- a/tests/platforms/test_host_collector.py +++ b/tests/platforms/test_host_collector.py @@ -13,11 +13,11 @@ from instana.tracer import InstanaTracer from instana.recorder import StanRecorder from instana.agent.host import HostAgent +from instana.collector.helpers.runtime import PATH_OF_DEPRECATED_INSTALLATION_VIA_HOST_AGENT from instana.collector.host import HostCollector from instana.singletons import get_agent, set_agent, get_tracer, set_tracer from instana.version import VERSION - class TestHostCollector(unittest.TestCase): def __init__(self, methodName='runTest'): super(TestHostCollector, self).__init__(methodName) @@ -47,8 +47,8 @@ def tearDown(self): set_agent(self.original_agent) set_tracer(self.original_tracer) - if '/tmp/.instana/python' in sys.path: - sys.path.remove('/tmp/.instana/python') + if PATH_OF_DEPRECATED_INSTALLATION_VIA_HOST_AGENT in sys.path: + sys.path.remove(PATH_OF_DEPRECATED_INSTALLATION_VIA_HOST_AGENT) def create_agent_and_setup_tracer(self): self.agent = HostAgent() @@ -226,7 +226,7 @@ def test_prepare_payload_with_autowrapt(self, mock_should_send_snapshot_data): def test_prepare_payload_with_autotrace(self, mock_should_send_snapshot_data): mock_should_send_snapshot_data.return_value = True - sys.path.append('/tmp/.instana/python') + sys.path.append(PATH_OF_DEPRECATED_INSTALLATION_VIA_HOST_AGENT) self.create_agent_and_setup_tracer()