Skip to content

Commit 9065fd1

Browse files
committed
filesystem storage defaults to rootfs
1 parent 13c7ae1 commit 9065fd1

File tree

5 files changed

+49
-8
lines changed

5 files changed

+49
-8
lines changed

apiserver/client/client.go

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import (
3030
"github.com/juju/juju/state/multiwatcher"
3131
statestorage "github.com/juju/juju/state/storage"
3232
"github.com/juju/juju/storage"
33+
"github.com/juju/juju/storage/provider"
3334
"github.com/juju/juju/version"
3435
)
3536

@@ -323,6 +324,10 @@ func (c *Client) ServiceDeploy(args params.ServiceDeploy) error {
323324
// TODO(axw) stop checking feature flag once storage has graduated.
324325
var storageConstraints map[string]storage.Constraints
325326
if featureflag.Enabled(feature.Storage) {
327+
storageConstraints = args.Storage
328+
if storageConstraints == nil {
329+
storageConstraints = make(map[string]storage.Constraints)
330+
}
326331
// Validate the storage parameters against the charm metadata,
327332
// and ensure there are no conflicting parameters.
328333
if err := validateCharmStorage(args, ch); err != nil {
@@ -343,15 +348,23 @@ func (c *Client) ServiceDeploy(args params.ServiceDeploy) error {
343348
store,
344349
)
345350
}
346-
// TODO(axw) when storage pools, providers etc. are implemented,
347-
// and we have a "loop" storage provider, we should create minimal
348-
// constraints with the "loop" pool here.
349-
return errors.Errorf(
350-
"no constraints specified for charm storage %q, loop not implemented",
351-
store,
352-
)
351+
if charmStorage.CountMin <= 0 {
352+
continue
353+
}
354+
if charmStorage.Type == charm.StorageBlock {
355+
// TODO(axw) clarify what the rules are for "block" kind when
356+
// no constraints are specified. For "filesystem" we use rootfs.
357+
return errors.Errorf(
358+
"no constraints specified for block charm storage %q",
359+
store,
360+
)
361+
}
362+
storageConstraints[store] = storage.Constraints{
363+
// The pool is the provider type since rootfs provider has no configuration.
364+
Pool: string(provider.RootfsProviderType),
365+
Count: uint64(charmStorage.CountMin),
366+
}
353367
}
354-
storageConstraints = args.Storage
355368
}
356369

357370
var settings charm.Settings

apiserver/client/client_test.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1519,6 +1519,25 @@ func (s *clientSuite) TestClientServiceDeployWithUnsupportedStoragePool(c *gc.C)
15191519
`.*pool "host-loop-pool" uses storage provider "hostloop" which is not supported for environments of type "dummy"`)
15201520
}
15211521

1522+
func (s *clientSuite) TestClientServiceDeployDefaultFilesystemStorage(c *gc.C) {
1523+
s.setupStoragePool(c)
1524+
s.makeMockCharmStore()
1525+
curl, bundle := addCharm(c, "storage-filesystem")
1526+
var cons constraints.Value
1527+
err := s.APIState.Client().ServiceDeployWithNetworks(curl.String(), "service", 1, "", cons, "", nil, nil)
1528+
c.Assert(err, jc.ErrorIsNil)
1529+
service := s.assertPrincipalDeployed(c, "service", curl, false, bundle, cons)
1530+
storageConstraintsOut, err := service.StorageConstraints()
1531+
c.Assert(err, jc.ErrorIsNil)
1532+
c.Assert(storageConstraintsOut, gc.DeepEquals, map[string]state.StorageConstraints{
1533+
"data": {
1534+
Count: 1,
1535+
Size: 1024,
1536+
Pool: "rootfs",
1537+
},
1538+
})
1539+
}
1540+
15221541
func (s *clientSuite) setupServiceDeploy(c *gc.C, args string) (*charm.URL, charm.Charm, constraints.Value) {
15231542
s.makeMockCharmStore()
15241543
curl, bundle := addCharm(c, "dummy")
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
#!/bin/bash
2+
echo "Done!"
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
name: storage-filesystem
2+
summary: A charm needing filesystem storage
3+
description: See above
4+
storage:
5+
data:
6+
type: filesystem
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
1

0 commit comments

Comments
 (0)