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

Proposed by Eric Snow
Status: Merged
Approved by: Eric Snow
Approved revision: 49
Merged at revision: 40
Proposed branch: lp:~ericsnowcurrently/fake-juju/python-lib-testing
Merge into: lp:~landscape/fake-juju/trunk-old
Prerequisite: lp:~ericsnowcurrently/fake-juju/python-lib-classes
Diff against target: 72 lines (+68/-0)
1 file modified
python/fakejuju/testing.py (+68/-0)
To merge this branch: bzr merge lp:~ericsnowcurrently/fake-juju/python-lib-testing
Reviewer Review Type Date Requested Status
Free Ekanayaka (community) Approve
🤖 Landscape Builder test results Approve
Review via email: mp+307897@code.launchpad.net

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

Commit message

Add the fakejuju.testing module.

This is essentially fake-juju part of txjuju.testing.

Description of the change

Add the fakejuju.testing module.

This is essentially fake-juju part of txjuju.testing.

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: 49
Branch: lp:~ericsnowcurrently/fake-juju/python-lib-testing
Jenkins: https://ci.lscape.net/job/latch-test-xenial/18/

review: Approve (test results)
Revision history for this message
Free Ekanayaka (free.ekanayaka) wrote :

+1

It's a bit weird to have to depend on txjuju, if you don't fully need the functionality of txjuju.prepare_for_bootstrap perhaps you could implement a minimal standalone version of it in this package and drop the dependency.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== added file 'python/fakejuju/testing.py'
2--- python/fakejuju/testing.py 1970-01-01 00:00:00 +0000
3+++ python/fakejuju/testing.py 2016-10-06 22:54:06 +0000
4@@ -0,0 +1,68 @@
5+# Copyright 2016 Canonical Limited. All rights reserved.
6+
7+import txjuju
8+from fixtures import Fixture, TempDir
9+from testtools.content import content_from_file
10+
11+from . import fakejuju
12+
13+
14+JUJU1_VER = "1.25.6"
15+JUJU2_VER = "2.0-beta17"
16+JUJU_VER = JUJU1_VER
17+
18+
19+class FakeJujuFixture(Fixture):
20+ """Manages a fake-juju process."""
21+
22+ CONTROLLER = "test"
23+ ADMIN_SECRET = "sekret"
24+ VERSION = JUJU_VER
25+
26+ def __init__(self, controller=None, password=None, logs_dir=None,
27+ version=None):
28+ """
29+ @param logs_dir: If given, copy logs to this directory upon cleanup,
30+ otherwise, print it as test plain text detail upon failure.
31+ """
32+ if controller is None:
33+ controller = self.CONTROLLER
34+ if password is None:
35+ password = self.ADMIN_SECRET
36+ if version is None:
37+ version = self.VERSION
38+
39+ self._controller = controller
40+ self._password = password
41+ self._logs_dir = logs_dir
42+ self._version = version
43+
44+ def setUp(self):
45+ super(FakeJujuFixture, self).setUp()
46+ self._juju_home = self.useFixture(TempDir())
47+ self._juju = fakejuju.FakeJuju.make(
48+ self._juju_home.path, self._version, self._logs_dir)
49+
50+ if not self._logs_dir:
51+ # Attach logs as testtools details.
52+ self.addDetail("log-file", content_from_file(self._juju.logfile))
53+
54+ spec = fakejuju.get_bootstrap_spec(self._controller, self._password)
55+ cfgfile = txjuju.prepare_for_bootstrap(
56+ spec, self._version, self._juju_home)
57+ cli = self._juju.cli()
58+ cli.bootstrap(spec, cfgfile=cfgfile)
59+ api_info = cli.api_info(spec.name)
60+ if self._version.startswith("1."):
61+ # fake-juju doesn't give us the password, so we have to
62+ # set it here.
63+ api_info = api_info._replace(password=self._password)
64+ self.api_info = api_info
65+
66+ def cleanUp(self):
67+ self._juju.destroy_controller(self._controller)
68+ super(FakeJujuFixture, self).cleanUp()
69+
70+ def add_failure(self, entity):
71+ """Make the given entity fail with an error status."""
72+ self._juju.failures.fail_entity(entity)

Subscribers

People subscribed via source and target branches

to all changes: