From 4fdbdd34fb5fea55571a18b2438ececa953928ff Mon Sep 17 00:00:00 2001 From: Cédric Ollivier Date: Wed, 10 Nov 2021 15:42:57 +0100 Subject: Update linters and fix all new issues MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit It mostly add encoding in open calls and leverage f-strings. Change-Id: Ifead18fc724a452c1067dcf91dc577032edc9c59 Signed-off-by: Cédric Ollivier --- .../tests/unit/openstack/cinder/test_cinder.py | 11 +++++------ functest/tests/unit/openstack/rally/test_rally.py | 22 +++++++++++----------- .../tests/unit/openstack/tempest/test_tempest.py | 4 ++-- functest/tests/unit/openstack/vmtp/test_vmtp.py | 10 ++++++---- .../tests/unit/openstack/vping/test_vping_ssh.py | 8 ++++---- 5 files changed, 28 insertions(+), 27 deletions(-) (limited to 'functest/tests/unit/openstack') diff --git a/functest/tests/unit/openstack/cinder/test_cinder.py b/functest/tests/unit/openstack/cinder/test_cinder.py index 4052408d9..d3c9cabb6 100644 --- a/functest/tests/unit/openstack/cinder/test_cinder.py +++ b/functest/tests/unit/openstack/cinder/test_cinder.py @@ -59,7 +59,7 @@ class CinderTesting(unittest.TestCase): self.cinder.prepare() args[0].assert_called_with() args[1].assert_called_once_with( - '{}-vm2_{}'.format(self.cinder.case_name, self.cinder.guid), + f'{self.cinder.case_name}-vm2_{self.cinder.guid}', security_groups=[self.cinder.sec.id], key_name=self.cinder.keypair.id) self.cinder.cloud.create_volume.assert_not_called() @@ -81,13 +81,12 @@ class CinderTesting(unittest.TestCase): self.cinder.prepare() args[0].assert_called_once_with() args[1].assert_called_once_with( - '{}-vm2_{}'.format(self.cinder.case_name, self.cinder.guid), + f'{self.cinder.case_name}-vm2_{self.cinder.guid}', security_groups=[self.cinder.sec.id], key_name=self.cinder.keypair.id) self.cinder.connect.assert_called_once_with(args[1].return_value) self.cinder.cloud.create_volume.assert_called_once_with( - name='{}-volume_{}'.format( - self.cinder.case_name, self.cinder.guid), + name=f'{self.cinder.case_name}-volume_{self.cinder.guid}', size='2', timeout=self.cinder.volume_timeout, wait=True) @mock.patch('scp.SCPClient.put') @@ -101,7 +100,7 @@ class CinderTesting(unittest.TestCase): self.cinder.ssh.exec_command.return_value = (None, stdout, mock.Mock()) self.assertEqual(self.cinder._write_data(), 0) self.cinder.ssh.exec_command.assert_called_once_with( - "sh ~/write_data.sh {}".format(env.get('VOLUME_DEVICE_NAME'))) + f"sh ~/write_data.sh {env.get('VOLUME_DEVICE_NAME')}") self.cinder.cloud.attach_volume.assert_called_once_with( self.cinder.sshvm, self.cinder.volume, timeout=self.cinder.volume_timeout) @@ -138,7 +137,7 @@ class CinderTesting(unittest.TestCase): stdout.channel.recv_exit_status.return_value = 0 self.assertEqual(self.cinder._read_data(), 0) self.cinder.ssh2.exec_command.assert_called_once_with( - "sh ~/read_data.sh {}".format(env.get('VOLUME_DEVICE_NAME'))) + f"sh ~/read_data.sh {env.get('VOLUME_DEVICE_NAME')}") self.cinder.cloud.attach_volume.assert_called_once_with( self.cinder.vm2, self.cinder.volume, timeout=self.cinder.volume_timeout) diff --git a/functest/tests/unit/openstack/rally/test_rally.py b/functest/tests/unit/openstack/rally/test_rally.py index c281d4f52..f3c2e7cf6 100644 --- a/functest/tests/unit/openstack/rally/test_rally.py +++ b/functest/tests/unit/openstack/rally/test_rally.py @@ -50,7 +50,7 @@ class OSRallyTesting(unittest.TestCase): @staticmethod def check_scenario_file(value): - yaml_file = 'opnfv-{}.yaml'.format('test_file_name') + yaml_file = 'opnfv-test_file_name.yaml' if yaml_file in value: return False return True @@ -64,7 +64,7 @@ class OSRallyTesting(unittest.TestCase): @staticmethod def check_temp_dir(value): - yaml_file = 'opnfv-{}.yaml'.format('test_file_name') + yaml_file = 'opnfv-test_file_name.yaml' if yaml_file in value: return True return False @@ -95,7 +95,7 @@ class OSRallyTesting(unittest.TestCase): self, mock_method, mock_os_makedirs, mock_path_exists): mock_path_exists.side_effect = self.check_temp_dir - yaml_file = 'opnfv-{}.yaml'.format('test_file_name') + yaml_file = 'opnfv-test_file_name.yaml' ret_val = os.path.join(self.rally_base.temp_dir, yaml_file) self.assertEqual(self.rally_base._prepare_test_list('test_file_name'), ret_val) @@ -423,8 +423,8 @@ class OSRallyTesting(unittest.TestCase): @mock.patch('subprocess.check_output', side_effect=subprocess.CalledProcessError('', '')) def test_export_task_ko(self, *args): - file_name = "{}/{}.html".format( - self.rally_base.results_dir, self.rally_base.case_name) + file_name = (f"{self.rally_base.results_dir}/" + f"{self.rally_base.case_name}.html") with self.assertRaises(subprocess.CalledProcessError): self.rally_base.export_task(file_name) cmd = ["rally", "task", "export", "--type", "html", "--deployment", @@ -434,8 +434,8 @@ class OSRallyTesting(unittest.TestCase): @mock.patch('subprocess.check_output', return_value=b'') def test_export_task(self, *args): - file_name = "{}/{}.html".format( - self.rally_base.results_dir, self.rally_base.case_name) + file_name = (f"{self.rally_base.results_dir}/" + f"{self.rally_base.case_name}.html") self.assertEqual(self.rally_base.export_task(file_name), None) cmd = ["rally", "task", "export", "--type", "html", "--deployment", str(getattr(config.CONF, 'rally_deployment_name')), @@ -445,8 +445,8 @@ class OSRallyTesting(unittest.TestCase): @mock.patch('subprocess.check_output', side_effect=subprocess.CalledProcessError('', '')) def test_verify_report_ko(self, *args): - file_name = "{}/{}.html".format( - self.rally_base.results_dir, self.rally_base.case_name) + file_name = (f"{self.rally_base.results_dir}/" + f"{self.rally_base.case_name}.html") with self.assertRaises(subprocess.CalledProcessError): self.rally_base.verify_report(file_name, "1") cmd = ["rally", "verify", "report", "--type", "html", "--uuid", "1", @@ -455,8 +455,8 @@ class OSRallyTesting(unittest.TestCase): @mock.patch('subprocess.check_output', return_value=b'') def test_verify_report(self, *args): - file_name = "{}/{}.html".format( - self.rally_base.results_dir, self.rally_base.case_name) + file_name = (f"{self.rally_base.results_dir}/" + f"{self.rally_base.case_name}.html") self.assertEqual(self.rally_base.verify_report(file_name, "1"), None) cmd = ["rally", "verify", "report", "--type", "html", "--uuid", "1", "--to", file_name] diff --git a/functest/tests/unit/openstack/tempest/test_tempest.py b/functest/tests/unit/openstack/tempest/test_tempest.py index e27b52ef4..efc4393c8 100644 --- a/functest/tests/unit/openstack/tempest/test_tempest.py +++ b/functest/tests/unit/openstack/tempest/test_tempest.py @@ -83,8 +83,8 @@ class OSTempestTesting(unittest.TestCase): testr_mode = self.tempestcommon.mode verifier_repo_dir = 'test_verifier_repo_dir' self.tempestcommon.verifier_repo_dir = verifier_repo_dir - cmd = "(cd {0}; stestr list '{1}' >{2} 2>/dev/null)".format( - verifier_repo_dir, testr_mode, self.tempestcommon.list) + cmd = (f"(cd {verifier_repo_dir}; stestr list '{testr_mode}' > " + f"{self.tempestcommon.list} 2>/dev/null)") self.tempestcommon.generate_test_list(mode=testr_mode) args[0].assert_called_once_with(cmd, shell=True) args[2].assert_called_once_with('/etc/tempest.conf') diff --git a/functest/tests/unit/openstack/vmtp/test_vmtp.py b/functest/tests/unit/openstack/vmtp/test_vmtp.py index c1ad30afd..850273476 100644 --- a/functest/tests/unit/openstack/vmtp/test_vmtp.py +++ b/functest/tests/unit/openstack/vmtp/test_vmtp.py @@ -66,10 +66,12 @@ class VmtpTesting(unittest.TestCase): def test_generate_keys1(self, *args): self.testcase.generate_keys() self.testcase.cloud.create_keypair.assert_called_once_with( - 'vmtp_{}'.format(self.testcase.guid)) + f'vmtp_{self.testcase.guid}') self.testcase.cloud.delete_keypair.assert_called_once_with('id') - calls = [mock.call(self.testcase.privkey_filename, 'w'), - mock.call(self.testcase.pubkey_filename, 'w')] + calls = [mock.call( + self.testcase.privkey_filename, 'w', encoding='utf-8'), + mock.call( + self.testcase.pubkey_filename, 'w', encoding='utf-8')] args[0].assert_has_calls(calls, any_order=True) @mock.patch('six.moves.builtins.open') @@ -79,7 +81,7 @@ class VmtpTesting(unittest.TestCase): side_effect=shade.OpenStackCloudException(None)) as mock_obj, \ self.assertRaises(shade.OpenStackCloudException): self.testcase.generate_keys() - mock_obj.assert_called_once_with('vmtp_{}'.format(self.testcase.guid)) + mock_obj.assert_called_once_with(f'vmtp_{self.testcase.guid}') args[0].assert_not_called() diff --git a/functest/tests/unit/openstack/vping/test_vping_ssh.py b/functest/tests/unit/openstack/vping/test_vping_ssh.py index bc1148da4..a07148aab 100644 --- a/functest/tests/unit/openstack/vping/test_vping_ssh.py +++ b/functest/tests/unit/openstack/vping/test_vping_ssh.py @@ -47,7 +47,7 @@ class VpingSSHTesting(unittest.TestCase): self.vping.prepare() args[0].assert_called_once_with() args[1].assert_called_once_with( - '{}-vm2_{}'.format(self.vping.case_name, self.vping.guid), + f'{self.vping.case_name}-vm2_{self.vping.guid}', security_groups=[self.vping.sec.id]) @mock.patch('functest.opnfv_tests.openstack.vping.vping_ssh.VPingSSH.' @@ -58,7 +58,7 @@ class VpingSSHTesting(unittest.TestCase): self.vping.prepare() args[0].assert_called_once_with() args[1].assert_called_once_with( - '{}-vm2_{}'.format(self.vping.case_name, self.vping.guid), + f'{self.vping.case_name}-vm2_{self.vping.guid}', security_groups=[self.vping.sec.id]) @mock.patch('functest.opnfv_tests.openstack.vping.vping_ssh.VPingSSH.' @@ -70,7 +70,7 @@ class VpingSSHTesting(unittest.TestCase): with self.assertRaises(ssh_exception.SSHException): self.vping.execute() self.vping.ssh.exec_command.assert_called_once_with( - 'ping -c 1 {}'.format(self.vping.vm2.private_v4)) + f'ping -c 1 {self.vping.vm2.private_v4}') args[0].assert_called_once_with('foo') @mock.patch('functest.opnfv_tests.openstack.vping.vping_ssh.VPingSSH.' @@ -94,7 +94,7 @@ class VpingSSHTesting(unittest.TestCase): self.assertEqual(self.vping.execute(), ret) mock_check.assert_called_once_with('foo') self.vping.ssh.exec_command.assert_called_once_with( - 'ping -c 1 {}'.format(self.vping.vm2.private_v4)) + f'ping -c 1 {self.vping.vm2.private_v4}') def test_execute1(self): self._test_execute() -- cgit 1.2.3-korg