Skip to content

Commit

Permalink
Merge "Port test_nfs to Python 3"
Browse files Browse the repository at this point in the history
  • Loading branch information
Jenkins authored and openstack-gerrit committed Aug 27, 2015
2 parents 9991226 + 125fec9 commit 3b40049
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 17 deletions.
30 changes: 13 additions & 17 deletions cinder/tests/unit/test_nfs.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

import errno
import os
import testtools

import mock
from mox3 import mox as mox_lib
Expand Down Expand Up @@ -1140,8 +1139,8 @@ def test_setup_should_throw_error_if_shares_config_not_configured(self):

mock_os_path_exists = self.mock_object(os.path, 'exists')

with testtools.ExpectedException(exception.NfsException,
".*no NFS config file configured.*"):
with self.assertRaisesRegex(exception.NfsException,
".*no NFS config file configured.*"):
drv.do_setup(self.context)

self.assertEqual(0, mock_os_path_exists.call_count)
Expand All @@ -1154,8 +1153,8 @@ def test_setup_should_throw_error_if_shares_file_does_not_exist(self):
mock_os_path_exists = self.mock_object(os.path, 'exists')
mock_os_path_exists.return_value = False

with testtools.ExpectedException(exception.NfsException,
"NFS config file.*doesn't exist"):
with self.assertRaisesRegex(exception.NfsException,
"NFS config file.*doesn't exist"):
drv.do_setup(self.context)

mock_os_path_exists.assert_has_calls(
Expand All @@ -1170,9 +1169,8 @@ def test_setup_should_throw_error_if_oversub_ratio_less_than_zero(self):
mock_os_path_exists = self.mock_object(os.path, 'exists')
mock_os_path_exists.return_value = True

with testtools.ExpectedException(
exception.InvalidConfigurationValue,
".*'nfs_oversub_ratio' invalid.*"):
with self.assertRaisesRegex(exception.InvalidConfigurationValue,
".*'nfs_oversub_ratio' invalid.*"):
drv.do_setup(self.context)

mock_os_path_exists.assert_has_calls(
Expand Down Expand Up @@ -1205,9 +1203,8 @@ def test_setup_should_throw_error_if_used_ratio_less_than_zero(self):
mock_os_path_exists = self.mock_object(os.path, 'exists')
mock_os_path_exists.return_value = True

with testtools.ExpectedException(
exception.InvalidConfigurationValue,
".*'nfs_used_ratio' invalid.*"):
with self.assertRaisesRegex(exception.InvalidConfigurationValue,
".*'nfs_used_ratio' invalid.*"):
drv.do_setup(self.context)

mock_os_path_exists.assert_has_calls(
Expand All @@ -1222,9 +1219,8 @@ def test_setup_should_throw_error_if_used_ratio_greater_than_one(self):
mock_os_path_exists = self.mock_object(os.path, 'exists')
mock_os_path_exists.return_value = True

with testtools.ExpectedException(
exception.InvalidConfigurationValue,
".*'nfs_used_ratio' invalid.*"):
with self.assertRaisesRegex(exception.InvalidConfigurationValue,
".*'nfs_used_ratio' invalid.*"):
drv.do_setup(self.context)

mock_os_path_exists.assert_has_calls(
Expand Down Expand Up @@ -1259,8 +1255,8 @@ def test_setup_should_throw_exception_if_nfs_client_is_not_installed(self):
mock_execute.side_effect = OSError(
errno.ENOENT, 'No such file or directory.')

with testtools.ExpectedException(
exception.NfsException, 'mount.nfs is not installed'):
with self.assertRaisesRegex(exception.NfsException,
'mount.nfs is not installed'):
drv.do_setup(self.context)

mock_os_path_exists.assert_has_calls(
Expand All @@ -1284,7 +1280,7 @@ def test_setup_should_throw_exception_if_mount_nfs_command_fails(self):
mock_execute.side_effect = OSError(
errno.EPERM, 'Operation... BROKEN')

with testtools.ExpectedException(OSError, '.*Operation... BROKEN'):
with self.assertRaisesRegex(OSError, '.*Operation... BROKEN'):
drv.do_setup(self.context)

mock_os_path_exists.assert_has_calls(
Expand Down
1 change: 1 addition & 0 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ commands =
cinder.tests.unit.test_ibm_xiv_ds8k \
cinder.tests.unit.test_infortrend_cli \
cinder.tests.unit.test_netapp_nfs \
cinder.tests.unit.test_nfs \
cinder.tests.unit.test_nimble \
cinder.tests.unit.test_qos_specs \
cinder.tests.unit.test_quota \
Expand Down

0 comments on commit 3b40049

Please sign in to comment.