blob: 38a6d5413ffc1f09770be2db9193993007e15342 [file] [log] [blame]
Joe Topjian99a06132015-02-22 05:06:25 +00001// +build acceptance compute servers
2
3package v2
4
5import (
Joe Topjian99a06132015-02-22 05:06:25 +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/networks"
Joe Topjian99a06132015-02-22 05:06:25 +000010)
11
Joe Topjian924f7012016-07-25 18:19:17 +000012func TestNetworksList(t *testing.T) {
Joe Topjian1c15e3f2016-08-08 10:48:38 -060013 client, err := clients.NewComputeV2Client()
Joe Topjian924f7012016-07-25 18:19:17 +000014 if err != nil {
15 t.Fatalf("Unable to create a compute client: %v", err)
16 }
17
18 allPages, err := networks.List(client).AllPages()
19 if err != nil {
20 t.Fatalf("Unable to list networks: %v", err)
21 }
22
23 allNetworks, err := networks.ExtractNetworks(allPages)
24 if err != nil {
25 t.Fatalf("Unable to list networks: %v", err)
26 }
27
28 for _, network := range allNetworks {
Joe Topjian1c15e3f2016-08-08 10:48:38 -060029 PrintNetwork(t, &network)
Joe Topjian924f7012016-07-25 18:19:17 +000030 }
31}
32
33func TestNetworksGet(t *testing.T) {
Joe Topjian1c15e3f2016-08-08 10:48:38 -060034 choices, err := clients.AcceptanceTestChoicesFromEnv()
Joe Topjian924f7012016-07-25 18:19:17 +000035 if err != nil {
36 t.Fatal(err)
37 }
38
Joe Topjian1c15e3f2016-08-08 10:48:38 -060039 client, err := clients.NewComputeV2Client()
Joe Topjian924f7012016-07-25 18:19:17 +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 := GetNetworkIDFromNetworks(t, client, choices.NetworkName)
Joe Topjian924f7012016-07-25 18:19:17 +000045 if err != nil {
46 t.Fatal(err)
47 }
48
49 network, err := networks.Get(client, networkID).Extract()
50 if err != nil {
51 t.Fatalf("Unable to get network %s: %v", networkID, err)
52 }
53
Joe Topjian1c15e3f2016-08-08 10:48:38 -060054 PrintNetwork(t, network)
Joe Topjian99a06132015-02-22 05:06:25 +000055}