|
| 1 | +# |
| 2 | +# Licensed under the Apache License, Version 2.0 (the "License"); you may |
| 3 | +# not use this file except in compliance with the License. You may obtain |
| 4 | +# a copy of the License at |
| 5 | +# |
| 6 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 7 | +# |
| 8 | +# Unless required by applicable law or agreed to in writing, software |
| 9 | +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 10 | +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| 11 | +# License for the specific language governing permissions and limitations |
| 12 | +# under the License. |
| 13 | +# |
| 14 | + |
| 15 | +import mock |
| 16 | + |
| 17 | +from openstackclient.tests import fakes |
| 18 | +from openstackclient.tests.identity.v2_0 import fakes as identity_fakes |
| 19 | +from openstackclient.tests import utils |
| 20 | + |
| 21 | +volume_id = "ce26708d-a7f8-4b4b-9861-4a80256615a6" |
| 22 | +volume_name = "fake_volume" |
| 23 | +volume_description = "fake description" |
| 24 | +volume_status = "available" |
| 25 | +volume_size = 20 |
| 26 | +volume_type = "fake_lvmdriver-1" |
| 27 | +volume_metadata = { |
| 28 | + "foo": "bar" |
| 29 | +} |
| 30 | +volume_snapshot_id = 1 |
| 31 | +volume_availability_zone = "nova" |
| 32 | +volume_attachments = ["fake_attachments"] |
| 33 | + |
| 34 | +VOLUME = { |
| 35 | + "id": volume_id, |
| 36 | + "name": volume_name, |
| 37 | + "description": volume_description, |
| 38 | + "status": volume_status, |
| 39 | + "size": volume_size, |
| 40 | + "volume_type": volume_type, |
| 41 | + "metadata": volume_metadata, |
| 42 | + "snapshot_id": volume_snapshot_id, |
| 43 | + "availability_zone": volume_availability_zone, |
| 44 | + "attachments": volume_attachments |
| 45 | +} |
| 46 | + |
| 47 | +VOLUME_columns = tuple(sorted(VOLUME)) |
| 48 | +VOLUME_data = tuple((VOLUME[x] for x in sorted(VOLUME))) |
| 49 | + |
| 50 | + |
| 51 | +snapshot_id = "cb2d364e-4d1c-451a-8c68-b5bbcb340fb2" |
| 52 | +snapshot_name = "fake_snapshot" |
| 53 | +snapshot_description = "fake description" |
| 54 | +snapshot_size = 10 |
| 55 | +snapshot_metadata = { |
| 56 | + "foo": "bar" |
| 57 | +} |
| 58 | +snapshot_volume_id = "bdbae8dc-e6ca-43c0-8076-951cc1b093a4" |
| 59 | + |
| 60 | +SNAPSHOT = { |
| 61 | + "id": snapshot_id, |
| 62 | + "name": snapshot_name, |
| 63 | + "description": snapshot_description, |
| 64 | + "size": snapshot_size, |
| 65 | + "metadata": snapshot_metadata |
| 66 | +} |
| 67 | + |
| 68 | +SNAPSHOT_columns = tuple(sorted(SNAPSHOT)) |
| 69 | +SNAPSHOT_data = tuple((SNAPSHOT[x] for x in sorted(SNAPSHOT))) |
| 70 | + |
| 71 | + |
| 72 | +type_id = "5520dc9e-6f9b-4378-a719-729911c0f407" |
| 73 | +type_description = "fake description" |
| 74 | +type_name = "fake-lvmdriver-1" |
| 75 | +type_extra_specs = { |
| 76 | + "foo": "bar" |
| 77 | +} |
| 78 | + |
| 79 | +TYPE = { |
| 80 | + 'id': type_id, |
| 81 | + 'name': type_name, |
| 82 | + 'description': type_description, |
| 83 | + 'extra_specs': type_extra_specs |
| 84 | +} |
| 85 | + |
| 86 | +TYPE_columns = tuple(sorted(TYPE)) |
| 87 | +TYPE_data = tuple((TYPE[x] for x in sorted(TYPE))) |
| 88 | + |
| 89 | +backup_id = "3c409fe6-4d03-4a06-aeab-18bdcdf3c8f4" |
| 90 | +backup_volume_id = "bdbae8dc-e6ca-43c0-8076-951cc1b093a4" |
| 91 | +backup_name = "fake_backup" |
| 92 | +backup_description = "fake description" |
| 93 | +backup_object_count = None |
| 94 | +backup_container = None |
| 95 | +backup_size = 10 |
| 96 | + |
| 97 | +BACKUP = { |
| 98 | + "id": backup_id, |
| 99 | + "name": backup_name, |
| 100 | + "volume_id": backup_volume_id, |
| 101 | + "description": backup_description, |
| 102 | + "object_count": backup_object_count, |
| 103 | + "container": backup_container, |
| 104 | + "size": backup_size |
| 105 | +} |
| 106 | + |
| 107 | +BACKUP_columns = tuple(sorted(BACKUP)) |
| 108 | +BACKUP_data = tuple((BACKUP[x] for x in sorted(BACKUP))) |
| 109 | + |
| 110 | + |
| 111 | +class FakeVolumeClient(object): |
| 112 | + def __init__(self, **kwargs): |
| 113 | + self.volumes = mock.Mock() |
| 114 | + self.volumes.resource_class = fakes.FakeResource(None, {}) |
| 115 | + self.volume_snapshots = mock.Mock() |
| 116 | + self.volume_snapshots.resource_class = fakes.FakeResource(None, {}) |
| 117 | + self.backups = mock.Mock() |
| 118 | + self.backups.resource_class = fakes.FakeResource(None, {}) |
| 119 | + self.volume_types = mock.Mock() |
| 120 | + self.volume_types.resource_class = fakes.FakeResource(None, {}) |
| 121 | + self.auth_token = kwargs['token'] |
| 122 | + self.management_url = kwargs['endpoint'] |
| 123 | + |
| 124 | + |
| 125 | +class TestVolume(utils.TestCommand): |
| 126 | + def setUp(self): |
| 127 | + super(TestVolume, self).setUp() |
| 128 | + |
| 129 | + self.app.client_manager.volume = FakeVolumeClient( |
| 130 | + endpoint=fakes.AUTH_URL, |
| 131 | + token=fakes.AUTH_TOKEN |
| 132 | + ) |
| 133 | + self.app.client_manager.identity = identity_fakes.FakeIdentityv2Client( |
| 134 | + endpoint=fakes.AUTH_URL, |
| 135 | + token=fakes.AUTH_TOKEN |
| 136 | + ) |
0 commit comments