165
// setGUI populates the configuration with the Juju GUI tools.
166
func (cfg *testInstanceConfig) setGUI(path string) *testInstanceConfig {
167
cfg.GUI = &tools.GUIArchive{
168
URL: "file://" + filepath.ToSlash(path),
169
Version: version.MustParse("1.2.3"),
162
176
// maybeSetModelConfig sets the Config field to the given envConfig, if not
164
178
func (cfg *testInstanceConfig) maybeSetModelConfig(envConfig *config.Config) *testInstanceConfig {
165
179
if envConfig != nil {
166
180
cfg.Config = envConfig
182
cfg.HostedModelConfig = map[string]interface{}{"name": "hosted-model"}
309
326
cat > '/var/lib/juju/agents/machine-0/agent\.conf' << 'EOF'\\n.*\\nEOF
310
327
chmod 0600 '/var/lib/juju/agents/machine-0/agent\.conf'
311
328
echo 'Bootstrapping Juju machine agent'.*
312
/var/lib/juju/tools/1\.2\.3-precise-amd64/jujud bootstrap-state --data-dir '/var/lib/juju' --model-config '[^']*' --instance-id 'i-bootstrap' --bootstrap-constraints 'mem=4096M' --constraints 'mem=2048M' --debug
329
/var/lib/juju/tools/1\.2\.3-precise-amd64/jujud bootstrap-state --data-dir '/var/lib/juju' --model-config '[^']*' --hosted-model-config '[^']*' --instance-id 'i-bootstrap' --bootstrap-constraints 'mem=4096M' --constraints 'mem=2048M' --debug
313
330
ln -s 1\.2\.3-precise-amd64 '/var/lib/juju/tools/machine-0'
314
331
echo 'Starting Juju machine agent \(jujud-machine-0\)'.*
315
332
cat > /etc/init/jujud-machine-0\.conf << 'EOF'\\ndescription "juju agent for machine-0"\\nauthor "Juju Team <juju@lists\.ubuntu\.com>"\\nstart on runlevel \[2345\]\\nstop on runlevel \[!2345\]\\nrespawn\\nnormal exit 0\\n\\nlimit nofile 20000 20000\\n\\nscript\\n\\n\\n # Ensure log files are properly protected\\n touch /var/log/juju/machine-0\.log\\n chown syslog:syslog /var/log/juju/machine-0\.log\\n chmod 0600 /var/log/juju/machine-0\.log\\n\\n exec '/var/lib/juju/tools/machine-0/jujud' machine --data-dir '/var/lib/juju' --machine-id 0 --debug >> /var/log/juju/machine-0\.log 2>&1\\nend script\\nEOF\\n
329
346
sha256sum \$bin/tools\.tar\.gz > \$bin/juju1\.2\.3-raring-amd64\.sha256
330
347
grep '1234' \$bin/juju1\.2\.3-raring-amd64.sha256 \|\| \(echo "Tools checksum mismatch"; exit 1\)
331
348
printf %s '{"version":"1\.2\.3-raring-amd64","url":"http://foo\.com/tools/released/juju1\.2\.3-raring-amd64\.tgz","sha256":"1234","size":10}' > \$bin/downloaded-tools\.txt
332
/var/lib/juju/tools/1\.2\.3-raring-amd64/jujud bootstrap-state --data-dir '/var/lib/juju' --model-config '[^']*' --instance-id 'i-bootstrap' --bootstrap-constraints 'mem=4096M' --constraints 'mem=2048M' --debug
349
/var/lib/juju/tools/1\.2\.3-raring-amd64/jujud bootstrap-state --data-dir '/var/lib/juju' --model-config '[^']*' --hosted-model-config '[^']*' --instance-id 'i-bootstrap' --bootstrap-constraints 'mem=4096M' --constraints 'mem=2048M' --debug
333
350
ln -s 1\.2\.3-raring-amd64 '/var/lib/juju/tools/machine-0'
334
351
rm \$bin/tools\.tar\.gz && rm \$bin/juju1\.2\.3-raring-amd64\.sha256
404
// non controller with GUI (the GUI is not installed)
406
cfg: makeNormalConfig("quantal").setGUI("/path/to/gui.tar.bz2"),
409
install -D -m 644 /dev/null '/etc/init/juju-clean-shutdown\.conf'
410
printf '%s\\n' '.*"Stop all network interfaces on shutdown".*' > '/etc/init/juju-clean-shutdown\.conf'
411
install -D -m 644 /dev/null '/var/lib/juju/nonce.txt'
412
printf '%s\\n' 'FAKE_NONCE' > '/var/lib/juju/nonce.txt'
413
test -e /proc/self/fd/9 \|\| exec 9>&2
414
\(\[ ! -e /home/ubuntu/\.profile \] \|\| grep -q '.juju-proxy' /home/ubuntu/.profile\) \|\| printf .* >> /home/ubuntu/.profile
415
mkdir -p /var/lib/juju/locks
416
\(id ubuntu &> /dev/null\) && chown ubuntu:ubuntu /var/lib/juju/locks
417
mkdir -p /var/log/juju
418
chown syslog:adm /var/log/juju
419
bin='/var/lib/juju/tools/1\.2\.3-quantal-amd64'
421
echo 'Fetching tools.*
422
curl .* --noproxy "\*" --insecure -o \$bin/tools\.tar\.gz 'https://state-addr\.testing\.invalid:54321/tools/1\.2\.3-quantal-amd64'
423
sha256sum \$bin/tools\.tar\.gz > \$bin/juju1\.2\.3-quantal-amd64\.sha256
424
grep '1234' \$bin/juju1\.2\.3-quantal-amd64.sha256 \|\| \(echo "Tools checksum mismatch"; exit 1\)
425
tar zxf \$bin/tools.tar.gz -C \$bin
426
printf %s '{"version":"1\.2\.3-quantal-amd64","url":"http://foo\.com/tools/released/juju1\.2\.3-quantal-amd64\.tgz","sha256":"1234","size":10}' > \$bin/downloaded-tools\.txt
427
mkdir -p '/var/lib/juju/agents/machine-99'
428
cat > '/var/lib/juju/agents/machine-99/agent\.conf' << 'EOF'\\n.*\\nEOF
429
chmod 0600 '/var/lib/juju/agents/machine-99/agent\.conf'
430
ln -s 1\.2\.3-quantal-amd64 '/var/lib/juju/tools/machine-99'
431
echo 'Starting Juju machine agent \(jujud-machine-99\)'.*
432
cat > /etc/init/jujud-machine-99\.conf << 'EOF'\\ndescription "juju agent for machine-99"\\nauthor "Juju Team <juju@lists\.ubuntu\.com>"\\nstart on runlevel \[2345\]\\nstop on runlevel \[!2345\]\\nrespawn\\nnormal exit 0\\n\\nlimit nofile 20000 20000\\n\\nscript\\n\\n\\n # Ensure log files are properly protected\\n touch /var/log/juju/machine-99\.log\\n chown syslog:syslog /var/log/juju/machine-99\.log\\n chmod 0600 /var/log/juju/machine-99\.log\\n\\n exec '/var/lib/juju/tools/machine-99/jujud' machine --data-dir '/var/lib/juju' --machine-id 99 --debug >> /var/log/juju/machine-99\.log 2>&1\\nend script\\nEOF\\n
433
start jujud-machine-99
434
rm \$bin/tools\.tar\.gz && rm \$bin/juju1\.2\.3-quantal-amd64\.sha256
387
438
// CentOS non controller with systemd
389
440
cfg: makeNormalConfig("centos7"),
430
481
setEnvConfig: true,
431
482
inexactMatch: true,
433
/var/lib/juju/tools/1\.2\.3-precise-amd64/jujud bootstrap-state --data-dir '/var/lib/juju' --model-config '[^']*' --instance-id 'i-bootstrap' --constraints 'mem=2048M' --debug
484
/var/lib/juju/tools/1\.2\.3-precise-amd64/jujud bootstrap-state --data-dir '/var/lib/juju' --model-config '[^']*' --hosted-model-config '[^']*' --instance-id 'i-bootstrap' --constraints 'mem=2048M' --debug
437
488
// empty environ contraints.
439
490
cfg: makeBootstrapConfig("precise").mutate(func(cfg *testInstanceConfig) {
440
cfg.EnvironConstraints = constraints.Value{}
491
cfg.ModelConstraints = constraints.Value{}
442
493
setEnvConfig: true,
443
494
inexactMatch: true,
445
/var/lib/juju/tools/1\.2\.3-precise-amd64/jujud bootstrap-state --data-dir '/var/lib/juju' --model-config '[^']*' --instance-id 'i-bootstrap' --bootstrap-constraints 'mem=4096M' --debug
496
/var/lib/juju/tools/1\.2\.3-precise-amd64/jujud bootstrap-state --data-dir '/var/lib/juju' --model-config '[^']*' --hosted-model-config '[^']*' --instance-id 'i-bootstrap' --bootstrap-constraints 'mem=4096M' --debug
647
func (*cloudinitSuite) TestCloudInitWithGUI(c *gc.C) {
648
guiPath := path.Join(c.MkDir(), "gui.tar.bz2")
649
err := ioutil.WriteFile(guiPath, []byte("content"), 0644)
650
cfg := makeBootstrapConfig("precise").setGUI(guiPath)
651
envConfig := minimalModelConfig(c)
652
testConfig := cfg.maybeSetModelConfig(envConfig).render()
653
ci, err := cloudinit.New(testConfig.Series)
654
c.Assert(err, jc.ErrorIsNil)
655
udata, err := cloudconfig.NewUserdataConfig(&testConfig, ci)
656
c.Assert(err, jc.ErrorIsNil)
657
err = udata.Configure()
658
c.Assert(err, jc.ErrorIsNil)
659
c.Check(ci, gc.NotNil)
660
data, err := ci.RenderYAML()
661
c.Assert(err, jc.ErrorIsNil)
663
configKeyValues := make(map[interface{}]interface{})
664
err = goyaml.Unmarshal(data, &configKeyValues)
665
c.Assert(err, jc.ErrorIsNil)
667
guiJson, err := json.Marshal(cfg.GUI)
668
c.Assert(err, jc.ErrorIsNil)
670
scripts := getScripts(configKeyValues)
671
expectedScripts := regexp.QuoteMeta(fmt.Sprintf(`sha256sum $gui/gui.tar.bz2 > $gui/jujugui.sha256
672
grep '1234' $gui/jujugui.sha256 || (echo Juju GUI checksum mismatch; exit 1)
673
printf %%s '%s' > $gui/downloaded-gui.txt
674
rm $gui/gui.tar.bz2 $gui/jujugui.sha256 $gui/downloaded-gui.txt
676
assertScriptMatch(c, scripts, expectedScripts, false)
679
func (*cloudinitSuite) TestCloudInitWithGUIError(c *gc.C) {
680
cfg := makeBootstrapConfig("precise").setGUI("/path/to/gui.tar.bz2")
681
envConfig := minimalModelConfig(c)
682
testConfig := cfg.maybeSetModelConfig(envConfig).render()
683
ci, err := cloudinit.New(testConfig.Series)
684
c.Assert(err, jc.ErrorIsNil)
685
udata, err := cloudconfig.NewUserdataConfig(&testConfig, ci)
686
c.Assert(err, jc.ErrorIsNil)
687
err = udata.Configure()
688
c.Assert(err, gc.ErrorMatches, "cannot fetch Juju GUI: cannot read Juju GUI archive: .*")
596
691
func (*cloudinitSuite) TestCloudInitConfigure(c *gc.C) {
597
692
for i, test := range cloudinitTests {
598
693
testConfig := test.cfg.maybeSetModelConfig(minimalModelConfig(c)).render()
633
728
expected := "jujud bootstrap-state --data-dir '.*' --model-config '.*'" +
729
" --hosted-model-config '[^']*'" +
634
730
" --instance-id '.*' --bootstrap-constraints 'mem=4096M'" +
635
731
" --constraints 'mem=2048M' --show-log"
636
732
assertScriptMatch(c, scripts, expected, false)
976
1072
ModelTag: testing.ModelTag,
978
1074
Config: minimalModelConfig(c),
1075
HostedModelConfig: map[string]interface{}{"name": "hosted-model"},
979
1076
DataDir: jujuDataDir("quantal"),
980
1077
LogDir: jujuLogDir("quantal"),
981
1078
MetricsSpoolDir: metricsSpoolDir("quantal"),