Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Address pylint warning deprecated-method #3059

Merged
merged 3 commits into from
Feb 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions azurelinuxagent/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ def daemon(self):
"""
set_daemon_version(AGENT_VERSION)
logger.set_prefix("Daemon")
threading.current_thread().setName("Daemon") # pylint: disable=deprecated-method
threading.current_thread().name = "Daemon"
child_args = None \
if self.conf_file_path is None \
else "-configuration-path:{0}".format(self.conf_file_path)
Expand Down Expand Up @@ -171,7 +171,7 @@ def run_exthandlers(self, debug=False):
Run the update and extension handler
"""
logger.set_prefix("ExtHandler")
threading.current_thread().setName("ExtHandler") # pylint: disable=deprecated-method
threading.current_thread().name = "ExtHandler"

#
# Agents < 2.2.53 used to echo the log to the console. Since the extension handler could have been started by
Expand Down
2 changes: 1 addition & 1 deletion azurelinuxagent/common/event.py
Original file line number Diff line number Diff line change
Expand Up @@ -604,7 +604,7 @@ def add_common_event_parameters(self, event, event_timestamp):
TelemetryEventParam(CommonTelemetryEventSchema.OpcodeName, event_timestamp.strftime(logger.Logger.LogTimeFormatInUTC)),
TelemetryEventParam(CommonTelemetryEventSchema.EventTid, threading.current_thread().ident),
TelemetryEventParam(CommonTelemetryEventSchema.EventPid, os.getpid()),
TelemetryEventParam(CommonTelemetryEventSchema.TaskName, threading.current_thread().getName())] # pylint: disable=deprecated-method
TelemetryEventParam(CommonTelemetryEventSchema.TaskName, threading.current_thread().name)]

if event.eventId == TELEMETRY_EVENT_EVENT_ID and event.providerId == TELEMETRY_EVENT_PROVIDER_ID:
# Currently only the GuestAgentExtensionEvents has these columns, the other tables dont have them so skipping
Expand Down
4 changes: 2 additions & 2 deletions azurelinuxagent/common/logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"""
import sys
from datetime import datetime, timedelta
from threading import currentThread
from threading import current_thread

from azurelinuxagent.common.future import ustr

Expand Down Expand Up @@ -137,7 +137,7 @@ def write_log(log_appender): # pylint: disable=W0612
msg = msg_format
time = datetime.utcnow().strftime(Logger.LogTimeFormatInUTC)
level_str = LogLevel.STRINGS[level]
thread_name = currentThread().getName() # pylint: disable=deprecated-method
thread_name = current_thread().name
if self.prefix is not None:
log_item = u"{0} {1} {2} {3} {4}\n".format(time, level_str, thread_name, self.prefix, msg)
else:
Expand Down
4 changes: 2 additions & 2 deletions azurelinuxagent/common/singletonperthread.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from threading import Lock, currentThread
from threading import Lock, current_thread


class _SingletonPerThreadMetaClass(type):
Expand All @@ -9,7 +9,7 @@ class _SingletonPerThreadMetaClass(type):
def __call__(cls, *args, **kwargs):
with cls._lock:
# Object Name = className__threadName
obj_name = "%s__%s" % (cls.__name__, currentThread().getName()) # pylint: disable=deprecated-method
obj_name = "%s__%s" % (cls.__name__, current_thread().name)
if obj_name not in cls._instances:
cls._instances[obj_name] = super(_SingletonPerThreadMetaClass, cls).__call__(*args, **kwargs)
return cls._instances[obj_name]
Expand Down
8 changes: 4 additions & 4 deletions azurelinuxagent/ga/collect_logs.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,8 @@ def is_alive(self):

def start(self):
self.event_thread = threading.Thread(target=self.daemon)
self.event_thread.setDaemon(True) # pylint: disable=deprecated-method
self.event_thread.setName(self.get_thread_name()) # pylint: disable=deprecated-method
self.event_thread.daemon = True
self.event_thread.name = self.get_thread_name()
self.event_thread.start()

def join(self):
Expand Down Expand Up @@ -303,8 +303,8 @@ def is_alive(self):

def start(self):
self.event_thread = threading.Thread(target=self.daemon)
self.event_thread.setDaemon(True) # pylint: disable=deprecated-method
self.event_thread.setName(self.get_thread_name()) # pylint: disable=deprecated-method
self.event_thread.daemon = True
self.event_thread.name = self.get_thread_name()
self.event_thread.start()

def daemon(self):
Expand Down
4 changes: 2 additions & 2 deletions azurelinuxagent/ga/collect_telemetry_events.py
Original file line number Diff line number Diff line change
Expand Up @@ -542,8 +542,8 @@ def is_alive(self):

def start(self):
self.thread = threading.Thread(target=self.daemon)
self.thread.setDaemon(True) # pylint: disable=deprecated-method
self.thread.setName(CollectTelemetryEventsHandler.get_thread_name()) # pylint: disable=deprecated-method
self.thread.daemon = True
self.thread.name = CollectTelemetryEventsHandler.get_thread_name()
self.thread.start()

def stop(self):
Expand Down
4 changes: 2 additions & 2 deletions azurelinuxagent/ga/env.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,8 +213,8 @@ def is_alive(self):

def start(self):
self.env_thread = threading.Thread(target=self.daemon)
self.env_thread.setDaemon(True) # pylint: disable=deprecated-method
self.env_thread.setName(self.get_thread_name()) # pylint: disable=deprecated-method
self.env_thread.daemon = True
self.env_thread.name = self.get_thread_name()
self.env_thread.start()

def daemon(self):
Expand Down
4 changes: 2 additions & 2 deletions azurelinuxagent/ga/monitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -281,8 +281,8 @@ def is_alive(self):

def start(self):
self.monitor_thread = threading.Thread(target=self.daemon)
self.monitor_thread.setDaemon(True) # pylint: disable=deprecated-method
self.monitor_thread.setName(self.get_thread_name()) # pylint: disable=deprecated-method
self.monitor_thread.daemon = True
self.monitor_thread.name = self.get_thread_name()
self.monitor_thread.start()

def daemon(self):
Expand Down
4 changes: 2 additions & 2 deletions azurelinuxagent/ga/send_telemetry_events.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ def is_alive(self):

def start(self):
self._thread = threading.Thread(target=self._process_telemetry_thread)
self._thread.setDaemon(True) # pylint: disable=deprecated-method
self._thread.setName(self.get_thread_name()) # pylint: disable=deprecated-method
self._thread.daemon = True
self._thread.name = self.get_thread_name()
self._thread.start()

def stop(self):
Expand Down
2 changes: 1 addition & 1 deletion tests/ga/test_send_telemetry_events.py
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ def test_it_should_enqueue_and_send_events_properly(self, mock_lib_dir, *_):
with patch("os.path.getmtime", return_value=test_mtime):
with patch('os.getpid', return_value=test_eventpid):
with patch("threading.Thread.ident", new_callable=PropertyMock(return_value=test_eventtid)):
with patch("threading.Thread.getName", return_value=test_taskname):
with patch("threading.Thread.name", new_callable=PropertyMock(return_value=test_taskname)):
monitor_handler.run()

TestSendTelemetryEventsHandler._stop_handler(telemetry_handler)
Expand Down
4 changes: 2 additions & 2 deletions tests_e2e/tests/scripts/agent_cpu_quota-start_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def __init__(self):
self._stopped = False

def run(self):
threading.current_thread().setName("*Stress*") # pylint: disable=deprecated-method
threading.current_thread().name = "*Stress*"

while not self._stopped:
try:
Expand All @@ -55,7 +55,7 @@ def stop(self):


try:
threading.current_thread().setName("*StartService*") # pylint: disable=deprecated-method
threading.current_thread().name = "*StartService*"
logger.set_prefix("E2ETest")
logger.add_logger_appender(logger.AppenderType.FILE, logger.LogLevel.INFO, "/var/log/waagent.log")

Expand Down
Loading