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

Subscribers

People subscribed via source and target branches

to all changes: