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

Proposed by Eric Snow
Status: Merged
Approved by: Eric Snow
Approved revision: 58
Merged at revision: 35
Proposed branch: lp:~ericsnowcurrently/fake-juju/beta16
Merge into: lp:~landscape/fake-juju/trunk-old
Diff against target: 513 lines (+281/-69)
7 files modified
2.0-beta17/fake-juju.go (+13/-13)
Makefile (+18/-4)
patches/juju-core_2.0-beta17.patch (+6/-6)
tests/_jujuclient.py (+69/-0)
tests/jujuclient-archive/UPGRADE (+51/-0)
tests/jujuclient-archive/requirements (+4/-0)
tests/test_fake.py (+120/-46)
To merge this branch: bzr merge lp:~ericsnowcurrently/fake-juju/beta16
Reviewer Review Type Date Requested Status
🤖 Landscape Builder test results Approve
Данило Шеган (community) Approve
Simon Poirier (community) Approve
Review via email: mp+304714@code.launchpad.net

Commit message

Update to use beta17.

Description of the change

Update to use beta17.

Testing instructions:

Run the unit 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: Fail
Revno: 41
Branch: lp:~ericsnowcurrently/fake-juju/beta16
Jenkins: https://ci.lscape.net/job/latch-test/10140/

review: Needs Fixing (test results)
Revision history for this message
Simon Poirier (simpoir) wrote :

+1 look generally good, apart from the currently broken download url.

IMHO, it would be slightly more readable to separate tests and use @unittest.skipUnless()

review: Approve
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: 41
Branch: lp:~ericsnowcurrently/fake-juju/beta16
Jenkins: https://ci.lscape.net/job/latch-test/10152/

review: Needs Fixing (test results)
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: 41
Branch: lp:~ericsnowcurrently/fake-juju/beta16
Jenkins: https://ci.lscape.net/job/latch-test/10173/

review: Needs Fixing (test results)
Revision history for this message
Данило Шеган (danilo) wrote :

First up, this branch fails in CI because of a missing python3-pip dependency: please add that to the ci-test target in the Makefile (there's already an apt-get line there, so you'll want to swap places between that and the python3 -m pip call).

I've got it passing locally with that, so reviewing further with that in mind.

Revision history for this message
Данило Шеган (danilo) wrote :

Eric, thanks a lot for working on this! Other than the above problem, which is guarded by the latch bot, I don't see any significant issues. I do have a few nitpicks (some of it applies to the code you just moved around), and some things I believe could be addressed in follow-up branches (like actually splitting the tests for 1.x and 2.x, which might even remove the need for the run_on_all_machines monkey-patch).

review: Approve
Revision history for this message
Eric Snow (ericsnowcurrently) :
42. By Eric Snow

Fix dependency ordering.

43. By Eric Snow

Drop a superfluous line.

44. By Eric Snow

Update a comment.

45. By Eric Snow

Elaborate on the reason for the Juju2Client wrapper.

46. By Eric Snow

Use Juju terminology correctly.

47. By Eric Snow

Split the Juju 2.x tests from the Juju 1.x tests.

48. By Eric Snow

Ignore a ResourceWarning coming from jujuclient.

49. By Eric Snow

Simplify the download rule.

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: 49
Branch: lp:~ericsnowcurrently/fake-juju/beta16
Jenkins: https://ci.lscape.net/job/latch-test/10220/

review: Needs Fixing (test results)
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: 49
Branch: lp:~ericsnowcurrently/fake-juju/beta16
Jenkins: https://ci.lscape.net/job/latch-test/10221/

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

Add a script to support instally jujuclient without PyPI.

51. By Eric Snow

Add files to support installing jujuclient without PyPI.

52. By Eric Snow

Fix go formatting.

53. By Eric Snow

Install jujuclient from a local archive rather than PyPI.

54. By Eric Snow

Always delete the Go src dir.

55. By Eric Snow

Move the jujuclient archives under the tests dir.

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: 55
Branch: lp:~ericsnowcurrently/fake-juju/beta16
Jenkins: https://ci.lscape.net/job/latch-test-xenial/2/

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

Ignore a missing directory.

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: 56
Branch: lp:~ericsnowcurrently/fake-juju/beta16
Jenkins: https://ci.lscape.net/job/latch-test-xenial/3/

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

lint

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: 57
Branch: lp:~ericsnowcurrently/fake-juju/beta16
Jenkins: https://ci.lscape.net/job/latch-test-xenial/4/

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

Hush up pyflakes.

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: 58
Branch: lp:~ericsnowcurrently/fake-juju/beta16
Jenkins: https://ci.lscape.net/job/latch-test-xenial/5/

review: Approve (test results)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== renamed directory '2.0-beta13' => '2.0-beta17'
2=== modified file '2.0-beta17/fake-juju.go'
3--- 2.0-beta13/fake-juju.go 2016-07-19 19:03:20 +0000
4+++ 2.0-beta17/fake-juju.go 2016-09-15 20:39:05 +0000
5@@ -2,39 +2,39 @@
6
7 import (
8 "bufio"
9+ "encoding/json"
10+ "errors"
11 "fmt"
12 gc "gopkg.in/check.v1"
13+ "io"
14+ "io/ioutil"
15+ "log"
16 "os"
17 "os/exec"
18 "path/filepath"
19+ "strings"
20 "syscall"
21 "testing"
22 "time"
23- "encoding/json"
24- "errors"
25- "io/ioutil"
26- "log"
27- "strings"
28
29 "github.com/juju/juju/agent"
30 "github.com/juju/juju/api"
31- "github.com/juju/juju/juju/osenv"
32- "github.com/juju/juju/network"
33- "github.com/juju/juju/state"
34- states "github.com/juju/juju/status"
35 "github.com/juju/juju/cmd/juju/controller"
36 "github.com/juju/juju/instance"
37+ "github.com/juju/juju/juju/osenv"
38 jujutesting "github.com/juju/juju/juju/testing"
39 "github.com/juju/juju/jujuclient"
40+ "github.com/juju/juju/network"
41 _ "github.com/juju/juju/provider/maas"
42+ "github.com/juju/juju/state"
43+ states "github.com/juju/juju/status"
44 coretesting "github.com/juju/juju/testing"
45 "github.com/juju/juju/testing/factory"
46 "github.com/juju/juju/version"
47- "gopkg.in/juju/names.v2"
48 semversion "github.com/juju/version"
49 corecharm "gopkg.in/juju/charmrepo.v2-unstable"
50+ "gopkg.in/juju/names.v2"
51 goyaml "gopkg.in/yaml.v1"
52- "io"
53 )
54
55 func main() {
56@@ -81,7 +81,7 @@
57 command := exec.Command(os.Args[0])
58 command.Env = os.Environ()
59 command.Env = append(
60- command.Env, "ADMIN_PASSWORD="+"pwd")
61+ command.Env, "ADMIN_PASSWORD="+"pwd")
62 defaultSeries := "trusty"
63 command.Env = append(command.Env, "DEFAULT_SERIES="+defaultSeries)
64 stdout, err := command.StdoutPipe()
65@@ -175,7 +175,7 @@
66 store := jujuclient.NewFileClientStore()
67 // hard-coded value in juju testing
68 // This will be replaced in JUJU_DATA copy of the juju client config.
69- currentController := "kontroll"
70+ currentController := "kontroll"
71 one, err := store.ControllerByName("kontroll")
72 if err != nil {
73 return nil, err
74
75=== modified file 'Makefile'
76--- Makefile 2016-07-28 14:44:34 +0000
77+++ Makefile 2016-09-15 20:39:05 +0000
78@@ -1,11 +1,13 @@
79 JUJU1_VERSIONS = 1.24.7 1.25.6
80-JUJU2_VERSIONS = 2.0-beta13
81+JUJU2_VERSIONS = 2.0-beta17
82 VERSIONS = $(JUJU1_VERSIONS) $(JUJU2_VERSIONS)
83 GO_VERSION = 1.6
84 TARBALLS = $(foreach version,$(VERSIONS),juju-core_$(version).tar.gz)
85 BUILT_VERSIONS = $(foreach version,$(VERSIONS),$(version)/$(version))
86 JUJU_TARBALL = juju-core_$(JUJU_VERSION).tar.gz
87 JUJU_PATCH = patches/juju-core_$(JUJU_VERSION).patch
88+JUJUCLIENT_DOWNLOADS = $(shell pwd)/tests/jujuclient-archive
89+JUJUCLIENT_REQ = $(JUJUCLIENT_DOWNLOADS)/requirements
90
91 .PHONY: build
92 build: $(BUILT_VERSIONS)
93@@ -22,13 +24,21 @@
94 ci-test:
95 sudo apt-get -y install --force-yes \
96 wget \
97+ python3-pip \
98 golang-go \
99- python-jujuclient \
100 golang-1.6
101+ # See tests/jujuclient-archive/UPGRADE when a newer jujuclient version is needed.
102+ sudo python3 -m pip install \
103+ --ignore-installed \
104+ --no-cache-dir \
105+ --no-index \
106+ --find-links $(JUJUCLIENT_DOWNLOADS) \
107+ --requirement $(JUJUCLIENT_REQ)
108 make test
109
110 .PHONY: build-common
111 build-common: $(JUJU_TARBALL) $(JUJU_PATCH)
112+ rm -rf $(JUJU_VERSION)/src # Go doesn't play nice with existing files.
113 tar -C $(JUJU_VERSION) --strip=1 -z -xf $(JUJU_TARBALL)
114 patch -p0 < $(JUJU_PATCH)
115 cd $(JUJU_VERSION) && GOPATH=$(shell pwd)/$(JUJU_VERSION) PATH=$(PATH) go build
116@@ -60,7 +70,11 @@
117 .PHONY: test
118 # Use xargs here so that we don't throw away the return codes, and correctly fail if any of the tests fail
119 test: $(BUILT_VERSIONS)
120- @echo -n $(VERSIONS) | xargs -t -d' ' -I {} env JUJU_VERSION={} python -m unittest tests.test_fake
121+ @echo -n $(VERSIONS) | xargs -t -d' ' -I {} env JUJU_VERSION={} python3 -m unittest tests.test_fake
122
123 juju-core_%.tar.gz:
124- wget https://launchpad.net/juju-core/$(shell ((echo $* | grep -q beta) && echo trunk) || (echo $* | cut -f 1,2 -d .))/$*/+download/$@
125+ case $* in \
126+ 1.*) PROJECT="juju-core" ;;\
127+ 2.*) PROJECT="juju" ;;\
128+ esac;\
129+ wget https://launchpad.net/$$PROJECT/$(shell (echo $* | cut -f 1 -d - | cut -f 1,2 -d .))/$*/+download/$@
130
131=== renamed file 'patches/juju-core_2.0-beta13.patch' => 'patches/juju-core_2.0-beta17.patch'
132--- patches/juju-core_2.0-beta13.patch 2016-07-22 21:27:41 +0000
133+++ patches/juju-core_2.0-beta17.patch 2016-09-15 20:39:05 +0000
134@@ -1,5 +1,5 @@
135---- 2.0-beta13/src/github.com/juju/juju/testcharms/charm.go 2016-03-10 13:45:57.000000000 +0100
136-+++ 2.0-beta13/src/github.com/juju/juju/testcharms/charm.go 2016-03-21 10:46:24.312966629 +0100
137+--- 2.0-beta17/src/github.com/juju/juju/testcharms/charm.go 2016-03-10 13:45:57.000000000 +0100
138++++ 2.0-beta17/src/github.com/juju/juju/testcharms/charm.go 2016-03-21 10:46:24.312966629 +0100
139 @@ -17,7 +17,9 @@
140 )
141
142@@ -11,8 +11,8 @@
143
144 // UploadCharm uploads a charm using the given charm store client, and returns
145 // the resulting charm URL and charm.
146---- 2.0-beta13/src/github.com/juju/juju/provider/dummy/environs.go 2015-07-06 15:01:14.200568258 +0200
147-+++ 2.0-beta13/src/github.com/juju/juju/provider/dummy/environs.go 2015-07-06 15:18:32.648549661 +0200
148+--- 2.0-beta17/src/github.com/juju/juju/provider/dummy/environs.go 2015-07-06 15:01:14.200568258 +0200
149++++ 2.0-beta17/src/github.com/juju/juju/provider/dummy/environs.go 2015-07-06 15:18:32.648549661 +0200
150 @@ -633,9 +633,9 @@
151
152 // PrecheckInstance is specified in the state.Prechecker interface.
153@@ -26,8 +26,8 @@
154 return nil
155 }
156
157---- 2.0-beta13/src/github.com/juju/juju/testing/cert.go 2016-03-18 09:25:34 +0000
158-+++ 2.0-beta13/src/github.com/juju/juju/testing/cert.go 2016-03-18 09:26:04 +0000
159+--- 2.0-beta17/src/github.com/juju/juju/testing/cert.go 2016-03-18 09:25:34 +0000
160++++ 2.0-beta17/src/github.com/juju/juju/testing/cert.go 2016-03-18 09:26:04 +0000
161 @@ -52,7 +52,7 @@
162 }
163
164
165=== added file 'tests/_jujuclient.py'
166--- tests/_jujuclient.py 1970-01-01 00:00:00 +0000
167+++ tests/_jujuclient.py 2016-09-15 20:39:05 +0000
168@@ -0,0 +1,69 @@
169+
170+import os.path
171+import ssl
172+import sys
173+
174+try:
175+ from jujuclient.juju1.environment import Environment as Juju1Client
176+ from jujuclient.juju2.environment import Environment as Juju2Client
177+except ImportError:
178+ sys.exit("latest jujuclient not installed "
179+ "(try python3 -m pip install jujuclient)")
180+
181+
182+# XXX No support for cert files in Environment._http_conn, so
183+# add it via monkey patching.
184+if hasattr(ssl, "_create_unverified_context"):
185+ ssl._create_default_https_context = ssl._create_unverified_context
186+
187+
188+ENVIRONMENTS_YAML = """environments:
189+ {name}:
190+ admin-secret: test
191+ default-series: trusty
192+ type: {type}
193+"""
194+
195+
196+def prepare(name, type, cfgdir, env, version=None):
197+
198+ if str(version).startswith("1"):
199+ environments_yaml = os.path.join(cfgdir, "environments.yaml")
200+ with open(environments_yaml, "w") as fd:
201+ fd.write(ENVIRONMENTS_YAML.format(**locals()))
202+ env["JUJU_HOME"] = cfgdir
203+ else:
204+ env["JUJU_DATA"] = cfgdir
205+
206+
207+def connect(endpoint, password, uuid, version=None):
208+ """Return a connected client to the Juju API endpoint."""
209+ JujuClient = Juju2Client
210+ midpath = "model"
211+ if str(version).startswith("1."):
212+ JujuClient = Juju1Client
213+ midpath = "environment"
214+ endpoint = "/".join(["wss:/", endpoint, midpath, uuid, "api"])
215+
216+ # TODO make use of the cert
217+ # ca_cert = os.path.join(self.juju_home, "cert.ca")
218+ client = JujuClient(endpoint)
219+ client.login(password)
220+ return client
221+
222+
223+class Juju2Client(Juju2Client):
224+ """A wrapper around the actual client that fixes busted code.
225+
226+ This can go away once the following bug(s) are fixed:
227+ * https://bugs.launchpad.net/python-jujuclient/+bug/1619479
228+ """
229+
230+ def run_on_all_machines(self, command, timeout=None):
231+ """Run the given shell command on all machines in the model."""
232+ return self._rpc({
233+ "type": self.actions.name,
234+ "version": self.actions.version,
235+ "request": "RunOnAllMachines",
236+ "params": {"commands": command,
237+ "timeout": timeout}})
238
239=== added directory 'tests/jujuclient-archive'
240=== added file 'tests/jujuclient-archive/PyYAML-3.12.tar.gz'
241Binary files tests/jujuclient-archive/PyYAML-3.12.tar.gz 1970-01-01 00:00:00 +0000 and tests/jujuclient-archive/PyYAML-3.12.tar.gz 2016-09-15 20:39:05 +0000 differ
242=== added file 'tests/jujuclient-archive/UPGRADE'
243--- tests/jujuclient-archive/UPGRADE 1970-01-01 00:00:00 +0000
244+++ tests/jujuclient-archive/UPGRADE 2016-09-15 20:39:05 +0000
245@@ -0,0 +1,51 @@
246+#!/usr/bin/env bash
247+
248+PACKAGE=jujuclient
249+#ARCHIVES_DIR=${PACKAGE}-archive
250+ARCHIVES_DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
251+REQ_FILE=$ARCHIVES_DIR/requirements
252+VENV_DIR=/tmp/$PACKAGE
253+
254+set -x
255+sudo apt-get install python3-venv
256+{ set +x; } 2>/dev/null
257+
258+echo
259+echo Building the requirements file.
260+echo '###############################'
261+set -x
262+rm -r $VENV_DIR &>/dev/null
263+python3 -m venv $VENV_DIR
264+exclude=$($VENV_DIR/bin/python3 -m pip list | awk '{print $1}' | tr '\n' '|' | sed 's/|$//')
265+$VENV_DIR/bin/python3 -m pip install --no-cache-dir $PACKAGE
266+$VENV_DIR/bin/python3 -m pip freeze | grep -E -v $exclude > $REQ_FILE
267+rm -r $VENV_DIR &>/dev/null
268+{ set +x; } 2>/dev/null
269+
270+echo
271+echo Downloading the archives.
272+echo '#########################'
273+set -x
274+python3 -m pip download --dest $ARCHIVES_DIR --requirement $REQ_FILE
275+{ set +x; } 2>/dev/null
276+
277+
278+#############################################
279+# Uncomment the following to test installing.
280+#############################################
281+
282+#INSTALL=True
283+
284+if [[ -n $INSTALL ]]; then
285+ echo
286+ echo Install the pinned packages.
287+ echo '############################'
288+ set -x
289+ sudo python3 -m pip install \
290+ --ignore-installed \
291+ --no-cache-dir \
292+ --no-index \
293+ --find-links $ARCHIVES_DIR \
294+ --requirement $REQ_FILE
295+ { set +x; } 2>/dev/null
296+fi
297
298=== added file 'tests/jujuclient-archive/jujuclient-0.53.2.tar.gz'
299Binary files tests/jujuclient-archive/jujuclient-0.53.2.tar.gz 1970-01-01 00:00:00 +0000 and tests/jujuclient-archive/jujuclient-0.53.2.tar.gz 2016-09-15 20:39:05 +0000 differ
300=== added file 'tests/jujuclient-archive/requirements'
301--- tests/jujuclient-archive/requirements 1970-01-01 00:00:00 +0000
302+++ tests/jujuclient-archive/requirements 2016-09-15 20:39:05 +0000
303@@ -0,0 +1,4 @@
304+jujuclient==0.53.2
305+PyYAML==3.12
306+six==1.10.0
307+websocket-client==0.37.0
308
309=== added file 'tests/jujuclient-archive/six-1.10.0-py2.py3-none-any.whl'
310Binary files tests/jujuclient-archive/six-1.10.0-py2.py3-none-any.whl 1970-01-01 00:00:00 +0000 and tests/jujuclient-archive/six-1.10.0-py2.py3-none-any.whl 2016-09-15 20:39:05 +0000 differ
311=== added file 'tests/jujuclient-archive/websocket_client-0.37.0.tar.gz'
312Binary files tests/jujuclient-archive/websocket_client-0.37.0.tar.gz 1970-01-01 00:00:00 +0000 and tests/jujuclient-archive/websocket_client-0.37.0.tar.gz 2016-09-15 20:39:05 +0000 differ
313=== modified file 'tests/test_fake.py'
314--- tests/test_fake.py 2016-04-01 09:55:10 +0000
315+++ tests/test_fake.py 2016-09-15 20:39:05 +0000
316@@ -1,14 +1,23 @@
317+
318+import datetime
319+import json
320 import os
321-import tempfile
322+import os.path
323 import shutil
324 import subprocess
325-import json
326-import ssl
327-
328-from jujuclient import Environment
329-
330-from unittest import TestCase
331-from unittest.case import SkipTest
332+import tempfile
333+import unittest
334+import warnings
335+
336+from . import _jujuclient
337+
338+
339+# Quiet pyflakes on Python 2.
340+try:
341+ ResourceWarning
342+except NameError:
343+ ResourceWarning = Warning
344+
345
346 ROOT_DIR = os.path.dirname(os.path.dirname(__file__))
347
348@@ -17,58 +26,62 @@
349
350 DUMMY_CHARM = os.path.join(ROOT_DIR, "tests", "charms", "dummy")
351
352-ENVIRONMENTS_YAML = """environments:
353- test:
354- admin-secret: test
355- default-series: trusty
356- type: dummy
357-"""
358-
359-# XXX No support for cert files in Environment._http_conn, so
360-# add it via monkey patching.
361-if hasattr(ssl, "_create_unverified_context"):
362- ssl._create_default_https_context = ssl._create_unverified_context
363-
364-
365-class JujuFakeTest(TestCase):
366+
367+class _JujuFakeTest:
368+
369+ # These are set on the child classes.
370+ destroycmd = None
371+ bootstrap = None
372
373 def setUp(self):
374- super(JujuFakeTest, self).setUp()
375- if JUJU_VERSION.startswith("2.0"):
376- raise SkipTest("Juju 2.0 still not fully supported")
377- self.juju_home = tempfile.mkdtemp()
378- environments_yaml = os.path.join(self.juju_home, "environments.yaml")
379- with open(environments_yaml, "w") as fd:
380- fd.write(ENVIRONMENTS_YAML)
381+ super(_JujuFakeTest, self).setUp()
382+
383 self.env = os.environ.copy()
384- self.env["JUJU_HOME"] = self.juju_home
385- self.juju_fake = os.path.join(JUJU_VERSION, JUJU_VERSION)
386- subprocess.check_call([JUJU_FAKE, "bootstrap"], env=self.env)
387- output = subprocess.check_output([JUJU_FAKE, "api-info"], env=self.env)
388- api_info = json.loads(output)
389- endpoint = "wss://" + str(api_info["state-servers"][0]) + "/"
390- # TODO make use of the cert
391- # ca_cert = os.path.join(self.juju_home, "cert.ca")
392- self.environment = Environment(endpoint)
393- self.environment.login("test")
394+ self.juju_home = cfgdir = tempfile.mkdtemp()
395+ _jujuclient.prepare("dummy", "dummy", cfgdir, self.env, JUJU_VERSION)
396+
397+ endpoint, uuid, password = self.bootstrap("dummy", "dummy", self.env)
398+ self.api = _jujuclient.connect(endpoint, password, uuid, JUJU_VERSION)
399
400 def tearDown(self):
401- subprocess.check_call([JUJU_FAKE, "destroy-environment"], env=self.env)
402+ subprocess.check_call([JUJU_FAKE, self.destroycmd], env=self.env)
403+ self.api.close()
404+
405 shutil.rmtree(self.juju_home)
406- super(JujuFakeTest, self).tearDown()
407+
408+ super(_JujuFakeTest, self).tearDown()
409+
410+
411+@unittest.skipUnless(JUJU_VERSION.startswith("1."), "wrong Juju version")
412+class Juju1FakeTest(_JujuFakeTest, unittest.TestCase):
413+
414+ destroycmd = "destroy-environment"
415+
416+ def bootstrap(self, name, type, env):
417+ """Return the API endpoint after bootstrapping the controller."""
418+ subprocess.check_call([JUJU_FAKE, "bootstrap", "-e", name], env=env)
419+
420+ output = subprocess.check_output([JUJU_FAKE, "api-info"], env=env)
421+ api_info = json.loads(output.decode())
422+ endpoint = str(api_info["state-servers"][0])
423+ uuid = api_info["environ-uuid"]
424+ password = "test"
425+ return endpoint, uuid, password
426
427 def test_info(self):
428- info = self.environment.info()
429+ info = self.api.info()
430 self.assertEqual("dummy", info["ProviderType"])
431
432 def test_local_charm(self):
433- charm = self.environment.add_local_charm_dir(DUMMY_CHARM, "trusty")
434- self.environment.deploy("dummy", charm["CharmURL"], num_units=0)
435+ with warnings.catch_warnings():
436+ warnings.simplefilter("ignore", ResourceWarning)
437+ charm = self.api.add_local_charm_dir(DUMMY_CHARM, "trusty")
438+ self.api.deploy("dummy", charm['CharmURL'], num_units=0)
439
440 def test_run_on_all_machines(self):
441 timeout = 5 * 10 ** 9
442- result = self.environment.run_on_all_machines(
443- "/foo/bar", timeout=timeout)
444+ result = self.api.run_on_all_machines("/foo/bar", timeout=timeout)
445+
446 self.assertEqual(
447 {"Results": [
448 {"Code": 0,
449@@ -78,3 +91,64 @@
450 "Error": "",
451 "UnitId": ""}]},
452 result)
453+
454+
455+@unittest.skipUnless(JUJU_VERSION.startswith("2."), "wrong Juju version")
456+class Juju2FakeTest(_JujuFakeTest, unittest.TestCase):
457+
458+ destroycmd = "destroy-controller"
459+
460+ def bootstrap(self, name, type, env):
461+ """Return the API endpoint after bootstrapping the controller."""
462+ args = [JUJU_FAKE, "bootstrap", "--no-gui", name, type]
463+ subprocess.check_call(args, env=env)
464+
465+ args = [JUJU_FAKE, "show-controller", "--format", "json",
466+ "--show-password", name]
467+ output = subprocess.check_output(args, env=env)
468+ api_info = json.loads(output.decode())
469+ endpoint = str(api_info[name]["details"]["api-endpoints"][0])
470+ model = api_info[name]["current-model"]
471+ uuid = api_info[name]["models"][model]["uuid"]
472+ password = api_info[name]["account"]["password"]
473+ return endpoint, uuid, password
474+
475+ def test_info(self):
476+ info = self.api.info()
477+ self.assertEqual("dummy", info["provider-type"])
478+
479+ def test_local_charm(self):
480+ with warnings.catch_warnings():
481+ warnings.simplefilter("ignore", ResourceWarning)
482+ charm = self.api.add_local_charm_dir(DUMMY_CHARM, "trusty")
483+ self.api.deploy("dummy", charm['charm-url'], num_units=0)
484+
485+ def test_run_on_all_machines(self):
486+ timeout = 5 * 10 ** 9
487+ now = datetime.datetime.utcnow()
488+ result = self.api.run_on_all_machines("/foo/bar", timeout=timeout)
489+
490+ tag = result["results"][0]["action"]["tag"]
491+ self.assertTrue(tag.startswith("action-"))
492+ self.maxDiff = None
493+ enqueuedstr = result["results"][0]["enqueued"]
494+ enqueued = datetime.datetime.strptime(
495+ enqueuedstr, "%Y-%m-%dT%H:%M:%SZ")
496+ self.assertLess(enqueued - now, datetime.timedelta(seconds=1))
497+ self.assertEqual(
498+ {"results": [
499+ {"action": {
500+ "name": "juju-run",
501+ "parameters": {
502+ "command": "/foo/bar",
503+ "timeout": 5000000000,
504+ },
505+ "receiver": "machine-0",
506+ "tag": tag,
507+ },
508+ "completed": "0001-01-01T00:00:00Z",
509+ "enqueued": enqueuedstr,
510+ "started": "0001-01-01T00:00:00Z",
511+ "status": "pending",
512+ }]},
513+ result)

Subscribers

People subscribed via source and target branches

to all changes: