Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Baremetal virtual media Get API #3303

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Mar 11, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion internal/acceptance/openstack/baremetal/v1/nodes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Although, it does look like you have updated it, so my confidence on that is low.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, the issue is driver related, the test is using ipmi but the feature only supports redfish. I'm looking into fixing it.


node, err := CreateNode(t, client)
th.AssertNoErr(t, err)
Expand All @@ -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) {
Expand Down
12 changes: 12 additions & 0 deletions openstack/baremetal/v1/nodes/requests.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions openstack/baremetal/v1/nodes/results.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
35 changes: 35 additions & 0 deletions openstack/baremetal/v1/nodes/testing/fixtures_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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",
Expand Down
20 changes: 20 additions & 0 deletions openstack/baremetal/v1/nodes/testing/requests_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
Loading