~rogpeppe/juju-core/502-upgrades-simplify

« back to all changes in this revision

Viewing changes to environs/cloudinit/cloudinit_test.go

[r=dimitern],[bug=1240667] Fixed bug #1240667: pin priority for cloud-tools

This introduces several new calls in cloudinit,
which deal with apt sources, their preferences
(/etc/apt/preferences.d/) and packages that we
install from there.

Basically, when deploying a precise machine that
needs to install mongodb-server package, we add
the cloud-tools pocket, but by default this will
add it as an apt source with a higher priority
than the main archive. As a consequence, charms
that try to install packages from main, which
are also in the cloud-tools pocket get the latter,
rather than the former (i.e. the described problem
with python-django's version 1.5 in cloud-tools vs.
1.14 in main, which breaks openstack-dashboard charm).

Now, when adding the cloud-tools archive we also
change its apt preferences, so that its priority
as an apt source is lower than main, which means
when installing mongodb-server during cloudinit
we need to explicitly specity --target-release
'precise-updates/cloud-tools' to pick the version
from cloud-tools.

Live tested on EC2 and works as expected.

https://codereview.appspot.com/61410051/

R=gz, rogpeppe

Show diffs side-by-side

added added

removed removed

Lines of Context:
119
119
printf '%s\\n' '.*' > '/var/lib/juju/agents/machine-0/format'
120
120
install -m 600 /dev/null '/var/lib/juju/agents/machine-0/agent\.conf'
121
121
printf '%s\\n' '.*' > '/var/lib/juju/agents/machine-0/agent\.conf'
 
122
install -D -m 644 /dev/null '/etc/apt/preferences\.d/50-cloud-tools'
 
123
printf '%s\\n' '.*' > '/etc/apt/preferences\.d/50-cloud-tools'
122
124
install -D -m 600 /dev/null '/var/lib/juju/system-identity'
123
125
printf '%s\\n' '.*' > '/var/lib/juju/system-identity'
124
126
install -D -m 600 /dev/null '/var/lib/juju/server\.pem'
559
561
        }
560
562
}
561
563
 
562
 
// CheckPackage checks that the cloudinit will or won't install the given
 
564
// checkPackage checks that the cloudinit will or won't install the given
563
565
// package, depending on the value of match.
564
566
func checkPackage(c *gc.C, x map[interface{}]interface{}, pkg string, match bool) {
565
567
        pkgs0 := x["packages"]
575
577
        found := false
576
578
        for _, p0 := range pkgs {
577
579
                p := p0.(string)
578
 
                if p == pkg {
 
580
                hasTargetRelease := strings.Contains(p, "--target-release")
 
581
                hasQuotedPkg := strings.Contains(p, "'"+pkg+"'")
 
582
                if p == pkg || (hasTargetRelease && hasQuotedPkg) {
579
583
                        found = true
580
584
                }
581
585
        }
587
591
        }
588
592
}
589
593
 
590
 
// CheckAptSources checks that the cloudinit will or won't install the given
 
594
// checkAptSources checks that the cloudinit will or won't install the given
591
595
// source, depending on the value of match.
592
596
func checkAptSource(c *gc.C, x map[interface{}]interface{}, source, key string, match bool) {
593
597
        sources0 := x["apt_sources"]