Browse Source

Remove usage of six.PY2

Neutron is python 3 only so these can be removed.

Another step in removing all of six usage from neutron.

Change-Id: Ica0913e689bb5b472053661b30f951477d3ec960
changes/85/730385/1
Brian Haley 1 year ago
parent
commit
a2a2301675
  1. 10
      neutron/__init__.py
  2. 11
      neutron/common/coordination.py
  3. 16
      neutron/tests/unit/agent/linux/test_utils.py

10
neutron/__init__.py

@ -13,19 +13,15 @@
# License for the specific language governing permissions and limitations
# under the License.
import builtins
import gettext
from debtcollector import removals
import six
if six.PY2:
# pylint: disable=unexpected-keyword-arg
gettext.install('neutron', unicode=1)
else:
gettext.install('neutron')
gettext.install('neutron')
six.moves.builtins.__dict__['_'] = removals.remove(
builtins.__dict__['_'] = removals.remove(
message='Builtin _ translation function is deprecated in OpenStack; '
'use the function from _i18n module for your project.')(_) # noqa

11
neutron/common/coordination.py

@ -19,7 +19,6 @@ import decorator
from oslo_concurrency import lockutils
from oslo_log import log
from oslo_utils import timeutils
import six
LOG = log.getLogger(__name__)
@ -61,13 +60,9 @@ def synchronized(lock_name):
@decorator.decorator
def _synchronized(f, *a, **k):
if six.PY2:
# pylint: disable=deprecated-method
call_args = inspect.getcallargs(f, *a, **k)
else:
sig = inspect.signature(f).bind(*a, **k)
sig.apply_defaults()
call_args = sig.arguments
sig = inspect.signature(f).bind(*a, **k)
sig.apply_defaults()
call_args = sig.arguments
call_args['f_name'] = f.__name__
lock_format_name = lock_name.format(**call_args)
t1 = timeutils.now()

16
neutron/tests/unit/agent/linux/test_utils.py

@ -17,7 +17,6 @@ import signal
import socket
from unittest import mock
import six
import testtools
from neutron_lib import exceptions
@ -154,16 +153,11 @@ class AgentUtilsExecuteTest(base.BaseTestCase):
def test_encode_process_input(self):
str_idata = "%s\n" % self.test_file[:-1]
str_odata = "%s\n" % self.test_file
if six.PY3:
bytes_idata = str_idata.encode(encoding='utf-8')
bytes_odata = str_odata.encode(encoding='utf-8')
self.mock_popen.return_value = [bytes_odata, b'']
result = utils.execute(['cat'], process_input=str_idata)
self.mock_popen.assert_called_once_with(bytes_idata)
else:
self.mock_popen.return_value = [str_odata, '']
result = utils.execute(['cat'], process_input=str_idata)
self.mock_popen.assert_called_once_with(str_idata)
bytes_idata = str_idata.encode(encoding='utf-8')
bytes_odata = str_odata.encode(encoding='utf-8')
self.mock_popen.return_value = [bytes_odata, b'']
result = utils.execute(['cat'], process_input=str_idata)
self.mock_popen.assert_called_once_with(bytes_idata)
self.assertEqual(str_odata, result)
def test_return_str_data(self):

Loading…
Cancel
Save