Example #1
0
// Verifies that it is possible to get a share network
func TestGet(t *testing.T) {
	th.SetupHTTP()
	defer th.TeardownHTTP()

	MockGetResponse(t)

	var nilTime time.Time
	expected := sharenetworks.ShareNetwork{
		ID:              "7f950b52-6141-4a08-bbb5-bb7ffa3ea5fd",
		Name:            "net_my1",
		CreatedAt:       gophercloud.JSONRFC3339MilliNoZ(time.Date(2015, 9, 4, 14, 56, 45, 0, time.UTC)),
		Description:     "descr",
		NetworkType:     "",
		CIDR:            "",
		NovaNetID:       "",
		NeutronNetID:    "998b42ee-2cee-4d36-8b95-67b5ca1f2109",
		NeutronSubnetID: "53482b62-2c84-4a53-b6ab-30d9d9800d06",
		IPVersion:       0,
		SegmentationID:  0,
		UpdatedAt:       gophercloud.JSONRFC3339MilliNoZ(nilTime),
		ProjectID:       "16e1ab15c35a457e9c2b2aa189f544e1",
	}

	n, err := sharenetworks.Get(client.ServiceClient(), "7f950b52-6141-4a08-bbb5-bb7ffa3ea5fd").Extract()
	th.AssertNoErr(t, err)

	th.CheckDeepEquals(t, &expected, n)
}
Example #2
0
// Verifies that it is possible to update a share network using nova network
func TestUpdateNova(t *testing.T) {
	th.SetupHTTP()
	defer th.TeardownHTTP()

	MockUpdateNovaResponse(t)

	expected := sharenetworks.ShareNetwork{
		ID:              "713df749-aac0-4a54-af52-10f6c991e80c",
		Name:            "net_my2",
		CreatedAt:       gophercloud.JSONRFC3339MilliNoZ(time.Date(2015, 9, 4, 14, 54, 25, 0, time.UTC)),
		Description:     "new description",
		NetworkType:     "",
		CIDR:            "",
		NovaNetID:       "new-nova-id",
		NeutronNetID:    "",
		NeutronSubnetID: "",
		IPVersion:       4,
		SegmentationID:  0,
		UpdatedAt:       gophercloud.JSONRFC3339MilliNoZ(time.Date(2015, 9, 7, 8, 2, 53, 512184000, time.UTC)),
		ProjectID:       "16e1ab15c35a457e9c2b2aa189f544e1",
	}

	options := sharenetworks.UpdateOpts{
		Name:        "net_my2",
		Description: "new description",
		NovaNetID:   "new-nova-id",
	}

	v, err := sharenetworks.Update(client.ServiceClient(), "713df749-aac0-4a54-af52-10f6c991e80c", options).Extract()
	th.AssertNoErr(t, err)
	th.CheckDeepEquals(t, &expected, v)
}
Example #3
0
func TestList(t *testing.T) {
	th.SetupHTTP()
	defer th.TeardownHTTP()

	MockListResponse(t)

	count := 0

	snapshots.List(client.ServiceClient(), &snapshots.ListOpts{}).EachPage(func(page pagination.Page) (bool, error) {
		count++
		actual, err := snapshots.ExtractSnapshots(page)
		if err != nil {
			t.Errorf("Failed to extract snapshots: %v", err)
			return false, err
		}

		expected := []snapshots.Snapshot{
			{
				ID:          "289da7f8-6440-407c-9fb4-7db01ec49164",
				Name:        "snapshot-001",
				VolumeID:    "521752a6-acf6-4b2d-bc7a-119f9148cd8c",
				Status:      "available",
				Size:        30,
				CreatedAt:   gophercloud.JSONRFC3339MilliNoZ(time.Date(2012, 2, 14, 20, 53, 7, 0, time.UTC)),
				Description: "Daily Backup",
			},
			{
				ID:          "96c3bda7-c82a-4f50-be73-ca7621794835",
				Name:        "snapshot-002",
				VolumeID:    "76b8950a-8594-4e5b-8dce-0dfa9c696358",
				Status:      "available",
				Size:        25,
				CreatedAt:   gophercloud.JSONRFC3339MilliNoZ(time.Date(2012, 2, 14, 20, 53, 8, 0, time.UTC)),
				Description: "Weekly Backup",
			},
		}

		th.CheckDeepEquals(t, expected, actual)

		return true, nil
	})

	if count != 1 {
		t.Errorf("Expected 1 page, got %d", count)
	}
}
Example #4
0
func TestGet(t *testing.T) {
	th.SetupHTTP()
	defer th.TeardownHTTP()

	MockGetResponse(t)

	s, err := shares.Get(client.ServiceClient(), shareID).Extract()
	th.AssertNoErr(t, err)
	th.AssertDeepEquals(t, s, &shares.Share{
		AvailabilityZone:   "nova",
		ShareNetworkID:     "713df749-aac0-4a54-af52-10f6c991e80c",
		ShareServerID:      "e268f4aa-d571-43dd-9ab3-f49ad06ffaef",
		SnapshotID:         "",
		ID:                 shareID,
		Size:               1,
		ShareType:          "25747776-08e5-494f-ab40-a64b9d20d8f7",
		ShareTypeName:      "default",
		ConsistencyGroupID: "9397c191-8427-4661-a2e8-b23820dc01d4",
		ProjectID:          "16e1ab15c35a457e9c2b2aa189f544e1",
		Metadata: map[string]string{
			"project": "my_app",
			"aim":     "doc",
		},
		Status:          "available",
		Description:     "My custom share London",
		Host:            "manila2@generic1#GENERIC1",
		HasReplicas:     false,
		ReplicationType: "",
		TaskState:       "",
		SnapshotSupport: true,
		Name:            "my_test_share",
		CreatedAt: gophercloud.JSONRFC3339MilliNoZ(time.Date(
			2015, time.September, 18, 10, 25, 24, 0, time.UTC)),
		ShareProto:               "NFS",
		VolumeType:               "default",
		SourceCgsnapshotMemberID: "",
		IsPublic:                 true,
		Links: []map[string]string{
			{
				"href": "http://172.18.198.54:8786/v2/16e1ab15c35a457e9c2b2aa189f544e1/shares/011d21e2-fbc3-4e4a-9993-9ea223f73264",
				"rel":  "self",
			},
			{
				"href": "http://172.18.198.54:8786/16e1ab15c35a457e9c2b2aa189f544e1/shares/011d21e2-fbc3-4e4a-9993-9ea223f73264",
				"rel":  "bookmark",
			},
		},
	})
}
Example #5
0
func TestGet(t *testing.T) {
	th.SetupHTTP()
	defer th.TeardownHTTP()

	MockGetResponse(t)

	actual, err := volumes.Get(client.ServiceClient(), "d32019d3-bc6e-4319-9c1d-6722fc136a22").Extract()
	th.AssertNoErr(t, err)

	expected := &volumes.Volume{
		Status: "active",
		Name:   "vol-001",
		Attachments: []map[string]interface{}{
			{
				"attachment_id": "03987cd1-0ad5-40d1-9b2a-7cc48295d4fa",
				"id":            "47e9ecc5-4045-4ee3-9a4b-d859d546a0cf",
				"volume_id":     "6c80f8ac-e3e2-480c-8e6e-f1db92fe4bfe",
				"server_id":     "d1c4788b-9435-42e2-9b81-29f3be1cd01f",
				"host_name":     "mitaka",
				"device":        "/",
			},
		},
		AvailabilityZone: "us-east1",
		Bootable:         "false",
		CreatedAt:        gophercloud.JSONRFC3339MilliNoZ(time.Date(2012, 2, 14, 20, 53, 07, 0, time.UTC)),
		Description:      "Another volume.",
		VolumeType:       "289da7f8-6440-407c-9fb4-7db01ec49164",
		SnapshotID:       "",
		SourceVolID:      "",
		Metadata: map[string]string{
			"contents": "junk",
		},
		ID:   "521752a6-acf6-4b2d-bc7a-119f9148cd8c",
		Size: 30,
	}

	th.AssertDeepEquals(t, expected, actual)
}
Example #6
0
			"vpn_private_address": "10.0.0.10",
			"vpn_public_address": null,
			"vpn_public_port": 1001
		}
}
`

// FirstNetwork is the first result in ListOutput.
var nilTime time.Time
var FirstNetwork = networks.Network{
	Bridge:            "br100",
	BridgeInterface:   "eth0",
	Broadcast:         "10.0.0.7",
	CIDR:              "10.0.0.0/29",
	CIDRv6:            "",
	CreatedAt:         gophercloud.JSONRFC3339MilliNoZ(time.Date(2011, 8, 15, 6, 19, 19, 387525000, time.UTC)),
	Deleted:           false,
	DeletedAt:         gophercloud.JSONRFC3339MilliNoZ(nilTime),
	DHCPStart:         "10.0.0.3",
	DNS1:              "",
	DNS2:              "",
	Gateway:           "10.0.0.1",
	Gatewayv6:         "",
	Host:              "nsokolov-desktop",
	ID:                "20c8acc0-f747-4d71-a389-46d078ebf047",
	Injected:          false,
	Label:             "mynet_0",
	MultiHost:         false,
	Netmask:           "255.255.255.248",
	Netmaskv6:         "",
	Priority:          0,
Example #7
0
// Verifies that share networks can be listed correctly
func TestListDetail(t *testing.T) {
	th.SetupHTTP()
	defer th.TeardownHTTP()

	MockListResponse(t)

	allPages, err := sharenetworks.ListDetail(client.ServiceClient(), &sharenetworks.ListOpts{}).AllPages()

	th.AssertNoErr(t, err)
	actual, err := sharenetworks.ExtractShareNetworks(allPages)
	th.AssertNoErr(t, err)

	var nilTime time.Time
	expected := []sharenetworks.ShareNetwork{
		{
			ID:              "32763294-e3d4-456a-998d-60047677c2fb",
			Name:            "net_my1",
			CreatedAt:       gophercloud.JSONRFC3339MilliNoZ(time.Date(2015, 9, 4, 14, 57, 13, 0, time.UTC)),
			Description:     "descr",
			NetworkType:     "",
			CIDR:            "",
			NovaNetID:       "",
			NeutronNetID:    "998b42ee-2cee-4d36-8b95-67b5ca1f2109",
			NeutronSubnetID: "53482b62-2c84-4a53-b6ab-30d9d9800d06",
			IPVersion:       0,
			SegmentationID:  0,
			UpdatedAt:       gophercloud.JSONRFC3339MilliNoZ(nilTime),
			ProjectID:       "16e1ab15c35a457e9c2b2aa189f544e1",
		},
		{
			ID:              "713df749-aac0-4a54-af52-10f6c991e80c",
			Name:            "net_my",
			CreatedAt:       gophercloud.JSONRFC3339MilliNoZ(time.Date(2015, 9, 4, 14, 54, 25, 0, time.UTC)),
			Description:     "desecr",
			NetworkType:     "",
			CIDR:            "",
			NovaNetID:       "",
			NeutronNetID:    "998b42ee-2cee-4d36-8b95-67b5ca1f2109",
			NeutronSubnetID: "53482b62-2c84-4a53-b6ab-30d9d9800d06",
			IPVersion:       0,
			SegmentationID:  0,
			UpdatedAt:       gophercloud.JSONRFC3339MilliNoZ(nilTime),
			ProjectID:       "16e1ab15c35a457e9c2b2aa189f544e1",
		},
		{
			ID:              "fa158a3d-6d9f-4187-9ca5-abbb82646eb2",
			Name:            "",
			CreatedAt:       gophercloud.JSONRFC3339MilliNoZ(time.Date(2015, 9, 4, 14, 51, 41, 0, time.UTC)),
			Description:     "",
			NetworkType:     "",
			CIDR:            "",
			NovaNetID:       "",
			NeutronNetID:    "",
			NeutronSubnetID: "",
			IPVersion:       0,
			SegmentationID:  0,
			UpdatedAt:       gophercloud.JSONRFC3339MilliNoZ(nilTime),
			ProjectID:       "16e1ab15c35a457e9c2b2aa189f544e1",
		},
	}

	th.CheckDeepEquals(t, expected, actual)
}
Example #8
0
func TestListWithExtensions(t *testing.T) {
	th.SetupHTTP()
	defer th.TeardownHTTP()

	MockListResponse(t)

	count := 0

	volumes.List(client.ServiceClient(), &volumes.ListOpts{}).EachPage(func(page pagination.Page) (bool, error) {
		count++
		actual, err := volumes.ExtractVolumes(page)
		if err != nil {
			t.Errorf("Failed to extract volumes: %v", err)
			return false, err
		}

		expected := []volumes.Volume{
			{
				ID:   "289da7f8-6440-407c-9fb4-7db01ec49164",
				Name: "vol-001",
				Attachments: []volumes.Attachment{{
					ServerID:     "83ec2e3b-4321-422b-8706-a84185f52a0a",
					AttachmentID: "05551600-a936-4d4a-ba42-79a037c1-c91a",
					AttachedAt:   gophercloud.JSONRFC3339MilliNoZ(time.Date(2016, 8, 6, 14, 48, 20, 0, time.UTC)),
					HostName:     "foobar",
					VolumeID:     "d6cacb1a-8b59-4c88-ad90-d70ebb82bb75",
					Device:       "/dev/vdc",
					ID:           "d6cacb1a-8b59-4c88-ad90-d70ebb82bb75",
				}},
				AvailabilityZone:   "nova",
				Bootable:           "false",
				ConsistencyGroupID: "",
				CreatedAt:          gophercloud.JSONRFC3339MilliNoZ(time.Date(2015, 9, 17, 3, 35, 3, 0, time.UTC)),
				Description:        "",
				Encrypted:          false,
				Metadata:           map[string]string{"foo": "bar"},
				Multiattach:        false,
				//TenantID:                  "304dc00909ac4d0da6c62d816bcb3459",
				//ReplicationDriverData:     "",
				//ReplicationExtendedStatus: "",
				ReplicationStatus: "disabled",
				Size:              75,
				SnapshotID:        "",
				SourceVolID:       "",
				Status:            "available",
				UserID:            "ff1ce52c03ab433aaba9108c2e3ef541",
				VolumeType:        "lvmdriver-1",
			},
			{
				ID:                 "96c3bda7-c82a-4f50-be73-ca7621794835",
				Name:               "vol-002",
				Attachments:        []volumes.Attachment{},
				AvailabilityZone:   "nova",
				Bootable:           "false",
				ConsistencyGroupID: "",
				CreatedAt:          gophercloud.JSONRFC3339MilliNoZ(time.Date(2015, 9, 17, 3, 32, 29, 0, time.UTC)),
				Description:        "",
				Encrypted:          false,
				Metadata:           map[string]string{},
				Multiattach:        false,
				//TenantID:                  "304dc00909ac4d0da6c62d816bcb3459",
				//ReplicationDriverData:     "",
				//ReplicationExtendedStatus: "",
				ReplicationStatus: "disabled",
				Size:              75,
				SnapshotID:        "",
				SourceVolID:       "",
				Status:            "available",
				UserID:            "ff1ce52c03ab433aaba9108c2e3ef541",
				VolumeType:        "lvmdriver-1",
			},
		}

		th.CheckDeepEquals(t, expected, actual)

		return true, nil
	})

	if count != 1 {
		t.Errorf("Expected 1 page, got %d", count)
	}
}
Example #9
0
	th.Mux.HandleFunc("/testContainer/testObject", func(w http.ResponseWriter, r *http.Request) {
		th.TestMethod(t, r, "GET")
		th.TestHeader(t, r, "X-Auth-Token", fake.TokenID)
		th.TestHeader(t, r, "Accept", "application/json")
		w.Header().Set("Date", "Wed, 10 Nov 2009 23:00:00 GMT")
		w.WriteHeader(http.StatusOK)
		fmt.Fprintf(w, "Successful download with Gophercloud")
	})
}

// ExpectedListInfo is the result expected from a call to `List` when full
// info is requested.
var ExpectedListInfo = []objects.Object{
	{
		Hash:         "451e372e48e0f6b1114fa0724aa79fa1",
		LastModified: gophercloud.JSONRFC3339MilliNoZ(time.Date(2016, time.August, 17, 22, 11, 58, 602650000, time.UTC)), //"2016-08-17T22:11:58.602650"
		Bytes:        14,
		Name:         "goodbye",
		ContentType:  "application/octet-stream",
	},
	{
		Hash:         "451e372e48e0f6b1114fa0724aa79fa1",
		LastModified: gophercloud.JSONRFC3339MilliNoZ(time.Date(2016, time.August, 17, 22, 11, 58, 602650000, time.UTC)),
		Bytes:        14,
		Name:         "hello",
		ContentType:  "application/octet-stream",
	},
}

// ExpectedListNames is the result expected from a call to `List` when just
// object names are requested.