Coverage for manila/tests/services/test_api.py: 100%

23 statements  

« prev     ^ index     » next       coverage.py v7.11.0, created at 2026-02-18 22:19 +0000

1# Licensed under the Apache License, Version 2.0 (the "License"); you may 

2# not use this file except in compliance with the License. You may obtain 

3# a copy of the License at 

4# 

5# http://www.apache.org/licenses/LICENSE-2.0 

6# 

7# Unless required by applicable law or agreed to in writing, software 

8# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 

9# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 

10# License for the specific language governing permissions and limitations 

11# under the License. 

12 

13from unittest import mock 

14from webob import exc 

15 

16from manila import context 

17from manila.services import api as service_api 

18from manila import test 

19 

20 

21class ServicesApiTest(test.TestCase): 

22 

23 def setUp(self): 

24 super(ServicesApiTest, self).setUp() 

25 self.context = context.get_admin_context() 

26 self.share_rpcapi = mock.Mock() 

27 self.share_rpcapi.ensure_shares = mock.Mock() 

28 self.services_api = service_api.API() 

29 self.mock_object( 

30 self.services_api, 'share_rpcapi', self.share_rpcapi 

31 ) 

32 

33 def test_ensure_shares(self): 

34 host = 'fake_host@fakebackend' 

35 fake_service = { 

36 'id': 'fake_service_id', 

37 'state': 'up' 

38 } 

39 

40 self.services_api.ensure_shares(self.context, fake_service, host) 

41 

42 self.share_rpcapi.ensure_driver_resources.assert_called_once_with( 

43 self.context, host 

44 ) 

45 

46 def test_ensure_shares_host_down(self): 

47 host = 'fake_host@fakebackend' 

48 fake_service = { 

49 'id': 'fake_service_id', 

50 'state': 'down' 

51 } 

52 

53 self.assertRaises( 

54 exc.HTTPConflict, 

55 self.services_api.ensure_shares, 

56 self.context, 

57 fake_service, 

58 host 

59 ) 

60 

61 self.share_rpcapi.ensure_shares.assert_not_called()