Skip to content

Commit 753afd8

Browse files
authored
Merge pull request #600 from zeenix/fix-ci-tests
Bring back acceptance-tests to CI
2 parents 68c8d11 + 92d4ea8 commit 753afd8

11 files changed

+339
-72
lines changed

.travis.yml

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,31 @@
1-
dist: trusty
1+
dist: xenial
22
sudo: false
33
language: go
44
go:
55
- 1.11.x
66
env:
7-
- GO111MODULE=on GOFLAGS=-mod=vendor
7+
- GO111MODULE=on GOFLAGS=-mod=vendor LIBVIRT_DEFAULT_URI='qemu+unix:///session' TF_LIBVIRT_DISABLE_PRIVILEGED_TESTS=1 TF_LIBVIRT_RNG_DEV='/dev/random' TF_LOG=DEBUG
88
git:
99
depth: 1
1010
go_import_path: github.com/dmacvicar/terraform-provider-libvirt
1111
install: true
1212
before_script:
1313
- curl -sLo /tmp/terraform.zip https://releases.hashicorp.com/terraform/0.12.0/terraform_0.12.0_linux_amd64.zip
1414
- sudo unzip /tmp/terraform.zip -d /usr/local/bin
15+
- sudo bash ./travis/setup-host
1516
addons:
1617
apt:
1718
packages:
1819
- libvirt-dev
20+
- libvirt-daemon
21+
- qemu-system-x86
22+
- qemu-utils
23+
- genisoimage
1924
- xsltproc
2025
script:
2126
- make fmt-check
2227
- make vet-check
2328
- make lint-check
2429
- make tf-check
2530
- make test
31+
- make testacc TEST_ARGS="-test.failfast"

CONTRIBUTING.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,20 @@ Or run a group of test with a verbose loglevel:
6767
TF_LOG=DEBUG make testacc TEST_ARGS="-run TestAccLibvirtNet*"
6868
```
6969

70+
If you run the tests on an unprivileged connection (e.g session libvirt), some of the acceptance tests will need to be disabled (mainly the networking ones) through an environment
71+
variable:
72+
73+
```bash
74+
LIBVIRT_DEFAULT_URI='qemu+unix:///session' TF_LIBVIRT_DISABLE_PRIVILEGED_TESTS=1 make testacc
75+
```
76+
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+
7084
### Code coverage:
7185

7286
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

libvirt/helpers_test.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,12 @@ func testAccEnabled() bool {
5050
return v == "1" || strings.ToLower(v) == "true"
5151
}
5252

53+
func skipIfPrivilegedDisabled(t *testing.T) {
54+
if os.Getenv("TF_LIBVIRT_DISABLE_PRIVILEGED_TESTS") != "" {
55+
t.Skip("skipping test; Enviornemnt variable `TF_LIBVIRT_DISABLE_PRIVILEGED_TESTS` is set")
56+
}
57+
}
58+
5359
// //////////////////////////////////////////////////////////////////
5460
// general
5561
// //////////////////////////////////////////////////////////////////

libvirt/resource_libvirt_cloud_init_test.go

Lines changed: 41 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ import (
1313
func TestAccLibvirtCloudInit_CreateCloudInitDiskAndUpdate(t *testing.T) {
1414
var volume libvirt.StorageVol
1515
randomResourceName := acctest.RandStringFromCharSet(10, acctest.CharSetAlpha)
16+
randomPoolName := acctest.RandStringFromCharSet(10, acctest.CharSetAlpha)
17+
randomPoolPath := "/tmp/terraform-provider-libvirt-pool-" + randomPoolName
1618
// this structs are contents values we expect.
1719
expectedContents := Expected{UserData: "#cloud-config", NetworkConfig: "network:", MetaData: "instance-id: bamboo"}
1820
expectedContents2 := Expected{UserData: "#cloud-config2", NetworkConfig: "network2:", MetaData: "instance-id: bamboo2"}
@@ -27,12 +29,18 @@ func TestAccLibvirtCloudInit_CreateCloudInitDiskAndUpdate(t *testing.T) {
2729
Steps: []resource.TestStep{
2830
{
2931
Config: fmt.Sprintf(`
32+
resource "libvirt_pool" "%s" {
33+
name = "%s"
34+
type = "dir"
35+
path = "%s"
36+
}
3037
resource "libvirt_cloudinit_disk" "%s" {
3138
name = "%s"
3239
user_data = "#cloud-config"
3340
meta_data = "instance-id: bamboo"
3441
network_config = "network:"
35-
}`, randomResourceName, randomIsoName),
42+
pool = "${libvirt_pool.%s.name}"
43+
}`, randomPoolName, randomPoolName, randomPoolPath, randomResourceName, randomIsoName, randomPoolName),
3644

3745
Check: resource.ComposeTestCheckFunc(
3846
resource.TestCheckResourceAttr(
@@ -43,12 +51,18 @@ func TestAccLibvirtCloudInit_CreateCloudInitDiskAndUpdate(t *testing.T) {
4351
},
4452
{
4553
Config: fmt.Sprintf(`
54+
resource "libvirt_pool" "%s" {
55+
name = "%s"
56+
type = "dir"
57+
path = "%s"
58+
}
4659
resource "libvirt_cloudinit_disk" "%s" {
4760
name = "%s"
4861
user_data = "#cloud-config2"
4962
meta_data = "instance-id: bamboo2"
5063
network_config = "network2:"
51-
}`, randomResourceName, randomIsoName),
64+
pool = "${libvirt_pool.%s.name}"
65+
}`, randomPoolName, randomPoolName, randomPoolPath, randomResourceName, randomIsoName, randomPoolName),
5266

5367
Check: resource.ComposeTestCheckFunc(
5468
resource.TestCheckResourceAttr(
@@ -59,10 +73,16 @@ func TestAccLibvirtCloudInit_CreateCloudInitDiskAndUpdate(t *testing.T) {
5973
},
6074
{
6175
Config: fmt.Sprintf(`
76+
resource "libvirt_pool" "%s" {
77+
name = "%s"
78+
type = "dir"
79+
path = "%s"
80+
}
6281
resource "libvirt_cloudinit_disk" "%s" {
6382
name = "%s"
6483
user_data = "#cloud-config2"
65-
}`, randomResourceName, randomIsoName),
84+
pool = "${libvirt_pool.%s.name}"
85+
}`, randomPoolName, randomPoolName, randomPoolPath, randomResourceName, randomIsoName, randomPoolName),
6686
Check: resource.ComposeTestCheckFunc(
6787
resource.TestCheckResourceAttr(
6888
"libvirt_cloudinit_disk."+randomResourceName, "name", randomIsoName),
@@ -74,10 +94,16 @@ func TestAccLibvirtCloudInit_CreateCloudInitDiskAndUpdate(t *testing.T) {
7494
// https://github.com/dmacvicar/terraform-provider-libvirt/issues/313
7595
{
7696
Config: fmt.Sprintf(`
97+
resource "libvirt_pool" "%s" {
98+
name = "%s"
99+
type = "dir"
100+
path = "%s"
101+
}
77102
resource "libvirt_cloudinit_disk" "%s" {
78103
name = "%s"
79104
user_data = "#cloud-config4"
80-
}`, randomResourceName, randomIsoName),
105+
pool = "${libvirt_pool.%s.name}"
106+
}`, randomPoolName, randomPoolName, randomPoolPath, randomResourceName, randomIsoName, randomPoolName),
81107
ExpectNonEmptyPlan: true,
82108
PlanOnly: true,
83109
Check: resource.ComposeTestCheckFunc(
@@ -98,13 +124,20 @@ func TestAccLibvirtCloudInit_CreateCloudInitDiskAndUpdate(t *testing.T) {
98124
func TestAccLibvirtCloudInit_ManuallyDestroyed(t *testing.T) {
99125
var volume libvirt.StorageVol
100126
randomResourceName := acctest.RandStringFromCharSet(10, acctest.CharSetAlpha)
127+
randomPoolName := acctest.RandStringFromCharSet(10, acctest.CharSetAlpha)
128+
randomPoolPath := "/tmp/terraform-provider-libvirt-pool-" + randomPoolName
101129

102130
testAccCheckLibvirtCloudInitConfigBasic := fmt.Sprintf(`
103-
resource "libvirt_cloudinit_disk" "%s" {
104-
name = "%s"
105-
pool = "default"
131+
resource "libvirt_pool" "%s" {
132+
name = "%s"
133+
type = "dir"
134+
path = "%s"
135+
}
136+
resource "libvirt_cloudinit_disk" "%s" {
137+
name = "%s"
138+
pool = "${libvirt_pool.%s.name}"
106139
user_data = "#cloud-config\nssh_authorized_keys: []\n"
107-
}`, randomResourceName, randomResourceName)
140+
}`, randomPoolName, randomPoolName, randomPoolPath, randomResourceName, randomResourceName, randomPoolName)
108141

109142
resource.Test(t, resource.TestCase{
110143
PreCheck: func() { testAccPreCheck(t) },

libvirt/resource_libvirt_coreos_ignition_test.go

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ func TestAccLibvirtIgnition_Basic(t *testing.T) {
1414
var volume libvirt.StorageVol
1515
randomServiceName := acctest.RandStringFromCharSet(10, acctest.CharSetAlpha) + ".service"
1616
randomIgnitionName := acctest.RandStringFromCharSet(10, acctest.CharSetAlpha)
17+
randomPoolName := acctest.RandStringFromCharSet(10, acctest.CharSetAlpha)
18+
randomPoolPath := "/tmp/terraform-provider-libvirt-pool-" + randomPoolName
1719
var config = fmt.Sprintf(`
1820
data "ignition_systemd_unit" "acceptance-test-systemd" {
1921
name = "%s"
@@ -26,11 +28,18 @@ func TestAccLibvirtIgnition_Basic(t *testing.T) {
2628
]
2729
}
2830
31+
resource "libvirt_pool" "%s" {
32+
name = "%s"
33+
type = "dir"
34+
path = "%s"
35+
}
36+
2937
resource "libvirt_ignition" "ignition" {
3038
name = "%s"
3139
content = "${data.ignition_config.acceptance-test-config.rendered}"
40+
pool = "${libvirt_pool.%s.name}"
3241
}
33-
`, randomServiceName, randomIgnitionName)
42+
`, randomServiceName, randomPoolName, randomPoolName, randomPoolPath, randomIgnitionName, randomPoolName)
3443

3544
resource.Test(t, resource.TestCase{
3645
PreCheck: func() { testAccPreCheck(t) },
@@ -44,7 +53,7 @@ func TestAccLibvirtIgnition_Basic(t *testing.T) {
4453
resource.TestCheckResourceAttr(
4554
"libvirt_ignition.ignition", "name", randomIgnitionName),
4655
resource.TestCheckResourceAttr(
47-
"libvirt_ignition.ignition", "pool", "default"),
56+
"libvirt_ignition.ignition", "pool", randomPoolName),
4857
),
4958
},
5059
},

0 commit comments

Comments
 (0)