PageRenderTime 48ms CodeModel.GetById 25ms RepoModel.GetById 0ms app.codeStats 0ms

/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/imageservice/v2/imageservice.go

https://gitlab.com/unofficial-mirrors/openshift-origin
Go | 55 lines | 39 code | 9 blank | 7 comment | 4 complexity | ebc3e659d94361734495c7d474e45cae MD5 | raw file
  1. // Package v2 contains common functions for creating imageservice resources
  2. // for use in acceptance tests. See the `*_test.go` files for example usages.
  3. package v2
  4. import (
  5. "testing"
  6. "github.com/gophercloud/gophercloud"
  7. "github.com/gophercloud/gophercloud/acceptance/tools"
  8. "github.com/gophercloud/gophercloud/openstack/imageservice/v2/images"
  9. )
  10. // CreateEmptyImage will create an image, but with no actual image data.
  11. // An error will be returned if an image was unable to be created.
  12. func CreateEmptyImage(t *testing.T, client *gophercloud.ServiceClient) (*images.Image, error) {
  13. var image *images.Image
  14. name := tools.RandomString("ACPTTEST", 16)
  15. t.Logf("Attempting to create image: %s", name)
  16. protected := false
  17. visibility := images.ImageVisibilityPrivate
  18. createOpts := &images.CreateOpts{
  19. Name: name,
  20. ContainerFormat: "bare",
  21. DiskFormat: "qcow2",
  22. MinDisk: 0,
  23. MinRAM: 0,
  24. Protected: &protected,
  25. Visibility: &visibility,
  26. Properties: map[string]string{
  27. "architecture": "x86_64",
  28. },
  29. }
  30. image, err := images.Create(client, createOpts).Extract()
  31. if err != nil {
  32. return image, err
  33. }
  34. t.Logf("Created image %s: %#v", name, image)
  35. return image, nil
  36. }
  37. // DeleteImage deletes an image.
  38. // A fatal error will occur if the image failed to delete. This works best when
  39. // used as a deferred function.
  40. func DeleteImage(t *testing.T, client *gophercloud.ServiceClient, image *images.Image) {
  41. err := images.Delete(client, image.ID).ExtractErr()
  42. if err != nil {
  43. t.Fatalf("Unable to delete image %s: %v", image.ID, err)
  44. }
  45. t.Logf("Deleted image: %s", image.ID)
  46. }