Files
charm-manila-ganesha/unit_tests/test_lib_charm_openstack_manila_ganesha.py
Hervé Beraud 31a79c3905 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: I7413322f3a3fdb16208abf52253c0447a9fe3e89
2021-12-15 09:54:02 +00:00

66 lines
2.6 KiB
Python

# Copyright 209 Canonical Ltd
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from unittest import mock
import charms_openstack.test_utils as test_utils
import charm.openstack.manila_ganesha as manila_ganesha
class Helper(test_utils.PatchHelper):
def setUp(self):
super().setUp()
self.patch_release(manila_ganesha.ManilaGaneshaCharm.release)
class TestManilaGaneshaCharm(Helper):
def test_request_ceph_permissions(self):
c = manila_ganesha.ManilaGaneshaCharm()
ceph = mock.MagicMock()
ceph.get_current_request.return_value = None
c.request_ceph_permissions(ceph)
ceph.send_request_if_needed.assert_called_once()
def test_access_ip_without_vip(self):
self.patch_object(manila_ganesha, 'is_clustered')
self.patch_object(manila_ganesha.ch_net_ip, 'get_relation_ip')
self.patch_object(manila_ganesha.ch_net_ip, 'is_address_in_network')
self.is_clustered.return_value = False
self.get_relation_ip.return_value = "10.0.0.1"
c = manila_ganesha.ManilaGaneshaCharm()
self.assertEqual(c.access_ip, "10.0.0.1")
self.is_clustered.assert_called_once()
self.get_relation_ip.assert_called_once_with('tenant-storage')
self.is_address_in_network.assert_not_called()
def test_access_ip_with_vip(self):
self.patch_object(manila_ganesha, 'config')
self.patch_object(manila_ganesha, 'is_clustered')
self.patch_object(manila_ganesha.ch_net_ip, 'get_relation_ip')
self.patch_object(manila_ganesha.ch_net_ip, 'is_address_in_network')
self.patch_object(manila_ganesha.ch_net_ip, 'resolve_network_cidr')
self.config.return_value = {'vip': '10.0.0.10'}
self.is_clustered.return_value = True
self.get_relation_ip.return_value = "10.0.0.1"
self.resolve_network_cidr.return_value = '10.0.0.0/24'
c = manila_ganesha.ManilaGaneshaCharm()
self.assertEqual(c.access_ip, "10.0.0.10")
self.is_clustered.assert_called_once()
self.get_relation_ip.assert_called_once_with('tenant-storage')
self.is_address_in_network.assert_called_once_with(
'10.0.0.0/24', '10.0.0.10')