aboutsummaryrefslogtreecommitdiffstats
path: root/functest/tests
diff options
context:
space:
mode:
authorCédric Ollivier <cedric.ollivier@orange.com>2021-11-10 15:42:57 +0100
committerCédric Ollivier <cedric.ollivier@orange.com>2021-11-15 09:27:07 +0100
commit4fdbdd34fb5fea55571a18b2438ececa953928ff (patch)
tree44f1d6ff38cedad25b058ba18844e1004b7385db /functest/tests
parente25e576af33547657c278e2dae49b033bf6a1fa1 (diff)
Update linters and fix all new issues
It mostly add encoding in open calls and leverage f-strings. Change-Id: Ifead18fc724a452c1067dcf91dc577032edc9c59 Signed-off-by: Cédric Ollivier <cedric.ollivier@orange.com>
Diffstat (limited to 'functest/tests')
-rw-r--r--functest/tests/unit/odl/test_odl.py49
-rw-r--r--functest/tests/unit/openstack/cinder/test_cinder.py11
-rw-r--r--functest/tests/unit/openstack/rally/test_rally.py22
-rw-r--r--functest/tests/unit/openstack/tempest/test_tempest.py4
-rw-r--r--functest/tests/unit/openstack/vmtp/test_vmtp.py10
-rw-r--r--functest/tests/unit/openstack/vping/test_vping_ssh.py8
-rw-r--r--functest/tests/unit/utils/test_functest_utils.py16
7 files changed, 61 insertions, 59 deletions
diff --git a/functest/tests/unit/odl/test_odl.py b/functest/tests/unit/odl/test_odl.py
index 24ac04591..c675c2988 100644
--- a/functest/tests/unit/odl/test_odl.py
+++ b/functest/tests/unit/odl/test_odl.py
@@ -33,10 +33,10 @@ class ODLTesting(unittest.TestCase):
logging.disable(logging.CRITICAL)
_keystone_ip = "127.0.0.1"
- _neutron_url = u"https://127.0.0.1:9696"
- _neutron_id = u"dummy"
+ _neutron_url = "https://127.0.0.1:9696"
+ _neutron_id = "dummy"
_sdn_controller_ip = "127.0.0.3"
- _os_auth_url = "http://{}:5000/v3".format(_keystone_ip)
+ _os_auth_url = f"http://{_keystone_ip}:5000/v3"
_os_projectname = "admin"
_os_username = "admin"
_os_password = "admin"
@@ -63,8 +63,7 @@ class ODLTesting(unittest.TestCase):
self.test = odl.ODLTests(case_name='odl', project_name='functest')
self.defaultargs = {'odlusername': self._odl_username,
'odlpassword': self._odl_password,
- 'neutronurl': "http://{}:9696".format(
- self._keystone_ip),
+ 'neutronurl': f"http://{self._keystone_ip}:9696",
'osauthurl': self._os_auth_url,
'osusername': self._os_username,
'osuserdomainname': self._os_userdomainname,
@@ -105,7 +104,7 @@ class ODLRobotTesting(ODLTesting):
mock_method.assert_called_once_with(
os.path.join(odl.ODLTests.odl_test_repo,
'csit/variables/Variables.robot'), inplace=True)
- self.assertEqual(args[0].getvalue(), "{}\n".format(msg2))
+ self.assertEqual(args[0].getvalue(), f"{msg2}\n")
def test_set_vars_auth_default(self):
self._test_set_vars(
@@ -160,19 +159,19 @@ class ODLMainTesting(ODLTesting):
args[0].assert_called_once_with(self.test.odl_variables_file)
if len(args) > 1:
variable = [
- 'KEYSTONEURL:{}://{}'.format(
- urllib.parse.urlparse(self._os_auth_url).scheme,
- urllib.parse.urlparse(self._os_auth_url).netloc),
- 'NEUTRONURL:{}'.format(self._neutron_url),
- 'OS_AUTH_URL:"{}"'.format(self._os_auth_url),
- 'OSUSERNAME:"{}"'.format(self._os_username),
- 'OSUSERDOMAINNAME:"{}"'.format(self._os_userdomainname),
- 'OSTENANTNAME:"{}"'.format(self._os_projectname),
- 'OSPROJECTDOMAINNAME:"{}"'.format(self._os_projectdomainname),
- 'OSPASSWORD:"{}"'.format(self._os_password),
- 'ODL_SYSTEM_IP:{}'.format(self._sdn_controller_ip),
- 'PORT:{}'.format(self._odl_webport),
- 'RESTCONFPORT:{}'.format(self._odl_restconfport)]
+ ('KEYSTONEURL:'
+ f'{urllib.parse.urlparse(self._os_auth_url).scheme}://'
+ f'{urllib.parse.urlparse(self._os_auth_url).netloc}'),
+ f'NEUTRONURL:{self._neutron_url}',
+ f'OS_AUTH_URL:"{self._os_auth_url}"',
+ f'OSUSERNAME:"{self._os_username}"',
+ f'OSUSERDOMAINNAME:"{self._os_userdomainname}"',
+ f'OSTENANTNAME:"{self._os_projectname}"',
+ f'OSPROJECTDOMAINNAME:"{self._os_projectdomainname}"',
+ f'OSPASSWORD:"{self._os_password}"',
+ f'ODL_SYSTEM_IP:{self._sdn_controller_ip}',
+ f'PORT:{self._odl_webport}',
+ f'RESTCONFPORT:{self._odl_restconfport}']
args[1].assert_called_once_with(
odl.ODLTests.basic_suite_dir, odl.ODLTests.neutron_suite_dir,
include=[],
@@ -551,8 +550,8 @@ class ODLArgParserTesting(ODLTesting):
self.defaultargs['odlip'] = self._sdn_controller_ip
self.assertEqual(
self.parser.parse_args(
- ["--neutronurl={}".format(self._neutron_url),
- "--odlip={}".format(self._sdn_controller_ip)]),
+ [f"--neutronurl={self._neutron_url}",
+ f"--odlip={self._sdn_controller_ip}"]),
self.defaultargs)
@mock.patch('sys.stderr', new_callable=six.StringIO)
@@ -565,7 +564,7 @@ class ODLArgParserTesting(ODLTesting):
def _test_arg(self, arg, value):
self.defaultargs[arg] = value
self.assertEqual(
- self.parser.parse_args(["--{}={}".format(arg, value)]),
+ self.parser.parse_args([f"--{arg}={value}"]),
self.defaultargs)
def test_odlusername(self):
@@ -606,7 +605,7 @@ class ODLArgParserTesting(ODLTesting):
def test_pushtodb(self):
self.defaultargs['pushtodb'] = True
- self.assertEqual(self.parser.parse_args(["--{}".format('pushtodb')]),
+ self.assertEqual(self.parser.parse_args(["--pushtodb"]),
self.defaultargs)
def test_multiple_args(self):
@@ -614,8 +613,8 @@ class ODLArgParserTesting(ODLTesting):
self.defaultargs['odlip'] = self._sdn_controller_ip
self.assertEqual(
self.parser.parse_args(
- ["--neutronurl={}".format(self._neutron_url),
- "--odlip={}".format(self._sdn_controller_ip)]),
+ [f"--neutronurl={self._neutron_url}",
+ f"--odlip={self._sdn_controller_ip}"]),
self.defaultargs)
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()
diff --git a/functest/tests/unit/utils/test_functest_utils.py b/functest/tests/unit/utils/test_functest_utils.py
index 1fab8f175..07a57a49a 100644
--- a/functest/tests/unit/utils/test_functest_utils.py
+++ b/functest/tests/unit/utils/test_functest_utils.py
@@ -108,9 +108,10 @@ class FunctestUtilsTesting(unittest.TestCase):
self.cmd, info=True, error_msg=self.error_msg, verbose=True,
output_file=self.output_file)
self.assertEqual(resp, 1)
- msg_exec = ("Executing command: '%s'" % self.cmd)
+ msg_exec = f"Executing command: '{self.cmd}'"
mock_logger_info.assert_called_once_with(msg_exec)
- mopen.assert_called_once_with(self.output_file, "w")
+ mopen.assert_called_once_with(
+ self.output_file, "w", encoding='utf-8')
mock_logger_error.assert_called_once_with(self.error_msg)
@mock.patch('functest.utils.functest_utils.LOGGER.info')
@@ -129,9 +130,10 @@ class FunctestUtilsTesting(unittest.TestCase):
self.cmd, info=True, error_msg=self.error_msg, verbose=True,
output_file=self.output_file)
self.assertEqual(resp, 0)
- msg_exec = ("Executing command: '%s'" % self.cmd)
+ msg_exec = (f"Executing command: '{self.cmd}'")
mock_logger_info.assert_called_once_with(msg_exec)
- mopen.assert_called_once_with(self.output_file, "w")
+ mopen.assert_called_once_with(
+ self.output_file, "w", encoding='utf-8')
@mock.patch('sys.stdout')
def test_exec_cmd_args_missing_ok(self, stdout=None):
@@ -175,9 +177,9 @@ class FunctestUtilsTesting(unittest.TestCase):
mock_yaml.return_value = self.file_yaml
functest_utils.get_parameter_from_yaml(self.parameter,
self.test_file)
- self.assertTrue(("The parameter %s is not"
- " defined in config_functest.yaml" %
- self.parameter) in excep.exception)
+ self.assertTrue((f"The parameter {self.parameter} is not"
+ " defined in config_functest.yaml"
+ ) in excep.exception)
def test_get_param_from_yaml_def(self):
with mock.patch('six.moves.builtins.open', mock.mock_open()), \