Merge lp:~ericsnowcurrently/fake-juju/testing-fixes into lp:~landscape/fake-juju/trunk-old

Proposed by Eric Snow
Status: Merged
Approved by: Eric Snow
Approved revision: 62
Merged at revision: 44
Proposed branch: lp:~ericsnowcurrently/fake-juju/testing-fixes
Merge into: lp:~landscape/fake-juju/trunk-old
Prerequisite: lp:~ericsnowcurrently/fake-juju/fake-juju-data-dir
Diff against target: 170 lines (+71/-10)
4 files modified
1.25.6/fake-juju.go (+25/-6)
2.0-beta17/fake-juju.go (+13/-0)
python/fakejuju/fakejuju.py (+4/-0)
python/fakejuju/tests/test_fakejuju.py (+29/-4)
To merge this branch: bzr merge lp:~ericsnowcurrently/fake-juju/testing-fixes
Reviewer Review Type Date Requested Status
🤖 Landscape Builder test results Approve
Alberto Donato (community) Approve
Review via email: mp+308972@code.launchpad.net

This proposal supersedes a proposal from 2016-10-20.

Commit message

Fix a couple of broken behaviors for testing.

Without these fixes fake-juju can cause problems in tests.

Description of the change

Fix a couple of broken behaviors for testing.

Without these fixes fake-juju can cause problems in tests.

To post a comment you must log in.
Revision history for this message
🤖 Landscape Builder (landscape-builder) :
review: Abstain (executing tests)
Revision history for this message
🤖 Landscape Builder (landscape-builder) wrote :

Command: make ci-test
Result: Success
Revno: 59
Branch: lp:~ericsnowcurrently/fake-juju/testing-fixes
Jenkins: https://ci.lscape.net/job/latch-test-xenial/314/

review: Approve (test results)
Revision history for this message
Alberto Donato (ack) wrote :

Nice, +1

review: Approve
Revision history for this message
Alberto Donato (ack) wrote :

Unrelated, but can we drop 1.24.7?

Revision history for this message
Eric Snow (ericsnowcurrently) wrote :

> Unrelated, but can we drop 1.24.7?

+1

I've created lp:1636510 for this work.

60. By Eric Snow

Merge from parent.

Revision history for this message
🤖 Landscape Builder (landscape-builder) :
review: Abstain (executing tests)
Revision history for this message
🤖 Landscape Builder (landscape-builder) wrote :

Command: make ci-test
Result: Fail
Revno: 60
Branch: lp:~ericsnowcurrently/fake-juju/testing-fixes
Jenkins: https://ci.lscape.net/job/latch-test-xenial/334/

review: Needs Fixing (test results)
61. By Eric Snow

Fix a rename.

Revision history for this message
🤖 Landscape Builder (landscape-builder) :
review: Abstain (executing tests)
Revision history for this message
🤖 Landscape Builder (landscape-builder) wrote :

Command: make ci-test
Result: Success
Revno: 61
Branch: lp:~ericsnowcurrently/fake-juju/testing-fixes
Jenkins: https://ci.lscape.net/job/latch-test-xenial/335/

review: Approve (test results)
62. By Eric Snow

Merge from parent.

Revision history for this message
🤖 Landscape Builder (landscape-builder) :
review: Abstain (executing tests)
Revision history for this message
🤖 Landscape Builder (landscape-builder) wrote :

Command: make ci-test
Result: Success
Revno: 62
Branch: lp:~ericsnowcurrently/fake-juju/testing-fixes
Jenkins: https://ci.lscape.net/job/latch-test-xenial/347/

review: Approve (test results)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file '1.25.6/fake-juju.go'
--- 1.25.6/fake-juju.go 2016-10-26 18:46:45 +0000
+++ 1.25.6/fake-juju.go 2016-10-26 18:46:45 +0000
@@ -77,10 +77,11 @@
77 if err != nil {77 if err != nil {
78 return err78 return err
79 }79 }
80 password := config.AdminSecret()
81
80 command := exec.Command(os.Args[0])82 command := exec.Command(os.Args[0])
81 command.Env = os.Environ()83 command.Env = os.Environ()
82 command.Env = append(84 command.Env = append(command.Env, "ADMIN_PASSWORD="+password)
83 command.Env, "ADMIN_PASSWORD="+config.AdminSecret())
84 defaultSeries, _ := config.DefaultSeries()85 defaultSeries, _ := config.DefaultSeries()
85 command.Env = append(command.Env, "DEFAULT_SERIES="+defaultSeries)86 command.Env = append(command.Env, "DEFAULT_SERIES="+defaultSeries)
86 stdout, err := command.StdoutPipe()87 stdout, err := command.StdoutPipe()
@@ -93,10 +94,17 @@
93 if err != nil {94 if err != nil {
94 return err95 return err
95 }96 }
97 // Get the API info before changing it. The new values might
98 // not work yet.
99 apiInfo := result.apiInfo()
100 // We actually want to report the API user we added in SetUpTest().
101 result.username = "admin"
102 if password != "" {
103 result.password = password
104 }
96 if err := result.apply(filenames, envName); err != nil {105 if err := result.apply(filenames, envName); err != nil {
97 return err106 return err
98 }107 }
99 apiInfo := result.apiInfo()
100108
101 dialOpts := api.DialOpts{109 dialOpts := api.DialOpts{
102 DialAddressInterval: 50 * time.Millisecond,110 DialAddressInterval: 50 * time.Millisecond,
@@ -141,8 +149,7 @@
141 if err != nil {149 if err != nil {
142 return err150 return err
143 }151 }
144 username := strings.Replace(string(info.Username), "dummy-", "", 1)152 fmt.Printf("{\"user\": \"%s\", \"password\": \"%s\", \"environ-uuid\": \"%s\", \"state-servers\": [\"%s\"]}\n", info.Username, info.Password, info.Uuid, info.EndpointAddr)
145 fmt.Printf("{\"user\": \"%s\", \"password\": \"%s\", \"environ-uuid\": \"%s\", \"state-servers\": [\"%s\"]}\n", username, info.Password, info.Uuid, info.EndpointAddr)
146 return nil153 return nil
147}154}
148155
@@ -509,7 +516,6 @@
509 c.Assert(err, gc.IsNil)516 c.Assert(err, gc.IsNil)
510517
511 apiInfo := s.APIInfo(c)518 apiInfo := s.APIInfo(c)
512 //fmt.Println(apiInfo.Addrs[0])
513 jujuHome := osenv.JujuHome()519 jujuHome := osenv.JujuHome()
514 // IMPORTANT: don't remove this logging because it's used by the520 // IMPORTANT: don't remove this logging because it's used by the
515 // bootstrap command.521 // bootstrap command.
@@ -557,6 +563,19 @@
557 log.Println("Failed to open commands FIFO")563 log.Println("Failed to open commands FIFO")
558 }564 }
559 c.Assert(err, gc.IsNil)565 c.Assert(err, gc.IsNil)
566 defer func() {
567 if err := fd.Close(); err != nil {
568 c.Logf("failed closing FIFO file: %s", err)
569 }
570 // Mark the controller as destroyed by renaming some files.
571 if err := os.Rename(fifoPath, fifoPath+".destroyed"); err != nil {
572 c.Logf("failed renaming FIFO file: %s", err)
573 }
574 infofile := s.filenames.infoFile()
575 if err := os.Rename(infofile, infofile+".destroyed"); err != nil {
576 c.Logf("failed renaming info file: %s", err)
577 }
578 }()
560 scanner := bufio.NewScanner(fd)579 scanner := bufio.NewScanner(fd)
561 log.Println("Listen for commands on FIFO", fifoPath)580 log.Println("Listen for commands on FIFO", fifoPath)
562 scanner.Scan()581 scanner.Scan()
563582
=== modified file '2.0-beta17/fake-juju.go'
--- 2.0-beta17/fake-juju.go 2016-10-26 18:46:45 +0000
+++ 2.0-beta17/fake-juju.go 2016-10-26 18:46:45 +0000
@@ -548,6 +548,19 @@
548 log.Println("Failed to open commands FIFO")548 log.Println("Failed to open commands FIFO")
549 }549 }
550 c.Assert(err, gc.IsNil)550 c.Assert(err, gc.IsNil)
551 defer func() {
552 if err := fd.Close(); err != nil {
553 c.Logf("failed closing FIFO file: %s", err)
554 }
555 // Mark the controller as destroyed by renaming some files.
556 if err := os.Rename(fifoPath, fifoPath+".destroyed"); err != nil {
557 c.Logf("failed renaming FIFO file: %s", err)
558 }
559 infofile := s.filenames.infoFile()
560 if err := os.Rename(infofile, infofile+".destroyed"); err != nil {
561 c.Logf("failed renaming info file: %s", err)
562 }
563 }()
551 scanner := bufio.NewScanner(fd)564 scanner := bufio.NewScanner(fd)
552 log.Println("Listen for commands on FIFO", fifoPath)565 log.Println("Listen for commands on FIFO", fifoPath)
553 scanner.Scan()566 scanner.Scan()
554567
=== modified file 'python/fakejuju/fakejuju.py'
--- python/fakejuju/fakejuju.py 2016-10-26 18:46:45 +0000
+++ python/fakejuju/fakejuju.py 2016-10-26 18:46:45 +0000
@@ -147,3 +147,7 @@
147 cli.bootstrap(spec, cfgfile=cfgfile)147 cli.bootstrap(spec, cfgfile=cfgfile)
148 api_info = cli.api_info(spec.name)148 api_info = cli.api_info(spec.name)
149 return cli, api_info149 return cli, api_info
150
151 def is_bootstrapped(self):
152 """Return True if a fake-juju controller is running."""
153 return os.path.exists(self.fifo)
150154
=== modified file 'python/fakejuju/tests/test_fakejuju.py'
--- python/fakejuju/tests/test_fakejuju.py 2016-10-26 18:46:45 +0000
+++ python/fakejuju/tests/test_fakejuju.py 2016-10-26 18:46:45 +0000
@@ -305,12 +305,8 @@
305 version, bindir, datadir, cfgdir, expected)305 version, bindir, datadir, cfgdir, expected)
306 fakejuju = FakeJuju.from_version(version, cfgdir, bindir=bindir)306 fakejuju = FakeJuju.from_version(version, cfgdir, bindir=bindir)
307307
308 # Make the calls.
309 cli, api_info = fakejuju.bootstrap("spam", cfgdir, "secret")308 cli, api_info = fakejuju.bootstrap("spam", cfgdir, "secret")
310 cli.destroy_controller()
311309
312 with open(logfilename) as logfile:
313 calls = [line.strip() for line in logfile]
314 files = []310 files = []
315 files.extend(os.path.join(os.path.basename(datadir), name)311 files.extend(os.path.join(os.path.basename(datadir), name)
316 for name in os.listdir(datadir))312 for name in os.listdir(datadir))
@@ -319,6 +315,10 @@
319 with open(os.path.join(cfgdir, "environments.yaml")) as envfile:315 with open(os.path.join(cfgdir, "environments.yaml")) as envfile:
320 data = envfile.read()316 data = envfile.read()
321317
318 cli.destroy_controller()
319 with open(logfilename) as logfile:
320 calls = [line.strip() for line in logfile]
321
322 self.maxDiff = None322 self.maxDiff = None
323 self.assertEqual(api_info, {323 self.assertEqual(api_info, {
324 'controller': expected,324 'controller': expected,
@@ -352,6 +352,31 @@
352 },352 },
353 })353 })
354354
355 def test_is_bootstrapped_true(self):
356 """FakeJuju.is_bootstrapped() returns True if the fifo file exists."""
357 with tempdir() as datadir:
358 fakejuju = FakeJuju.from_version("1.25.6", datadir)
359 with open(fakejuju.fifo, "w"):
360 pass
361 result = fakejuju.is_bootstrapped()
362
363 self.assertTrue(result)
364
365 def test_is_bootstrapped_false(self):
366 """FakeJuju.is_bootstrapped() returns False if the fifo is gone."""
367 with tempdir() as datadir:
368 fakejuju = FakeJuju.from_version("1.25.6", datadir)
369 result = fakejuju.is_bootstrapped()
370
371 self.assertFalse(result)
372
373 def test_is_bootstrapped_datadir_missing(self):
374 """FakeJuju.is_bootstrapped() returns False if the data dir is gone."""
375 fakejuju = FakeJuju.from_version("1.25.6", "/tmp/fakejuju-no-exist")
376 result = fakejuju.is_bootstrapped()
377
378 self.assertFalse(result)
379
355380
356FAKE_JUJU_SCRIPT = """\381FAKE_JUJU_SCRIPT = """\
357#!/usr/bin/env python382#!/usr/bin/env python

Subscribers

People subscribed via source and target branches

to all changes: