Skip to content

Commit 2c9e9e3

Browse files
committed
domain: Allow overriding RNG device through env
On some systems (e.g Ubuntu-using travis runner), `/dev/urandom` isn't available it seems to let's allow overriding the RNG device through an environment variable, `TF_LIBVIRT_RNG_DEV`.
1 parent 0b6e43b commit 2c9e9e3

File tree

2 files changed

+22
-8
lines changed

2 files changed

+22
-8
lines changed

CONTRIBUTING.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,13 @@ variable:
7474
LIBVIRT_DEFAULT_URI='qemu+unix:///session' TF_LIBVIRT_DISABLE_PRIVILEGED_TESTS=1 make testacc
7575
```
7676

77+
If '/dev/random' is not available on the platform you run the acceptance tests on, you can override the device used
78+
through an environment variable as well:
79+
80+
```bash
81+
TF_LIBVIRT_RNG_DEV='/dev/random' make testacc
82+
```
83+
7784
### Code coverage:
7885

7986
Run first the testacc suite.

libvirt/domain_def.go

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -69,14 +69,6 @@ func newDomainDef() libvirtxml.Domain {
6969
},
7070
},
7171
},
72-
RNGs: []libvirtxml.DomainRNG{
73-
{
74-
Model: "virtio",
75-
Backend: &libvirtxml.DomainRNGBackend{
76-
Random: &libvirtxml.DomainRNGBackendRandom{Device: "/dev/urandom"},
77-
},
78-
},
79-
},
8072
},
8173
Features: &libvirtxml.DomainFeatureList{
8274
PAE: &libvirtxml.DomainFeature{},
@@ -91,6 +83,21 @@ func newDomainDef() libvirtxml.Domain {
9183
domainDef.Type = "kvm"
9284
}
9385

86+
// FIXME: We should allow setting this from configuration as well.
87+
rngDev := os.Getenv("TF_LIBVIRT_RNG_DEV")
88+
if rngDev == "" {
89+
rngDev = "/dev/urandom"
90+
}
91+
92+
domainDef.Devices.RNGs = []libvirtxml.DomainRNG{
93+
{
94+
Model: "virtio",
95+
Backend: &libvirtxml.DomainRNGBackend{
96+
Random: &libvirtxml.DomainRNGBackendRandom{Device: rngDev},
97+
},
98+
},
99+
}
100+
94101
return domainDef
95102
}
96103

0 commit comments

Comments
 (0)