Skip to content

Commit 5bf280d

Browse files
authored
Merge pull request #2782 from EmilienM/backport_tag_volume
[v1] (manual clean backport) Add tag field to compute block_device_v2
2 parents 23e5dbd + 4ecebfb commit 5bf280d

5 files changed

Lines changed: 70 additions & 1 deletion

File tree

acceptance/openstack/compute/v2/bootfromvolume_test.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,13 +51,19 @@ func TestBootFromNewVolume(t *testing.T) {
5151
choices, err := clients.AcceptanceTestChoicesFromEnv()
5252
th.AssertNoErr(t, err)
5353

54+
// minimum required microversion for getting volume tags is 2.70
55+
// https://docs.openstack.org/nova/latest/reference/api-microversion-history.html#id64
56+
client.Microversion = "2.70"
57+
58+
tagName := "tag1"
5459
blockDevices := []bootfromvolume.BlockDevice{
5560
{
5661
DeleteOnTermination: true,
5762
DestinationType: bootfromvolume.DestinationVolume,
5863
SourceType: bootfromvolume.SourceImage,
5964
UUID: choices.ImageID,
6065
VolumeSize: 2,
66+
Tag: tagName,
6167
},
6268
}
6369

@@ -73,6 +79,8 @@ func TestBootFromNewVolume(t *testing.T) {
7379

7480
tools.PrintResource(t, server)
7581
tools.PrintResource(t, attachments)
82+
attachmentTag := *attachments[0].Tag
83+
th.AssertEquals(t, attachmentTag, tagName)
7684

7785
if server.Image != nil {
7886
t.Fatalf("server image should be nil")

acceptance/openstack/compute/v2/compute.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,6 @@ func CreateBootableVolumeServer(t *testing.T, client *gophercloud.ServiceClient,
178178
}
179179

180180
th.AssertEquals(t, newServer.Name, name)
181-
th.AssertEquals(t, newServer.Flavor["id"], choices.FlavorID)
182181

183182
return newServer, nil
184183
}

openstack/compute/v2/extensions/bootfromvolume/requests.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,12 @@ type BlockDevice struct {
7979
// VolumeType is the volume type of the block device.
8080
// This requires Compute API microversion 2.67 or later.
8181
VolumeType string `json:"volume_type,omitempty"`
82+
83+
// Tag is an arbitrary string that can be applied to a block device.
84+
// Information about the device tags can be obtained from the metadata API
85+
// and the config drive, allowing devices to be easily identified.
86+
// This requires Compute API microversion 2.42 or later.
87+
Tag string `json:"tag,omitempty"`
8288
}
8389

8490
// CreateOptsExt is a structure that extends the server `CreateOpts` structure

openstack/compute/v2/extensions/bootfromvolume/testing/fixtures.go

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -308,3 +308,53 @@ var NewVolumeTypeRequest = bootfromvolume.CreateOptsExt{
308308
},
309309
},
310310
}
311+
312+
const ExpectedImageAndExistingVolumeWithTagRequest = `
313+
{
314+
"server": {
315+
"name": "createdserver",
316+
"imageRef": "asdfasdfasdf",
317+
"flavorRef": "performance1-1",
318+
"block_device_mapping_v2":[
319+
{
320+
"boot_index": 0,
321+
"delete_on_termination": true,
322+
"destination_type":"local",
323+
"source_type":"image",
324+
"uuid":"asdfasdfasdf"
325+
},
326+
{
327+
"boot_index": -1,
328+
"delete_on_termination": true,
329+
"destination_type":"volume",
330+
"source_type":"volume",
331+
"tag": "volume-tag",
332+
"uuid":"123456",
333+
"volume_size": 1
334+
}
335+
]
336+
}
337+
}
338+
`
339+
340+
var ImageAndExistingVolumeWithTagRequest = bootfromvolume.CreateOptsExt{
341+
CreateOptsBuilder: BaseCreateOptsWithImageRef,
342+
BlockDevice: []bootfromvolume.BlockDevice{
343+
{
344+
BootIndex: 0,
345+
DeleteOnTermination: true,
346+
DestinationType: bootfromvolume.DestinationLocal,
347+
SourceType: bootfromvolume.SourceImage,
348+
UUID: "asdfasdfasdf",
349+
},
350+
{
351+
BootIndex: -1,
352+
DeleteOnTermination: true,
353+
DestinationType: bootfromvolume.DestinationVolume,
354+
SourceType: bootfromvolume.SourceVolume,
355+
Tag: "volume-tag",
356+
UUID: "123456",
357+
VolumeSize: 1,
358+
},
359+
},
360+
}

openstack/compute/v2/extensions/bootfromvolume/testing/requests_test.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,3 +47,9 @@ func TestBootFromNewVolumeType(t *testing.T) {
4747
th.AssertNoErr(t, err)
4848
th.CheckJSONEquals(t, ExpectedNewVolumeTypeRequest, actual)
4949
}
50+
51+
func TestAttachExistingVolumeWithTag(t *testing.T) {
52+
actual, err := ImageAndExistingVolumeWithTagRequest.ToServerCreateMap()
53+
th.AssertNoErr(t, err)
54+
th.CheckJSONEquals(t, ExpectedImageAndExistingVolumeWithTagRequest, actual)
55+
}

0 commit comments

Comments
 (0)