Skip to content

Commit

Permalink
Update jimmctl migrate for consistency
Browse files Browse the repository at this point in the history
jimmctl migrate accepts a model tag of the form "model-<UUID>", other commands that are specifically targeted at models don't require the "model" prefix. Make `jimmctl migrate` work similarly since we already know we are expecting model UUIDs.
  • Loading branch information
kian99 committed Jun 10, 2024
1 parent dabe109 commit 6daf9fb
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 14 deletions.
19 changes: 9 additions & 10 deletions cmd/jimmctl/cmd/migratemodel.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,14 @@ import (

var migrateModelCommandDoc = `
The migrate command migrates a model(s) to a new controller. Specify
a model-tag to migrate and the destination controller name.
A model-tag is of the form "model-<UUID>" while a controller name is
simply the name of the controller.
a model-uuid to migrate and the destination controller name.
Note that multiple models can be targeted for migration by supplying
multiple model tags.
multiple model uuids.
Example:
jimmctl migrate <controller-name> <model-tag>
jimmctl migrate <controller-name> <model-tag> <model-tag> <model-tag>
jimmctl migrate <controller-name> <model-uuid>
jimmctl migrate <controller-name> <model-uuid> <model-uuid> <model-uuid>
`

// NewMigrateModelCommand returns a command to migrate models.
Expand Down Expand Up @@ -72,18 +70,19 @@ func (c *migrateModelCommand) SetFlags(f *gnuflag.FlagSet) {
// Init implements the cmd.Command interface.
func (c *migrateModelCommand) Init(args []string) error {
if len(args) < 2 {
return errors.E("Missing controller and model tag arguments")
return errors.E("Missing controller name and model uuid arguments")
}
for i, arg := range args {
if i == 0 {
c.targetController = arg
continue
}
_, err := names.ParseModelTag(arg)
mt := names.NewModelTag(arg)
_, err := names.ParseModelTag(mt.String())
if err != nil {
return errors.E(err, fmt.Sprintf("%s is not a valid model tag", arg))
return errors.E(err, fmt.Sprintf("%s is not a valid model uuid", arg))
}
c.modelTags = append(c.modelTags, arg)
c.modelTags = append(c.modelTags, mt.String())
}
return nil
}
Expand Down
8 changes: 4 additions & 4 deletions cmd/jimmctl/cmd/migratemodel_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func (s *migrateModelSuite) TestMigrateModelCommandSuperuser(c *gc.C) {

// alice is superuser
bClient := jimmtest.NewUserSessionLogin(c, "alice")
context, err := cmdtesting.RunCommand(c, cmd.NewMigrateModelCommandForTesting(s.ClientStore(), bClient), "controller-1", mt.String(), mt2.String())
context, err := cmdtesting.RunCommand(c, cmd.NewMigrateModelCommandForTesting(s.ClientStore(), bClient), "controller-1", mt.Id(), mt2.Id())
c.Assert(err, gc.IsNil)
c.Assert(cmdtesting.Stdout(context), gc.Matches, migrationResultRegex)
}
Expand All @@ -62,12 +62,12 @@ func (s *migrateModelSuite) TestMigrateModelCommandFailsWithInvalidModelTag(c *g

// alice is superuser
bClient := jimmtest.NewUserSessionLogin(c, "alice")
_, err := cmdtesting.RunCommand(c, cmd.NewMigrateModelCommandForTesting(s.ClientStore(), bClient), "controller-1", "model-001", "model-002")
c.Assert(err, gc.ErrorMatches, ".* is not a valid model tag")
_, err := cmdtesting.RunCommand(c, cmd.NewMigrateModelCommandForTesting(s.ClientStore(), bClient), "controller-1", "001", "002")
c.Assert(err, gc.ErrorMatches, ".* is not a valid model uuid")
}

func (s *migrateModelSuite) TestMigrateModelCommandFailsWithMissingArgs(c *gc.C) {
bClient := jimmtest.NewUserSessionLogin(c, "alice")
_, err := cmdtesting.RunCommand(c, cmd.NewMigrateModelCommandForTesting(s.ClientStore(), bClient), "myController")
c.Assert(err, gc.ErrorMatches, "Missing controller and model tag arguments")
c.Assert(err, gc.ErrorMatches, "Missing controller name and model uuid arguments")
}

0 comments on commit 6daf9fb

Please sign in to comment.