-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Commands to empty storage pools and heads
- Loading branch information
Phil Manavopoulos
committed
Mar 27, 2017
1 parent
49babef
commit c29094c
Showing
6 changed files
with
164 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package main | ||
|
||
import ( | ||
"github.com/BytemarkHosting/bytemark-client/util/log" | ||
"github.com/urfave/cli" | ||
) | ||
|
||
func init() { | ||
adminCommands = append(adminCommands, cli.Command{ | ||
Name: "empty", | ||
Action: cli.ShowSubcommandHelp, | ||
Subcommands: []cli.Command{ | ||
{ | ||
Name: "storage_pool", | ||
Usage: "empty a storage pool", | ||
UsageText: "bytemark --admin empty storage_pool <storage_pool>", | ||
Flags: []cli.Flag{ | ||
cli.StringFlag{ | ||
Name: "storage_pool", | ||
Usage: "the ID or label of the storage pool to be emptied", | ||
}, | ||
}, | ||
Action: With(OptionalArgs("storage_pool"), RequiredFlags("storage_pool"), AuthProvider, func(c *Context) error { | ||
if err := global.Client.EmptyStoragePool(c.String("storage_pool")); err != nil { | ||
return err | ||
} | ||
|
||
log.Output("Storage pool updated") | ||
|
||
return nil | ||
}), | ||
}, | ||
{ | ||
Name: "head", | ||
Usage: "empty a head", | ||
UsageText: "bytemark --admin empty head <head>", | ||
Flags: []cli.Flag{ | ||
cli.StringFlag{ | ||
Name: "head", | ||
Usage: "the ID or label of the head to be emptied", | ||
}, | ||
}, | ||
Action: With(OptionalArgs("head"), RequiredFlags("head"), AuthProvider, func(c *Context) error { | ||
if err := global.Client.EmptyHead(c.String("head")); err != nil { | ||
return err | ||
} | ||
|
||
log.Output("Head updated") | ||
|
||
return nil | ||
}), | ||
}, | ||
}, | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"github.com/cheekybits/is" | ||
"testing" | ||
) | ||
|
||
func TestEmptyStoragePool(t *testing.T) { | ||
is := is.New(t) | ||
_, c := baseTestAuthSetup(t, true) | ||
|
||
c.When("EmptyStoragePool", "pool1").Return(nil).Times(1) | ||
|
||
err := global.App.Run([]string{"bytemark", "empty", "storage_pool", "pool1"}) | ||
|
||
is.Nil(err) | ||
|
||
if ok, err := c.Verify(); !ok { | ||
t.Fatal(err) | ||
} | ||
} | ||
|
||
func TestEmptyStoragePoolError(t *testing.T) { | ||
is := is.New(t) | ||
_, c := baseTestAuthSetup(t, true) | ||
|
||
c.When("EmptyStoragePool", "pool1").Return(fmt.Errorf("Could not empty storage pool")).Times(1) | ||
|
||
err := global.App.Run([]string{"bytemark", "empty", "storage_pool", "pool1"}) | ||
|
||
is.NotNil(err) | ||
|
||
if ok, err := c.Verify(); !ok { | ||
t.Fatal(err) | ||
} | ||
} | ||
|
||
func TestEmptyHead(t *testing.T) { | ||
is := is.New(t) | ||
_, c := baseTestAuthSetup(t, true) | ||
|
||
c.When("EmptyHead", "pool1").Return(nil).Times(1) | ||
|
||
err := global.App.Run([]string{"bytemark", "empty", "head", "pool1"}) | ||
|
||
is.Nil(err) | ||
|
||
if ok, err := c.Verify(); !ok { | ||
t.Fatal(err) | ||
} | ||
} | ||
|
||
func TestEmptyHeadError(t *testing.T) { | ||
is := is.New(t) | ||
_, c := baseTestAuthSetup(t, true) | ||
|
||
c.When("EmptyHead", "pool1").Return(fmt.Errorf("Could not empty storage pool")).Times(1) | ||
|
||
err := global.App.Run([]string{"bytemark", "empty", "head", "pool1"}) | ||
|
||
is.NotNil(err) | ||
|
||
if ok, err := c.Verify(); !ok { | ||
t.Fatal(err) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters