Debian Codegraph @

config_tempest/tests/services/test_volume.py

raw symbols SCIP
1 # Copyright 2018 Red Hat, Inc.
2 # All Rights Reserved.
3 #
4 # Licensed under the Apache License, Version 2.0 (the "License"); you may
5 # not use this file except in compliance with the License. You may obtain
6 # a copy of the License at
7 #
8 # http://www.apache.org/licenses/LICENSE-2.0
9 #
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 # License for the specific language governing permissions and limitations
14 # under the License.
15
16 from unittest import mock
17
18 from config_tempest.services import volume
19 from config_tempest.tempest_conf import TempestConf
20 from config_tempest.tests.base import BaseServiceTest
21
22
23 class TestVolumeService(BaseServiceTest):
24 def setUp(self):
25 super(TestVolumeService, self).setUp()
26 self.Service = volume.VolumeService("ServiceName",
27 "ServiceType",
28 self.FAKE_URL,
29 self.FAKE_TOKEN,
30 disable_ssl_validation=False)
31 self.conf = TempestConf()
32
33 def test_set_get_extensions(self):
34 exp_resp = ['NMN', 'OS-DCF']
35 self._set_get_extensions(self.Service, exp_resp, self.FAKE_EXTENSIONS)
36
37 def test_set_get_versions(self):
38 exp_resp = ['v2.0', 'v2.1']
39 self._set_get_versions(self.Service, exp_resp, self.FAKE_VERSIONS)
40
41 @mock.patch('config_tempest.services.services.Services.is_service')
42 @mock.patch('config_tempest.services.volume.C.LOG')
43 def test_post_configuration_no_volume(self, mock_logging, mock_is_service):
44 mock_is_service.return_value = False
45 self.Service.post_configuration(self.conf, mock_is_service)
46 self.assertTrue(mock_logging.info.called)
47 self.assertEqual(self.conf.get('volume-feature-enabled', 'backup'),
48 'False')
49
50 @mock.patch('config_tempest.services.services.Services.is_service')
51 def test_post_configuration_state_down(self, mock_is_service):
52 client_service_mock = self.FakeServiceClient(services={
53 'services': [
54 {
55 "state": "down"
56 }
57 ]
58 })
59 self.Service.client = client_service_mock
60 mock_is_service.return_value = True
61 self.Service.post_configuration(self.conf, mock_is_service)
62 self.assertEqual(self.conf.get('volume-feature-enabled',
63 'backup'), 'False')
64
65 @mock.patch('config_tempest.services.services.Services.is_service')
66 def test_post_configuration_no_service(self, mock_is_service):
67 client_service_mock = self.FakeServiceClient(services={
68 'services': []
69 })
70 self.Service.client = client_service_mock
71 mock_is_service.return_value = True
72 self.Service.post_configuration(self.conf, mock_is_service)
73 self.assertEqual(self.conf.get('volume-feature-enabled',
74 'backup'), 'False')