func (*utilsSuite) TestCompression(c *gc.C) { cdata := utils.Gzip(data) c.Assert(len(cdata) < len(data), gc.Equals, true) data1, err := utils.Gunzip(cdata) c.Assert(err, gc.IsNil) c.Assert(data1, gc.DeepEquals, data) data1, err = utils.Gunzip(compressedData) c.Assert(err, gc.IsNil) c.Assert(data1, gc.DeepEquals, data) }
// ComposeUserData fills out the provided cloudinit configuration structure // so it is suitable for initialising a machine with the given configuration, // and then renders it and returns it as a binary (gzipped) blob of user data. // // If the provided cloudcfg is nil, a new one will be created internally. func ComposeUserData(mcfg *cloudinit.MachineConfig, cloudcfg *coreCloudinit.Config) ([]byte, error) { if cloudcfg == nil { cloudcfg = coreCloudinit.New() } if err := configureCloudinit(mcfg, cloudcfg); err != nil { return nil, err } data, err := cloudcfg.Render() logger.Tracef("Generated cloud init:\n%s", string(data)) if err != nil { return nil, err } return utils.Gzip(data), nil }