Skip to content
This repository has been archived by the owner on Jul 26, 2021. It is now read-only.

Commit

Permalink
Make the tests work with the CloudStack Simulator
Browse files Browse the repository at this point in the history
  • Loading branch information
Sander van Harmelen committed Dec 26, 2018
1 parent 30eb8f3 commit f85ae6c
Show file tree
Hide file tree
Showing 35 changed files with 847 additions and 1,003 deletions.
6 changes: 3 additions & 3 deletions GNUmakefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
TEST?=$$(go list ./... |grep -v 'vendor')
GOFMT_FILES?=$$(find . -name '*.go' |grep -v vendor)
TEST?=$$(go list ./... | grep -v 'vendor')
GOFMT_FILES?=$$(find . -name '*.go' | grep -v vendor)
WEBSITE_REPO=github.com/hashicorp/terraform-website
PKG_NAME=cloudstack

Expand All @@ -14,7 +14,7 @@ test: fmtcheck
xargs -t -n4 go test $(TESTARGS) -timeout=30s -parallel=4

testacc: fmtcheck
TF_ACC=1 go test $(TEST) -v $(TESTARGS) -timeout 120m
TF_ACC=1 go test $(TEST) -v $(TESTARGS) -timeout 30m

vet:
@echo "go vet ."
Expand Down
12 changes: 6 additions & 6 deletions cloudstack/data_source_cloudstack_template.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ func dataSourceCloudstackTemplate() *schema.Resource {
Computed: true,
},

"tags": tagsSchema(),
// "tags": tagsSchema(),
},
}
}
Expand Down Expand Up @@ -118,11 +118,11 @@ func templateDescriptionAttributes(d *schema.ResourceData, template *cloudstack.
d.Set("name", template.Name)
d.Set("size", template.Size)

tags := make(map[string]interface{})
for _, tag := range template.Tags {
tags[tag.Key] = tag.Value
}
d.Set("tags", tags)
// tags := make(map[string]interface{})
// for _, tag := range template.Tags {
// tags[tag.Key] = tag.Value
// }
// d.Set("tags", tags)

return nil
}
Expand Down
184 changes: 0 additions & 184 deletions cloudstack/provider_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,190 +60,6 @@ func testAccPreCheck(t *testing.T) {
if v := os.Getenv("CLOUDSTACK_SECRET_KEY"); v == "" {
t.Fatal("CLOUDSTACK_SECRET_KEY must be set for acceptance tests")
}
if v := os.Getenv("CLOUDSTACK_2ND_NIC_IPADDRESS"); v == "" {
t.Fatal("CLOUDSTACK_2ND_NIC_IPADDRESS must be set for acceptance tests")
}
if v := os.Getenv("CLOUDSTACK_2ND_NIC_NETWORK"); v == "" {
t.Fatal("CLOUDSTACK_2ND_NIC_NETWORK must be set for acceptance tests")
}
if v := os.Getenv("CLOUDSTACK_DISK_OFFERING_1"); v == "" {
t.Fatal("CLOUDSTACK_DISK_OFFERING_1 must be set for acceptance tests")
}
if v := os.Getenv("CLOUDSTACK_DISK_OFFERING_2"); v == "" {
t.Fatal("CLOUDSTACK_DISK_OFFERING_2 must be set for acceptance tests")
}
if v := os.Getenv("CLOUDSTACK_HYPERVISOR"); v == "" {
t.Fatal("CLOUDSTACK_HYPERVISOR must be set for acceptance tests")
}
if v := os.Getenv("CLOUDSTACK_SERVICE_OFFERING_1"); v == "" {
t.Fatal("CLOUDSTACK_SERVICE_OFFERING_1 must be set for acceptance tests")
}
if v := os.Getenv("CLOUDSTACK_SERVICE_OFFERING_2"); v == "" {
t.Fatal("CLOUDSTACK_SERVICE_OFFERING_2 must be set for acceptance tests")
}
if v := os.Getenv("CLOUDSTACK_NETWORK_1"); v == "" {
t.Fatal("CLOUDSTACK_NETWORK_1 must be set for acceptance tests")
}
if v := os.Getenv("CLOUDSTACK_NETWORK_1_IPADDRESS1"); v == "" {
t.Fatal("CLOUDSTACK_NETWORK_1_IPADDRESS1 must be set for acceptance tests")
}
if v := os.Getenv("CLOUDSTACK_NETWORK_1_IPADDRESS2"); v == "" {
t.Fatal("CLOUDSTACK_NETWORK_1_IPADDRESS2 must be set for acceptance tests")
}
if v := os.Getenv("CLOUDSTACK_NETWORK_2"); v == "" {
t.Fatal("CLOUDSTACK_NETWORK_2 must be set for acceptance tests")
}
if v := os.Getenv("CLOUDSTACK_NETWORK_2_CIDR"); v == "" {
t.Fatal("CLOUDSTACK_NETWORK_2_CIDR must be set for acceptance tests")
}
if v := os.Getenv("CLOUDSTACK_NETWORK_2_OFFERING"); v == "" {
t.Fatal("CLOUDSTACK_NETWORK_2_OFFERING must be set for acceptance tests")
}
if v := os.Getenv("CLOUDSTACK_NETWORK_2_IPADDRESS"); v == "" {
t.Fatal("CLOUDSTACK_NETWORK_2_IPADDRESS must be set for acceptance tests")
}
if v := os.Getenv("CLOUDSTACK_VPC_CIDR_1"); v == "" {
t.Fatal("CLOUDSTACK_VPC_CIDR_1 must be set for acceptance tests")
}
if v := os.Getenv("CLOUDSTACK_VPC_CIDR_2"); v == "" {
t.Fatal("CLOUDSTACK_VPC_CIDR_2 must be set for acceptance tests")
}
if v := os.Getenv("CLOUDSTACK_VPC_OFFERING"); v == "" {
t.Fatal("CLOUDSTACK_VPC_OFFERING must be set for acceptance tests")
}
if v := os.Getenv("CLOUDSTACK_VPC_NETWORK_CIDR"); v == "" {
t.Fatal("CLOUDSTACK_VPC_NETWORK_CIDR must be set for acceptance tests")
}
if v := os.Getenv("CLOUDSTACK_VPC_NETWORK_OFFERING"); v == "" {
t.Fatal("CLOUDSTACK_VPC_NETWORK_OFFERING must be set for acceptance tests")
}
if v := os.Getenv("CLOUDSTACK_PUBLIC_IPADDRESS"); v == "" {
t.Fatal("CLOUDSTACK_PUBLIC_IPADDRESS must be set for acceptance tests")
}
if v := os.Getenv("CLOUDSTACK_SSH_PUBLIC_KEY"); v == "" {
t.Fatal("CLOUDSTACK_SSH_PUBLIC_KEY must be set for acceptance tests")
}
if v := os.Getenv("CLOUDSTACK_TEMPLATE"); v == "" {
t.Fatal("CLOUDSTACK_TEMPLATE must be set for acceptance tests")
}
if v := os.Getenv("CLOUDSTACK_TEMPLATE_FORMAT"); v == "" {
t.Fatal("CLOUDSTACK_TEMPLATE_FORMAT must be set for acceptance tests")
}
if v := os.Getenv("CLOUDSTACK_TEMPLATE_URL"); v == "" {
t.Fatal("CLOUDSTACK_TEMPLATE_URL must be set for acceptance tests")
}
if v := os.Getenv("CLOUDSTACK_TEMPLATE_OS_TYPE"); v == "" {
t.Fatal("CLOUDSTACK_TEMPLATE_OS_TYPE must be set for acceptance tests")
}
if v := os.Getenv("CLOUDSTACK_PROJECT_NAME"); v == "" {
t.Fatal("CLOUDSTACK_PROJECT_NAME must be set for acceptance tests")
}
if v := os.Getenv("CLOUDSTACK_PROJECT_NETWORK"); v == "" {
t.Fatal("CLOUDSTACK_PROJECT_NETWORK must be set for acceptance tests")
}
if v := os.Getenv("CLOUDSTACK_ZONE"); v == "" {
t.Fatal("CLOUDSTACK_ZONE must be set for acceptance tests")
}
if v := os.Getenv("CLOUDSTACK_PRIVGW_GATEWAY"); v == "" {
t.Fatal("CLOUDSTACK_PRIVGW_GATEWAY must be set for acceptance tests")
}
if v := os.Getenv("CLOUDSTACK_PRIVGW_IPADDRESS"); v == "" {
t.Fatal("CLOUDSTACK_PRIVGW_IPADDRESS must be set for acceptance tests")
}
if v := os.Getenv("CLOUDSTACK_PRIVGW_NETMASK"); v == "" {
t.Fatal("CLOUDSTACK_PRIVGW_NETMASK must be set for acceptance tests")
}
if v := os.Getenv("CLOUDSTACK_PRIVGW_VLAN"); v == "" {
t.Fatal("CLOUDSTACK_PRIVGW_VLAN must be set for acceptance tests")
}
if v := os.Getenv("CLOUDSTACK_STATIC_ROUTE_CIDR"); v == "" {
t.Fatal("CLOUDSTACK_STATIC_ROUTE_CIDR must be set for acceptance tests")
}
}

// Name of a valid disk offering
var CLOUDSTACK_DISK_OFFERING_1 = os.Getenv("CLOUDSTACK_DISK_OFFERING_1")

// Name of a disk offering that CLOUDSTACK_DISK_OFFERING_1 can resize to
var CLOUDSTACK_DISK_OFFERING_2 = os.Getenv("CLOUDSTACK_DISK_OFFERING_2")

// Name of a valid service offering
var CLOUDSTACK_SERVICE_OFFERING_1 = os.Getenv("CLOUDSTACK_SERVICE_OFFERING_1")

// Name of a service offering that CLOUDSTACK_SERVICE_OFFERING_1 can resize to
var CLOUDSTACK_SERVICE_OFFERING_2 = os.Getenv("CLOUDSTACK_SERVICE_OFFERING_2")

// Name of a network that already exists
var CLOUDSTACK_NETWORK_1 = os.Getenv("CLOUDSTACK_NETWORK_1")

// A valid IP address in CLOUDSTACK_NETWORK_1
var CLOUDSTACK_NETWORK_1_IPADDRESS1 = os.Getenv("CLOUDSTACK_NETWORK_1_IPADDRESS1")

// A valid IP address in CLOUDSTACK_NETWORK_1
var CLOUDSTACK_NETWORK_1_IPADDRESS2 = os.Getenv("CLOUDSTACK_NETWORK_1_IPADDRESS2")

// Name for a network that will be created
var CLOUDSTACK_NETWORK_2 = os.Getenv("CLOUDSTACK_NETWORK_2")

// Any range
var CLOUDSTACK_NETWORK_2_CIDR = os.Getenv("CLOUDSTACK_NETWORK_2_CIDR")

// Name of an available network offering with specifyvlan=false
var CLOUDSTACK_NETWORK_2_OFFERING = os.Getenv("CLOUDSTACK_NETWORK_2_OFFERING")

// An IP address in CLOUDSTACK_NETWORK_2_CIDR
var CLOUDSTACK_NETWORK_2_IPADDRESS = os.Getenv("CLOUDSTACK_NETWORK_2_IPADDRESS")

// A network that already exists and isn't CLOUDSTACK_NETWORK_1
var CLOUDSTACK_2ND_NIC_NETWORK = os.Getenv("CLOUDSTACK_2ND_NIC_NETWORK")

// An IP address in CLOUDSTACK_2ND_NIC_NETWORK
var CLOUDSTACK_2ND_NIC_IPADDRESS = os.Getenv("CLOUDSTACK_2ND_NIC_IPADDRESS")

// Any range
var CLOUDSTACK_VPC_CIDR_1 = os.Getenv("CLOUDSTACK_VPC_CIDR_1")

// Any range that doesn't overlap to CLOUDSTACK_VPC_CIDR_1, will be VPNed
var CLOUDSTACK_VPC_CIDR_2 = os.Getenv("CLOUDSTACK_VPC_CIDR_2")

// An available VPC offering
var CLOUDSTACK_VPC_OFFERING = os.Getenv("CLOUDSTACK_VPC_OFFERING")

// A sub-range of CLOUDSTACK_VPC_CIDR_1 with same starting point
var CLOUDSTACK_VPC_NETWORK_CIDR = os.Getenv("CLOUDSTACK_VPC_NETWORK_CIDR")

// Name of an available network offering with forvpc=true
var CLOUDSTACK_VPC_NETWORK_OFFERING = os.Getenv("CLOUDSTACK_VPC_NETWORK_OFFERING")

// Path to a public IP that exists for CLOUDSTACK_NETWORK_1
var CLOUDSTACK_PUBLIC_IPADDRESS = os.Getenv("CLOUDSTACK_PUBLIC_IPADDRESS")

// Path to a public key on local disk
var CLOUDSTACK_SSH_PUBLIC_KEY = os.Getenv("CLOUDSTACK_SSH_PUBLIC_KEY")

// Name of a template that exists already for building VMs
var CLOUDSTACK_TEMPLATE = os.Getenv("CLOUDSTACK_TEMPLATE")

// Details of a template that will be added
var CLOUDSTACK_TEMPLATE_FORMAT = os.Getenv("CLOUDSTACK_TEMPLATE_FORMAT")
var CLOUDSTACK_HYPERVISOR = os.Getenv("CLOUDSTACK_HYPERVISOR")
var CLOUDSTACK_TEMPLATE_URL = os.Getenv("CLOUDSTACK_TEMPLATE_URL")
var CLOUDSTACK_TEMPLATE_OS_TYPE = os.Getenv("CLOUDSTACK_TEMPLATE_OS_TYPE")

// Name of a project that exists already
var CLOUDSTACK_PROJECT_NAME = os.Getenv("CLOUDSTACK_PROJECT_NAME")

// Name of a network that exists already in CLOUDSTACK_PROJECT_NAME
var CLOUDSTACK_PROJECT_NETWORK = os.Getenv("CLOUDSTACK_PROJECT_NETWORK")

// Name of a zone that exists already
var CLOUDSTACK_ZONE = os.Getenv("CLOUDSTACK_ZONE")

// Details of the private gateway that will be added to VPC testing this, should be done using ROOT keys
var CLOUDSTACK_PRIVGW_GATEWAY = os.Getenv("CLOUDSTACK_PRIVGW_GATEWAY")
var CLOUDSTACK_PRIVGW_IPADDRESS = os.Getenv("CLOUDSTACK_PRIVGW_IPADDRESS")
var CLOUDSTACK_PRIVGW_NETMASK = os.Getenv("CLOUDSTACK_PRIVGW_NETMASK")
var CLOUDSTACK_PRIVGW_VLAN = os.Getenv("CLOUDSTACK_PRIVGW_VLAN")

// Details of the static route that will be added to private gateway testing this.
var CLOUDSTACK_STATIC_ROUTE_CIDR = os.Getenv("CLOUDSTACK_STATIC_ROUTE_CIDR")
8 changes: 4 additions & 4 deletions cloudstack/resource_cloudstack_affinity_group_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,8 @@ func testAccCheckCloudStackAffinityGroupDestroy(s *terraform.State) error {
return nil
}

var testAccCloudStackAffinityGroup = fmt.Sprintf(`
const testAccCloudStackAffinityGroup = `
resource "cloudstack_affinity_group" "foo" {
name = "terraform-affinity-group"
type = "host anti-affinity"
}`)
name = "terraform-affinity-group"
type = "host anti-affinity"
}`
41 changes: 20 additions & 21 deletions cloudstack/resource_cloudstack_disk.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ func resourceCloudStackDisk() *schema.Resource {
ForceNew: true,
},

"tags": tagsSchema(),
// "tags": tagsSchema(),
},
}
}
Expand Down Expand Up @@ -128,15 +128,14 @@ func resourceCloudStackDiskCreate(d *schema.ResourceData, meta interface{}) erro
d.SetId(r.Id)

// Set tags if necessary
err = setTags(cs, d, "Volume")
if err != nil {
return fmt.Errorf("Error setting tags on the new disk %s: %s", name, err)
}
d.SetPartial("tags")
// err = setTags(cs, d, "Volume")
// if err != nil {
// return fmt.Errorf("Error setting tags on the new disk %s: %s", name, err)
// }
// d.SetPartial("tags")

if d.Get("attach").(bool) {
err := resourceCloudStackDiskAttach(d, meta)
if err != nil {
if err := resourceCloudStackDiskAttach(d, meta); err != nil {
return fmt.Errorf("Error attaching the new disk %s to virtual machine: %s", name, err)
}

Expand Down Expand Up @@ -169,11 +168,11 @@ func resourceCloudStackDiskRead(d *schema.ResourceData, meta interface{}) error
d.Set("attach", v.Virtualmachineid != "") // If attached this contains a virtual machine ID
d.Set("size", int(v.Size/(1024*1024*1024))) // Needed to get GB's again

tags := make(map[string]interface{})
for _, tag := range v.Tags {
tags[tag.Key] = tag.Value
}
d.Set("tags", tags)
// tags := make(map[string]interface{})
// for _, tag := range v.Tags {
// tags[tag.Key] = tag.Value
// }
// d.Set("tags", tags)

setValueOrID(d, "disk_offering", v.Diskofferingname, v.Diskofferingid)
setValueOrID(d, "project", v.Project, v.Projectid)
Expand Down Expand Up @@ -211,7 +210,7 @@ func resourceCloudStackDiskUpdate(d *schema.ResourceData, meta interface{}) erro
// Set the disk_offering ID
p.SetDiskofferingid(diskofferingid)

if d.Get("size").(int) != 0 {
if d.HasChange("size") {
// Set the size
p.SetSize(int64(d.Get("size").(int)))
}
Expand Down Expand Up @@ -259,13 +258,13 @@ func resourceCloudStackDiskUpdate(d *schema.ResourceData, meta interface{}) erro
}

// Check is the tags have changed and if so, update the tags
if d.HasChange("tags") {
err := updateTags(cs, d, "Volume")
if err != nil {
return fmt.Errorf("Error updating tags on disk %s: %s", name, err)
}
d.SetPartial("tags")
}
// if d.HasChange("tags") {
// err := updateTags(cs, d, "Volume")
// if err != nil {
// return fmt.Errorf("Error updating tags on disk %s: %s", name, err)
// }
// d.SetPartial("tags")
// }

d.Partial(false)

Expand Down
Loading

0 comments on commit f85ae6c

Please sign in to comment.