Skip to content

Commit b56a61c

Browse files
jimnydevdpap-qsdmacvicar
authored
feat: lvm storage pool impl (#1088)
* feat: lvm storage pool impl This feature also adds support for target and source blocks in pool. Deprecating the old top-level path, and opening the door for supporting more pool backends, following libvirt description closer. - refactor the lvm pool implementation - add proper source and target so we can add more pool implementations later - handle deprecation of top level path properly - less checks, lets libvirt handle it - add acceptance tests - refactor the test helper block device creation out of domain - add docs - skip the tests if the host does not support logical pools - skip early if acceptance tests are disabled * fix: dir path is actually on target, not source * add name attribute to pool source * cleanup support for existing vg * move code to configure provider to common function --------- Co-authored-by: dpap <[email protected]> Co-authored-by: Duncan Mac-Vicar P. <[email protected]> Co-authored-by: Boris Momčilović <[email protected]>
1 parent 72a3214 commit b56a61c

File tree

10 files changed

+590
-127
lines changed

10 files changed

+590
-127
lines changed

go.mod

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ require (
2828
github.com/coreos/go-systemd/v22 v22.0.0 // indirect
2929
github.com/coreos/ignition/v2 v2.14.0 // indirect
3030
github.com/coreos/vcontext v0.0.0-20211021162308-f1dbbca7bef4 // indirect
31+
github.com/diskfs/go-diskfs v1.4.2 // indirect
32+
github.com/djherbis/times v1.6.0 // indirect
33+
github.com/elliotwutingfeng/asciiset v0.0.0-20230602022725-51bbb787efab // indirect
3134
github.com/fatih/color v1.17.0 // indirect
3235
github.com/golang/protobuf v1.5.4 // indirect
3336
github.com/google/go-cmp v0.6.0 // indirect
@@ -52,6 +55,7 @@ require (
5255
github.com/hashicorp/terraform-svchost v0.1.1 // indirect
5356
github.com/hashicorp/yamux v0.1.1 // indirect
5457
github.com/hooklift/assert v0.0.0-20170704181755-9d1defd6d214 // indirect
58+
github.com/klauspost/compress v1.17.4 // indirect
5559
github.com/mattn/go-colorable v0.1.13 // indirect
5660
github.com/mattn/go-isatty v0.0.20 // indirect
5761
github.com/mitchellh/copystructure v1.2.0 // indirect
@@ -60,8 +64,12 @@ require (
6064
github.com/mitchellh/mapstructure v1.5.0 // indirect
6165
github.com/mitchellh/reflectwalk v1.0.2 // indirect
6266
github.com/oklog/run v1.1.0 // indirect
67+
github.com/pierrec/lz4/v4 v4.1.17 // indirect
6368
github.com/pkg/errors v0.9.1 // indirect
69+
github.com/pkg/xattr v0.4.9 // indirect
6470
github.com/pmezard/go-difflib v1.0.0 // indirect
71+
github.com/sirupsen/logrus v1.9.4-0.20230606125235-dd1b4c2e81af // indirect
72+
github.com/ulikunitz/xz v0.5.11 // indirect
6573
github.com/vincent-petithory/dataurl v1.0.0 // indirect
6674
github.com/vmihailenco/msgpack v4.0.4+incompatible // indirect
6775
github.com/vmihailenco/msgpack/v4 v4.3.12 // indirect
@@ -88,7 +96,7 @@ replace git.apache.org/thrift.git => github.com/apache/thrift v0.0.0-20180902110
8896

8997
replace golang.org/x/crypto v0.0.0-20220112180741-5e0467b6c7ce => github.com/dmacvicar/golang-x-crypto v0.0.0-20220126233154-a96af8f07497
9098

91-
go 1.22.0
99+
go 1.23
92100

93101
toolchain go1.23.1
94102

go.sum

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,14 @@ github.com/digitalocean/go-libvirt v0.0.0-20221205150000-2939327a8519 h1:OpkN/n4
109109
github.com/digitalocean/go-libvirt v0.0.0-20221205150000-2939327a8519/go.mod h1:WyJJyfmJ0gWJvjV+ZH4DOgtOYZc1KOvYyBXWCLKxsUU=
110110
github.com/digitalocean/go-libvirt v0.0.0-20240916165608-bff44a349d9d h1:3lleylIw0Dvrlff8+3c+xp0MboNcRz9tMinZNeiGFpc=
111111
github.com/digitalocean/go-libvirt v0.0.0-20240916165608-bff44a349d9d/go.mod h1:+tYha+y/luhAZImNm1TtQjBE2NWEtP5HDLyE5XG+RNA=
112+
github.com/diskfs/go-diskfs v1.4.2 h1:khBr9RTkqAZFaMYK7PP8NooL30hqj3bSgRmj3Ouguls=
113+
github.com/diskfs/go-diskfs v1.4.2/go.mod h1:ss1uAUBhgDdEOewZFDWWpYqJFjNPbK7hYSjRoQE+D94=
114+
github.com/djherbis/times v1.6.0 h1:w2ctJ92J8fBvWPxugmXIv7Nz7Q3iDMKNx9v5ocVH20c=
115+
github.com/djherbis/times v1.6.0/go.mod h1:gOHeRAz2h+VJNZ5Gmc/o7iD9k4wW7NMVqieYCY99oc0=
112116
github.com/dmacvicar/terraform-provider-ignition/v2 v2.1.3-0.20210701165004-13acf61ca184 h1:z9nAMxjTxJXAOmGWMvW5SS0xUwCEJNVjfTesp+07ynE=
113117
github.com/dmacvicar/terraform-provider-ignition/v2 v2.1.3-0.20210701165004-13acf61ca184/go.mod h1:pToe90z63vSP7LIYtZ85Q+g88WvRmdNsg73YZYJZg64=
118+
github.com/elliotwutingfeng/asciiset v0.0.0-20230602022725-51bbb787efab h1:h1UgjJdAAhj+uPL68n7XASS6bU+07ZX1WJvVS2eyoeY=
119+
github.com/elliotwutingfeng/asciiset v0.0.0-20230602022725-51bbb787efab/go.mod h1:GLo/8fDswSAniFG+BFIaiSPcK610jyzgEhWYPQwuQdw=
114120
github.com/emirpasic/gods v1.12.0 h1:QAUIPSaCu4G+POclxeqb3F+WPpdKqFGlw36+yOzGlrg=
115121
github.com/emirpasic/gods v1.12.0/go.mod h1:YfzfFFoVP/catgzJb4IKIqXjX78Ha8FMSDh3ymbK86o=
116122
github.com/envoyproxy/go-control-plane v0.9.0/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4=
@@ -144,6 +150,7 @@ github.com/go-sql-driver/mysql v1.5.0/go.mod h1:DCzpHaOWr8IXmIStZouvnhqoel9Qv2LB
144150
github.com/go-test/deep v1.0.3/go.mod h1:wGDj63lr65AM2AQyKZd/NYHGb0R+1RLqB8NKt3aSFNA=
145151
github.com/go-test/deep v1.0.4 h1:u2CU3YKy9I2pmu9pX0eq50wCgjfGIt539SqR7FbHiho=
146152
github.com/go-test/deep v1.0.4/go.mod h1:wGDj63lr65AM2AQyKZd/NYHGb0R+1RLqB8NKt3aSFNA=
153+
github.com/go-test/deep v1.0.8 h1:TDsG77qcSprGbC6vTN8OuXp5g+J+b5Pcguhf7Zt61VM=
147154
github.com/godbus/dbus/v5 v5.0.3/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA=
148155
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q=
149156
github.com/golang/groupcache v0.0.0-20190702054246-869f871628b6/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc=
@@ -345,6 +352,8 @@ github.com/kevinburke/ssh_config v1.2.0/go.mod h1:CT57kijsi8u/K/BOFA39wgDQJ9CxiF
345352
github.com/keybase/go-crypto v0.0.0-20161004153544-93f5b35093ba/go.mod h1:ghbZscTyKdM07+Fw3KSi0hcJm+AlEUWj8QLlPtijN/M=
346353
github.com/kisielk/errcheck v1.2.0/go.mod h1:/BMXB+zMLi60iA8Vv6Ksmxu/1UDYcXs4uQLJ+jE2L00=
347354
github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck=
355+
github.com/klauspost/compress v1.17.4 h1:Ej5ixsIri7BrIjBkRZLTo6ghwrEtHFk7ijlczPW4fZ4=
356+
github.com/klauspost/compress v1.17.4/go.mod h1:/dCuZOvVtNoHsyb+cuJD3itjs3NbnF6KH9zAO4BDxPM=
348357
github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
349358
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
350359
github.com/kr/pretty v0.2.1 h1:Fmg33tUaq4/8ym9TJN1x7sLJnHVwhP33CNkpYV/7rwI=
@@ -412,11 +421,16 @@ github.com/nsf/jsondiff v0.0.0-20200515183724-f29ed568f4ce/go.mod h1:uFMI8w+ref4
412421
github.com/oklog/run v1.0.0/go.mod h1:dlhp/R75TPv97u0XWUtDeV/lRKWPKSdTuV0TZvrmrQA=
413422
github.com/oklog/run v1.1.0 h1:GEenZ1cK0+q0+wsJew9qUg/DyD8k3JzYsZAi5gYi2mA=
414423
github.com/oklog/run v1.1.0/go.mod h1:sVPdnTZT1zYwAJeCMu2Th4T21pA3FPOQRfWjQlk7DVU=
424+
github.com/pierrec/lz4 v2.0.5+incompatible h1:2xWsjqPFWcplujydGg4WmhC/6fZqK42wMM8aXeqhl0I=
415425
github.com/pierrec/lz4 v2.0.5+incompatible/go.mod h1:pdkljMzZIN41W+lC3N2tnIh5sFi+IEE17M5jbnwPHcY=
426+
github.com/pierrec/lz4/v4 v4.1.17 h1:kV4Ip+/hUBC+8T6+2EgburRtkE9ef4nbY3f4dFhGjMc=
427+
github.com/pierrec/lz4/v4 v4.1.17/go.mod h1:gZWDp/Ze/IJXGXf23ltt2EXimqmTUXEy0GFuRQyBid4=
416428
github.com/pin/tftp v2.1.0+incompatible/go.mod h1:xVpZOMCXTy+A5QMjEVN0Glwa1sUvaJhFXbr/aAxuxGY=
417429
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
418430
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
419431
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
432+
github.com/pkg/xattr v0.4.9 h1:5883YPCtkSd8LFbs13nXplj9g9tlrwoJRjgpgMu1/fE=
433+
github.com/pkg/xattr v0.4.9/go.mod h1:di8WF84zAKk8jzR1UBTEWh9AUlIZZ7M/JNt8e9B6ktU=
420434
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
421435
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
422436
github.com/posener/complete v1.1.1/go.mod h1:em0nMJCgc9GFtwrmVmEMR/ZL6WyhyjMBndrE9hABlRI=
@@ -427,6 +441,8 @@ github.com/sergi/go-diff v1.0.0/go.mod h1:0CfEIISq7TuYL3j771MWULgwwjU+GofnZX9QAm
427441
github.com/sergi/go-diff v1.1.0/go.mod h1:STckp+ISIX8hZLjrqAeVduY0gWCT9IjLuqbuNXdaHfM=
428442
github.com/sergi/go-diff v1.2.0 h1:XU+rvMAioB0UC3q1MFrIQy4Vo5/4VsRDQQXHsEya6xQ=
429443
github.com/sirupsen/logrus v1.4.1/go.mod h1:ni0Sbl8bgC9z8RoU9G6nDWqqs/fq4eDPysMBDgk/93Q=
444+
github.com/sirupsen/logrus v1.9.4-0.20230606125235-dd1b4c2e81af h1:Sp5TG9f7K39yfB+If0vjp97vuT74F72r8hfRpP8jLU0=
445+
github.com/sirupsen/logrus v1.9.4-0.20230606125235-dd1b4c2e81af/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ=
430446
github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d/go.mod h1:OnSkiWE9lh6wB0YB77sQom3nweQdgAjqCqsofrRNTgc=
431447
github.com/smartystreets/goconvey v0.0.0-20190222223459-a17d461953aa/go.mod h1:2RVY1rIf+2J2o/IM9+vPq9RzmHDSseB7FoXiSNIUsoU=
432448
github.com/spf13/pflag v1.0.2/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4=
@@ -450,6 +466,8 @@ github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsT
450466
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
451467
github.com/ulikunitz/xz v0.5.5/go.mod h1:2bypXElzHzzJZwzH67Y6wb67pO62Rzfn7BSiF4ABRW8=
452468
github.com/ulikunitz/xz v0.5.8/go.mod h1:nbz6k7qbPmH4IRqmfOplQw/tblSgqTqBwxkY0oWt/14=
469+
github.com/ulikunitz/xz v0.5.11 h1:kpFauv27b6ynzBNT/Xy+1k+fK4WswhN/6PN5WhFAGw8=
470+
github.com/ulikunitz/xz v0.5.11/go.mod h1:nbz6k7qbPmH4IRqmfOplQw/tblSgqTqBwxkY0oWt/14=
453471
github.com/vincent-petithory/dataurl v0.0.0-20160330182126-9a301d65acbb/go.mod h1:FHafX5vmDzyP+1CQATJn7WFKc9CvnvxyvZy6I1MrG/U=
454472
github.com/vincent-petithory/dataurl v0.0.0-20191104211930-d1553a71de50/go.mod h1:FHafX5vmDzyP+1CQATJn7WFKc9CvnvxyvZy6I1MrG/U=
455473
github.com/vincent-petithory/dataurl v1.0.0 h1:cXw+kPto8NLuJtlMsI152irrVw9fRDX8AbShPRpg2CI=
@@ -650,8 +668,11 @@ golang.org/x/sys v0.0.0-20210502180810-71e4cd670f79/go.mod h1:h1NjWce9XRLGQEsW7w
650668
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
651669
golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
652670
golang.org/x/sys v0.0.0-20210927094055-39ccf1dd6fa6/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
671+
golang.org/x/sys v0.0.0-20220408201424-a24fb2fb8a0f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
653672
golang.org/x/sys v0.0.0-20220503163025-988cb79eb6c6/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
654673
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
674+
golang.org/x/sys v0.0.0-20220615213510-4f61da869c0c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
675+
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
655676
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
656677
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
657678
golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
Lines changed: 178 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,178 @@
1+
package test
2+
3+
import (
4+
"fmt"
5+
"log"
6+
"os"
7+
"os/exec"
8+
"path/filepath"
9+
"strings"
10+
"testing"
11+
)
12+
13+
type TempBlockDevice struct {
14+
TempFile string
15+
LoopDevice string
16+
}
17+
18+
// returns the temporary file, the device path and the error.
19+
func CreateTempFormattedLoopDevice(t *testing.T, name string) (*TempBlockDevice, error) {
20+
blockDev, err := CreateTempLoopDevice(t, name)
21+
if err != nil {
22+
return nil, err
23+
}
24+
25+
//nolint:gosec
26+
cmd := exec.Command("/sbin/mkfs.ext4", "-F", "-q", blockDev.LoopDevice)
27+
log.Printf("[DEBUG] executing command: %s", strings.Join(cmd.Args, " "))
28+
if err := cmd.Run(); err != nil {
29+
if err := cleanupLoop(blockDev.LoopDevice); err != nil {
30+
return nil, err
31+
}
32+
33+
if err := cleanupFile(blockDev.TempFile); err != nil {
34+
return nil, err
35+
}
36+
37+
return nil, fmt.Errorf("error formatting file system: %w", err)
38+
}
39+
40+
return blockDev, nil
41+
}
42+
43+
// returns the temporary file, the device and the error.
44+
func CreateTempLVMGroupDevice(t *testing.T, name string) (*TempBlockDevice, error) {
45+
blockDev, err := CreateTempLoopDevice(t, name)
46+
if err != nil {
47+
return nil, err
48+
}
49+
50+
//nolint:gosec
51+
cmd := exec.Command("sudo", "pvcreate", blockDev.LoopDevice)
52+
log.Printf("[DEBUG] executing command: %s", strings.Join(cmd.Args, " "))
53+
if err := cmd.Run(); err != nil {
54+
if err := cleanupLoop(blockDev.LoopDevice); err != nil {
55+
return nil, err
56+
}
57+
58+
if err := cleanupFile(blockDev.TempFile); err != nil {
59+
return nil, err
60+
}
61+
62+
return nil, fmt.Errorf("error creating LVM partition on %s: %w", blockDev.LoopDevice, err)
63+
}
64+
65+
//nolint:gosec
66+
cmd = exec.Command("sudo", "vgcreate", name, blockDev.LoopDevice)
67+
log.Printf("[DEBUG] executing command: %s", strings.Join(cmd.Args, " "))
68+
if err := cmd.Run(); err != nil {
69+
if err := cleanupLoop(blockDev.LoopDevice); err != nil {
70+
return nil, err
71+
}
72+
73+
if err := cleanupFile(blockDev.TempFile); err != nil {
74+
return nil, err
75+
}
76+
77+
return nil, fmt.Errorf("error creating LVM partition on %s: %w", blockDev.LoopDevice, err)
78+
}
79+
80+
return blockDev, nil
81+
}
82+
83+
// returns the temporary file, the device and the error.
84+
func CreateTempLoopDevice(t *testing.T, name string) (*TempBlockDevice, error) {
85+
log.Print("[DEBUG] creating a temporary file for loop device")
86+
87+
// Create a 1MB temp file
88+
filename := filepath.Join(t.TempDir(), name)
89+
90+
//nolint:gosec
91+
cmd := exec.Command("dd", "if=/dev/zero", fmt.Sprintf("of=%s", filename), "bs=1024", "count=2048")
92+
log.Printf("[DEBUG] executing command: %s\n", strings.Join(cmd.Args, " "))
93+
if err := cmd.Run(); err != nil {
94+
if err := cleanupFile(filename); err != nil {
95+
return nil, err
96+
}
97+
98+
return nil, fmt.Errorf("Error creating file %s: %w", filename, err)
99+
}
100+
101+
// Find an available loop device.
102+
cmd = exec.Command("sudo", "/sbin/losetup", "--find")
103+
loopdevStr, err := cmd.Output()
104+
log.Printf("[DEBUG] executing command: %s", strings.Join(cmd.Args, " "))
105+
if err != nil {
106+
if err := cleanupFile(filename); err != nil {
107+
return nil, err
108+
}
109+
110+
return nil, fmt.Errorf("Error searching for available loop device: %w", err)
111+
}
112+
loopdev := filepath.Clean(strings.TrimRight(string(loopdevStr), "\n"))
113+
114+
// give the same permissions to the loop device as the backing file.
115+
cmd = exec.Command("sudo", "chown", "--reference", filename, loopdev)
116+
log.Printf("[DEBUG] executing command: %s", strings.Join(cmd.Args, " "))
117+
if err := cmd.Run(); err != nil {
118+
if err := cleanupFile(filename); err != nil {
119+
return nil, err
120+
}
121+
122+
return nil, fmt.Errorf("Error copying permissions from %s: %w", filename, err)
123+
}
124+
125+
// attach the file to a loop device.
126+
cmd = exec.Command("sudo", "/sbin/losetup", loopdev, filename)
127+
log.Printf("[DEBUG] executing command: %s", strings.Join(cmd.Args, " "))
128+
if err := cmd.Run(); err != nil {
129+
if err := cleanupFile(filename); err != nil {
130+
return nil, err
131+
}
132+
133+
return nil, fmt.Errorf("Error setting up loop device: %w", err)
134+
}
135+
136+
log.Printf("[DEBUG] temporary file %s attached to loop device %s", filename, loopdev)
137+
138+
return &TempBlockDevice{TempFile: filename, LoopDevice: loopdev}, nil
139+
}
140+
141+
func (b *TempBlockDevice) Cleanup() error {
142+
err := cleanupLoop(b.LoopDevice)
143+
if err != nil {
144+
return err
145+
}
146+
147+
err = cleanupFile(b.TempFile)
148+
if err != nil {
149+
return err
150+
}
151+
152+
return nil
153+
}
154+
155+
func cleanupLoop(loopDevice string) error {
156+
cmd := exec.Command("sudo", "losetup", "-d", loopDevice)
157+
if err := cmd.Run(); err != nil {
158+
log.Printf("[DEBUG] error detaching loop device %s: %s", loopDevice, err)
159+
return err
160+
}
161+
log.Printf("[DEBUG] detaching loop device %s", loopDevice)
162+
163+
return nil
164+
}
165+
166+
func cleanupFile(tempFile string) error {
167+
if err := os.Remove(tempFile); err != nil {
168+
log.Printf("[DEBUG] error removing temporary file %s: %s", tempFile, err)
169+
return err
170+
}
171+
log.Printf("[DEBUG] removing temporary file %s", tempFile)
172+
173+
return nil
174+
}
175+
176+
func (b *TempBlockDevice) String() string {
177+
return fmt.Sprintf("TempFile: %s, LoopDevice: %s", b.TempFile, b.LoopDevice)
178+
}

libvirt/pool.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ func poolExistsStateRefreshFunc(virConn *libvirt.Libvirt, uuid libvirt.UUID) ret
1818
_, err := virConn.StoragePoolLookupByUUID(uuid)
1919
if err != nil {
2020
if isError(err, libvirt.ErrNoStoragePool) {
21-
log.Printf("pool %s does not exist", uuid)
21+
log.Printf("pool %v does not exist", uuidString(uuid))
2222
return virConn, poolStateConfNotExists, nil
2323
}
2424
return virConn, poolStateConfNotExists, err
@@ -28,7 +28,7 @@ func poolExistsStateRefreshFunc(virConn *libvirt.Libvirt, uuid libvirt.UUID) ret
2828
}
2929

3030
func waitForStatePoolExists(ctx context.Context, virConn *libvirt.Libvirt, uuid libvirt.UUID) error {
31-
log.Printf("Waiting for pool %s to appear...", uuid)
31+
log.Printf("Waiting for pool %v to appear...", uuidString(uuid))
3232
stateConf := &retry.StateChangeConf{
3333
Pending: []string{poolStateConfNotExists},
3434
Target: []string{poolStateConfExists},
@@ -46,7 +46,7 @@ func waitForStatePoolExists(ctx context.Context, virConn *libvirt.Libvirt, uuid
4646

4747
// waitForStatePoolDeleted waits for a storage pool to be removed.
4848
func waitForStatePoolDeleted(ctx context.Context, virConn *libvirt.Libvirt, uuid libvirt.UUID) error {
49-
log.Printf("waiting for pool %s to be deleted...", uuid)
49+
log.Printf("waiting for pool %v to be deleted...", uuidString(uuid))
5050
stateConf := &retry.StateChangeConf{
5151
Pending: []string{poolStateConfExists},
5252
Target: []string{poolStateConfNotExists},

libvirt/pool_def.go

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package libvirt
2+
3+
import (
4+
"encoding/xml"
5+
6+
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
7+
8+
"github.com/digitalocean/go-libvirt"
9+
"libvirt.org/go/libvirtxml"
10+
)
11+
12+
func newDefPoolFromLibvirt(virConn *libvirt.Libvirt, pool libvirt.StoragePool) (libvirtxml.StoragePool, diag.Diagnostics) {
13+
poolDefXML, err := virConn.StoragePoolGetXMLDesc(pool, 0)
14+
if err != nil {
15+
return libvirtxml.StoragePool{}, diag.Errorf("could not get XML description for pool %s: %s", pool.Name, err)
16+
}
17+
poolDef, err := newDefPoolFromXML(poolDefXML)
18+
if err != nil {
19+
return libvirtxml.StoragePool{}, diag.Errorf("could not get a pool definition from XML for %s: %s", pool.Name, err)
20+
}
21+
return poolDef, nil
22+
}
23+
24+
func newDefPoolFromXML(s string) (libvirtxml.StoragePool, error) {
25+
var poolDef libvirtxml.StoragePool
26+
err := xml.Unmarshal([]byte(s), &poolDef)
27+
if err != nil {
28+
return libvirtxml.StoragePool{}, err
29+
}
30+
return poolDef, nil
31+
}

0 commit comments

Comments
 (0)