Move from platform.linux_distribution to distro.id
The builtin platform.linux_distribution[1] is deprecated and will be removed in 3.8 and the recommended replacement is distro. This also raises a "deprecated method" error in pylint. This patch moves us over to the future by following the recommendation in the python docs and switching to use the "distro" module. [1] https://docs.python.org/2/library/platform.html \ #platform.linux_distribution Depends-On: https://review.openstack.org/578983 Change-Id: I29e2673572eab75b553da6b01143b007701808fd
This commit is contained in:
parent
0322cbc5c3
commit
14cb07f2d9
.pylintrclower-constraints.txtrequirements.txt
octavia
amphorae/backends/agent/api_server
tests
functional/amphorae/backend/agent/api_server
unit/amphorae/backends/agent/api_server
@ -54,8 +54,7 @@ disable=
|
|||||||
too-many-statements,
|
too-many-statements,
|
||||||
multiple-statements,
|
multiple-statements,
|
||||||
duplicate-except,
|
duplicate-except,
|
||||||
keyword-arg-before-vararg,
|
keyword-arg-before-vararg
|
||||||
deprecated-method
|
|
||||||
|
|
||||||
[BASIC]
|
[BASIC]
|
||||||
# Variable names can be 1 to 31 characters long, with lowercase and underscores
|
# Variable names can be 1 to 31 characters long, with lowercase and underscores
|
||||||
|
@ -25,6 +25,7 @@ debtcollector==1.19.0
|
|||||||
decorator==4.2.1
|
decorator==4.2.1
|
||||||
deprecation==2.0
|
deprecation==2.0
|
||||||
diskimage-builder==1.1.2
|
diskimage-builder==1.1.2
|
||||||
|
distro===1.2.0
|
||||||
doc8==0.6.0
|
doc8==0.6.0
|
||||||
docutils==0.14
|
docutils==0.14
|
||||||
dogpile.cache==0.6.5
|
dogpile.cache==0.6.5
|
||||||
|
@ -14,11 +14,11 @@
|
|||||||
|
|
||||||
import ipaddress
|
import ipaddress
|
||||||
import os
|
import os
|
||||||
import platform
|
|
||||||
import shutil
|
import shutil
|
||||||
import stat
|
import stat
|
||||||
import subprocess
|
import subprocess
|
||||||
|
|
||||||
|
import distro
|
||||||
import jinja2
|
import jinja2
|
||||||
from oslo_config import cfg
|
from oslo_config import cfg
|
||||||
from oslo_log import log as logging
|
from oslo_log import log as logging
|
||||||
@ -45,7 +45,7 @@ class BaseOS(object):
|
|||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def get_os_util(cls):
|
def get_os_util(cls):
|
||||||
os_name = platform.linux_distribution(full_distribution_name=False)[0]
|
os_name = distro.id()
|
||||||
for subclass in BaseOS.__subclasses__():
|
for subclass in BaseOS.__subclasses__():
|
||||||
if subclass.is_os_name(os_name):
|
if subclass.is_os_name(os_name):
|
||||||
return subclass(os_name)
|
return subclass(os_name)
|
||||||
@ -219,7 +219,7 @@ class Ubuntu(BaseOS):
|
|||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def is_os_name(cls, os_name):
|
def is_os_name(cls, os_name):
|
||||||
return os_name in ['Ubuntu']
|
return os_name in ['ubuntu']
|
||||||
|
|
||||||
def cmd_get_version_of_installed_package(self, package_name):
|
def cmd_get_version_of_installed_package(self, package_name):
|
||||||
return "dpkg --status {name}".format(name=package_name)
|
return "dpkg --status {name}".format(name=package_name)
|
||||||
@ -303,7 +303,7 @@ class RH(BaseOS):
|
|||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def is_os_name(cls, os_name):
|
def is_os_name(cls, os_name):
|
||||||
return os_name in ['fedora', 'redhat', 'centos']
|
return os_name in ['fedora', 'rhel', 'centos']
|
||||||
|
|
||||||
def cmd_get_version_of_installed_package(self, package_name):
|
def cmd_get_version_of_installed_package(self, package_name):
|
||||||
return "rpm -qi {name}".format(name=package_name)
|
return "rpm -qi {name}".format(name=package_name)
|
||||||
|
@ -45,13 +45,13 @@ class TestServerTestCase(base.TestCase):
|
|||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
super(TestServerTestCase, self).setUp()
|
super(TestServerTestCase, self).setUp()
|
||||||
with mock.patch('platform.linux_distribution',
|
with mock.patch('distro.id',
|
||||||
return_value=['Ubuntu', 'Foo', 'Bar']):
|
return_value='ubuntu'):
|
||||||
self.ubuntu_test_server = server.Server()
|
self.ubuntu_test_server = server.Server()
|
||||||
self.ubuntu_app = self.ubuntu_test_server.app.test_client()
|
self.ubuntu_app = self.ubuntu_test_server.app.test_client()
|
||||||
|
|
||||||
with mock.patch('platform.linux_distribution',
|
with mock.patch('distro.id',
|
||||||
return_value=['centos', 'Foo', 'Bar']):
|
return_value='centos'):
|
||||||
self.centos_test_server = server.Server()
|
self.centos_test_server = server.Server()
|
||||||
self.centos_app = self.centos_test_server.app.test_client()
|
self.centos_app = self.centos_test_server.app.test_client()
|
||||||
|
|
||||||
|
@ -34,8 +34,8 @@ class ListenerTestCase(base.TestCase):
|
|||||||
self.jinja_cfg = jinja_cfg.JinjaTemplater(
|
self.jinja_cfg = jinja_cfg.JinjaTemplater(
|
||||||
base_amp_path=BASE_AMP_PATH,
|
base_amp_path=BASE_AMP_PATH,
|
||||||
base_crt_dir=BASE_CRT_PATH)
|
base_crt_dir=BASE_CRT_PATH)
|
||||||
self.mock_platform = mock.patch("platform.linux_distribution").start()
|
self.mock_platform = mock.patch("distro.id").start()
|
||||||
self.mock_platform.return_value = ("Ubuntu",)
|
self.mock_platform.return_value = "ubuntu"
|
||||||
self.test_listener = listener.Listener()
|
self.test_listener = listener.Listener()
|
||||||
|
|
||||||
def test_parse_haproxy_config(self):
|
def test_parse_haproxy_config(self):
|
||||||
|
@ -32,33 +32,33 @@ class TestOSUtils(base.TestCase):
|
|||||||
|
|
||||||
self.base_os_util = osutils.BaseOS('unknown')
|
self.base_os_util = osutils.BaseOS('unknown')
|
||||||
|
|
||||||
with mock.patch('platform.linux_distribution',
|
with mock.patch('distro.id',
|
||||||
return_value=['Ubuntu', 'Foo', 'Bar']):
|
return_value='ubuntu'):
|
||||||
self.ubuntu_os_util = osutils.BaseOS.get_os_util()
|
self.ubuntu_os_util = osutils.BaseOS.get_os_util()
|
||||||
|
|
||||||
with mock.patch('platform.linux_distribution',
|
with mock.patch('distro.id',
|
||||||
return_value=['centos', 'Foo', 'Bar']):
|
return_value='centos'):
|
||||||
self.rh_os_util = osutils.BaseOS.get_os_util()
|
self.rh_os_util = osutils.BaseOS.get_os_util()
|
||||||
|
|
||||||
def test_get_os_util(self):
|
def test_get_os_util(self):
|
||||||
with mock.patch('platform.linux_distribution',
|
with mock.patch('distro.id',
|
||||||
return_value=['Ubuntu', 'Foo', 'Bar']):
|
return_value='ubuntu'):
|
||||||
returned_cls = osutils.BaseOS.get_os_util()
|
returned_cls = osutils.BaseOS.get_os_util()
|
||||||
self.assertIsInstance(returned_cls, osutils.Ubuntu)
|
self.assertIsInstance(returned_cls, osutils.Ubuntu)
|
||||||
with mock.patch('platform.linux_distribution',
|
with mock.patch('distro.id',
|
||||||
return_value=['fedora', 'Foo', 'Bar']):
|
return_value='fedora'):
|
||||||
returned_cls = osutils.BaseOS.get_os_util()
|
returned_cls = osutils.BaseOS.get_os_util()
|
||||||
self.assertIsInstance(returned_cls, osutils.RH)
|
self.assertIsInstance(returned_cls, osutils.RH)
|
||||||
with mock.patch('platform.linux_distribution',
|
with mock.patch('distro.id',
|
||||||
return_value=['redhat', 'Foo', 'Bar']):
|
return_value='rhel'):
|
||||||
returned_cls = osutils.BaseOS.get_os_util()
|
returned_cls = osutils.BaseOS.get_os_util()
|
||||||
self.assertIsInstance(returned_cls, osutils.RH)
|
self.assertIsInstance(returned_cls, osutils.RH)
|
||||||
with mock.patch('platform.linux_distribution',
|
with mock.patch('distro.id',
|
||||||
return_value=['centos', 'Foo', 'Bar']):
|
return_value='centos'):
|
||||||
returned_cls = osutils.BaseOS.get_os_util()
|
returned_cls = osutils.BaseOS.get_os_util()
|
||||||
self.assertIsInstance(returned_cls, osutils.RH)
|
self.assertIsInstance(returned_cls, osutils.RH)
|
||||||
with mock.patch('platform.linux_distribution',
|
with mock.patch('distro.id',
|
||||||
return_value=['FakeOS', 'Foo', 'Bar']):
|
return_value='FakeOS'):
|
||||||
self.assertRaises(
|
self.assertRaises(
|
||||||
octavia_exceptions.InvalidAmphoraOperatingSystem,
|
octavia_exceptions.InvalidAmphoraOperatingSystem,
|
||||||
osutils.BaseOS.get_os_util)
|
osutils.BaseOS.get_os_util)
|
||||||
|
@ -37,8 +37,8 @@ class TestPlug(base.TestCase):
|
|||||||
def setUp(self):
|
def setUp(self):
|
||||||
super(TestPlug, self).setUp()
|
super(TestPlug, self).setUp()
|
||||||
self.mock_netifaces = mock.patch.object(plug, "netifaces").start()
|
self.mock_netifaces = mock.patch.object(plug, "netifaces").start()
|
||||||
self.mock_platform = mock.patch("platform.linux_distribution").start()
|
self.mock_platform = mock.patch("distro.id").start()
|
||||||
self.mock_platform.return_value = ("Ubuntu",)
|
self.mock_platform.return_value = "ubuntu"
|
||||||
self.osutil = osutils.BaseOS.get_os_util()
|
self.osutil = osutils.BaseOS.get_os_util()
|
||||||
self.test_plug = plug.Plug(self.osutil)
|
self.test_plug = plug.Plug(self.osutil)
|
||||||
self.addCleanup(self.mock_netifaces.stop)
|
self.addCleanup(self.mock_netifaces.stop)
|
||||||
@ -57,8 +57,7 @@ class TestPlug(base.TestCase):
|
|||||||
self.assertEqual(FAKE_INTERFACE, interface)
|
self.assertEqual(FAKE_INTERFACE, interface)
|
||||||
|
|
||||||
def test__interface_by_mac_case_insensitive_rh(self):
|
def test__interface_by_mac_case_insensitive_rh(self):
|
||||||
with mock.patch('platform.linux_distribution',
|
with mock.patch('distro.id', return_value='centos'):
|
||||||
return_value=['centos', 'Foo']):
|
|
||||||
osutil = osutils.BaseOS.get_os_util()
|
osutil = osutils.BaseOS.get_os_util()
|
||||||
self.test_plug = plug.Plug(osutil)
|
self.test_plug = plug.Plug(osutil)
|
||||||
interface = self.test_plug._interface_by_mac(
|
interface = self.test_plug._interface_by_mac(
|
||||||
@ -160,8 +159,8 @@ class TestPlug(base.TestCase):
|
|||||||
class TestPlugNetwork(base.TestCase):
|
class TestPlugNetwork(base.TestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
super(TestPlugNetwork, self).setUp()
|
super(TestPlugNetwork, self).setUp()
|
||||||
self.mock_platform = mock.patch("platform.linux_distribution").start()
|
self.mock_platform = mock.patch("distro.id").start()
|
||||||
self.mock_platform.return_value = ("Ubuntu",)
|
self.mock_platform.return_value = "ubuntu"
|
||||||
self.osutil = osutils.BaseOS.get_os_util()
|
self.osutil = osutils.BaseOS.get_os_util()
|
||||||
self.test_plug = plug.Plug(self.osutil)
|
self.test_plug = plug.Plug(self.osutil)
|
||||||
|
|
||||||
|
@ -40,6 +40,7 @@ diskimage-builder!=1.6.0,!=1.7.0,!=1.7.1,>=1.1.2 # Apache-2.0
|
|||||||
futures>=3.0.0;python_version=='2.7' or python_version=='2.6' # BSD
|
futures>=3.0.0;python_version=='2.7' or python_version=='2.6' # BSD
|
||||||
castellan>=0.16.0 # Apache-2.0
|
castellan>=0.16.0 # Apache-2.0
|
||||||
tenacity>=4.9.0 # Apache-2.0
|
tenacity>=4.9.0 # Apache-2.0
|
||||||
|
distro>=1.2.0 # Apache-2.0
|
||||||
|
|
||||||
#for the amphora api
|
#for the amphora api
|
||||||
Flask!=0.11,>=0.10 # BSD
|
Flask!=0.11,>=0.10 # BSD
|
||||||
|
Loading…
x
Reference in New Issue
Block a user