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
1=== modified file '1.25.6/fake-juju.go'
2--- 1.25.6/fake-juju.go 2016-10-26 18:46:45 +0000
3+++ 1.25.6/fake-juju.go 2016-10-26 18:46:45 +0000
4@@ -77,10 +77,11 @@
5 if err != nil {
6 return err
7 }
8+ password := config.AdminSecret()
9+
10 command := exec.Command(os.Args[0])
11 command.Env = os.Environ()
12- command.Env = append(
13- command.Env, "ADMIN_PASSWORD="+config.AdminSecret())
14+ command.Env = append(command.Env, "ADMIN_PASSWORD="+password)
15 defaultSeries, _ := config.DefaultSeries()
16 command.Env = append(command.Env, "DEFAULT_SERIES="+defaultSeries)
17 stdout, err := command.StdoutPipe()
18@@ -93,10 +94,17 @@
19 if err != nil {
20 return err
21 }
22+ // Get the API info before changing it. The new values might
23+ // not work yet.
24+ apiInfo := result.apiInfo()
25+ // We actually want to report the API user we added in SetUpTest().
26+ result.username = "admin"
27+ if password != "" {
28+ result.password = password
29+ }
30 if err := result.apply(filenames, envName); err != nil {
31 return err
32 }
33- apiInfo := result.apiInfo()
34
35 dialOpts := api.DialOpts{
36 DialAddressInterval: 50 * time.Millisecond,
37@@ -141,8 +149,7 @@
38 if err != nil {
39 return err
40 }
41- username := strings.Replace(string(info.Username), "dummy-", "", 1)
42- fmt.Printf("{\"user\": \"%s\", \"password\": \"%s\", \"environ-uuid\": \"%s\", \"state-servers\": [\"%s\"]}\n", username, info.Password, info.Uuid, info.EndpointAddr)
43+ fmt.Printf("{\"user\": \"%s\", \"password\": \"%s\", \"environ-uuid\": \"%s\", \"state-servers\": [\"%s\"]}\n", info.Username, info.Password, info.Uuid, info.EndpointAddr)
44 return nil
45 }
46
47@@ -509,7 +516,6 @@
48 c.Assert(err, gc.IsNil)
49
50 apiInfo := s.APIInfo(c)
51- //fmt.Println(apiInfo.Addrs[0])
52 jujuHome := osenv.JujuHome()
53 // IMPORTANT: don't remove this logging because it's used by the
54 // bootstrap command.
55@@ -557,6 +563,19 @@
56 log.Println("Failed to open commands FIFO")
57 }
58 c.Assert(err, gc.IsNil)
59+ defer func() {
60+ if err := fd.Close(); err != nil {
61+ c.Logf("failed closing FIFO file: %s", err)
62+ }
63+ // Mark the controller as destroyed by renaming some files.
64+ if err := os.Rename(fifoPath, fifoPath+".destroyed"); err != nil {
65+ c.Logf("failed renaming FIFO file: %s", err)
66+ }
67+ infofile := s.filenames.infoFile()
68+ if err := os.Rename(infofile, infofile+".destroyed"); err != nil {
69+ c.Logf("failed renaming info file: %s", err)
70+ }
71+ }()
72 scanner := bufio.NewScanner(fd)
73 log.Println("Listen for commands on FIFO", fifoPath)
74 scanner.Scan()
75
76=== modified file '2.0-beta17/fake-juju.go'
77--- 2.0-beta17/fake-juju.go 2016-10-26 18:46:45 +0000
78+++ 2.0-beta17/fake-juju.go 2016-10-26 18:46:45 +0000
79@@ -548,6 +548,19 @@
80 log.Println("Failed to open commands FIFO")
81 }
82 c.Assert(err, gc.IsNil)
83+ defer func() {
84+ if err := fd.Close(); err != nil {
85+ c.Logf("failed closing FIFO file: %s", err)
86+ }
87+ // Mark the controller as destroyed by renaming some files.
88+ if err := os.Rename(fifoPath, fifoPath+".destroyed"); err != nil {
89+ c.Logf("failed renaming FIFO file: %s", err)
90+ }
91+ infofile := s.filenames.infoFile()
92+ if err := os.Rename(infofile, infofile+".destroyed"); err != nil {
93+ c.Logf("failed renaming info file: %s", err)
94+ }
95+ }()
96 scanner := bufio.NewScanner(fd)
97 log.Println("Listen for commands on FIFO", fifoPath)
98 scanner.Scan()
99
100=== modified file 'python/fakejuju/fakejuju.py'
101--- python/fakejuju/fakejuju.py 2016-10-26 18:46:45 +0000
102+++ python/fakejuju/fakejuju.py 2016-10-26 18:46:45 +0000
103@@ -147,3 +147,7 @@
104 cli.bootstrap(spec, cfgfile=cfgfile)
105 api_info = cli.api_info(spec.name)
106 return cli, api_info
107+
108+ def is_bootstrapped(self):
109+ """Return True if a fake-juju controller is running."""
110+ return os.path.exists(self.fifo)
111
112=== modified file 'python/fakejuju/tests/test_fakejuju.py'
113--- python/fakejuju/tests/test_fakejuju.py 2016-10-26 18:46:45 +0000
114+++ python/fakejuju/tests/test_fakejuju.py 2016-10-26 18:46:45 +0000
115@@ -305,12 +305,8 @@
116 version, bindir, datadir, cfgdir, expected)
117 fakejuju = FakeJuju.from_version(version, cfgdir, bindir=bindir)
118
119- # Make the calls.
120 cli, api_info = fakejuju.bootstrap("spam", cfgdir, "secret")
121- cli.destroy_controller()
122
123- with open(logfilename) as logfile:
124- calls = [line.strip() for line in logfile]
125 files = []
126 files.extend(os.path.join(os.path.basename(datadir), name)
127 for name in os.listdir(datadir))
128@@ -319,6 +315,10 @@
129 with open(os.path.join(cfgdir, "environments.yaml")) as envfile:
130 data = envfile.read()
131
132+ cli.destroy_controller()
133+ with open(logfilename) as logfile:
134+ calls = [line.strip() for line in logfile]
135+
136 self.maxDiff = None
137 self.assertEqual(api_info, {
138 'controller': expected,
139@@ -352,6 +352,31 @@
140 },
141 })
142
143+ def test_is_bootstrapped_true(self):
144+ """FakeJuju.is_bootstrapped() returns True if the fifo file exists."""
145+ with tempdir() as datadir:
146+ fakejuju = FakeJuju.from_version("1.25.6", datadir)
147+ with open(fakejuju.fifo, "w"):
148+ pass
149+ result = fakejuju.is_bootstrapped()
150+
151+ self.assertTrue(result)
152+
153+ def test_is_bootstrapped_false(self):
154+ """FakeJuju.is_bootstrapped() returns False if the fifo is gone."""
155+ with tempdir() as datadir:
156+ fakejuju = FakeJuju.from_version("1.25.6", datadir)
157+ result = fakejuju.is_bootstrapped()
158+
159+ self.assertFalse(result)
160+
161+ def test_is_bootstrapped_datadir_missing(self):
162+ """FakeJuju.is_bootstrapped() returns False if the data dir is gone."""
163+ fakejuju = FakeJuju.from_version("1.25.6", "/tmp/fakejuju-no-exist")
164+ result = fakejuju.is_bootstrapped()
165+
166+ self.assertFalse(result)
167+
168
169 FAKE_JUJU_SCRIPT = """\
170 #!/usr/bin/env python

Subscribers

People subscribed via source and target branches

to all changes: