[openstack-dev] [Cinder] Need some help with mock

Deepak Shetty dpkshetty at gmail.com
Mon Apr 28 18:00:03 UTC 2014


 I was writing this in test_glusterfs.py

    def test_ensure_shares_unmounted_1share(self):
        with contextlib.nested(
            mock.patch.object(self._driver, '_load_shares_config'),
            mock.patch.object(self._driver, '_ensure_share_unmounted')
        ) as (self._fake_load_shares_config, mock_ensure_share_unmounted):

            #mock_shares = {'127.7.7.7:/gluster1': None}
            #mock_load_shares_config.return_value = mock_shares
            #self._driver.shares = mock_load_shares_config.return_value

            self._driver._ensure_shares_unmounted()

            mock_ensure_share_unmounted.assert_called_once()
            mock_ensure_share_unmounted.assert_called_once_with(
                '127.7.7.7:/gluster1')

for my patch @ https://review.openstack.org/#/c/86888/6

and i get the output as ..

======================================================================
FAIL:
cinder.tests.test_glusterfs.GlusterFsDriverTestCase.test_ensure_shares_unmounted_1share
----------------------------------------------------------------------
...
...

stderr: {{{
cinder/tests/test_glusterfs.py:736: DeprecationWarning: With-statements now
directly support multiple context managers
  mock.patch.object(self._driver, '_ensure_share_unmounted')
}}}

Traceback (most recent call last):
  File "cinder/tests/test_glusterfs.py", line 747, in
test_ensure_shares_unmounted_1share
    '127.7.7.7:/gluster1')
  File "/usr/lib/python2.7/site-packages/mock.py", line 845, in
assert_called_once_with
    raise AssertionError(msg)
AssertionError: Expected to be called once. Called 0 times.


Can you help with why
'mock_ensure_share_unmounted.assert_called_once()' check passes
but
'mock_ensure_share_unmounted.assert_called_once_with('127.7.7.7:/gluster1')
check fails ?


In glusterfs.py ...

    def _ensure_shares_unmounted(self):
        self._load_shares_config(self.configuration.glusterfs_shares_config)
        for share in self.shares.keys():
            try:
                self._ensure_share_unmounted(share)
            except Exception as exc:
                LOG.warning(_('Exception during unmounting %s') % (exc,))


thanx,
deepak
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.openstack.org/pipermail/openstack-dev/attachments/20140428/4d5ed9dd/attachment.html>


More information about the OpenStack-dev mailing list