Skip to content

Commit

Permalink
(Failed) attempt to fix this by applying blocked operations during xe…
Browse files Browse the repository at this point in the history
…nstore data handling

Signed-off-by: Dom Del Nano <ddelnano@gmail.com>
  • Loading branch information
ddelnano committed Mar 20, 2024
1 parent 3fab225 commit 546f613
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 10 deletions.
20 changes: 10 additions & 10 deletions client/vm.go
Original file line number Diff line number Diff line change
Expand Up @@ -322,14 +322,6 @@ func (c *Client) CreateVm(vmReq Vm, createTime time.Duration) (*Vm, error) {
params["startDelay"] = startDelay
}

if len(vmReq.BlockedOperations) > 0 {
blockedOperations := map[string]string{}
for _, v := range vmReq.BlockedOperations {
blockedOperations[v] = "true"
}
params["blockedOperations"] = blockedOperations
}

if installation.Method != "" {
params["installation"] = map[string]string{
"method": installation.Method,
Expand Down Expand Up @@ -361,12 +353,20 @@ func (c *Client) CreateVm(vmReq Vm, createTime time.Duration) (*Vm, error) {
return nil, err
}

xsParams := map[string]interface{}{
postCreateParams := map[string]interface{}{
"id": vmId,
"xenStoreData": vmReq.XenstoreData,
}
if len(vmReq.BlockedOperations) > 0 {
blockedOperations := map[string]string{}
for _, v := range vmReq.BlockedOperations {
blockedOperations[v] = "true"
}
postCreateParams["blockedOperations"] = blockedOperations
}

var success bool
err = c.Call("vm.set", xsParams, &success)
err = c.Call("vm.set", postCreateParams, &success)

if err != nil {
return nil, err
Expand Down
25 changes: 25 additions & 0 deletions xoa/resource_xenorchestra_vm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1470,6 +1470,31 @@ func TestAccXenorchestraVm_replaceExistingVifs(t *testing.T) {
})
}

func TestAccXenorchestraVm_createAllowsBlockedOperations(t *testing.T) {
resourceName := "xenorchestra_vm.bar"
vmName := fmt.Sprintf("%s - %s", accTestPrefix, t.Name())
resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckXenorchestraVmDestroy,
Steps: []resource.TestStep{
{
Config: testAccVmConfigUpdateAttr(
vmName,
`
blocked_operations = ["copy"]
`),
Check: resource.ComposeAggregateTestCheckFunc(
testAccVmExists(resourceName),
resource.TestCheckResourceAttrSet(resourceName, "id"),
resource.TestCheckResourceAttr(resourceName, "blocked_operations.#", "1"),
resource.TestCheckResourceAttr(resourceName, "blocked_operations.0", "copy"),
),
},
},
})
}

func TestAccXenorchestraVm_updatesWithoutReboot(t *testing.T) {
resourceName := "xenorchestra_vm.bar"

Expand Down

0 comments on commit 546f613

Please sign in to comment.