blob: 9b6b52702200702db7e319bc2d6eb71cf43f59d6 [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"
Joe Topjian66a046c2017-01-19 22:07:26 -07009 "github.com/gophercloud/gophercloud/acceptance/tools"
Jon Perritt27249f42016-02-18 10:35:59 -060010 "github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/tenantnetworks"
Joe Topjianc21202d2015-02-27 21:32:58 +000011)
12
Joe Topjian5346c002016-07-25 17:05:32 +000013func TestTenantNetworksList(t *testing.T) {
Joe Topjian1c15e3f2016-08-08 10:48:38 -060014 client, err := clients.NewComputeV2Client()
Joe Topjian5346c002016-07-25 17:05:32 +000015 if err != nil {
16 t.Fatalf("Unable to create a compute client: %v", err)
17 }
18
Joe Topjianc21202d2015-02-27 21:32:58 +000019 allPages, err := tenantnetworks.List(client).AllPages()
20 if err != nil {
21 t.Fatalf("Unable to list networks: %v", err)
22 }
23
Joe Topjian5346c002016-07-25 17:05:32 +000024 allTenantNetworks, err := tenantnetworks.ExtractNetworks(allPages)
Joe Topjianc21202d2015-02-27 21:32:58 +000025 if err != nil {
26 t.Fatalf("Unable to list networks: %v", err)
27 }
28
Joe Topjian5346c002016-07-25 17:05:32 +000029 for _, network := range allTenantNetworks {
Joe Topjian66a046c2017-01-19 22:07:26 -070030 tools.PrintResource(t, network)
Joe Topjianc21202d2015-02-27 21:32:58 +000031 }
Joe Topjianc21202d2015-02-27 21:32:58 +000032}
33
Joe Topjian5346c002016-07-25 17:05:32 +000034func TestTenantNetworksGet(t *testing.T) {
Joe Topjian1c15e3f2016-08-08 10:48:38 -060035 choices, err := clients.AcceptanceTestChoicesFromEnv()
Joe Topjianc21202d2015-02-27 21:32:58 +000036 if err != nil {
37 t.Fatal(err)
38 }
39
Joe Topjian1c15e3f2016-08-08 10:48:38 -060040 client, err := clients.NewComputeV2Client()
Joe Topjianc21202d2015-02-27 21:32:58 +000041 if err != nil {
42 t.Fatalf("Unable to create a compute client: %v", err)
43 }
44
Joe Topjian1c15e3f2016-08-08 10:48:38 -060045 networkID, err := GetNetworkIDFromTenantNetworks(t, client, choices.NetworkName)
Joe Topjianc21202d2015-02-27 21:32:58 +000046 if err != nil {
Joe Topjian5346c002016-07-25 17:05:32 +000047 t.Fatal(err)
Joe Topjianc21202d2015-02-27 21:32:58 +000048 }
49
Joe Topjian5346c002016-07-25 17:05:32 +000050 network, err := tenantnetworks.Get(client, networkID).Extract()
Joe Topjianc21202d2015-02-27 21:32:58 +000051 if err != nil {
Joe Topjian5346c002016-07-25 17:05:32 +000052 t.Fatalf("Unable to get network %s: %v", networkID, err)
Joe Topjianc21202d2015-02-27 21:32:58 +000053 }
54
Joe Topjian66a046c2017-01-19 22:07:26 -070055 tools.PrintResource(t, network)
Joe Topjianc21202d2015-02-27 21:32:58 +000056}