@@ -108,99 +108,61 @@ def _is_multiattach(volume_id):
108
108
self .MULTIATTACH_RO_MIGRATE_NEW_VOL ]
109
109
110
110
def fake_get (self_api , context , volume_id , microversion = None ):
111
+ volume = {
112
+ 'display_name' : volume_id ,
113
+ 'id' : volume_id ,
114
+ 'size' : 1 ,
115
+ 'multiattach' : _is_multiattach (volume_id ),
116
+ 'availability_zone' : self .az
117
+ }
111
118
112
- # TODO(lyarwood): Refactor this block into something sensible and
113
- # reusable by other tests.
114
- # Check for the special swap volumes.
115
- attachments = self .volume_to_attachment [volume_id ]
116
- if volume_id in (self .SWAP_OLD_VOL , self .SWAP_ERR_OLD_VOL ):
117
- volume = {
118
- 'status' : 'available' ,
119
- 'display_name' : 'TEST1' ,
120
- 'attach_status' : 'detached' ,
121
- 'id' : volume_id ,
122
- 'multiattach' : False ,
123
- 'size' : 1
124
- }
125
- if (
126
- (
127
- self .swap_volume_instance_uuid and
128
- volume_id == self .SWAP_OLD_VOL
129
- ) or (
130
- self .swap_volume_instance_error_uuid and
131
- volume_id == self .SWAP_ERR_OLD_VOL
132
- )
133
- ):
134
- if volume_id == self .SWAP_OLD_VOL :
119
+ # Add any attachment details the fixture has
120
+ fixture_attachments = self .volume_to_attachment [volume_id ]
121
+ if fixture_attachments :
122
+ attachments = {}
123
+ for attachment in list (fixture_attachments .values ()):
124
+ instance_uuid = attachment ['instance_uuid' ]
125
+ # legacy cruft left over from notification tests
126
+ if (
127
+ volume_id == self .SWAP_OLD_VOL and
128
+ self .swap_volume_instance_uuid
129
+ ):
135
130
instance_uuid = self .swap_volume_instance_uuid
136
- else :
131
+
132
+ if (
133
+ volume_id == self .SWAP_ERR_OLD_VOL and
134
+ self .swap_volume_instance_error_uuid
135
+ ):
137
136
instance_uuid = self .swap_volume_instance_error_uuid
137
+ attachments [instance_uuid ] = {
138
+ 'attachment_id' : attachment ['id' ],
139
+ 'mountpoint' : '/dev/vdb' ,
140
+ }
138
141
139
- if attachments :
140
- attachment = list (attachments .values ())[0 ]
141
-
142
- volume .update ({
143
- 'status' : 'in-use' ,
144
- 'attachments' : {
145
- instance_uuid : {
146
- 'mountpoint' : '/dev/vdb' ,
147
- 'attachment_id' : attachment ['id' ]
148
- }
149
- },
150
- 'attach_status' : 'attached' ,
151
- })
152
- return volume
153
-
154
- # Check to see if the volume is attached.
155
- if attachments :
156
- # The volume is attached.
157
- attachment = list (attachments .values ())[0 ]
158
- volume = {
142
+ volume .update ({
159
143
'status' : 'in-use' ,
160
- 'display_name' : volume_id ,
161
144
'attach_status' : 'attached' ,
162
- 'id' : volume_id ,
163
- 'multiattach' : _is_multiattach (volume_id ),
164
- 'size' : 1 ,
165
- 'attachments' : {
166
- attachment ['instance_uuid' ]: {
167
- 'attachment_id' : attachment ['id' ],
168
- 'mountpoint' : '/dev/vdb'
169
- }
170
- }
171
- }
145
+ 'attachments' : attachments ,
146
+ })
147
+ # Otherwise mark the volume as avilable and detached
172
148
else :
173
- # This is a test that does not care about the actual details.
174
- volume = {
149
+ volume .update ({
175
150
'status' : 'available' ,
176
- 'display_name' : volume_id ,
177
151
'attach_status' : 'detached' ,
178
- 'id' : volume_id ,
179
- 'multiattach' : _is_multiattach (volume_id ),
180
- 'size' : 1
181
- }
152
+ })
182
153
183
- if 'availability_zone' not in volume :
184
- volume ['availability_zone' ] = self .az
154
+ if volume_id == self .IMAGE_BACKED_VOL :
155
+ volume ['bootable' ] = True
156
+ volume ['volume_image_metadata' ] = {
157
+ 'image_id' : '155d900f-4e14-4e4c-a73d-069cbf4541e6'
158
+ }
185
159
186
- # Check for our special image-backed volume.
187
- if volume_id in (
188
- self .IMAGE_BACKED_VOL , self .IMAGE_WITH_TRAITS_BACKED_VOL ,
189
- ):
190
- # Make it a bootable volume.
160
+ if volume_id == self .IMAGE_WITH_TRAITS_BACKED_VOL :
191
161
volume ['bootable' ] = True
192
- if volume_id == self .IMAGE_BACKED_VOL :
193
- # Add the image_id metadata.
194
- volume ['volume_image_metadata' ] = {
195
- # There would normally be more image metadata in here.
196
- 'image_id' : '155d900f-4e14-4e4c-a73d-069cbf4541e6'
197
- }
198
- elif volume_id == self .IMAGE_WITH_TRAITS_BACKED_VOL :
199
- # Add the image_id metadata with traits.
200
- volume ['volume_image_metadata' ] = {
201
- 'image_id' : '155d900f-4e14-4e4c-a73d-069cbf4541e6' ,
202
- "trait:HW_CPU_X86_SGX" : "required" ,
203
- }
162
+ volume ['volume_image_metadata' ] = {
163
+ 'image_id' : '155d900f-4e14-4e4c-a73d-069cbf4541e6' ,
164
+ "trait:HW_CPU_X86_SGX" : "required" ,
165
+ }
204
166
205
167
# If we haven't called migrate_volume_completion then return
206
168
# a migration_status of migrating
0 commit comments