Joe Topjian | c21202d | 2015-02-27 21:32:58 +0000 | [diff] [blame] | 1 | // +build acceptance compute servers |
| 2 | |
| 3 | package v2 |
| 4 | |
| 5 | import ( |
Joe Topjian | c21202d | 2015-02-27 21:32:58 +0000 | [diff] [blame] | 6 | "testing" |
| 7 | |
Joe Topjian | 1c15e3f | 2016-08-08 10:48:38 -0600 | [diff] [blame] | 8 | "github.com/gophercloud/gophercloud/acceptance/clients" |
Jon Perritt | 27249f4 | 2016-02-18 10:35:59 -0600 | [diff] [blame] | 9 | "github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/tenantnetworks" |
Joe Topjian | c21202d | 2015-02-27 21:32:58 +0000 | [diff] [blame] | 10 | ) |
| 11 | |
Joe Topjian | 5346c00 | 2016-07-25 17:05:32 +0000 | [diff] [blame] | 12 | func TestTenantNetworksList(t *testing.T) { |
Joe Topjian | 1c15e3f | 2016-08-08 10:48:38 -0600 | [diff] [blame] | 13 | client, err := clients.NewComputeV2Client() |
Joe Topjian | 5346c00 | 2016-07-25 17:05:32 +0000 | [diff] [blame] | 14 | if err != nil { |
| 15 | t.Fatalf("Unable to create a compute client: %v", err) |
| 16 | } |
| 17 | |
Joe Topjian | c21202d | 2015-02-27 21:32:58 +0000 | [diff] [blame] | 18 | allPages, err := tenantnetworks.List(client).AllPages() |
| 19 | if err != nil { |
| 20 | t.Fatalf("Unable to list networks: %v", err) |
| 21 | } |
| 22 | |
Joe Topjian | 5346c00 | 2016-07-25 17:05:32 +0000 | [diff] [blame] | 23 | allTenantNetworks, err := tenantnetworks.ExtractNetworks(allPages) |
Joe Topjian | c21202d | 2015-02-27 21:32:58 +0000 | [diff] [blame] | 24 | if err != nil { |
| 25 | t.Fatalf("Unable to list networks: %v", err) |
| 26 | } |
| 27 | |
Joe Topjian | 5346c00 | 2016-07-25 17:05:32 +0000 | [diff] [blame] | 28 | for _, network := range allTenantNetworks { |
Joe Topjian | 1c15e3f | 2016-08-08 10:48:38 -0600 | [diff] [blame] | 29 | PrintTenantNetwork(t, &network) |
Joe Topjian | c21202d | 2015-02-27 21:32:58 +0000 | [diff] [blame] | 30 | } |
Joe Topjian | c21202d | 2015-02-27 21:32:58 +0000 | [diff] [blame] | 31 | } |
| 32 | |
Joe Topjian | 5346c00 | 2016-07-25 17:05:32 +0000 | [diff] [blame] | 33 | func TestTenantNetworksGet(t *testing.T) { |
Joe Topjian | 1c15e3f | 2016-08-08 10:48:38 -0600 | [diff] [blame] | 34 | choices, err := clients.AcceptanceTestChoicesFromEnv() |
Joe Topjian | c21202d | 2015-02-27 21:32:58 +0000 | [diff] [blame] | 35 | if err != nil { |
| 36 | t.Fatal(err) |
| 37 | } |
| 38 | |
Joe Topjian | 1c15e3f | 2016-08-08 10:48:38 -0600 | [diff] [blame] | 39 | client, err := clients.NewComputeV2Client() |
Joe Topjian | c21202d | 2015-02-27 21:32:58 +0000 | [diff] [blame] | 40 | if err != nil { |
| 41 | t.Fatalf("Unable to create a compute client: %v", err) |
| 42 | } |
| 43 | |
Joe Topjian | 1c15e3f | 2016-08-08 10:48:38 -0600 | [diff] [blame] | 44 | networkID, err := GetNetworkIDFromTenantNetworks(t, client, choices.NetworkName) |
Joe Topjian | c21202d | 2015-02-27 21:32:58 +0000 | [diff] [blame] | 45 | if err != nil { |
Joe Topjian | 5346c00 | 2016-07-25 17:05:32 +0000 | [diff] [blame] | 46 | t.Fatal(err) |
Joe Topjian | c21202d | 2015-02-27 21:32:58 +0000 | [diff] [blame] | 47 | } |
| 48 | |
Joe Topjian | 5346c00 | 2016-07-25 17:05:32 +0000 | [diff] [blame] | 49 | network, err := tenantnetworks.Get(client, networkID).Extract() |
Joe Topjian | c21202d | 2015-02-27 21:32:58 +0000 | [diff] [blame] | 50 | if err != nil { |
Joe Topjian | 5346c00 | 2016-07-25 17:05:32 +0000 | [diff] [blame] | 51 | t.Fatalf("Unable to get network %s: %v", networkID, err) |
Joe Topjian | c21202d | 2015-02-27 21:32:58 +0000 | [diff] [blame] | 52 | } |
| 53 | |
Joe Topjian | 1c15e3f | 2016-08-08 10:48:38 -0600 | [diff] [blame] | 54 | PrintTenantNetwork(t, network) |
Joe Topjian | c21202d | 2015-02-27 21:32:58 +0000 | [diff] [blame] | 55 | } |