Use unittest.mock instead of mock
The mock third party library was needed for mock support in py2 runtimes. Since we now only support py36 and later, we can use the standard lib unittest.mock module instead. Note that https://github.com/openstack/charms.openstack is used during tests and he need `mock`, unfortunatelly it doesn't declare `mock` in its requirements so it retrieve mock from other charm project (cross dependency). So we depend on charms.openstack first and when Ib1ed5b598a52375e29e247db9ab4786df5b6d142 will be merged then CI will pass without errors. Depends-On: Ib1ed5b598a52375e29e247db9ab4786df5b6d142 Change-Id: I538b5c2a9df4de66c9874e65247496e54c0522e8
This commit is contained in:
parent
bde329d973
commit
77fdcf3e27
@ -1,4 +1,4 @@
|
||||
- project:
|
||||
templates:
|
||||
- python35-charm-jobs
|
||||
- openstack-python3-ussuri-jobs
|
||||
- openstack-cover-jobs
|
||||
|
@ -13,11 +13,6 @@ setuptools<50.0.0 # https://github.com/pypa/setuptools/commit/04e3df22df840c6bb
|
||||
|
||||
requests>=2.18.4
|
||||
|
||||
# Newer mock seems to have some syntax which is newer than python3.5 (e.g.
|
||||
# f'{something}'
|
||||
mock>=1.2,<4.0.0; python_version < '3.6'
|
||||
mock>=1.2; python_version >= '3.6'
|
||||
|
||||
stestr>=2.2.0
|
||||
|
||||
# Dependency of stestr. Workaround for
|
||||
|
@ -12,7 +12,7 @@
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
import mock
|
||||
from unittest import mock
|
||||
import os
|
||||
import sys
|
||||
|
||||
|
@ -12,15 +12,15 @@
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
from mock import patch, mock
|
||||
import unittest.mock as mock
|
||||
import os
|
||||
|
||||
os.environ['JUJU_UNIT_NAME'] = 'cinder'
|
||||
|
||||
from test_utils import RESTART_MAP
|
||||
|
||||
with patch('cinder_utils.register_configs') as register_configs:
|
||||
with patch('cinder_utils.restart_map') as restart_map:
|
||||
with mock.patch('cinder_utils.register_configs') as register_configs:
|
||||
with mock.patch('cinder_utils.restart_map') as restart_map:
|
||||
restart_map.return_value = RESTART_MAP
|
||||
register_configs.return_value = 'test-config'
|
||||
import actions
|
||||
|
@ -12,7 +12,7 @@
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
from mock import patch, mock
|
||||
import unittest.mock as mock
|
||||
from test_utils import (
|
||||
CharmTestCase
|
||||
)
|
||||
@ -56,8 +56,8 @@ class CinderManageTestCase(CharmTestCase):
|
||||
self.subprocess.check_call.assert_called_once_with(
|
||||
['cinder-manage', 'service', 'remove', 'host', 'host@this#that'])
|
||||
|
||||
@patch.object(cinder_manage, 'cinder_manage_service_list')
|
||||
@patch.object(cinder_manage, 'cinder_manage_remove')
|
||||
@mock.patch.object(cinder_manage, 'cinder_manage_service_list')
|
||||
@mock.patch.object(cinder_manage, 'cinder_manage_remove')
|
||||
def test_remove_services(self, cinder_manage_remove,
|
||||
cinder_manage_service_list):
|
||||
self.action_get.return_value = 'svc1host'
|
||||
@ -70,8 +70,8 @@ class CinderManageTestCase(CharmTestCase):
|
||||
cinder_manage_remove.assert_called_once_with('svc1bin', 'svc1host')
|
||||
self.action_set.assert_called_once_with({'removed': 'svc1host'})
|
||||
|
||||
@patch.object(cinder_manage, 'cinder_manage_service_list')
|
||||
@patch.object(cinder_manage, 'cinder_manage_remove')
|
||||
@mock.patch.object(cinder_manage, 'cinder_manage_service_list')
|
||||
@mock.patch.object(cinder_manage, 'cinder_manage_remove')
|
||||
def test_remove_services_kilo(self, cinder_manage_remove,
|
||||
cinder_manage_service_list):
|
||||
self.action_get.return_value = 'svc1host'
|
||||
@ -84,8 +84,8 @@ class CinderManageTestCase(CharmTestCase):
|
||||
cinder_manage.remove_services('arg')
|
||||
self.action_fail.assert_called_once()
|
||||
|
||||
@patch.object(cinder_manage, 'cinder_manage_service_list')
|
||||
@patch.object(cinder_manage, 'cinder_manage_remove')
|
||||
@mock.patch.object(cinder_manage, 'cinder_manage_service_list')
|
||||
@mock.patch.object(cinder_manage, 'cinder_manage_remove')
|
||||
def test_remove_services_fail(self, cinder_manage_remove,
|
||||
cinder_manage_service_list):
|
||||
cinder_manage_remove.side_effect = Exception()
|
||||
@ -100,8 +100,8 @@ class CinderManageTestCase(CharmTestCase):
|
||||
self.action_fail.assert_called_once_with(
|
||||
'Cannot remove service: svc1host')
|
||||
|
||||
@patch.object(cinder_manage, 'cinder_manage_service_list')
|
||||
@patch.object(cinder_manage, 'cinder_manage_volume_update_host')
|
||||
@mock.patch.object(cinder_manage, 'cinder_manage_service_list')
|
||||
@mock.patch.object(cinder_manage, 'cinder_manage_volume_update_host')
|
||||
def test__rename_volume_host(self, cinder_manage_volume_update_host,
|
||||
cinder_manage_service_list):
|
||||
self.action_get.return_value = 'myhost'
|
||||
@ -112,8 +112,8 @@ class CinderManageTestCase(CharmTestCase):
|
||||
cinder_manage._rename_volume_host('a', 'b')
|
||||
cinder_manage_volume_update_host.assert_called_once_with('a', 'b')
|
||||
|
||||
@patch.object(cinder_manage, 'cinder_manage_service_list')
|
||||
@patch.object(cinder_manage, 'cinder_manage_volume_update_host')
|
||||
@mock.patch.object(cinder_manage, 'cinder_manage_service_list')
|
||||
@mock.patch.object(cinder_manage, 'cinder_manage_volume_update_host')
|
||||
def test__rename_volume_host_missing(self,
|
||||
cinder_manage_volume_update_host,
|
||||
cinder_manage_service_list):
|
||||
@ -124,8 +124,8 @@ class CinderManageTestCase(CharmTestCase):
|
||||
self.action_fail.assert_called_once_with(
|
||||
'Cannot update host attribute from a, a not found')
|
||||
|
||||
@patch.object(cinder_manage, 'cinder_manage_service_list')
|
||||
@patch.object(cinder_manage, 'cinder_manage_volume_update_host')
|
||||
@mock.patch.object(cinder_manage, 'cinder_manage_service_list')
|
||||
@mock.patch.object(cinder_manage, 'cinder_manage_volume_update_host')
|
||||
def test__rename_volume_host_fail(self,
|
||||
cinder_manage_volume_update_host,
|
||||
cinder_manage_service_list):
|
||||
@ -139,7 +139,7 @@ class CinderManageTestCase(CharmTestCase):
|
||||
cinder_manage_volume_update_host.assert_called_once_with('a', 'b')
|
||||
self.action_fail.assert_called_once_with('Cannot update host a')
|
||||
|
||||
@patch.object(cinder_manage, '_rename_volume_host')
|
||||
@mock.patch.object(cinder_manage, '_rename_volume_host')
|
||||
def test_rename_volume_host(self, _rename_volume_host):
|
||||
self.action_get.return_value = {
|
||||
'currenthost': 'orghost',
|
||||
@ -147,7 +147,7 @@ class CinderManageTestCase(CharmTestCase):
|
||||
cinder_manage.rename_volume_host('arg')
|
||||
_rename_volume_host.assert_called_once_with('orghost', 'newhost')
|
||||
|
||||
@patch.object(cinder_manage, '_rename_volume_host')
|
||||
@mock.patch.object(cinder_manage, '_rename_volume_host')
|
||||
def test_volume_host_add_driver(self, _rename_volume_host):
|
||||
self.action_get.return_value = {
|
||||
'currenthost': 'orghost',
|
||||
@ -157,7 +157,7 @@ class CinderManageTestCase(CharmTestCase):
|
||||
_rename_volume_host.assert_called_once_with(
|
||||
'orghost', 'orghost@lvmdriver-1#LVM')
|
||||
|
||||
@patch.object(cinder_manage, '_rename_volume_host')
|
||||
@mock.patch.object(cinder_manage, '_rename_volume_host')
|
||||
def test_volume_host_add_driver_novol_backend(self, _rename_volume_host):
|
||||
self.action_get.return_value = {
|
||||
'currenthost': 'orghost',
|
||||
@ -167,7 +167,7 @@ class CinderManageTestCase(CharmTestCase):
|
||||
_rename_volume_host.assert_called_once_with(
|
||||
'orghost', 'orghost@lvmdriver-1')
|
||||
|
||||
@patch.object(cinder_manage, 'subprocess')
|
||||
@mock.patch.object(cinder_manage, 'subprocess')
|
||||
def test_cinder_manage_service_list(self, subprocess):
|
||||
subprocess.check_output.return_value = SERVICE_LIST.encode()
|
||||
self.assertEqual(len(cinder_manage.cinder_manage_service_list()), 10)
|
||||
|
@ -14,7 +14,7 @@
|
||||
|
||||
import os
|
||||
|
||||
from mock import patch, MagicMock
|
||||
from unittest.mock import patch, MagicMock
|
||||
|
||||
from test_utils import (
|
||||
CharmTestCase,
|
||||
|
@ -15,7 +15,7 @@
|
||||
import os
|
||||
|
||||
from test_utils import CharmTestCase
|
||||
from mock import patch, MagicMock
|
||||
from unittest.mock import patch, MagicMock
|
||||
|
||||
import cinder_contexts as contexts
|
||||
|
||||
|
@ -17,7 +17,7 @@ import json
|
||||
|
||||
from six.moves import reload_module
|
||||
|
||||
from mock import (
|
||||
from unittest.mock import (
|
||||
patch,
|
||||
call
|
||||
)
|
||||
|
@ -16,7 +16,7 @@ import os
|
||||
import subprocess
|
||||
|
||||
from collections import OrderedDict
|
||||
from mock import patch, call, MagicMock, Mock
|
||||
from unittest.mock import patch, call, MagicMock, Mock
|
||||
|
||||
os.environ['JUJU_UNIT_NAME'] = 'cinder'
|
||||
import cinder_utils as cinder_utils
|
||||
|
@ -15,7 +15,7 @@
|
||||
import os
|
||||
import sys
|
||||
|
||||
from mock import patch, call, MagicMock
|
||||
from unittest.mock import patch, call, MagicMock
|
||||
|
||||
from test_utils import (
|
||||
CharmTestCase,
|
||||
|
@ -19,7 +19,7 @@ import yaml
|
||||
|
||||
from collections import OrderedDict
|
||||
|
||||
from mock import patch
|
||||
from unittest.mock import patch
|
||||
|
||||
|
||||
RESTART_MAP = OrderedDict([
|
||||
|
Loading…
x
Reference in New Issue
Block a user