func (s *ImportSuite) TestImportModel(c *gc.C) { model, err := s.State.Export() c.Check(err, jc.ErrorIsNil) controllerConfig, err := s.State.ModelConfig() c.Check(err, jc.ErrorIsNil) // Update the config values in the exported model for different values for // "state-port", "api-port", and "ca-cert". Also give the model a new UUID // and name so we can import it nicely. model.UpdateConfig(map[string]interface{}{ "name": "new-model", "uuid": utils.MustNewUUID().String(), "state-port": 12345, "api-port": 54321, "ca-cert": "not really a cert", }) bytes, err := description.Serialize(model) c.Check(err, jc.ErrorIsNil) dbModel, dbState, err := migration.ImportModel(s.State, bytes) c.Check(err, jc.ErrorIsNil) defer dbState.Close() dbConfig, err := dbModel.Config() c.Assert(err, jc.ErrorIsNil) attrs := dbConfig.AllAttrs() c.Assert(attrs["state-port"], gc.Equals, controllerConfig.StatePort()) c.Assert(attrs["api-port"], gc.Equals, controllerConfig.APIPort()) cacert, ok := controllerConfig.CACert() c.Assert(ok, jc.IsTrue) c.Assert(attrs["ca-cert"], gc.Equals, cacert) c.Assert(attrs["controller-uuid"], gc.Equals, controllerConfig.UUID()) }
func (s *ImportSuite) TestBadBytes(c *gc.C) { bytes := []byte("not a model") model, st, err := migration.ImportModel(s.State, bytes) c.Check(st, gc.IsNil) c.Check(model, gc.IsNil) c.Assert(err, gc.ErrorMatches, "yaml: unmarshal errors:\n.*") }
func (s *ImportSuite) TestImportModel(c *gc.C) { model, err := s.State.Export() c.Check(err, jc.ErrorIsNil) // Update the config values in the exported model for different values for // "state-port", "api-port", and "ca-cert". Also give the model a new UUID // and name so we can import it nicely. uuid := utils.MustNewUUID().String() model.UpdateConfig(map[string]interface{}{ "name": "new-model", "uuid": uuid, }) bytes, err := description.Serialize(model) c.Check(err, jc.ErrorIsNil) dbModel, dbState, err := migration.ImportModel(s.State, bytes) c.Check(err, jc.ErrorIsNil) defer dbState.Close() dbConfig, err := dbModel.Config() c.Assert(err, jc.ErrorIsNil) c.Assert(dbConfig.UUID(), gc.Equals, uuid) c.Assert(dbConfig.Name(), gc.Equals, "new-model") }
// Import takes a serialized Juju model, deserializes it, and // recreates it in the receiving controller. func (api *API) Import(serialized params.SerializedModel) error { _, st, err := migration.ImportModel(api.state, serialized.Bytes) if err != nil { return err } defer st.Close() // TODO(mjs) - post import checks return err }
// Import takes a serialized Juju model, deserializes it, and // recreates it in the receiving controller. func (api *API) Import(serialized params.SerializedModel) error { _, st, err := migration.ImportModel(api.state, serialized.Bytes) if err != nil { return err } defer st.Close() // TODO(mjs) - post import checks // NOTE(fwereade) - checks here would be sensible, but we will // also need to check after the binaries are imported too. return err }
func (c *MigrateCommand) importModel(ctx *cmd.Context, st *state.State) error { ctx.Infof("\nimport ") bytes, err := ioutil.ReadFile(c.filename) if err != nil { return errors.Trace(err) } env, newSt, err := migration.ImportModel(st, bytes) if err != nil { return errors.Trace(err) } defer newSt.Close() ctx.Infof("success, model %s/%s imported", env.Owner().Canonical(), env.Name()) return nil }