Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 1031a87

Browse filesBrowse files
authored
Merge pull request #3303 from hroyrh/vmedia_get
Baremetal virtual media Get API
2 parents b2be394 + 6751a7a commit 1031a87
Copy full SHA for 1031a87

File tree

5 files changed

+82
-1
lines changed
Filter options

5 files changed

+82
-1
lines changed

‎internal/acceptance/openstack/baremetal/v1/nodes_test.go

Copy file name to clipboardExpand all lines: internal/acceptance/openstack/baremetal/v1/nodes_test.go
+10-1Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ func TestNodesVirtualMedia(t *testing.T) {
219219

220220
client, err := clients.NewBareMetalV1Client()
221221
th.AssertNoErr(t, err)
222-
client.Microversion = "1.89"
222+
client.Microversion = "1.93"
223223

224224
node, err := CreateNode(t, client)
225225
th.AssertNoErr(t, err)
@@ -241,6 +241,15 @@ func TestNodesVirtualMedia(t *testing.T) {
241241

242242
err = nodes.DetachVirtualMedia(context.TODO(), client, node.UUID, nodes.DetachVirtualMediaOpts{}).ExtractErr()
243243
th.AssertNoErr(t, err)
244+
245+
err = nodes.GetVirtualMedia(context.TODO(), client, node.UUID).Err
246+
// Since Virtual Media GET api call is synchronous, we get a HTTP 400
247+
// response as CreateNode has ipmi driver hardcoded, but the api is
248+
// only supported by the redfish driver
249+
// (TODO: hroyrh) fix this once redfish driver is used in the tests
250+
if node.Driver == "redfish" {
251+
th.AssertNoErr(t, err)
252+
}
244253
}
245254

246255
func TestNodesServicingHold(t *testing.T) {

‎openstack/baremetal/v1/nodes/requests.go

Copy file name to clipboardExpand all lines: openstack/baremetal/v1/nodes/requests.go
+12Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1003,6 +1003,18 @@ func DetachVirtualMedia(ctx context.Context, client *gophercloud.ServiceClient,
10031003
return
10041004
}
10051005

1006+
// Request the list of virtual media devices attached to the Node.
1007+
// Requires microversion 1.93 or later.
1008+
func GetVirtualMedia(ctx context.Context, client *gophercloud.ServiceClient, id string) (r VirtualMediaGetResult) {
1009+
1010+
resp, err := client.Get(ctx, virtualMediaURL(client, id), &r.Body, &gophercloud.RequestOpts{
1011+
OkCodes: []int{200},
1012+
})
1013+
1014+
_, r.Header, r.Err = gophercloud.ParseResponse(resp, err)
1015+
return
1016+
}
1017+
10061018
// VirtualInterfaceOpts defines options for attaching a VIF to a node
10071019
type VirtualInterfaceOpts struct {
10081020
// The UUID or name of the VIF

‎openstack/baremetal/v1/nodes/results.go

Copy file name to clipboardExpand all lines: openstack/baremetal/v1/nodes/results.go
+5Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -711,6 +711,11 @@ type VirtualMediaDetachResult struct {
711711
gophercloud.ErrResult
712712
}
713713

714+
// Requires microversion 1.93 or later.
715+
type VirtualMediaGetResult struct {
716+
gophercloud.Result
717+
}
718+
714719
// VirtualInterfaceAttachResult is the response from an AttachVirtualInterface operation.
715720
type VirtualInterfaceAttachResult struct {
716721
gophercloud.ErrResult

‎openstack/baremetal/v1/nodes/testing/fixtures_test.go

Copy file name to clipboardExpand all lines: openstack/baremetal/v1/nodes/testing/fixtures_test.go
+35Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -900,6 +900,28 @@ const NodeVirtualMediaAttachBodyWithSource = `
900900
}
901901
`
902902

903+
const NodeVirtualMediaGetBodyAttached = `
904+
{
905+
"image": "https://example.com/image",
906+
"inserted": true,
907+
"media_types": [
908+
"CD",
909+
"DVD"
910+
]
911+
}
912+
`
913+
914+
const NodeVirtualMediaGetBodyNotAttached = `
915+
{
916+
"image": "",
917+
"inserted": false,
918+
"media_types": [
919+
"CD",
920+
"DVD"
921+
]
922+
}
923+
`
924+
903925
var (
904926
createdAtFoo, _ = time.Parse(time.RFC3339, "2019-01-31T19:59:28+00:00")
905927
createdAtBar, _ = time.Parse(time.RFC3339, "2019-01-31T19:59:29+00:00")
@@ -1850,6 +1872,19 @@ func HandleDetachVirtualMediaSuccessfully(t *testing.T, withType bool) {
18501872
})
18511873
}
18521874

1875+
func HandleGetVirtualMediaSuccessfully(t *testing.T, attached bool) {
1876+
th.Mux.HandleFunc("/nodes/1234asdf/vmedia", func(w http.ResponseWriter, r *http.Request) {
1877+
th.TestMethod(t, r, "GET")
1878+
th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
1879+
w.WriteHeader(http.StatusOK)
1880+
if attached {
1881+
fmt.Fprint(w, NodeVirtualMediaGetBodyAttached)
1882+
} else {
1883+
fmt.Fprint(w, NodeVirtualMediaGetBodyNotAttached)
1884+
}
1885+
})
1886+
}
1887+
18531888
// HandleListVirtualInterfacesSuccessfully sets up the test server to respond to a ListVirtualInterfaces request
18541889
func HandleListVirtualInterfacesSuccessfully(t *testing.T) {
18551890
th.Mux.HandleFunc("/nodes/1234asdf/vifs",

‎openstack/baremetal/v1/nodes/testing/requests_test.go

Copy file name to clipboardExpand all lines: openstack/baremetal/v1/nodes/testing/requests_test.go
+20Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -830,6 +830,26 @@ func TestVirtualMediaDetachWithTypes(t *testing.T) {
830830
th.AssertNoErr(t, err)
831831
}
832832

833+
func TestVirtualMediaGetAttached(t *testing.T) {
834+
th.SetupHTTP()
835+
defer th.TeardownHTTP()
836+
HandleGetVirtualMediaSuccessfully(t, true)
837+
838+
c := client.ServiceClient()
839+
err := nodes.GetVirtualMedia(context.TODO(), c, "1234asdf").Err
840+
th.AssertNoErr(t, err)
841+
}
842+
843+
func TestVirtualMediaGetNotAttached(t *testing.T) {
844+
th.SetupHTTP()
845+
defer th.TeardownHTTP()
846+
HandleGetVirtualMediaSuccessfully(t, false)
847+
848+
c := client.ServiceClient()
849+
err := nodes.GetVirtualMedia(context.TODO(), c, "1234asdf").Err
850+
th.AssertNoErr(t, err)
851+
}
852+
833853
func TestListVirtualInterfaces(t *testing.T) {
834854
th.SetupHTTP()
835855
defer th.TeardownHTTP()

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.