|
| 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 | + |
| 13 | +import json |
| 14 | + |
| 15 | +from openstackclient.tests.functional.volume.v1 import common |
| 16 | + |
| 17 | + |
| 18 | +class VolumeServiceTests(common.BaseVolumeTests): |
| 19 | + """Functional tests for volume service.""" |
| 20 | + |
| 21 | + def test_volume_service_list(self): |
| 22 | + cmd_output = json.loads(self.openstack( |
| 23 | + 'volume service list -f json')) |
| 24 | + |
| 25 | + # Get the nonredundant services and hosts |
| 26 | + services = list(set([x['Binary'] for x in cmd_output])) |
| 27 | + |
| 28 | + # Test volume service list --service |
| 29 | + cmd_output = json.loads(self.openstack( |
| 30 | + 'volume service list -f json ' + |
| 31 | + '--service ' + |
| 32 | + services[0] |
| 33 | + )) |
| 34 | + for x in cmd_output: |
| 35 | + self.assertEqual( |
| 36 | + services[0], |
| 37 | + x['Binary'] |
| 38 | + ) |
| 39 | + |
| 40 | + # TODO(zhiyong.dai): test volume service list --host after solving |
| 41 | + # https://bugs.launchpad.net/python-openstackclient/+bug/1664451 |
| 42 | + |
| 43 | + def test_volume_service_set(self): |
| 44 | + |
| 45 | + # Get a service and host |
| 46 | + cmd_output = json.loads(self.openstack( |
| 47 | + 'volume service list -f json' |
| 48 | + )) |
| 49 | + service_1 = cmd_output[0]['Binary'] |
| 50 | + host_1 = cmd_output[0]['Host'] |
| 51 | + |
| 52 | + # Test volume service set --enable |
| 53 | + raw_output = self.openstack( |
| 54 | + 'volume service set --enable ' + |
| 55 | + host_1 + ' ' + |
| 56 | + service_1 |
| 57 | + ) |
| 58 | + self.assertOutput('', raw_output) |
| 59 | + |
| 60 | + cmd_output = json.loads(self.openstack( |
| 61 | + 'volume service list -f json --long' |
| 62 | + )) |
| 63 | + self.assertEqual( |
| 64 | + 'enabled', |
| 65 | + cmd_output[0]['Status'] |
| 66 | + ) |
| 67 | + self.assertEqual( |
| 68 | + None, |
| 69 | + cmd_output[0]['Disabled Reason'] |
| 70 | + ) |
| 71 | + |
| 72 | + # Test volume service set --disable and --disable-reason |
| 73 | + disable_reason = 'disable_reason' |
| 74 | + raw_output = self.openstack( |
| 75 | + 'volume service set --disable ' + |
| 76 | + '--disable-reason ' + |
| 77 | + disable_reason + ' ' + |
| 78 | + host_1 + ' ' + |
| 79 | + service_1 |
| 80 | + ) |
| 81 | + self.assertOutput('', raw_output) |
| 82 | + |
| 83 | + cmd_output = json.loads(self.openstack( |
| 84 | + 'volume service list -f json --long' |
| 85 | + )) |
| 86 | + self.assertEqual( |
| 87 | + 'disabled', |
| 88 | + cmd_output[0]['Status'] |
| 89 | + ) |
| 90 | + self.assertEqual( |
| 91 | + disable_reason, |
| 92 | + cmd_output[0]['Disabled Reason'] |
| 93 | + ) |
0 commit comments