Samuel A. Falvo II | b5d93f2 | 2014-02-21 15:00:20 -0800 | [diff] [blame] | 1 | // +build acceptance |
| 2 | |
Samuel A. Falvo II | f370dc7 | 2014-02-13 15:05:34 -0800 | [diff] [blame] | 3 | package openstack |
| 4 | |
| 5 | import ( |
Samuel A. Falvo II | f370dc7 | 2014-02-13 15:05:34 -0800 | [diff] [blame] | 6 | "fmt" |
Samuel A. Falvo II | 10decf9 | 2014-02-13 17:05:35 -0800 | [diff] [blame] | 7 | "github.com/rackspace/gophercloud/openstack/compute/flavors" |
Samuel A. Falvo II | e246ac0 | 2014-02-13 23:20:09 -0800 | [diff] [blame] | 8 | "github.com/rackspace/gophercloud/openstack/compute/images" |
| 9 | "github.com/rackspace/gophercloud/openstack/compute/servers" |
Samuel A. Falvo II | f370dc7 | 2014-02-13 15:05:34 -0800 | [diff] [blame] | 10 | "os" |
Samuel A. Falvo II | e246ac0 | 2014-02-13 23:20:09 -0800 | [diff] [blame] | 11 | "testing" |
Samuel A. Falvo II | f370dc7 | 2014-02-13 15:05:34 -0800 | [diff] [blame] | 12 | ) |
| 13 | |
| 14 | func TestListServers(t *testing.T) { |
Samuel A. Falvo II | ce00073 | 2014-02-13 18:53:53 -0800 | [diff] [blame] | 15 | ts, err := setupForList() |
Samuel A. Falvo II | f370dc7 | 2014-02-13 15:05:34 -0800 | [diff] [blame] | 16 | if err != nil { |
| 17 | t.Error(err) |
| 18 | return |
| 19 | } |
| 20 | |
Samuel A. Falvo II | ce00073 | 2014-02-13 18:53:53 -0800 | [diff] [blame] | 21 | fmt.Fprintln(ts.w, "ID\tRegion\tName\tStatus\tIPv4\tIPv6\t") |
Samuel A. Falvo II | f370dc7 | 2014-02-13 15:05:34 -0800 | [diff] [blame] | 22 | |
| 23 | region := os.Getenv("OS_REGION_NAME") |
| 24 | n := 0 |
Samuel A. Falvo II | db02088 | 2014-02-13 15:37:57 -0800 | [diff] [blame] | 25 | for _, ep := range ts.eps { |
Samuel A. Falvo II | f370dc7 | 2014-02-13 15:05:34 -0800 | [diff] [blame] | 26 | if (region != "") && (region != ep.Region) { |
| 27 | continue |
| 28 | } |
| 29 | |
Samuel A. Falvo II | db02088 | 2014-02-13 15:37:57 -0800 | [diff] [blame] | 30 | client := servers.NewClient(ep.PublicURL, ts.a, ts.o) |
Samuel A. Falvo II | f370dc7 | 2014-02-13 15:05:34 -0800 | [diff] [blame] | 31 | |
| 32 | listResults, err := servers.List(client) |
| 33 | if err != nil { |
| 34 | t.Error(err) |
| 35 | return |
| 36 | } |
| 37 | |
| 38 | svrs, err := servers.GetServers(listResults) |
| 39 | if err != nil { |
| 40 | t.Error(err) |
| 41 | return |
| 42 | } |
| 43 | |
| 44 | n = n + len(svrs) |
| 45 | |
| 46 | for _, s := range svrs { |
Samuel A. Falvo II | ce00073 | 2014-02-13 18:53:53 -0800 | [diff] [blame] | 47 | fmt.Fprintf(ts.w, "%s\t%s\t%s\t%s\t%s\t%s\t\n", s.Id, s.Name, ep.Region, s.Status, s.AccessIPv4, s.AccessIPv6) |
Samuel A. Falvo II | f370dc7 | 2014-02-13 15:05:34 -0800 | [diff] [blame] | 48 | } |
| 49 | } |
Samuel A. Falvo II | db02088 | 2014-02-13 15:37:57 -0800 | [diff] [blame] | 50 | ts.w.Flush() |
Samuel A. Falvo II | f370dc7 | 2014-02-13 15:05:34 -0800 | [diff] [blame] | 51 | fmt.Printf("--------\n%d servers listed.\n", n) |
| 52 | } |
| 53 | |
Samuel A. Falvo II | f370dc7 | 2014-02-13 15:05:34 -0800 | [diff] [blame] | 54 | func TestListImages(t *testing.T) { |
Samuel A. Falvo II | ce00073 | 2014-02-13 18:53:53 -0800 | [diff] [blame] | 55 | ts, err := setupForList() |
Samuel A. Falvo II | f370dc7 | 2014-02-13 15:05:34 -0800 | [diff] [blame] | 56 | if err != nil { |
| 57 | t.Error(err) |
| 58 | return |
| 59 | } |
| 60 | |
Samuel A. Falvo II | db02088 | 2014-02-13 15:37:57 -0800 | [diff] [blame] | 61 | fmt.Fprintln(ts.w, "ID\tRegion\tName\tStatus\tCreated\t") |
Samuel A. Falvo II | f370dc7 | 2014-02-13 15:05:34 -0800 | [diff] [blame] | 62 | |
| 63 | region := os.Getenv("OS_REGION_NAME") |
| 64 | n := 0 |
Samuel A. Falvo II | db02088 | 2014-02-13 15:37:57 -0800 | [diff] [blame] | 65 | for _, ep := range ts.eps { |
Samuel A. Falvo II | f370dc7 | 2014-02-13 15:05:34 -0800 | [diff] [blame] | 66 | if (region != "") && (region != ep.Region) { |
| 67 | continue |
| 68 | } |
| 69 | |
Samuel A. Falvo II | db02088 | 2014-02-13 15:37:57 -0800 | [diff] [blame] | 70 | client := images.NewClient(ep.PublicURL, ts.a, ts.o) |
Samuel A. Falvo II | f370dc7 | 2014-02-13 15:05:34 -0800 | [diff] [blame] | 71 | |
| 72 | listResults, err := images.List(client) |
| 73 | if err != nil { |
| 74 | t.Error(err) |
| 75 | return |
| 76 | } |
| 77 | |
| 78 | imgs, err := images.GetImages(listResults) |
| 79 | if err != nil { |
| 80 | t.Error(err) |
| 81 | return |
| 82 | } |
| 83 | |
| 84 | n = n + len(imgs) |
| 85 | |
| 86 | for _, i := range imgs { |
Samuel A. Falvo II | db02088 | 2014-02-13 15:37:57 -0800 | [diff] [blame] | 87 | fmt.Fprintf(ts.w, "%s\t%s\t%s\t%s\t%s\t\n", i.Id, ep.Region, i.Name, i.Status, i.Created) |
Samuel A. Falvo II | f370dc7 | 2014-02-13 15:05:34 -0800 | [diff] [blame] | 88 | } |
| 89 | } |
Samuel A. Falvo II | db02088 | 2014-02-13 15:37:57 -0800 | [diff] [blame] | 90 | ts.w.Flush() |
Samuel A. Falvo II | f370dc7 | 2014-02-13 15:05:34 -0800 | [diff] [blame] | 91 | fmt.Printf("--------\n%d images listed.\n", n) |
| 92 | } |
| 93 | |
Samuel A. Falvo II | db02088 | 2014-02-13 15:37:57 -0800 | [diff] [blame] | 94 | func TestListFlavors(t *testing.T) { |
Samuel A. Falvo II | ce00073 | 2014-02-13 18:53:53 -0800 | [diff] [blame] | 95 | ts, err := setupForList() |
Samuel A. Falvo II | db02088 | 2014-02-13 15:37:57 -0800 | [diff] [blame] | 96 | if err != nil { |
| 97 | t.Error(err) |
| 98 | return |
| 99 | } |
| 100 | |
Samuel A. Falvo II | 10decf9 | 2014-02-13 17:05:35 -0800 | [diff] [blame] | 101 | fmt.Fprintln(ts.w, "ID\tRegion\tName\tRAM\tDisk\tVCPUs\t") |
Samuel A. Falvo II | db02088 | 2014-02-13 15:37:57 -0800 | [diff] [blame] | 102 | |
| 103 | region := os.Getenv("OS_REGION_NAME") |
| 104 | n := 0 |
| 105 | for _, ep := range ts.eps { |
| 106 | if (region != "") && (region != ep.Region) { |
| 107 | continue |
| 108 | } |
| 109 | |
| 110 | client := flavors.NewClient(ep.PublicURL, ts.a, ts.o) |
| 111 | |
| 112 | listResults, err := flavors.List(client) |
| 113 | if err != nil { |
| 114 | t.Error(err) |
| 115 | return |
| 116 | } |
| 117 | |
| 118 | flavs, err := flavors.GetFlavors(listResults) |
| 119 | if err != nil { |
| 120 | t.Error(err) |
| 121 | return |
| 122 | } |
| 123 | |
| 124 | n = n + len(flavs) |
| 125 | |
| 126 | for _, f := range flavs { |
Samuel A. Falvo II | 10decf9 | 2014-02-13 17:05:35 -0800 | [diff] [blame] | 127 | fmt.Fprintf(ts.w, "%s\t%s\t%s\t%d\t%d\t%d\t\n", f.Id, ep.Region, f.Name, f.Ram, f.Disk, f.VCpus) |
Samuel A. Falvo II | db02088 | 2014-02-13 15:37:57 -0800 | [diff] [blame] | 128 | } |
| 129 | } |
| 130 | ts.w.Flush() |
| 131 | fmt.Printf("--------\n%d images listed.\n", n) |
| 132 | } |
| 133 | |
Samuel A. Falvo II | ce00073 | 2014-02-13 18:53:53 -0800 | [diff] [blame] | 134 | func TestCreateDestroyServer(t *testing.T) { |
Samuel A. Falvo II | 0abdb10 | 2014-02-13 23:19:26 -0800 | [diff] [blame] | 135 | ts, err := setupForCRUD() |
Samuel A. Falvo II | ce00073 | 2014-02-13 18:53:53 -0800 | [diff] [blame] | 136 | if err != nil { |
| 137 | t.Error(err) |
| 138 | return |
| 139 | } |
| 140 | |
Samuel A. Falvo II | 0abdb10 | 2014-02-13 23:19:26 -0800 | [diff] [blame] | 141 | err = createServer(ts) |
Samuel A. Falvo II | ce00073 | 2014-02-13 18:53:53 -0800 | [diff] [blame] | 142 | if err != nil { |
| 143 | t.Error(err) |
| 144 | return |
| 145 | } |
| 146 | |
Samuel A. Falvo II | 0abdb10 | 2014-02-13 23:19:26 -0800 | [diff] [blame] | 147 | // We put this in a defer so that it gets executed even in the face of errors or panics. |
Samuel A. Falvo II | ce00073 | 2014-02-13 18:53:53 -0800 | [diff] [blame] | 148 | defer func() { |
Samuel A. Falvo II | 0abdb10 | 2014-02-13 23:19:26 -0800 | [diff] [blame] | 149 | servers.Delete(ts.client, ts.createdServer.Id) |
Samuel A. Falvo II | ce00073 | 2014-02-13 18:53:53 -0800 | [diff] [blame] | 150 | }() |
| 151 | |
Samuel A. Falvo II | 0abdb10 | 2014-02-13 23:19:26 -0800 | [diff] [blame] | 152 | err = waitForStatus(ts, "ACTIVE") |
| 153 | if err != nil { |
| 154 | t.Error(err) |
Samuel A. Falvo II | ce00073 | 2014-02-13 18:53:53 -0800 | [diff] [blame] | 155 | } |
| 156 | } |
| 157 | |
Samuel A. Falvo II | 22d3b77 | 2014-02-13 19:27:05 -0800 | [diff] [blame] | 158 | func TestUpdateServer(t *testing.T) { |
Samuel A. Falvo II | 0abdb10 | 2014-02-13 23:19:26 -0800 | [diff] [blame] | 159 | ts, err := setupForCRUD() |
Samuel A. Falvo II | 22d3b77 | 2014-02-13 19:27:05 -0800 | [diff] [blame] | 160 | if err != nil { |
| 161 | t.Error(err) |
| 162 | return |
| 163 | } |
| 164 | |
Samuel A. Falvo II | 0abdb10 | 2014-02-13 23:19:26 -0800 | [diff] [blame] | 165 | err = createServer(ts) |
Samuel A. Falvo II | 22d3b77 | 2014-02-13 19:27:05 -0800 | [diff] [blame] | 166 | if err != nil { |
| 167 | t.Error(err) |
| 168 | return |
| 169 | } |
| 170 | |
Samuel A. Falvo II | 22d3b77 | 2014-02-13 19:27:05 -0800 | [diff] [blame] | 171 | defer func() { |
Samuel A. Falvo II | 0abdb10 | 2014-02-13 23:19:26 -0800 | [diff] [blame] | 172 | servers.Delete(ts.client, ts.createdServer.Id) |
Samuel A. Falvo II | 22d3b77 | 2014-02-13 19:27:05 -0800 | [diff] [blame] | 173 | }() |
| 174 | |
Samuel A. Falvo II | 0abdb10 | 2014-02-13 23:19:26 -0800 | [diff] [blame] | 175 | err = waitForStatus(ts, "ACTIVE") |
Samuel A. Falvo II | 22d3b77 | 2014-02-13 19:27:05 -0800 | [diff] [blame] | 176 | if err != nil { |
| 177 | t.Error(err) |
| 178 | return |
| 179 | } |
| 180 | |
Samuel A. Falvo II | 0abdb10 | 2014-02-13 23:19:26 -0800 | [diff] [blame] | 181 | err = changeServerName(ts) |
Samuel A. Falvo II | 22d3b77 | 2014-02-13 19:27:05 -0800 | [diff] [blame] | 182 | if err != nil { |
| 183 | t.Error(err) |
| 184 | return |
| 185 | } |
Samuel A. Falvo II | ce00073 | 2014-02-13 18:53:53 -0800 | [diff] [blame] | 186 | } |
Samuel A. Falvo II | ca5f9a3 | 2014-03-11 17:52:58 -0700 | [diff] [blame] | 187 | |
Samuel A. Falvo II | 808bb63 | 2014-03-12 00:07:50 -0700 | [diff] [blame^] | 188 | func TestActionChangeAdminPassword(t *testing.T) { |
| 189 | t.Parallel() |
| 190 | |
Samuel A. Falvo II | ca5f9a3 | 2014-03-11 17:52:58 -0700 | [diff] [blame] | 191 | ts, err := setupForCRUD() |
| 192 | if err != nil { |
| 193 | t.Fatal(err) |
| 194 | } |
| 195 | |
| 196 | err = createServer(ts) |
| 197 | if err != nil { |
| 198 | t.Fatal(err) |
| 199 | } |
| 200 | |
| 201 | defer func(){ |
| 202 | servers.Delete(ts.client, ts.createdServer.Id) |
| 203 | }() |
| 204 | |
| 205 | err = waitForStatus(ts, "ACTIVE") |
| 206 | if err != nil { |
| 207 | t.Fatal(err) |
| 208 | } |
| 209 | |
| 210 | err = changeAdminPassword(ts) |
| 211 | if err != nil { |
| 212 | t.Fatal(err) |
| 213 | } |
Samuel A. Falvo II | 808bb63 | 2014-03-12 00:07:50 -0700 | [diff] [blame^] | 214 | } |
| 215 | |
| 216 | func TestActionReboot(t *testing.T) { |
| 217 | t.Parallel() |
| 218 | |
| 219 | ts, err := setupForCRUD() |
| 220 | if err != nil { |
| 221 | t.Fatal(err) |
| 222 | } |
| 223 | |
| 224 | err = createServer(ts) |
| 225 | if err != nil { |
| 226 | t.Fatal(err) |
| 227 | } |
| 228 | |
| 229 | defer func(){ |
| 230 | servers.Delete(ts.client, ts.createdServer.Id) |
| 231 | }() |
| 232 | |
| 233 | err = waitForStatus(ts, "ACTIVE") |
| 234 | if err != nil { |
| 235 | t.Fatal(err) |
| 236 | } |
Samuel A. Falvo II | 41c9f61 | 2014-03-11 19:00:10 -0700 | [diff] [blame] | 237 | |
| 238 | err = servers.Reboot(ts.client, ts.createdServer.Id, "aldhjflaskhjf") |
| 239 | if err == nil { |
| 240 | t.Fatal("Expected the SDK to provide an ArgumentError here") |
| 241 | } |
| 242 | |
| 243 | err = rebootServer(ts) |
| 244 | if err != nil { |
| 245 | t.Fatal(err) |
| 246 | } |
Samuel A. Falvo II | ca5f9a3 | 2014-03-11 17:52:58 -0700 | [diff] [blame] | 247 | } |
| 248 | |
Samuel A. Falvo II | 808bb63 | 2014-03-12 00:07:50 -0700 | [diff] [blame^] | 249 | func TestActionRebuild(t *testing.T) { |
| 250 | t.Parallel() |
| 251 | |
| 252 | ts, err := setupForCRUD() |
| 253 | if err != nil { |
| 254 | t.Fatal(err) |
| 255 | } |
| 256 | |
| 257 | err = createServer(ts) |
| 258 | if err != nil { |
| 259 | t.Fatal(err) |
| 260 | } |
| 261 | |
| 262 | defer func(){ |
| 263 | servers.Delete(ts.client, ts.createdServer.Id) |
| 264 | }() |
| 265 | |
| 266 | err = waitForStatus(ts, "ACTIVE") |
| 267 | if err != nil { |
| 268 | t.Fatal(err) |
| 269 | } |
| 270 | |
| 271 | err = rebuildServer(ts) |
| 272 | if err != nil { |
| 273 | t.Fatal(err) |
| 274 | } |
| 275 | } |
| 276 | |
| 277 | func TestActionResizeConfirm(t *testing.T) { |
| 278 | t.Parallel() |
| 279 | |
| 280 | ts, err := setupForCRUD() |
| 281 | if err != nil { |
| 282 | t.Fatal(err) |
| 283 | } |
| 284 | |
| 285 | err = createServer(ts) |
| 286 | if err != nil { |
| 287 | t.Fatal(err) |
| 288 | } |
| 289 | |
| 290 | defer func(){ |
| 291 | servers.Delete(ts.client, ts.createdServer.Id) |
| 292 | }() |
| 293 | |
| 294 | err = waitForStatus(ts, "ACTIVE") |
| 295 | if err != nil { |
| 296 | t.Fatal(err) |
| 297 | } |
| 298 | |
| 299 | err = resizeServer(ts) |
| 300 | if err != nil { |
| 301 | t.Fatal(err) |
| 302 | } |
| 303 | |
| 304 | err = confirmResize(ts) |
| 305 | if err != nil { |
| 306 | t.Fatal(err) |
| 307 | } |
| 308 | } |
| 309 | |
| 310 | func TestActionResizeRevert(t *testing.T) { |
| 311 | t.Parallel() |
| 312 | |
| 313 | ts, err := setupForCRUD() |
| 314 | if err != nil { |
| 315 | t.Fatal(err) |
| 316 | } |
| 317 | |
| 318 | err = createServer(ts) |
| 319 | if err != nil { |
| 320 | t.Fatal(err) |
| 321 | } |
| 322 | |
| 323 | defer func(){ |
| 324 | servers.Delete(ts.client, ts.createdServer.Id) |
| 325 | }() |
| 326 | |
| 327 | err = waitForStatus(ts, "ACTIVE") |
| 328 | if err != nil { |
| 329 | t.Fatal(err) |
| 330 | } |
| 331 | |
| 332 | err = resizeServer(ts) |
| 333 | if err != nil { |
| 334 | t.Fatal(err) |
| 335 | } |
| 336 | |
| 337 | err = revertResize(ts) |
| 338 | if err != nil { |
| 339 | t.Fatal(err) |
| 340 | } |
| 341 | } |