diff options
Diffstat (limited to 'functest/tests/unit/openstack')
-rw-r--r-- | functest/tests/unit/openstack/cinder/test_cinder.py | 11 | ||||
-rw-r--r-- | functest/tests/unit/openstack/rally/test_rally.py | 22 | ||||
-rw-r--r-- | functest/tests/unit/openstack/tempest/test_tempest.py | 47 | ||||
-rw-r--r-- | functest/tests/unit/openstack/vmtp/test_vmtp.py | 11 | ||||
-rw-r--r-- | functest/tests/unit/openstack/vping/test_vping_ssh.py | 32 |
5 files changed, 68 insertions, 55 deletions
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 87438ae7c..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') @@ -125,7 +125,8 @@ class OSTempestTesting(unittest.TestCase): return_value=['test1', 'test2']): self.tempestcommon.tempest_blacklist = Exception os.environ['DEPLOY_SCENARIO'] = 'deploy_scenario' - self.tempestcommon.apply_tempest_blacklist() + self.tempestcommon.apply_tempest_blacklist( + self.tempestcommon.tempest_blacklist) obj = mock_open() obj.write.assert_any_call('test1\n') obj.write.assert_any_call('test2\n') @@ -147,7 +148,8 @@ class OSTempestTesting(unittest.TestCase): mock.patch('functest.opnfv_tests.openstack.tempest.tempest.' 'yaml.safe_load', return_value=item_dict): os.environ['DEPLOY_SCENARIO'] = 'deploy_scenario' - self.tempestcommon.apply_tempest_blacklist() + self.tempestcommon.apply_tempest_blacklist( + self.tempestcommon.tempest_blacklist) obj = mock_open() obj.write.assert_any_call('test1\n') self.assertFalse(obj.write.assert_any_call('test2\n')) @@ -156,20 +158,17 @@ class OSTempestTesting(unittest.TestCase): args[2].assert_called_once_with( self.tempestcommon.list, self.tempestcommon.raw_list) + @mock.patch('functest.opnfv_tests.openstack.tempest.tempest.' + 'subprocess.Popen') + @mock.patch('six.moves.builtins.open', mock.mock_open()) @mock.patch('functest.opnfv_tests.openstack.tempest.tempest.LOGGER.info') - def test_run_verifier_tests_default(self, mock_logger_info): - with mock.patch('six.moves.builtins.open', mock.mock_open()), \ - mock.patch('six.moves.builtins.iter', - return_value=[r'\} tempest\.']), \ - mock.patch('functest.opnfv_tests.openstack.tempest.tempest.' - 'subprocess.Popen'): - self.tempestcommon.tempest_list = 'test_tempest_list' - cmd = ["rally", "verify", "start", "--load-list", - self.tempestcommon.tempest_list] - with self.assertRaises(Exception): - self.tempestcommon.run_verifier_tests() - mock_logger_info. \ - assert_any_call("Starting Tempest test suite: '%s'.", cmd) + def test_run_verifier_tests_default(self, *args): + self.tempestcommon.tempest_list = 'test_tempest_list' + cmd = ["rally", "verify", "start", "--load-list", + self.tempestcommon.tempest_list] + with self.assertRaises(Exception): + self.tempestcommon.run_verifier_tests() + args[0].assert_any_call("Starting Tempest test suite: '%s'.", cmd) @mock.patch('functest.opnfv_tests.openstack.tempest.tempest.' 'os.path.exists', return_value=False) @@ -270,10 +269,9 @@ class OSTempestTesting(unittest.TestCase): with mock.patch('functest.opnfv_tests.openstack.tempest.' 'tempest.subprocess.Popen') as mock_popen: - mock_stdout = mock.Mock() - attrs = {'stdout.readline.return_value': b'test_deploy_id'} - mock_stdout.configure_mock(**attrs) - mock_popen.return_value = mock_stdout + attrs = {'return_value.__enter__.return_value.' + 'stdout.readline.return_value': b'test_deploy_id'} + mock_popen.configure_mock(**attrs) self.assertEqual(self.tempestcommon.get_verifier_id(), 'test_deploy_id') @@ -282,10 +280,9 @@ class OSTempestTesting(unittest.TestCase): setattr(config.CONF, 'tempest_verifier_name', 'test_deploy_name') with mock.patch('functest.opnfv_tests.openstack.tempest.' 'tempest.subprocess.Popen') as mock_popen: - mock_stdout = mock.Mock() - attrs = {'stdout.readline.return_value': b'test_deploy_id'} - mock_stdout.configure_mock(**attrs) - mock_popen.return_value = mock_stdout + attrs = {'return_value.__enter__.return_value.' + 'stdout.readline.return_value': b'test_deploy_id'} + mock_popen.configure_mock(**attrs) self.assertEqual(rally.RallyBase.get_verifier_deployment_id(), 'test_deploy_id') diff --git a/functest/tests/unit/openstack/vmtp/test_vmtp.py b/functest/tests/unit/openstack/vmtp/test_vmtp.py index fcbb0c46b..850273476 100644 --- a/functest/tests/unit/openstack/vmtp/test_vmtp.py +++ b/functest/tests/unit/openstack/vmtp/test_vmtp.py @@ -66,21 +66,22 @@ 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') def test_generate_keys2(self, *args): - # pylint: disable=bad-continuation with mock.patch.object( self.testcase.cloud, "create_keypair", 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 05482ed6b..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,27 +58,43 @@ 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]) - def test_execute_exc(self): - self.vping.vm2 = munch.Munch(private_v4='127.0.0.1') + @mock.patch('functest.opnfv_tests.openstack.vping.vping_ssh.VPingSSH.' + 'check_regex_in_console', return_value=True) + def test_execute_exc(self, *args): + self.vping.vm2 = munch.Munch(private_v4='127.0.0.1', name='foo') self.vping.ssh = mock.Mock() self.vping.ssh.exec_command.side_effect = ssh_exception.SSHException 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.' + 'check_regex_in_console', return_value=False) + def test_execute_exc2(self, *args): + self.vping.vm2 = munch.Munch(private_v4='127.0.0.1', name='foo') + self.vping.ssh = mock.Mock() + self.vping.execute() + self.vping.ssh.exec_command.assert_not_called() + args[0].assert_called_once_with('foo') def _test_execute(self, ret=0): - self.vping.vm2 = munch.Munch(private_v4='127.0.0.1') + self.vping.vm2 = munch.Munch(private_v4='127.0.0.1', name='foo') self.vping.ssh = mock.Mock() stdout = mock.Mock() stdout.channel.recv_exit_status.return_value = ret self.vping.ssh.exec_command.return_value = (None, stdout, mock.Mock()) - self.assertEqual(self.vping.execute(), ret) + with mock.patch( + 'functest.opnfv_tests.openstack.vping.vping_ssh.VPingSSH.' + 'check_regex_in_console', return_value=True) as mock_check: + 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() |