make the move-syslog-config upgrade more lenient #2476

Merged
merged 2 commits into from Jun 3, 2015

Conversation

Projects
None yet
4 participants
Contributor

natefinch commented Jun 3, 2015

…about not being able to delete old config files. We don't actually care overly much if the old ones are left around, so now we just log if we can't delete them, rather than screwing the upgrade because of it.

upgrades/steps124.go
+ if err := osRemove(oldpath); err != nil {
+ // Don't fail the step if we can't get rid of the old files.
+ // We don't actually care if they still exist or not.
+ logger.Infof("Can't delete old config file %q: %s", oldpath, err)
@mjs

mjs Jun 3, 2015

Contributor

Warning?

@wallyworld

wallyworld Jun 3, 2015

Owner

Warning even?

upgrades/steps124_test.go
+
+ // ensure that we don't error out if we can't remove the old file.
+ // error out if one of the files exists in datadir but not logdir.
+ *upgrades.OsRemove = func(string) error { return os.ErrPermission }
@wallyworld

wallyworld Jun 3, 2015

Owner

why not patch?

upgrades/steps124_test.go
+
+ // should still exist in both places (i.e. check we didn't screw up the test)
+ _, err = os.Stat(file)
+ c.Assert(err, gc.IsNil)
@mjs

mjs Jun 3, 2015

Contributor

jc.ErrorIsNil

upgrades/steps124_test.go
+ _, err = os.Stat(file)
+ c.Assert(err, gc.IsNil)
+ _, err = os.Stat(filepath.Join(logdir, "logrotate.conf"))
+ c.Assert(err, gc.IsNil)
@mjs

mjs Jun 3, 2015

Contributor

Same

upgrades/steps124_test.go
+
+ ctx := fakeContext{cfg: fakeConfig{logdir: logdir, datadir: datadir}}
+ err = upgrades.MoveSyslogConfig(ctx)
+ c.Assert(err, gc.IsNil)
@mjs

mjs Jun 3, 2015

Contributor

jc.ErrorIsNil

upgrades/steps124_test.go
+ defer func() { *upgrades.OsRemove = os.Remove }()
+
+ err := ioutil.WriteFile(file, data, 0644)
+ c.Assert(err, gc.IsNil)
@mjs

mjs Jun 3, 2015

Contributor

jc.ErrorIsNil

upgrades/steps124_test.go
+ // should still exist in both places (i.e. check we didn't screw up the test)
+ _, err = os.Stat(file)
+ c.Assert(err, gc.IsNil)
+ _, err = os.Stat(filepath.Join(logdir, "logrotate.conf"))
@wallyworld

wallyworld Jun 3, 2015

Owner

isn't file = filepath.Join(logdir, "logrotate.conf")
so these 2 Stat()s are the same?

upgrades/steps124_test.go
+func (s *steps124Suite) TestMoveSyslogConfigCantDeleteOld(c *gc.C) {
+ logdir := c.MkDir()
+ datadir := c.MkDir()
+ data := []byte("data!")
@mjs

mjs Jun 3, 2015

Contributor

nit: given that this is a) obvious and b) only used once, surely you don't need a variable for it

Owner

wallyworld commented Jun 3, 2015

LGTM

Contributor

natefinch commented Jun 3, 2015

$$merge$$

Contributor

jujubot commented Jun 3, 2015

Status: merge request accepted. Url: http://juju-ci.vapour.ws:8080/job/github-merge-juju

Contributor

jujubot commented Jun 3, 2015

Build failed: Does not match ['fixes-1461150', 'fixes-1461246']
build url: http://juju-ci.vapour.ws:8080/job/github-merge-juju/3509

Contributor

natefinch commented Jun 3, 2015

fixes 1461246
$$merge$$

Contributor

jujubot commented Jun 3, 2015

Status: merge request accepted. Url: http://juju-ci.vapour.ws:8080/job/github-merge-juju

Contributor

jujubot commented Jun 3, 2015

Build failed: Does not match ['fixes-1461150', 'fixes-1461246']
build url: http://juju-ci.vapour.ws:8080/job/github-merge-juju/3511

Contributor

natefinch commented Jun 3, 2015

fixes-1461246
$$merge$$

Contributor

jujubot commented Jun 3, 2015

Status: merge request accepted. Url: http://juju-ci.vapour.ws:8080/job/github-merge-juju

Contributor

jujubot commented Jun 3, 2015

Build failed: Tests failed
build url: http://juju-ci.vapour.ws:8080/job/github-merge-juju/3512

Contributor

natefinch commented Jun 3, 2015

$$nobutseriously$$

Contributor

jujubot commented Jun 3, 2015

Status: merge request accepted. Url: http://juju-ci.vapour.ws:8080/job/github-merge-juju

jujubot added a commit that referenced this pull request Jun 3, 2015

Merge pull request #2476 from natefinch/upgrade-fix
make the move-syslog-config upgrade more lenient

…about not being able to delete old config files.  We don't actually care overly much if the old ones are left around, so now we just log if we can't delete them, rather than screwing the upgrade because of it.

@jujubot jujubot merged commit f479fac into juju:1.24 Jun 3, 2015

@natefinch natefinch deleted the natefinch:upgrade-fix branch Jun 3, 2015

jujubot added a commit that referenced this pull request Jul 14, 2015

Merge pull request #2505 from natefinch/fp-fix-1370896-master
FP: fix 1370896 on master

FP of #2458, #2476, and #2489 since the latter two are just fixes to the original PR. 

Fix 1370896 - juju has conf files in /var/log/juju on instances

Fixes https://bugs.launchpad.net/juju-core/+bug/1370896

All the rsyslog configuration files are now created in juju's data directory (by default, /var/lib/juju), instead of the log directory (/var/log/juju).  Also added an upgrade step to move the files from old location to new location.

I made a couple changes to how you create a SyslogConfig, mostly because it was using a function with a huge number of string arguments, which made it very difficult to read, and to understand what value was being assigned to what field.  This made updating the code almost impossible, because of minor positional differences in the function signatures.

I changed  syslog.NewAccumulateConfig and NewForwardConfig to just take a pointer to a SyslogConfig, since pretty much all they did was set exported fields on the type.  Now they just set the non-exported field, and the caller sets everything else in a struct literal.

I also changed it so that the Namespace field in SyslogConfig always stays just "Namespace", not "-Namespace", since it's an exported value, and having it be something different than what was set is really confusing.  Instead, we just add the dash when rendering to the template.

Changed the tests much the same way - just set up the struct and pass it in is so much easier to read than a huge function call with a ton of different string parameters in a random order.  Also changed the test template, so that there aren't hard-coded values in it, and instead actually use the values passed in.

(Review request: http://reviews.vapour.ws/r/1871/)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment