From 2bf694ee44e58973449a5bb1584afc6ee0f01e6d Mon Sep 17 00:00:00 2001 From: Takashi Kajinami Date: Thu, 3 Oct 2024 00:09:10 +0900 Subject: [PATCH] Get rid of pkg_resources ... because it was removed in Python 3.12 [1]. [1] https://docs.python.org/3/whatsnew/3.12.html#ensurepip Change-Id: I2d27da0db92c1eaae9f45a0905e3eb905a939571 --- ironic_python_agent/agent.py | 5 ++--- ironic_python_agent/tests/unit/test_agent.py | 6 +++--- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/ironic_python_agent/agent.py b/ironic_python_agent/agent.py index e5244a912..bcc85da2f 100644 --- a/ironic_python_agent/agent.py +++ b/ironic_python_agent/agent.py @@ -13,6 +13,7 @@ # limitations under the License. import collections +import importlib.metadata import ipaddress import random import socket @@ -26,7 +27,6 @@ from ironic_lib import mdns from oslo_concurrency import processutils from oslo_config import cfg from oslo_log import log -import pkg_resources from ironic_python_agent.api import app from ironic_python_agent import config @@ -233,8 +233,7 @@ class IronicPythonAgent(base.ExecuteCommandMixin): self.listen_address = listen_address self.advertise_address = advertise_address self.advertise_protocol = advertise_protocol - self.version = pkg_resources.get_distribution('ironic-python-agent')\ - .version + self.version = importlib.metadata.version('ironic-python-agent') self.api = app.Application(self, cfg.CONF) self.heartbeat_timeout = None self.started_at = None diff --git a/ironic_python_agent/tests/unit/test_agent.py b/ironic_python_agent/tests/unit/test_agent.py index 0a3daab31..2d4312b24 100644 --- a/ironic_python_agent/tests/unit/test_agent.py +++ b/ironic_python_agent/tests/unit/test_agent.py @@ -12,6 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. +import importlib.metadata import json import socket import time @@ -20,7 +21,6 @@ from unittest import mock from ironic_lib import exception as lib_exc from oslo_concurrency import processutils from oslo_config import cfg -import pkg_resources from stevedore import extension from ironic_python_agent import agent @@ -230,8 +230,8 @@ class TestBaseAgent(ironic_agent_base.IronicAgentTest): status = self.agent.get_status() self.assertIsInstance(status, agent.IronicPythonAgentStatus) self.assertEqual(started_at, status.started_at) - self.assertEqual(pkg_resources.get_distribution('ironic-python-agent') - .version, status.version) + self.assertEqual(importlib.metadata.version('ironic-python-agent'), + status.version) @mock.patch( 'ironic_python_agent.hardware_managers.cna._detect_cna_card',