Skip to content

Commit 04a5ac4

Browse files
committed
Baremetal: support deploy_steps for the provisioning API
Deploy steps work similarly to clean steps but during deployment. For: #2119
1 parent fec2b51 commit 04a5ac4

3 files changed

Lines changed: 76 additions & 5 deletions

File tree

openstack/baremetal/v1/nodes/requests.go

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -394,15 +394,36 @@ func GetSupportedBootDevices(client *gophercloud.ServiceClient, id string) (r Su
394394
return
395395
}
396396

397+
// An interface type for a deploy (or clean) step.
398+
type StepInterface string
399+
400+
const (
401+
InterfaceBIOS StepInterface = "bios"
402+
InterfaceDeploy StepInterface = "deploy"
403+
InterfaceManagement StepInterface = "management"
404+
InterfacePower StepInterface = "power"
405+
InterfaceRAID StepInterface = "raid"
406+
)
407+
397408
// A cleaning step has required keys ‘interface’ and ‘step’, and optional key ‘args’. If specified,
398409
// the value for ‘args’ is a keyword variable argument dictionary that is passed to the cleaning step
399410
// method.
400411
type CleanStep struct {
401-
Interface string `json:"interface" required:"true"`
412+
Interface StepInterface `json:"interface" required:"true"`
402413
Step string `json:"step" required:"true"`
403414
Args map[string]interface{} `json:"args,omitempty"`
404415
}
405416

417+
// A deploy step has required keys ‘interface’, ‘step’, ’args’ and ’priority’.
418+
// The value for ‘args’ is a keyword variable argument dictionary that is passed to the deploy step
419+
// method. Priority is a numeric priority at which the step is running.
420+
type DeployStep struct {
421+
Interface StepInterface `json:"interface" required:"true"`
422+
Step string `json:"step" required:"true"`
423+
Args map[string]interface{} `json:"args" required:"true"`
424+
Priority int `json:"priority" required:"true"`
425+
}
426+
406427
// ProvisionStateOptsBuilder allows extensions to add additional parameters to the
407428
// ChangeProvisionState request.
408429
type ProvisionStateOptsBuilder interface {
@@ -418,11 +439,12 @@ type ConfigDrive struct {
418439
}
419440

420441
// ProvisionStateOpts for a request to change a node's provision state. A config drive should be base64-encoded
421-
// gzipped ISO9660 image.
442+
// gzipped ISO9660 image. Deploy steps are supported starting with API 1.69.
422443
type ProvisionStateOpts struct {
423444
Target TargetProvisionState `json:"target" required:"true"`
424445
ConfigDrive interface{} `json:"configdrive,omitempty"`
425446
CleanSteps []CleanStep `json:"clean_steps,omitempty"`
447+
DeploySteps []DeployStep `json:"deploy_steps,omitempty"`
426448
RescuePassword string `json:"rescue_password,omitempty"`
427449
}
428450

openstack/baremetal/v1/nodes/testing/fixtures.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -547,6 +547,23 @@ const NodeProvisionStateActiveBody = `
547547
"configdrive": "http://127.0.0.1/images/test-node-config-drive.iso.gz"
548548
}
549549
`
550+
551+
const NodeProvisionStateActiveBodyWithSteps = `
552+
{
553+
"target": "active",
554+
"deploy_steps": [
555+
{
556+
"interface": "deploy",
557+
"step": "inject_files",
558+
"priority": 50,
559+
"args": {
560+
"files": []
561+
}
562+
}
563+
]
564+
}
565+
`
566+
550567
const NodeProvisionStateCleanBody = `
551568
{
552569
"target": "clean",
@@ -937,6 +954,15 @@ func HandleNodeChangeProvisionStateActive(t *testing.T) {
937954
})
938955
}
939956

957+
func HandleNodeChangeProvisionStateActiveWithSteps(t *testing.T) {
958+
th.Mux.HandleFunc("/nodes/1234asdf/states/provision", func(w http.ResponseWriter, r *http.Request) {
959+
th.TestMethod(t, r, "PUT")
960+
th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
961+
th.TestJSONRequest(t, r, NodeProvisionStateActiveBodyWithSteps)
962+
w.WriteHeader(http.StatusAccepted)
963+
})
964+
}
965+
940966
func HandleNodeChangeProvisionStateClean(t *testing.T) {
941967
th.Mux.HandleFunc("/nodes/1234asdf/states/provision", func(w http.ResponseWriter, r *http.Request) {
942968
th.TestMethod(t, r, "PUT")

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

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,29 @@ func TestNodeChangeProvisionStateActive(t *testing.T) {
254254
th.AssertNoErr(t, err)
255255
}
256256

257+
func TestNodeChangeProvisionStateActiveWithSteps(t *testing.T) {
258+
th.SetupHTTP()
259+
defer th.TeardownHTTP()
260+
HandleNodeChangeProvisionStateActiveWithSteps(t)
261+
262+
c := client.ServiceClient()
263+
err := nodes.ChangeProvisionState(c, "1234asdf", nodes.ProvisionStateOpts{
264+
Target: nodes.TargetActive,
265+
DeploySteps: []nodes.DeployStep{
266+
{
267+
Interface: nodes.InterfaceDeploy,
268+
Step: "inject_files",
269+
Priority: 50,
270+
Args: map[string]interface{}{
271+
"files": []interface{}{},
272+
},
273+
},
274+
},
275+
}).ExtractErr()
276+
277+
th.AssertNoErr(t, err)
278+
}
279+
257280
func TestHandleNodeChangeProvisionStateConfigDrive(t *testing.T) {
258281
th.SetupHTTP()
259282
defer th.TeardownHTTP()
@@ -280,7 +303,7 @@ func TestNodeChangeProvisionStateClean(t *testing.T) {
280303
Target: nodes.TargetClean,
281304
CleanSteps: []nodes.CleanStep{
282305
{
283-
Interface: "deploy",
306+
Interface: nodes.InterfaceDeploy,
284307
Step: "upgrade_firmware",
285308
Args: map[string]interface{}{
286309
"force": "True",
@@ -302,7 +325,7 @@ func TestNodeChangeProvisionStateCleanWithConflict(t *testing.T) {
302325
Target: nodes.TargetClean,
303326
CleanSteps: []nodes.CleanStep{
304327
{
305-
Interface: "deploy",
328+
Interface: nodes.InterfaceDeploy,
306329
Step: "upgrade_firmware",
307330
Args: map[string]interface{}{
308331
"force": "True",
@@ -341,7 +364,7 @@ func TestCleanStepRequiresStep(t *testing.T) {
341364
Target: nodes.TargetClean,
342365
CleanSteps: []nodes.CleanStep{
343366
{
344-
Interface: "deploy",
367+
Interface: nodes.InterfaceDeploy,
345368
Args: map[string]interface{}{
346369
"force": "True",
347370
},

0 commit comments

Comments
 (0)