blob: 7d9c167f30acd082885315e276c1440f7dbfcc2f [file] [log] [blame]
Joe Topjianc21202d2015-02-27 21:32:58 +00001// +build acceptance compute servers
2
3package v2
4
5import (
Joe Topjianc21202d2015-02-27 21:32:58 +00006 "testing"
7
Joe Topjian1c15e3f2016-08-08 10:48:38 -06008 "github.com/gophercloud/gophercloud/acceptance/clients"
Jon Perritt27249f42016-02-18 10:35:59 -06009 "github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/tenantnetworks"
Joe Topjianc21202d2015-02-27 21:32:58 +000010)
11
Joe Topjian5346c002016-07-25 17:05:32 +000012func TestTenantNetworksList(t *testing.T) {
Joe Topjian1c15e3f2016-08-08 10:48:38 -060013 client, err := clients.NewComputeV2Client()
Joe Topjian5346c002016-07-25 17:05:32 +000014 if err != nil {
15 t.Fatalf("Unable to create a compute client: %v", err)
16 }
17
Joe Topjianc21202d2015-02-27 21:32:58 +000018 allPages, err := tenantnetworks.List(client).AllPages()
19 if err != nil {
20 t.Fatalf("Unable to list networks: %v", err)
21 }
22
Joe Topjian5346c002016-07-25 17:05:32 +000023 allTenantNetworks, err := tenantnetworks.ExtractNetworks(allPages)
Joe Topjianc21202d2015-02-27 21:32:58 +000024 if err != nil {
25 t.Fatalf("Unable to list networks: %v", err)
26 }
27
Joe Topjian5346c002016-07-25 17:05:32 +000028 for _, network := range allTenantNetworks {
Joe Topjian1c15e3f2016-08-08 10:48:38 -060029 PrintTenantNetwork(t, &network)
Joe Topjianc21202d2015-02-27 21:32:58 +000030 }
Joe Topjianc21202d2015-02-27 21:32:58 +000031}
32
Joe Topjian5346c002016-07-25 17:05:32 +000033func TestTenantNetworksGet(t *testing.T) {
Joe Topjian1c15e3f2016-08-08 10:48:38 -060034 choices, err := clients.AcceptanceTestChoicesFromEnv()
Joe Topjianc21202d2015-02-27 21:32:58 +000035 if err != nil {
36 t.Fatal(err)
37 }
38
Joe Topjian1c15e3f2016-08-08 10:48:38 -060039 client, err := clients.NewComputeV2Client()
Joe Topjianc21202d2015-02-27 21:32:58 +000040 if err != nil {
41 t.Fatalf("Unable to create a compute client: %v", err)
42 }
43
Joe Topjian1c15e3f2016-08-08 10:48:38 -060044 networkID, err := GetNetworkIDFromTenantNetworks(t, client, choices.NetworkName)
Joe Topjianc21202d2015-02-27 21:32:58 +000045 if err != nil {
Joe Topjian5346c002016-07-25 17:05:32 +000046 t.Fatal(err)
Joe Topjianc21202d2015-02-27 21:32:58 +000047 }
48
Joe Topjian5346c002016-07-25 17:05:32 +000049 network, err := tenantnetworks.Get(client, networkID).Extract()
Joe Topjianc21202d2015-02-27 21:32:58 +000050 if err != nil {
Joe Topjian5346c002016-07-25 17:05:32 +000051 t.Fatalf("Unable to get network %s: %v", networkID, err)
Joe Topjianc21202d2015-02-27 21:32:58 +000052 }
53
Joe Topjian1c15e3f2016-08-08 10:48:38 -060054 PrintTenantNetwork(t, network)
Joe Topjianc21202d2015-02-27 21:32:58 +000055}