Browse Source

Drop six

Since we're python3 only, we don't need six anymore.

Change-Id: I82c35f364315129a41dd5cbea64c0c5a50662026
changes/48/810948/3
Alex Schultz 4 months ago
parent
commit
4d511679e8
  1. 1
      requirements.txt
  2. 2
      tripleoclient/constants.py
  3. 8
      tripleoclient/tests/test_export.py
  4. 4
      tripleoclient/tests/test_heat_launcher.py
  5. 24
      tripleoclient/tests/test_utils.py
  6. 10
      tripleoclient/tests/v1/overcloud_deploy/test_overcloud_deploy.py
  7. 4
      tripleoclient/tests/v1/overcloud_external_update/test_overcloud_external_update.py
  8. 4
      tripleoclient/tests/v1/overcloud_external_upgrade/test_overcloud_external_upgrade.py
  9. 2
      tripleoclient/tests/v1/overcloud_node/test_overcloud_node.py
  10. 6
      tripleoclient/tests/v1/overcloud_update/test_overcloud_update.py
  11. 10
      tripleoclient/tests/v1/overcloud_upgrade/test_overcloud_upgrade.py
  12. 8
      tripleoclient/tests/v1/test_container_image.py
  13. 8
      tripleoclient/tests/v1/test_overcloud_export.py
  14. 2
      tripleoclient/tests/v1/test_overcloud_export_ceph.py
  15. 2
      tripleoclient/tests/v1/test_overcloud_parameters.py
  16. 16
      tripleoclient/tests/v1/tripleo/test_tripleo_deploy.py
  17. 6
      tripleoclient/tests/v1/undercloud/test_install_upgrade.py
  18. 4
      tripleoclient/tests/v2/container_image/test_tripleo_container_image.py
  19. 4
      tripleoclient/tests/workflows/test_parameters.py
  20. 29
      tripleoclient/utils.py
  21. 6
      tripleoclient/v1/container_image.py
  22. 4
      tripleoclient/v1/overcloud_deploy.py
  23. 11
      tripleoclient/v1/overcloud_netenv_validate.py
  24. 8
      tripleoclient/v1/overcloud_node.py
  25. 7
      tripleoclient/v1/tripleo_deploy.py
  26. 4
      tripleoclient/v2/tripleo_container_image.py

1
requirements.txt

@ -10,7 +10,6 @@ python-heatclient>=1.10.0 # Apache-2.0
python-ironicclient!=2.5.2,!=2.7.1,!=3.0.0,>=2.3.0 # Apache-2.0
python-openstackclient>=5.2.0 # Apache-2.0
simplejson>=3.5.1 # MIT
six>=1.10.0 # MIT
osc-lib>=2.3.0 # Apache-2.0
tripleo-common>=16.0.0 # Apache-2.0
cryptography>=2.1 # BSD/Apache-2.0

2
tripleoclient/constants.py

@ -13,11 +13,11 @@
# under the License.
#
import configparser
import os
import sys
from osc_lib.i18n import _
from six.moves import configparser
from tripleo_common.image import kolla_builder
TRIPLEO_ARCHIVE_DIR = "/var/lib/tripleo/archive"

8
tripleoclient/tests/test_export.py

@ -105,7 +105,7 @@ class TestExport(TestCase):
mock_get_stack.return_value = self.mock_stack
self.mock_open = mock.mock_open(
read_data='{"an_key":"an_value","ovn_dbs_vip":"vip"}')
with mock.patch('six.moves.builtins.open', self.mock_open):
with mock.patch('builtins.open', self.mock_open):
data = export.export_stack(heat, "overcloud", should_filter=True)
expected = \
@ -206,7 +206,7 @@ class TestExport(TestCase):
self.assertEqual(expected_password_export, data)
def test_export_ceph_net_key(self):
with mock.patch('six.moves.builtins.open', self.mock_open_ceph_global):
with mock.patch('builtins.open', self.mock_open_ceph_global):
mon_key = export.export_ceph_net_key('dcn0',
config_download_dir='/foo')
self.assertEqual(mon_key, 'storage_ip')
@ -214,7 +214,7 @@ class TestExport(TestCase):
'/foo/dcn0/global_vars.yaml', 'r')
def test_export_storage_ips(self):
with mock.patch('six.moves.builtins.open', self.mock_open_ceph_inv):
with mock.patch('builtins.open', self.mock_open_ceph_inv):
storage_ips = export.export_storage_ips('dcn0',
config_download_dir='/foo',
ceph_net_key='foo_ip')
@ -237,7 +237,7 @@ class TestExport(TestCase):
'fsid': 'a5a22d37-e01f-4fa0-a440-c72585c7487f',
'dashboard_enabled': False
}
with mock.patch('six.moves.builtins.open', self.mock_open_ceph_all):
with mock.patch('builtins.open', self.mock_open_ceph_all):
data = export.export_ceph('dcn0', 'openstack',
config_download_dir='/foo',
mon_ips=['192.168.24.42'])

4
tripleoclient/tests/test_heat_launcher.py

@ -183,7 +183,7 @@ class TestHeatPodLauncher(base.TestCase):
mock_untar.side_effect = untar
mock_open = mock.mock_open()
with mock.patch('six.moves.builtins.open', mock_open):
with mock.patch('builtins.open', mock_open):
# pylint: disable=bad-str-strip-call
launcher.do_restore_db()
self.assertEqual(mock.call(str(three), launcher.heat_dir),
@ -197,7 +197,7 @@ class TestHeatPodLauncher(base.TestCase):
self.run.reset_mock()
two.touch()
mock_open = mock.mock_open()
with mock.patch('six.moves.builtins.open', mock_open):
with mock.patch('builtins.open', mock_open):
# pylint: disable=bad-str-strip-call
launcher.do_restore_db()
self.assertEqual(mock.call(str(two), launcher.heat_dir),

24
tripleoclient/tests/test_utils.py

@ -44,8 +44,8 @@ from tripleoclient import utils
from tripleoclient.tests import base
from tripleoclient.tests import fakes
from six.moves.configparser import ConfigParser
from six.moves.urllib import error as url_error
from configparser import ConfigParser
from urllib import error as url_error
from ansible_runner import Runner
@ -213,7 +213,7 @@ class TestRunAnsiblePlaybook(TestCase):
)
@mock.patch('os.chmod')
@mock.patch('six.moves.builtins.open')
@mock.patch('builtins.open')
@mock.patch('tripleoclient.utils.makedirs')
@mock.patch('os.path.exists', side_effect=(False, True, True))
def test_run_with_timeout(self, mock_exists, mock_mkdir, mock_open,
@ -235,7 +235,7 @@ class TestRunAnsiblePlaybook(TestCase):
mock_open.mock_calls)
@mock.patch('os.chmod')
@mock.patch('six.moves.builtins.open')
@mock.patch('builtins.open')
@mock.patch('tripleoclient.utils.makedirs')
@mock.patch('os.path.exists', side_effect=(False, True, True))
def test_run_with_extravar_file(self, mock_exists, mock_mkdir, mock_open,
@ -1506,7 +1506,7 @@ class TestStoreCliParam(TestCase):
self.a = 1
dt = datetime.datetime(2017, 11, 22)
with mock.patch("six.moves.builtins.open", mock_file):
with mock.patch("builtins.open", mock_file):
with mock.patch('tripleoclient.utils.datetime') as mock_date:
mock_date.datetime.now.return_value = dt
utils.store_cli_param("overcloud plan list", ArgsFake())
@ -1517,7 +1517,7 @@ class TestStoreCliParam(TestCase):
]
mock_file.assert_has_calls(expected_call, any_order=True)
@mock.patch('six.moves.builtins.open')
@mock.patch('builtins.open')
@mock.patch('os.path.isdir')
@mock.patch('os.path.exists')
def test_fail_to_write_data(self, mock_exists, mock_isdir, mock_open):
@ -1587,7 +1587,7 @@ class ProcessMultipleEnvironments(TestCase):
'parse', autospec=True, return_value=dict())
@mock.patch('yaml.safe_dump', autospec=True)
@mock.patch('yaml.safe_load', autospec=True)
@mock.patch('six.moves.builtins.open')
@mock.patch('builtins.open')
@mock.patch('tempfile.NamedTemporaryFile', autospec=True)
def test_rewrite_env_files(self,
mock_temp, mock_open,
@ -1830,13 +1830,13 @@ class TestDeploymentPythonInterpreter(TestCase):
class TestWaitApiPortReady(TestCase):
@mock.patch('six.moves.urllib.request.urlopen')
@mock.patch('urllib.request.urlopen')
def test_success(self, urlopen_mock):
has_errors = utils.wait_api_port_ready(8080)
self.assertFalse(has_errors)
@mock.patch(
'six.moves.urllib.request.urlopen',
'urllib.request.urlopen',
side_effect=[
url_error.HTTPError("", 201, None, None, None), socket.timeout,
url_error.URLError("")
@ -1849,7 +1849,7 @@ class TestWaitApiPortReady(TestCase):
self.assertEqual(sleep_mock.call_count, 30)
@mock.patch(
'six.moves.urllib.request.urlopen',
'urllib.request.urlopen',
side_effect=[
socket.timeout,
url_error.URLError(""),
@ -1862,7 +1862,7 @@ class TestWaitApiPortReady(TestCase):
self.assertEqual(sleep_mock.call_count, 4)
@mock.patch(
'six.moves.urllib.request.urlopen',
'urllib.request.urlopen',
side_effect=[
socket.timeout,
url_error.URLError(""),
@ -1875,7 +1875,7 @@ class TestWaitApiPortReady(TestCase):
self.assertEqual(urlopen_mock.call_count, 3)
self.assertEqual(sleep_mock.call_count, 3)
@mock.patch('six.moves.urllib.request.urlopen', side_effect=NameError)
@mock.patch('urllib.request.urlopen', side_effect=NameError)
@mock.patch('time.sleep')
def test_dont_retry_at_unknown_exception(self, urlopen_mock, sleep_mock):
with self.assertRaises(NameError):

10
tripleoclient/tests/v1/overcloud_deploy/test_overcloud_deploy.py

@ -14,9 +14,9 @@
#
import fixtures
from io import StringIO
import os
import shutil
import six
import tempfile
import yaml
@ -236,7 +236,7 @@ class TestDeployOvercloud(fakes.TestDeployOvercloud):
def _custom_create_params_env(parameters, tht_root,
stack):
for key, value in six.iteritems(parameters):
for key, value in parameters.items():
self.assertEqual(value, expected_parameters[key])
parameter_defaults = {"parameter_defaults": parameters}
return parameter_defaults
@ -354,7 +354,7 @@ class TestDeployOvercloud(fakes.TestDeployOvercloud):
'CtlplaneNetworkAttributes': {}}}
mock_process_env.return_value = {}, parameters_env
mock_open_context = mock.mock_open()
with mock.patch('six.moves.builtins.open', mock_open_context):
with mock.patch('builtins.open', mock_open_context):
self.cmd.take_action(parsed_args)
self.assertTrue(orchestration_client.stacks.create.called)
@ -1035,7 +1035,7 @@ class TestDeployOvercloud(fakes.TestDeployOvercloud):
def _custom_create_params_env(parameters, tht_root,
stack):
for key, value in six.iteritems(parameters):
for key, value in parameters.items():
self.assertEqual(value, expected_parameters[key])
parameter_defaults = {"parameter_defaults": parameters}
return parameter_defaults
@ -1783,7 +1783,7 @@ class TestGetDeploymentStatus(utils.TestCommand):
@mock.patch("tripleoclient.workflows.deployment.get_deployment_status")
def test_get_deployment_status(self, mock_get_deployment_status):
parsed_args = self.check_parser(self.cmd, [], [])
self.cmd.app.stdout = six.StringIO()
self.cmd.app.stdout = StringIO()
status = 'DEPLOY_SUCCESS'
mock_get_deployment_status.return_value = status

4
tripleoclient/tests/v1/overcloud_external_update/test_overcloud_external_update.py

@ -50,7 +50,7 @@ class TestOvercloudExternalUpdateRun(fakes.TestOvercloudExternalUpdateRun):
autospec=True)
@mock.patch('os.path.expanduser')
@mock.patch('oslo_concurrency.processutils.execute')
@mock.patch('six.moves.builtins.open')
@mock.patch('builtins.open')
def test_update_with_user_and_tags(self, mock_open, mock_execute,
mock_expanduser, update_ansible,
mock_run, mock_run_prepare):
@ -77,7 +77,7 @@ class TestOvercloudExternalUpdateRun(fakes.TestOvercloudExternalUpdateRun):
autospec=True)
@mock.patch('os.path.expanduser')
@mock.patch('oslo_concurrency.processutils.execute')
@mock.patch('six.moves.builtins.open')
@mock.patch('builtins.open')
def test_update_with_user_and_extra_vars(self, mock_open, mock_execute,
mock_expanduser, update_ansible,
mock_run, mock_run_prepare):

4
tripleoclient/tests/v1/overcloud_external_upgrade/test_overcloud_external_upgrade.py

@ -48,7 +48,7 @@ class TestOvercloudExternalUpgradeRun(fakes.TestOvercloudExternalUpgradeRun):
autospec=True)
@mock.patch('os.path.expanduser')
@mock.patch('oslo_concurrency.processutils.execute')
@mock.patch('six.moves.builtins.open')
@mock.patch('builtins.open')
def test_upgrade_with_user_and_tags(self, mock_open, mock_execute,
mock_expanduser, update_ansible,
mock_run, mock_run_prepare):
@ -75,7 +75,7 @@ class TestOvercloudExternalUpgradeRun(fakes.TestOvercloudExternalUpgradeRun):
autospec=True)
@mock.patch('os.path.expanduser')
@mock.patch('oslo_concurrency.processutils.execute')
@mock.patch('six.moves.builtins.open')
@mock.patch('builtins.open')
def test_upgrade_with_user_and_extra_vars(self, mock_open, mock_execute,
mock_expanduser, update_ansible,
mock_run, mock_run_prepare):

2
tripleoclient/tests/v1/overcloud_node/test_overcloud_node.py

@ -542,7 +542,7 @@ class TestImportNodeMultiArch(fakes.TestOvercloudNode):
}
]
mock_open = mock.mock_open(read_data=json.dumps(file_return_nodes))
with mock.patch('six.moves.builtins.open', mock_open):
with mock.patch('builtins.open', mock_open):
self.cmd.take_action(parsed_args)
nodes_list = copy.deepcopy(self.nodes_list)

6
tripleoclient/tests/v1/overcloud_update/test_overcloud_update.py

@ -39,7 +39,7 @@ class TestOvercloudUpdatePrepare(fakes.TestOvercloudUpdatePrepare):
@mock.patch('tripleoclient.utils.ensure_run_as_normal_user')
@mock.patch('tripleoclient.utils.prompt_user_for_confirmation',
return_value=True)
@mock.patch('six.moves.builtins.open')
@mock.patch('builtins.open')
@mock.patch('os.path.abspath')
@mock.patch('yaml.safe_load')
@mock.patch('shutil.copytree', autospec=True)
@ -77,7 +77,7 @@ class TestOvercloudUpdatePrepare(fakes.TestOvercloudUpdatePrepare):
@mock.patch('os.path.abspath')
@mock.patch('yaml.safe_load')
@mock.patch('shutil.copytree', autospec=True)
@mock.patch('six.moves.builtins.open')
@mock.patch('builtins.open')
@mock.patch('tripleoclient.v1.overcloud_deploy.DeployOvercloud.'
'take_action', autospec=True)
def test_update_out(self, mock_deploy, mock_open, mock_copy, mock_yaml,
@ -124,7 +124,7 @@ class TestOvercloudUpdateRun(fakes.TestOvercloudUpdateRun):
autospec=True)
@mock.patch('os.path.expanduser')
@mock.patch('oslo_concurrency.processutils.execute')
@mock.patch('six.moves.builtins.open')
@mock.patch('builtins.open')
def test_update_with_no_limit(
self, mock_open, mock_execute, mock_expanduser, update_ansible,
mock_confirm):

10
tripleoclient/tests/v1/overcloud_upgrade/test_overcloud_upgrade.py

@ -51,7 +51,7 @@ class TestOvercloudUpgradePrepare(fakes.TestOvercloudUpgradePrepare):
@mock.patch('tripleoclient.v1.overcloud_upgrade.UpgradePrepare.log',
autospec=True)
@mock.patch('yaml.safe_load')
@mock.patch('six.moves.builtins.open')
@mock.patch('builtins.open')
def test_upgrade_out(self,
mock_open,
mock_yaml,
@ -106,7 +106,7 @@ class TestOvercloudUpgradePrepare(fakes.TestOvercloudUpgradePrepare):
@mock.patch('tripleoclient.utils.get_stack',
autospec=True)
@mock.patch('tripleoclient.utils.prepend_environment', autospec=True)
@mock.patch('six.moves.builtins.open')
@mock.patch('builtins.open')
@mock.patch('yaml.safe_load')
def test_upgrade_failed(self, mock_yaml, mock_open,
add_env, mock_get_stack, mock_overcloud_deploy,
@ -170,7 +170,7 @@ class TestOvercloudUpgradeRun(fakes.TestOvercloudUpgradeRun):
autospec=True)
@mock.patch('os.path.expanduser')
@mock.patch('oslo_concurrency.processutils.execute')
@mock.patch('six.moves.builtins.open')
@mock.patch('builtins.open')
def test_upgrade_limit_with_playbook_and_user(
self, mock_open, mock_execute, mock_expanduser, upgrade_ansible,
mock_run, mock_run_prepare, mock_confirm):
@ -201,7 +201,7 @@ class TestOvercloudUpgradeRun(fakes.TestOvercloudUpgradeRun):
autospec=True)
@mock.patch('os.path.expanduser')
@mock.patch('oslo_concurrency.processutils.execute')
@mock.patch('six.moves.builtins.open')
@mock.patch('builtins.open')
def test_upgrade_nodes_with_playbook_no_skip_tags(
self, mock_open, mock_execute, mock_expanduser, upgrade_ansible,
mock_run, mock_run_prepare, mock_confirm):
@ -220,7 +220,7 @@ class TestOvercloudUpgradeRun(fakes.TestOvercloudUpgradeRun):
autospec=True)
@mock.patch('os.path.expanduser')
@mock.patch('oslo_concurrency.processutils.execute')
@mock.patch('six.moves.builtins.open')
@mock.patch('builtins.open')
def test_upgrade_with_no_limit(
self, mock_open, mock_execute, mock_expanduser, upgrade_ansible):
mock_expanduser.return_value = '/home/fake/'

8
tripleoclient/tests/v1/test_container_image.py

@ -14,18 +14,18 @@
#
import fixtures
from io import StringIO
import mock
import os
import requests
import shutil
import six
import sys
import tempfile
from urllib import parse
import uuid
import yaml
from osc_lib import exceptions as oscexc
from six.moves.urllib import parse
from tripleo_common.image import kolla_builder
from tripleoclient import constants
from tripleoclient.tests.v1.test_plugin import TestPluginV1
@ -888,7 +888,7 @@ class TestTripleoImagePrepareDefault(TestPluginV1):
self.app.command_options = [
'tripleo', 'container', 'image', 'prepare', 'default'
] + arglist
self.cmd.app.stdout = six.StringIO()
self.cmd.app.stdout = StringIO()
cmd = container_image.TripleOImagePrepareDefault(self.app, None)
parsed_args = self.check_parser(cmd, arglist, verifylist)
@ -958,7 +958,7 @@ class TestContainerImageBuild(TestPluginV1):
# Get the command object to test
self.cmd = container_image.BuildImage(self.app, None)
self.cmd.app.stdout = six.StringIO()
self.cmd.app.stdout = StringIO()
self.uuid = str(uuid.uuid4())
self.temp_dir = os.path.join(self.useFixture(
fixtures.TempDir()).join())

8
tripleoclient/tests/v1/test_overcloud_export.py

@ -46,7 +46,7 @@ class TestOvercloudExport(utils.TestCommand):
mock_exists.return_value = False
mock_export_passwords.return_value = {'key': 'value'}
mock_export_stack.return_value = {'key0': 'value0'}
with mock.patch('six.moves.builtins.open', self.mock_open):
with mock.patch('builtins.open', self.mock_open):
self.cmd.take_action(parsed_args)
mock_export_passwords.assert_called_once_with(
self.app.client_manager.orchestration,
@ -78,7 +78,7 @@ class TestOvercloudExport(utils.TestCommand):
verifylist = [('stack', 'foo')]
parsed_args = self.check_parser(self.cmd, argslist, verifylist)
mock_exists.return_value = False
with mock.patch('six.moves.builtins.open', self.mock_open):
with mock.patch('builtins.open', self.mock_open):
self.cmd.take_action(parsed_args)
mock_export_passwords.assert_called_once_with(
self.app.client_manager.orchestration,
@ -106,7 +106,7 @@ class TestOvercloudExport(utils.TestCommand):
('config_download_dir', '/tmp/bar')]
parsed_args = self.check_parser(self.cmd, argslist, verifylist)
mock_exists.return_value = False
with mock.patch('six.moves.builtins.open', self.mock_open):
with mock.patch('builtins.open', self.mock_open):
self.cmd.take_action(parsed_args)
mock_export_passwords.assert_called_once_with(
self.app.client_manager.orchestration,
@ -132,7 +132,7 @@ class TestOvercloudExport(utils.TestCommand):
('no_password_excludes', True)]
parsed_args = self.check_parser(self.cmd, argslist, verifylist)
mock_exists.return_value = False
with mock.patch('six.moves.builtins.open', self.mock_open):
with mock.patch('builtins.open', self.mock_open):
self.cmd.take_action(parsed_args)
mock_export_passwords.assert_called_once_with(
self.app.client_manager.orchestration,

2
tripleoclient/tests/v1/test_overcloud_export_ceph.py

@ -59,7 +59,7 @@ class TestOvercloudExportCeph(utils.TestCommand):
data['parameter_defaults']['CephExternalMultiConfig'] = [expected]
mock_export_ceph.return_value = expected
with mock.patch('six.moves.builtins.open', self.mock_open):
with mock.patch('builtins.open', self.mock_open):
self.cmd.take_action(parsed_args)
path = os.path.join(os.environ.get('HOME'),
'overcloud-deploy', 'dcn0', 'config-download')

2
tripleoclient/tests/v1/test_overcloud_parameters.py

@ -63,7 +63,7 @@ class TestGenerateFencingParameters(utils.TestCommand):
mock_gen_fence.return_value = '{"result":[]}'
with mock.patch('six.moves.builtins.open', mock_open_context):
with mock.patch('builtins.open', mock_open_context):
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
self.cmd.take_action(parsed_args)

16
tripleoclient/tests/v1/tripleo/test_tripleo_deploy.py

@ -206,7 +206,7 @@ class TestDeployUndercloud(TestPluginV1):
mock_exists.return_value = False
mock_open_context = mock.mock_open()
with mock.patch('six.moves.builtins.open', mock_open_context):
with mock.patch('builtins.open', mock_open_context):
self.cmd._update_passwords_env(self.temp_homedir, 'stack')
mock_open_handle = mock_open_context()
@ -384,7 +384,7 @@ class TestDeployUndercloud(TestPluginV1):
'_setup_heat_environments', autospec=True)
@mock.patch('yaml.safe_dump', autospec=True)
@mock.patch('yaml.safe_load', autospec=True)
@mock.patch('six.moves.builtins.open')
@mock.patch('builtins.open')
@mock.patch('tempfile.NamedTemporaryFile', autospec=True)
@mock.patch('tripleo_common.image.kolla_builder.'
'container_images_prepare_multi')
@ -501,7 +501,7 @@ class TestDeployUndercloud(TestPluginV1):
@mock.patch('yaml.safe_load', return_value={}, autospec=True)
@mock.patch('yaml.safe_dump', autospec=True)
@mock.patch('os.path.isfile', return_value=True)
@mock.patch('six.moves.builtins.open')
@mock.patch('builtins.open')
@mock.patch('tripleoclient.v1.tripleo_deploy.Deploy.'
'_process_hieradata_overrides', autospec=True)
@mock.patch('tripleoclient.v1.tripleo_deploy.Deploy.'
@ -702,7 +702,7 @@ class TestDeployUndercloud(TestPluginV1):
# TODO(cjeanner) drop once we have proper oslo.privsep
@mock.patch('getpass.getuser', return_value='stack')
@mock.patch('os.mkdir')
@mock.patch('six.moves.builtins.open')
@mock.patch('builtins.open')
@mock.patch('tripleoclient.v1.tripleo_deploy.Deploy.'
'_populate_templates_dir')
@mock.patch('tripleoclient.utils.archive_deploy_artifacts',
@ -797,7 +797,7 @@ class TestDeployUndercloud(TestPluginV1):
# TODO(cjeanner) drop once we have proper oslo.privsep
@mock.patch('getpass.getuser', return_value='stack')
@mock.patch('os.mkdir')
@mock.patch('six.moves.builtins.open')
@mock.patch('builtins.open')
@mock.patch('tripleoclient.v1.tripleo_deploy.Deploy.'
'_populate_templates_dir')
@mock.patch('tripleoclient.utils.archive_deploy_artifacts',
@ -882,7 +882,7 @@ class TestDeployUndercloud(TestPluginV1):
# TODO(cjeanner) drop once we have proper oslo.privsep
@mock.patch('getpass.getuser', return_value='stack')
@mock.patch('os.mkdir')
@mock.patch('six.moves.builtins.open')
@mock.patch('builtins.open')
@mock.patch('tripleoclient.v1.tripleo_deploy.Deploy.'
'_populate_templates_dir')
@mock.patch('tripleoclient.utils.archive_deploy_artifacts',
@ -1038,7 +1038,7 @@ class TestDeployUndercloud(TestPluginV1):
@mock.patch('os.chmod')
# TODO(cjeanner) drop once we have proper oslo.privsep
@mock.patch('os.mkdir')
@mock.patch('six.moves.builtins.open')
@mock.patch('builtins.open')
@mock.patch('tripleoclient.v1.tripleo_deploy.Deploy.'
'_populate_templates_dir')
@mock.patch('tripleoclient.utils.archive_deploy_artifacts',
@ -1097,7 +1097,7 @@ class TestDeployUndercloud(TestPluginV1):
@mock.patch('os.chmod')
# TODO(cjeanner) drop once we have proper oslo.privsep
@mock.patch('os.mkdir')
@mock.patch('six.moves.builtins.open')
@mock.patch('builtins.open')
@mock.patch('tripleoclient.v1.tripleo_deploy.Deploy.'
'_populate_templates_dir')
@mock.patch('tripleoclient.utils.archive_deploy_artifacts',

6
tripleoclient/tests/v1/undercloud/test_install_upgrade.py

@ -57,7 +57,7 @@ class TestUndercloudInstall(TestPluginV1):
# TODO(cjeanner) drop once we have proper oslo.privsep
@mock.patch('os.geteuid', return_value=1001)
@mock.patch('getpass.getuser', return_value='stack')
@mock.patch('six.moves.builtins.open')
@mock.patch('builtins.open')
@mock.patch('shutil.copy')
@mock.patch('os.mkdir')
@mock.patch('tripleoclient.utils.write_env_file', autospec=True)
@ -339,7 +339,7 @@ class TestUndercloudInstall(TestPluginV1):
# TODO(cjeanner) drop once we have proper oslo.privsep
@mock.patch('os.geteuid', return_value=1001)
@mock.patch('getpass.getuser', return_value='stack')
@mock.patch('six.moves.builtins.open')
@mock.patch('builtins.open')
@mock.patch('shutil.copy')
@mock.patch('os.mkdir')
@mock.patch('tripleoclient.utils.write_env_file', autospec=True)
@ -402,7 +402,7 @@ class TestUndercloudInstall(TestPluginV1):
# TODO(cjeanner) drop once we have proper oslo.privsep
@mock.patch('os.geteuid', return_value=1001)
@mock.patch('getpass.getuser', return_value='stack')
@mock.patch('six.moves.builtins.open')
@mock.patch('builtins.open')
@mock.patch('shutil.copy')
@mock.patch('os.mkdir')
@mock.patch('tripleoclient.utils.write_env_file', autospec=True)

4
tripleoclient/tests/v2/container_image/test_tripleo_container_image.py

@ -77,7 +77,7 @@ class TestContainerImages(deploy_fakes.TestDeployOvercloud):
mock_isfile.return_value = True
with mock.patch("os.path.isdir", autospec=True) as mock_isdir:
mock_isdir.return_value = True
with mock.patch('six.moves.builtins.open', mock_open):
with mock.patch('builtins.open', mock_open):
with mock.patch(
"tripleoclient.v2.tripleo_container_image.Build"
".find_image",
@ -88,7 +88,7 @@ class TestContainerImages(deploy_fakes.TestDeployOvercloud):
def test_find_image(self):
mock_open = mock.mock_open(read_data='---\ntcib_option: "data"')
with mock.patch('six.moves.builtins.open', mock_open):
with mock.patch('builtins.open', mock_open):
image = self.cmd.find_image("keystone", "some/path", "base-image")
self.assertEqual(image, {"tcib_option": "data"})

4
tripleoclient/tests/workflows/test_parameters.py

@ -37,7 +37,7 @@ class TestParameterWorkflows(utils.TestCommand):
self.app.client_manager.baremetal = mock.Mock()
@mock.patch('yaml.safe_load')
@mock.patch("six.moves.builtins.open")
@mock.patch("builtins.open")
@mock.patch('tripleoclient.utils.run_ansible_playbook', autospec=True)
@mock.patch('tripleoclient.utils.get_tripleo_ansible_inventory',
autospec=True)
@ -81,7 +81,7 @@ class TestParameterWorkflows(utils.TestCommand):
mock_playbook.assert_has_calls(calls, any_order=True)
@mock.patch('yaml.safe_load')
@mock.patch("six.moves.builtins.open")
@mock.patch("builtins.open")
@mock.patch('tripleoclient.utils.run_ansible_playbook', autospec=True)
@mock.patch('tripleoclient.utils.get_tripleo_ansible_inventory',
autospec=True)

29
tripleoclient/utils.py

@ -20,6 +20,7 @@ try:
except AttributeError:
collectionsAbc = collections
import configparser
import csv
import datetime
import errno
@ -38,7 +39,6 @@ import pwd
import re
import shutil
import simplejson
import six
import socket
import subprocess
import sys
@ -56,12 +56,11 @@ from heatclient.exc import HTTPNotFound
from osc_lib import exceptions as oscexc
from osc_lib.i18n import _
from oslo_concurrency import processutils
from six.moves import configparser
from heatclient import exc as hc_exc
from six.moves.urllib import error as url_error
from six.moves.urllib import parse as url_parse
from six.moves.urllib import request
from urllib import error as url_error
from urllib import parse as url_parse
from urllib import request
from tenacity import retry
from tenacity.stop import stop_after_attempt, stop_after_delay
@ -181,7 +180,7 @@ def _encode_envvars(env):
:type env: `dict`.
"""
for key, value in env.items():
env[key] = six.text_type(value)
env[key] = str(value)
else:
return env
@ -358,7 +357,7 @@ def run_ansible_playbook(playbook, inventory, workdir, playbook_dir=None,
def _inventory(inventory):
if inventory:
if isinstance(inventory, six.string_types):
if isinstance(inventory, str):
# check is file path
if os.path.exists(inventory):
return inventory
@ -733,10 +732,10 @@ def run_ansible_playbook(playbook, inventory, workdir, playbook_dir=None,
def convert(data):
"""Recursively converts dictionary keys,values to strings."""
if isinstance(data, six.string_types):
if isinstance(data, str):
return str(data)
if isinstance(data, collectionsAbc.Mapping):
return dict(map(convert, six.iteritems(data)))
return dict(map(convert, data.items()))
if isinstance(data, collectionsAbc.Iterable):
return type(data)(map(convert, data))
return data
@ -1223,7 +1222,7 @@ def check_stack_network_matches_env_files(stack, environment):
"""
def _get_networks(registry):
nets = set()
for k, v in six.iteritems(registry):
for k, v in registry.items():
if (k.startswith('OS::TripleO::Network::')
and not k.startswith('OS::TripleO::Network::Port')
and v != 'OS::Heat::None'):
@ -1609,7 +1608,7 @@ def replace_links_in_template(template_part, link_replacement):
def replaced_dict_value(key, value):
if ((key == 'get_file' or key == 'type') and
isinstance(value, six.string_types)):
isinstance(value, str)):
return link_replacement.get(value, value)
return replace_links_in_template(value, link_replacement)
@ -1618,7 +1617,7 @@ def replace_links_in_template(template_part, link_replacement):
if isinstance(template_part, dict):
return {k: replaced_dict_value(k, v)
for k, v in six.iteritems(template_part)}
for k, v in template_part.items()}
if isinstance(template_part, list):
return list(map(replaced_list_value, template_part))
return template_part
@ -1633,7 +1632,7 @@ def relative_link_replacement(link_replacement, current_dir):
"""
return {k: os.path.relpath(v, current_dir)
for k, v in six.iteritems(link_replacement)}
for k, v in link_replacement.items()}
def load_environment_directories(directories):
@ -1953,14 +1952,14 @@ def process_multiple_environments(created_env_files, tht_root,
# See bug https://bugs.launchpad.net/tripleo/+bug/1625783
# for details on why this is needed (backwards-compatibility)
log.debug("Error %s processing environment file %s"
% (six.text_type(ex), env_path))
% (str(ex), env_path))
# Use the temporary path as it's possible the environment
# itself was rendered via jinja.
with open(env_path, 'r') as f:
env_map = yaml.safe_load(f)
env_registry = env_map.get('resource_registry', {})
env_dirname = os.path.dirname(os.path.abspath(env_path))
for rsrc, rsrc_path in six.iteritems(env_registry):
for rsrc, rsrc_path in env_registry.items():
# We need to calculate the absolute path relative to
# env_path not cwd (which is what abspath uses).
abs_rsrc_path = os.path.normpath(

6
tripleoclient/v1/container_image.py

@ -16,6 +16,7 @@
import copy
import datetime
import errno
from io import StringIO
import json
import logging
import os
@ -27,8 +28,7 @@ import uuid
from osc_lib import exceptions as oscexc
from osc_lib.i18n import _
import six
from six.moves.urllib import parse
from urllib import parse
import yaml
from tripleo_common.image.builder import buildah
@ -45,7 +45,7 @@ from tripleoclient import utils
def build_env_file(params, command_options):
f = six.StringIO()
f = StringIO()
f.write('# Generated with the following on %s\n#\n' %
datetime.datetime.now().isoformat())
f.write('# openstack %s\n#\n\n' %

4
tripleoclient/v1/overcloud_deploy.py

@ -22,8 +22,8 @@ from oslo_utils import excutils
from prettytable import PrettyTable
from pwd import getpwuid
import shutil
import six
import time
import urllib
import yaml
from heatclient.common import template_utils
@ -443,7 +443,7 @@ class DeployOvercloud(command.Command):
# an FQDN depending on how what it's configured to output in the
# tripleo-heat-templates. Such a configuration can be done by
# overriding the EndpointMap through parameter_defaults.
overcloud_ip_or_fqdn = six.moves.urllib.parse.urlparse(
overcloud_ip_or_fqdn = urllib.parse.urlparse(
overcloud_endpoint).hostname
keystone_admin_ip = utils.get_endpoint('KeystoneAdmin', stack)

11
tripleoclient/v1/overcloud_netenv_validate.py

@ -19,7 +19,6 @@ import os
import ipaddress
from osc_lib.i18n import _
import six
import yaml
from tripleoclient import command
@ -87,7 +86,7 @@ class ValidateOvercloudNetenv(command.Command):
objs = []
for x in networks:
try:
objs += [ipaddress.ip_network(six.u(x))]
objs += [ipaddress.ip_network(str(x))]
except ValueError:
self.log.error('Invalid address: %s', x)
self.error_count += 1
@ -108,13 +107,13 @@ class ValidateOvercloudNetenv(command.Command):
for pool in pooldata:
try:
ip_start = ipaddress.ip_address(
six.u(pool['start']))
str(pool['start']))
except ValueError:
self.log.error('Invalid address: %s' % ip_start)
self.error_count += 1
ip_start = None
try:
ip_end = ipaddress.ip_address(six.u(pool['end']))
ip_end = ipaddress.ip_address(str(pool['end']))
except ValueError:
self.log.error('Invalid address: %s' % ip_start)
self.error_count += 1
@ -138,7 +137,7 @@ class ValidateOvercloudNetenv(command.Command):
subnet_item = poolitem.split('AllocationPools')[0] + 'NetCidr'
try:
subnet_obj = ipaddress.ip_network(
six.u(filedata[subnet_item]))
str(filedata[subnet_item]))
except ValueError:
self.log.error('Invalid address: %s', subnet_item)
self.error_count += 1
@ -156,7 +155,7 @@ class ValidateOvercloudNetenv(command.Command):
def check_vlan_ids(self, vlans):
invertdict = {}
for k, v in six.iteritems(vlans):
for k, v in vlans.items():
self.log.info('Checking Vlan ID {}'.format(k))
if v not in invertdict:
invertdict[v] = k

8
tripleoclient/v1/overcloud_node.py

@ -15,6 +15,7 @@
import collections
import datetime
from io import StringIO
import ipaddress
import json
import logging
@ -26,7 +27,6 @@ from openstack import exceptions as openstack_exc
from osc_lib import exceptions as oscexc
from osc_lib.i18n import _
from osc_lib import utils
import six
import yaml
from tripleoclient import command
@ -112,7 +112,7 @@ class DeleteNode(command.Command):
node_hostnames = [i['hostname'] for i in nodes if 'hostname' in i]
formatter = table.TableFormatter()
output = six.StringIO()
output = StringIO()
formatter.emit_list(
column_names=['hostname', 'name', 'id'],
data=nodes_data,
@ -626,7 +626,7 @@ class ExtractProvisionedNode(command.Command):
data.append(role)
# Write the file header
file_data = six.StringIO()
file_data = StringIO()
file_data.write('# Generated with the following on %s\n#\n' %
datetime.datetime.now().isoformat())
file_data.write('# openstack %s\n#\n\n' %
@ -639,7 +639,7 @@ class ExtractProvisionedNode(command.Command):
if parsed_args.output:
if (os.path.exists(parsed_args.output)
and not parsed_args.yes and sys.stdin.isatty()):
prompt_response = six.moves.input(
prompt_response = input(
('Overwrite existing file %s [y/N]?' % parsed_args.output)
).lower()
if not prompt_response.startswith('y'):

7
tripleoclient/v1/tripleo_deploy.py

@ -14,13 +14,13 @@
#
import argparse
import configparser
import json
import logging
import netaddr
import os
import pwd
import shutil
import six
import subprocess
import sys
import tempfile
@ -31,7 +31,6 @@ import yaml
from cliff import command
from heatclient.common import template_utils
from osc_lib.i18n import _
from six.moves import configparser
from tripleoclient import constants
from tripleoclient import exceptions
@ -1419,9 +1418,9 @@ class Deploy(command.Command):
try:
self._standalone_deploy(parsed_args)
except Exception as ex:
self.log.error("Exception: %s" % six.text_type(ex))
self.log.error("Exception: %s" % str(ex))
self.log.error(traceback.print_exc())
raise exceptions.DeploymentError(six.text_type(ex))
raise exceptions.DeploymentError(str(ex))
finally:
# Copy clouds.yaml from /etc/openstack so credentials can be
# read by the deployment user and not only root.

4
tripleoclient/v2/tripleo_container_image.py

@ -19,8 +19,6 @@ import re
import uuid
import yaml
import six
from osc_lib.i18n import _
from oslo_config import cfg
@ -377,7 +375,7 @@ class Build(command.Command):
self.image_paths[key] = os.path.join(work_dir, key)
utils.makedirs(dir_path=self.image_paths[key])
self.make_dir_tree(tree=value, work_dir=self.image_paths[key])
elif isinstance(tree, six.string_types):
elif isinstance(tree, str):
self.image_paths[tree] = os.path.join(work_dir, tree)
utils.makedirs(dir_path=self.image_paths[tree])

Loading…
Cancel
Save