PageRenderTime 38ms CodeModel.GetById 0ms RepoModel.GetById 0ms app.codeStats 0ms

/Godeps/_workspace/src/github.com/rackspace/gophercloud/acceptance/rackspace/compute/v2/keypairs_test.go

https://gitlab.com/JamesClonk/machine
Go | 87 lines | 69 code | 17 blank | 1 comment | 3 complexity | 4ad92d470d6c837455fd31b5b59ed650 MD5 | raw file
  1. // +build acceptance rackspace
  2. package v2
  3. import (
  4. "testing"
  5. "github.com/rackspace/gophercloud"
  6. "github.com/rackspace/gophercloud/acceptance/tools"
  7. os "github.com/rackspace/gophercloud/openstack/compute/v2/extensions/keypairs"
  8. "github.com/rackspace/gophercloud/pagination"
  9. "github.com/rackspace/gophercloud/rackspace/compute/v2/keypairs"
  10. th "github.com/rackspace/gophercloud/testhelper"
  11. )
  12. func deleteKeyPair(t *testing.T, client *gophercloud.ServiceClient, name string) {
  13. err := keypairs.Delete(client, name).ExtractErr()
  14. th.AssertNoErr(t, err)
  15. t.Logf("Successfully deleted key [%s].", name)
  16. }
  17. func TestCreateKeyPair(t *testing.T) {
  18. client, err := newClient()
  19. th.AssertNoErr(t, err)
  20. name := tools.RandomString("createdkey-", 8)
  21. k, err := keypairs.Create(client, os.CreateOpts{Name: name}).Extract()
  22. th.AssertNoErr(t, err)
  23. defer deleteKeyPair(t, client, name)
  24. t.Logf("Created a new keypair:")
  25. t.Logf(" name=[%s]", k.Name)
  26. t.Logf(" fingerprint=[%s]", k.Fingerprint)
  27. t.Logf(" publickey=[%s]", tools.Elide(k.PublicKey))
  28. t.Logf(" privatekey=[%s]", tools.Elide(k.PrivateKey))
  29. t.Logf(" userid=[%s]", k.UserID)
  30. }
  31. func TestImportKeyPair(t *testing.T) {
  32. client, err := newClient()
  33. th.AssertNoErr(t, err)
  34. name := tools.RandomString("importedkey-", 8)
  35. pubkey := "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDlIQ3r+zd97kb9Hzmujd3V6pbO53eb3Go4q2E8iqVGWQfZTrFdL9KACJnqJIm9HmncfRkUTxE37hqeGCCv8uD+ZPmPiZG2E60OX1mGDjbbzAyReRwYWXgXHopggZTLak5k4mwZYaxwaufbVBDRn847e01lZnaXaszEToLM37NLw+uz29sl3TwYy2R0RGHPwPc160aWmdLjSyd1Nd4c9pvvOP/EoEuBjIC6NJJwg2Rvg9sjjx9jYj0QUgc8CqKLN25oMZ69kNJzlFylKRUoeeVr89txlR59yehJWk6Uw6lYFTdJmcmQOFVAJ12RMmS1hLWCM8UzAgtw+EDa0eqBxBDl smash@winter"
  36. k, err := keypairs.Create(client, os.CreateOpts{
  37. Name: name,
  38. PublicKey: pubkey,
  39. }).Extract()
  40. th.AssertNoErr(t, err)
  41. defer deleteKeyPair(t, client, name)
  42. th.CheckEquals(t, pubkey, k.PublicKey)
  43. th.CheckEquals(t, "", k.PrivateKey)
  44. t.Logf("Imported an existing keypair:")
  45. t.Logf(" name=[%s]", k.Name)
  46. t.Logf(" fingerprint=[%s]", k.Fingerprint)
  47. t.Logf(" publickey=[%s]", tools.Elide(k.PublicKey))
  48. t.Logf(" privatekey=[%s]", tools.Elide(k.PrivateKey))
  49. t.Logf(" userid=[%s]", k.UserID)
  50. }
  51. func TestListKeyPairs(t *testing.T) {
  52. client, err := newClient()
  53. th.AssertNoErr(t, err)
  54. count := 0
  55. err = keypairs.List(client).EachPage(func(page pagination.Page) (bool, error) {
  56. count++
  57. t.Logf("--- %02d ---", count)
  58. ks, err := keypairs.ExtractKeyPairs(page)
  59. th.AssertNoErr(t, err)
  60. for i, keypair := range ks {
  61. t.Logf("[%02d] name=[%s]", i, keypair.Name)
  62. t.Logf(" fingerprint=[%s]", keypair.Fingerprint)
  63. t.Logf(" publickey=[%s]", tools.Elide(keypair.PublicKey))
  64. t.Logf(" privatekey=[%s]", tools.Elide(keypair.PrivateKey))
  65. t.Logf(" userid=[%s]", keypair.UserID)
  66. }
  67. return true, nil
  68. })
  69. th.AssertNoErr(t, err)
  70. }