diff --git a/internal/acceptance/openstack/baremetal/v1/nodes_test.go b/internal/acceptance/openstack/baremetal/v1/nodes_test.go index 1151135e62..be48ee9197 100644 --- a/internal/acceptance/openstack/baremetal/v1/nodes_test.go +++ b/internal/acceptance/openstack/baremetal/v1/nodes_test.go @@ -219,7 +219,7 @@ func TestNodesVirtualMedia(t *testing.T) { client, err := clients.NewBareMetalV1Client() th.AssertNoErr(t, err) - client.Microversion = "1.89" + client.Microversion = "1.93" node, err := CreateNode(t, client) th.AssertNoErr(t, err) @@ -241,6 +241,15 @@ func TestNodesVirtualMedia(t *testing.T) { err = nodes.DetachVirtualMedia(context.TODO(), client, node.UUID, nodes.DetachVirtualMediaOpts{}).ExtractErr() th.AssertNoErr(t, err) + + err = nodes.GetVirtualMedia(context.TODO(), client, node.UUID).Err + // Since Virtual Media GET api call is synchronous, we get a HTTP 400 + // response as CreateNode has ipmi driver hardcoded, but the api is + // only supported by the redfish driver + // (TODO: hroyrh) fix this once redfish driver is used in the tests + if node.Driver == "redfish" { + th.AssertNoErr(t, err) + } } func TestNodesServicingHold(t *testing.T) { diff --git a/openstack/baremetal/v1/nodes/requests.go b/openstack/baremetal/v1/nodes/requests.go index cddd269a3d..6268f5037e 100644 --- a/openstack/baremetal/v1/nodes/requests.go +++ b/openstack/baremetal/v1/nodes/requests.go @@ -1003,6 +1003,18 @@ func DetachVirtualMedia(ctx context.Context, client *gophercloud.ServiceClient, return } +// Request the list of virtual media devices attached to the Node. +// Requires microversion 1.93 or later. +func GetVirtualMedia(ctx context.Context, client *gophercloud.ServiceClient, id string) (r VirtualMediaGetResult) { + + resp, err := client.Get(ctx, virtualMediaURL(client, id), &r.Body, &gophercloud.RequestOpts{ + OkCodes: []int{200}, + }) + + _, r.Header, r.Err = gophercloud.ParseResponse(resp, err) + return +} + // VirtualInterfaceOpts defines options for attaching a VIF to a node type VirtualInterfaceOpts struct { // The UUID or name of the VIF diff --git a/openstack/baremetal/v1/nodes/results.go b/openstack/baremetal/v1/nodes/results.go index 3e1976d3ef..b33517a388 100644 --- a/openstack/baremetal/v1/nodes/results.go +++ b/openstack/baremetal/v1/nodes/results.go @@ -711,6 +711,11 @@ type VirtualMediaDetachResult struct { gophercloud.ErrResult } +// Requires microversion 1.93 or later. +type VirtualMediaGetResult struct { + gophercloud.Result +} + // VirtualInterfaceAttachResult is the response from an AttachVirtualInterface operation. type VirtualInterfaceAttachResult struct { gophercloud.ErrResult diff --git a/openstack/baremetal/v1/nodes/testing/fixtures_test.go b/openstack/baremetal/v1/nodes/testing/fixtures_test.go index 282d5dbc7f..371a4f00a9 100644 --- a/openstack/baremetal/v1/nodes/testing/fixtures_test.go +++ b/openstack/baremetal/v1/nodes/testing/fixtures_test.go @@ -900,6 +900,28 @@ const NodeVirtualMediaAttachBodyWithSource = ` } ` +const NodeVirtualMediaGetBodyAttached = ` +{ + "image": "https://example.com/image", + "inserted": true, + "media_types": [ + "CD", + "DVD" + ] +} +` + +const NodeVirtualMediaGetBodyNotAttached = ` +{ + "image": "", + "inserted": false, + "media_types": [ + "CD", + "DVD" + ] +} +` + var ( createdAtFoo, _ = time.Parse(time.RFC3339, "2019-01-31T19:59:28+00:00") createdAtBar, _ = time.Parse(time.RFC3339, "2019-01-31T19:59:29+00:00") @@ -1850,6 +1872,19 @@ func HandleDetachVirtualMediaSuccessfully(t *testing.T, withType bool) { }) } +func HandleGetVirtualMediaSuccessfully(t *testing.T, attached bool) { + th.Mux.HandleFunc("/nodes/1234asdf/vmedia", func(w http.ResponseWriter, r *http.Request) { + th.TestMethod(t, r, "GET") + th.TestHeader(t, r, "X-Auth-Token", client.TokenID) + w.WriteHeader(http.StatusOK) + if attached { + fmt.Fprint(w, NodeVirtualMediaGetBodyAttached) + } else { + fmt.Fprint(w, NodeVirtualMediaGetBodyNotAttached) + } + }) +} + // HandleListVirtualInterfacesSuccessfully sets up the test server to respond to a ListVirtualInterfaces request func HandleListVirtualInterfacesSuccessfully(t *testing.T) { th.Mux.HandleFunc("/nodes/1234asdf/vifs", diff --git a/openstack/baremetal/v1/nodes/testing/requests_test.go b/openstack/baremetal/v1/nodes/testing/requests_test.go index 487c350175..24452be0c2 100644 --- a/openstack/baremetal/v1/nodes/testing/requests_test.go +++ b/openstack/baremetal/v1/nodes/testing/requests_test.go @@ -830,6 +830,26 @@ func TestVirtualMediaDetachWithTypes(t *testing.T) { th.AssertNoErr(t, err) } +func TestVirtualMediaGetAttached(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + HandleGetVirtualMediaSuccessfully(t, true) + + c := client.ServiceClient() + err := nodes.GetVirtualMedia(context.TODO(), c, "1234asdf").Err + th.AssertNoErr(t, err) +} + +func TestVirtualMediaGetNotAttached(t *testing.T) { + th.SetupHTTP() + defer th.TeardownHTTP() + HandleGetVirtualMediaSuccessfully(t, false) + + c := client.ServiceClient() + err := nodes.GetVirtualMedia(context.TODO(), c, "1234asdf").Err + th.AssertNoErr(t, err) +} + func TestListVirtualInterfaces(t *testing.T) { th.SetupHTTP() defer th.TeardownHTTP()