Skip to content
This repository has been archived by the owner on Jul 16, 2020. It is now read-only.

Commit

Permalink
Merge pull request #995 from rbradford/populate-volume-size
Browse files Browse the repository at this point in the history
Populate volume size
  • Loading branch information
rbradford authored Jan 6, 2017
2 parents 837d0a9 + 4ad3fc2 commit 225e633
Show file tree
Hide file tree
Showing 8 changed files with 33 additions and 27 deletions.
1 change: 0 additions & 1 deletion ciao-controller/instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,6 @@ func addBlockDevice(c *controller, tenant string, instanceID string, device stor
// a block device is bootable.
data := types.BlockData{
BlockDevice: device,
Size: s.Size,
CreateTime: time.Now(),
TenantID: tenant,
Name: fmt.Sprintf("Storage for instance: %s", instanceID),
Expand Down
15 changes: 0 additions & 15 deletions ciao-controller/internal/datastore/datastore_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1346,7 +1346,6 @@ func TestAttachVolumeFailure(t *testing.T) {

data := types.BlockData{
BlockDevice: blockDevice,
Size: 0,
State: types.Available,
TenantID: newTenant.ID,
CreateTime: time.Now(),
Expand Down Expand Up @@ -1403,7 +1402,6 @@ func TestDetachVolumeFailure(t *testing.T) {

data := types.BlockData{
BlockDevice: blockDevice,
Size: 0,
State: types.Available,
TenantID: newTenant.ID,
CreateTime: time.Now(),
Expand Down Expand Up @@ -1495,7 +1493,6 @@ func TestAddBlockDevice(t *testing.T) {

data := types.BlockData{
BlockDevice: blockDevice,
Size: 0,
State: types.Available,
TenantID: newTenant.ID,
CreateTime: time.Now(),
Expand Down Expand Up @@ -1537,7 +1534,6 @@ func TestDeleteBlockDevice(t *testing.T) {

data := types.BlockData{
BlockDevice: blockDevice,
Size: 0,
State: types.Available,
TenantID: newTenant.ID,
CreateTime: time.Now(),
Expand Down Expand Up @@ -1585,7 +1581,6 @@ func TestUpdateBlockDevice(t *testing.T) {

data := types.BlockData{
BlockDevice: blockDevice,
Size: 0,
State: types.Available,
TenantID: newTenant.ID,
CreateTime: time.Now(),
Expand Down Expand Up @@ -1649,7 +1644,6 @@ func TestUpdateBlockDeviceErr(t *testing.T) {

data := types.BlockData{
BlockDevice: blockDevice,
Size: 0,
State: types.Available,
TenantID: newTenant.ID,
CreateTime: time.Now(),
Expand All @@ -1674,7 +1668,6 @@ func TestCreateStorageAttachment(t *testing.T) {

data := types.BlockData{
BlockDevice: blockDevice,
Size: 0,
State: types.Available,
TenantID: tenant.ID,
CreateTime: time.Now(),
Expand Down Expand Up @@ -1736,7 +1729,6 @@ func TestUpdateStorageAttachmentExisting(t *testing.T) {

data := types.BlockData{
BlockDevice: blockDevice,
Size: 0,
State: types.Available,
TenantID: tenant.ID,
CreateTime: time.Now(),
Expand Down Expand Up @@ -1804,7 +1796,6 @@ func TestUpdateStorageAttachmentNotExisting(t *testing.T) {

data := types.BlockData{
BlockDevice: blockDevice,
Size: 0,
State: types.Available,
TenantID: tenant.ID,
CreateTime: time.Now(),
Expand Down Expand Up @@ -1848,7 +1839,6 @@ func TestUpdateStorageAttachmentDeleted(t *testing.T) {

data := types.BlockData{
BlockDevice: blockDevice,
Size: 0,
State: types.Available,
TenantID: tenant.ID,
CreateTime: time.Now(),
Expand Down Expand Up @@ -1903,7 +1893,6 @@ func TestGetStorageAttachment(t *testing.T) {

data := types.BlockData{
BlockDevice: blockDevice,
Size: 0,
State: types.Available,
TenantID: tenant.ID,
CreateTime: time.Now(),
Expand Down Expand Up @@ -1960,7 +1949,6 @@ func TestGetStorageAttachmentError(t *testing.T) {

data := types.BlockData{
BlockDevice: blockDevice,
Size: 0,
State: types.Available,
TenantID: tenant.ID,
CreateTime: time.Now(),
Expand Down Expand Up @@ -2003,7 +1991,6 @@ func TestDeleteStorageAttachment(t *testing.T) {

data := types.BlockData{
BlockDevice: blockDevice,
Size: 0,
State: types.Available,
TenantID: tenant.ID,
CreateTime: time.Now(),
Expand Down Expand Up @@ -2070,7 +2057,6 @@ func TestDeleteStorageAttachmentError(t *testing.T) {

data := types.BlockData{
BlockDevice: blockDevice,
Size: 0,
State: types.Available,
TenantID: tenant.ID,
CreateTime: time.Now(),
Expand Down Expand Up @@ -2142,7 +2128,6 @@ func TestGetVolumeAttachments(t *testing.T) {

data := types.BlockData{
BlockDevice: blockDevice,
Size: 0,
State: types.Available,
TenantID: tenant.ID,
CreateTime: time.Now(),
Expand Down
4 changes: 0 additions & 4 deletions ciao-controller/internal/datastore/sqlite3db_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ func TestSQLiteDBGetTenantDevices(t *testing.T) {

data := types.BlockData{
BlockDevice: blockDevice,
Size: 0,
State: types.Available,
TenantID: uuid.Generate().String(),
CreateTime: time.Now(),
Expand Down Expand Up @@ -114,7 +113,6 @@ func TestSQLiteDBGetTenantWithStorage(t *testing.T) {

data := types.BlockData{
BlockDevice: blockDevice,
Size: 0,
State: types.Available,
TenantID: tenantID,
CreateTime: time.Now(),
Expand Down Expand Up @@ -155,7 +153,6 @@ func TestSQLiteDBGetAllBlockData(t *testing.T) {

data := types.BlockData{
BlockDevice: blockDevice,
Size: 0,
State: types.Available,
TenantID: uuid.Generate().String(),
CreateTime: time.Now(),
Expand Down Expand Up @@ -191,7 +188,6 @@ func TestSQLiteDBDeleteBlockData(t *testing.T) {

data := types.BlockData{
BlockDevice: blockDevice,
Size: 0,
State: types.Available,
TenantID: uuid.Generate().String(),
CreateTime: time.Now(),
Expand Down
1 change: 0 additions & 1 deletion ciao-controller/openstack_volume.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ func (c *controller) CreateVolume(tenant string, req block.RequestedVolume) (blo
// you should modify BlockData to include a "bootable" flag.
data := types.BlockData{
BlockDevice: bd,
Size: req.Size,
CreateTime: time.Now(),
TenantID: tenant,
State: types.Available,
Expand Down
1 change: 0 additions & 1 deletion ciao-controller/types/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,6 @@ const (
type BlockData struct {
storage.BlockDevice
TenantID string // the tenant who owns this volume
Size int // size in GB
State BlockState // status of
CreateTime time.Time // when we created the volume
Name string // a human readable name for this volume
Expand Down
2 changes: 1 addition & 1 deletion ciao-storage/block.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,5 +47,5 @@ type BlockDevice struct {
Local bool // local (ephemeral) or volume service backed
Swap bool // linux swap device (attempt swapon via cloudinit)
Tag string // arbitrary text identifier
Size int // gigabyte size for autocreation
Size int // size in GiB
}
34 changes: 31 additions & 3 deletions ciao-storage/ceph.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,22 @@ type CephDriver struct {
ID string
}

func (d CephDriver) getBlockDeviceSizeGiB(volumeUUID string) (int, error) {
bytes, err := d.GetBlockDeviceSize(volumeUUID)

if err != nil {
return 0, err
}

// When converting to GiB round up unless we've got a multiple of 1GiB
res := bytes / (1024 * 1024 * 1024)
rem := bytes % (1024 * 1024 * 1024)
if rem == 0 {
return int(res), nil
}
return int(res + 1), nil
}

// CreateBlockDevice will create a rbd image in the ceph cluster.
func (d CephDriver) CreateBlockDevice(volumeUUID string, imagePath string, size int) (BlockDevice, error) {
if volumeUUID == "" {
Expand Down Expand Up @@ -61,7 +77,7 @@ func (d CephDriver) CreateBlockDevice(volumeUUID string, imagePath string, size
return BlockDevice{}, fmt.Errorf("Error when running: %v: %v: %s", cmd.Args, err, out)
}

return BlockDevice{ID: volumeUUID}, nil
return BlockDevice{ID: volumeUUID, Size: size}, nil
}

// CreateBlockDeviceFromSnapshot will create a block device derived from the previously created snapshot.
Expand All @@ -77,7 +93,13 @@ func (d CephDriver) CreateBlockDeviceFromSnapshot(volumeUUID string, snapshotID
return BlockDevice{}, fmt.Errorf("Error when running: %v: %v: %s", cmd.Args, err, out)
}

return BlockDevice{ID: ID}, nil
size, err := d.getBlockDeviceSizeGiB(volumeUUID)
if err != nil {
d.DeleteBlockDevice(volumeUUID)
return BlockDevice{}, fmt.Errorf("Error when querying block device size: %v", err)
}

return BlockDevice{ID: ID, Size: size}, nil
}

// CreateBlockDeviceSnapshot creates and protects the snapshot with the provided name
Expand Down Expand Up @@ -113,7 +135,13 @@ func (d CephDriver) CopyBlockDevice(volumeUUID string) (BlockDevice, error) {
return BlockDevice{}, fmt.Errorf("Error when running: %v: %v: %s", cmd.Args, err, out)
}

return BlockDevice{ID: ID}, nil
size, err := d.getBlockDeviceSizeGiB(volumeUUID)
if err != nil {
d.DeleteBlockDevice(volumeUUID)
return BlockDevice{}, fmt.Errorf("Error when querying block device size: %v", err)
}

return BlockDevice{ID: ID, Size: size}, nil
}

// DeleteBlockDevice will remove a rbd image from the ceph cluster.
Expand Down
2 changes: 1 addition & 1 deletion ciao-storage/noop.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ type NoopDriver struct {

// CreateBlockDevice pretends to create a block device.
func (d *NoopDriver) CreateBlockDevice(volumeUUID string, image string, size int) (BlockDevice, error) {
return BlockDevice{ID: uuid.Generate().String()}, nil
return BlockDevice{ID: uuid.Generate().String(), Size: size}, nil
}

// CreateBlockDeviceFromSnapshot pretends to create a block device snapshot
Expand Down

0 comments on commit 225e633

Please sign in to comment.