From 6daf9fb682a4d90143e31ad0c7012054767dcf80 Mon Sep 17 00:00:00 2001 From: Kian Parvin Date: Mon, 10 Jun 2024 10:50:12 +0200 Subject: [PATCH] Update jimmctl migrate for consistency jimmctl migrate accepts a model tag of the form "model-", 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. --- cmd/jimmctl/cmd/migratemodel.go | 19 +++++++++---------- cmd/jimmctl/cmd/migratemodel_test.go | 8 ++++---- 2 files changed, 13 insertions(+), 14 deletions(-) diff --git a/cmd/jimmctl/cmd/migratemodel.go b/cmd/jimmctl/cmd/migratemodel.go index f17228d62..06770b63f 100644 --- a/cmd/jimmctl/cmd/migratemodel.go +++ b/cmd/jimmctl/cmd/migratemodel.go @@ -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-" 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 - jimmctl migrate + jimmctl migrate + jimmctl migrate ` // NewMigrateModelCommand returns a command to migrate models. @@ -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 } diff --git a/cmd/jimmctl/cmd/migratemodel_test.go b/cmd/jimmctl/cmd/migratemodel_test.go index 3fc953a46..f0ef7cdb3 100644 --- a/cmd/jimmctl/cmd/migratemodel_test.go +++ b/cmd/jimmctl/cmd/migratemodel_test.go @@ -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) } @@ -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") }