Merge lp:~nskaggs/juju-ci-tools/update-templates into lp:juju-ci-tools

Proposed by Nicholas Skaggs on 2016-03-31
Status: Rejected
Rejected by: Nicholas Skaggs on 2016-04-06
Proposed branch: lp:~nskaggs/juju-ci-tools/update-templates
Merge into: lp:juju-ci-tools
Diff against target: 179 lines (+74/-18)
4 files modified
jujupy.py (+15/-0)
template_assess.py.tmpl (+24/-11)
template_test.py.tmpl (+27/-7)
tests/test_jujupy.py (+8/-0)
To merge this branch: bzr merge lp:~nskaggs/juju-ci-tools/update-templates
Reviewer Review Type Date Requested Status
Nicholas Skaggs (community) Disapprove on 2016-04-06
Review via email: mp+290664@code.launchpad.net

Description of the change

Update templates for new ci tests

To post a comment you must log in.
Martin Packman (gz) wrote :

See inline comments for design suggestions and changes.

1339. By Nicholas Skaggs on 2016-04-01

flake8 fixes

1340. By Nicholas Skaggs on 2016-04-01

kill current version, fix make_charm, move to jujupy

Nicholas Skaggs (nskaggs) wrote :

Per Aaron, I'm tabling for now based on feedback. This takes the template away from the current decision to host a repository of charms, and changes how we view charms as needing 1.x and 2.x compatibility.

review: Disapprove

Unmerged revisions

1340. By Nicholas Skaggs on 2016-04-01

kill current version, fix make_charm, move to jujupy

1339. By Nicholas Skaggs on 2016-04-01

flake8 fixes

1338. By Nicholas Skaggs on 2016-04-01

only one more test hates me

1337. By Nicholas Skaggs on 2016-04-01

wip, fix unit tests

1336. By Nicholas Skaggs on 2016-03-31

add support for juju 1 and juju 2

1335. By Nicholas Skaggs on 2016-03-31

whitespace

1334. By Nicholas Skaggs on 2016-03-31

Update templates to be 2.0ish with xenial and dummy charm

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'jujupy.py'
2--- jujupy.py 2016-03-24 13:45:50 +0000
3+++ jujupy.py 2016-04-01 21:59:37 +0000
4@@ -1102,6 +1102,21 @@
5 def add_subnet(self, subnet, space):
6 self.juju('add-subnet', (subnet, space))
7
8+ # nas make charm_dir sane default of temp dir
9+ # allow name to also be sane temporary default
10+ def make_charm(charm_dir, name, summary=None,
11+ description=None, series=[],
12+ min_juju_version=None):
13+ metadata = os.path.join(charm_dir, 'metadata.yaml')
14+ content = {}
15+ content['name'] = name
16+ content['summary'] = summary
17+ content['description'] = description
18+ content['min-juju-version'] = min_juju_version
19+ content['series'] = series
20+ with open(metadata, 'w') as f:
21+ yaml.safe_dump(content, f, default_flow_style=False)
22+
23
24 class EnvJujuClient2B2(EnvJujuClient):
25
26
27=== modified file 'template_assess.py.tmpl'
28--- template_assess.py.tmpl 2016-03-21 21:04:42 +0000
29+++ template_assess.py.tmpl 2016-04-01 21:59:37 +0000
30@@ -5,30 +5,44 @@
31
32 import argparse
33 import logging
34+import os
35 import sys
36
37+import yaml
38+
39 from deploy_stack import (
40 BootstrapManager,
41 )
42 from utility import (
43 add_basic_testing_arguments,
44 configure_logging,
45+ temp_dir,
46 )
47
48-
49 __metaclass__ = type
50
51-
52 log = logging.getLogger("assess_TEMPLATE")
53
54-
55-def assess_TEMPLATE(client):
56+def assess_TEMPLATE(client, args):
57 # Deploy charms, there are several under ./repository
58- client.juju("deploy", ('local:trusty/my-charm',))
59- # Wait for the deployment to finish.
60- client.wait_for_started()
61- log.info("TODO: Add log line about any test")
62- # TODO: Add specific functional testing actions here.
63+ if get_current_version(client, args.juju_bin).startswith('1.'):
64+ log.info("Testing TEMPLATE")
65+ charm_name = 'dummy'
66+ make_charm(charm_dir, charm_name)
67+ client.deploy('local:' + charm_name)
68+ # Wait for the deployment to finish.
69+ client.wait_for_started()
70+ log.info("TODO: Add log line about any test")
71+ # TODO: Add specific functional testing actions here.
72+ else:
73+ with temp_dir() as charm_dir:
74+ log.info("Testing TEMPLATE")
75+ make_charm(charm_dir)
76+ client.deploy(charm)
77+ # Wait for the deployment to finish.
78+ client.wait_for_started()
79+ log.info("TODO: Add log line about any test")
80+ # TODO: Add specific functional testing actions here.
81
82
83 def parse_args(argv):
84@@ -45,9 +59,8 @@
85 configure_logging(args.verbose)
86 bs_manager = BootstrapManager.from_args(args)
87 with bs_manager.booted_context(args.upload_tools):
88- assess_TEMPLATE(bs_manager.client)
89+ assess_TEMPLATE(bs_manager.client, args)
90 return 0
91
92-
93 if __name__ == '__main__':
94 sys.exit(main())
95
96=== modified file 'template_test.py.tmpl'
97--- template_test.py.tmpl 2015-12-16 03:59:38 +0000
98+++ template_test.py.tmpl 2016-04-01 21:59:37 +0000
99@@ -1,18 +1,28 @@
100 """Tests for assess_TEMPLATE module."""
101
102 import logging
103-from mock import Mock, patch
104+from mock import (
105+ Mock,
106+ patch,
107+ call,
108+)
109+import os
110 import StringIO
111
112+import yaml
113+
114 from assess_TEMPLATE import (
115 assess_TEMPLATE,
116+ get_current_version,
117+ make_charm,
118+ main,
119 parse_args,
120- main,
121 )
122 from tests import (
123 parse_error,
124 TestCase,
125 )
126+from utility import temp_dir
127
128
129 class TestParseArgs(TestCase):
130@@ -55,15 +65,25 @@
131 mock_e.assert_called_once_with("an-env")
132 mock_c.assert_called_once_with(env, "/bin/juju", debug=False)
133 self.assertEqual(mock_bc.call_count, 1)
134- mock_assess.assert_called_once_with(client)
135+ mock_assess.assert_called_once_with(client, parse_args(argv))
136
137
138 class TestAssess(TestCase):
139
140- def test_TEMPLATE(self):
141+ def test_assess_TEMPLATE(self):
142+ argv = ["an-env", "/bin/juju", "/tmp/logs", "an-env-mod", "--verbose"]
143+ args = parse_args(argv)
144 mock_client = Mock(spec=["juju", "wait_for_started"])
145- assess_TEMPLATE(mock_client)
146- mock_client.juju.assert_called_once_with(
147- 'deploy', ('local:trusty/my-charm',))
148+ with patch("assess_TEMPLATE.get_current_version",
149+ autospec=True, return_value="2.0.0") as mock_gcv:
150+ with patch("assess_TEMPLATE.temp_dir",
151+ autospec=True) as mock_td:
152+ with patch("assess_TEMPLATE.make_charm",
153+ autospec=True) as mock_mc:
154+ assess_TEMPLATE(mock_client, args)
155 mock_client.wait_for_started.assert_called_once_with()
156+ mock_gcv.assert_called_once_with(mock_client, '/bin/juju')
157+ temp_dir = mock_td.return_value.__enter__.return_value
158+ call(mock_client, temp_dir)
159+ self.assertEqual(mock_td.call_count, 1)
160 self.assertNotIn("TODO", self.log_stream.getvalue())
161
162=== modified file 'tests/test_jujupy.py'
163--- tests/test_jujupy.py 2016-03-24 13:45:50 +0000
164+++ tests/test_jujupy.py 2016-04-01 21:59:37 +0000
165@@ -2603,6 +2603,14 @@
166 juju_mock.assert_called_once_with('add-subnet',
167 ('bar-subnet', 'foo-space'))
168
169+ def test_make_charm(self):
170+ client = EnvJujuClient(JujuData(None, {'type': 'local'}),
171+ '1.23-series-arch', None)
172+ with patch.object(client, 'juju', autospec=True) as juju_mock:
173+ client.make_charm('/tmp/make-charm', 'foo')
174+ juju_mock.assert_called_once_with('make-charm',
175+ ('/tmp/make-charm', 'foo'))
176+
177 def test__shell_environ_uses_pathsep(self):
178 client = EnvJujuClient(JujuData('foo'), None, 'foo/bar/juju')
179 with patch('os.pathsep', '!'):

Subscribers

People subscribed via source and target branches