Merge lp:~tvansteenburgh/juju-deployer/fix-git into lp:juju-deployer

Proposed by Tim Van Steenburgh
Status: Merged
Merged at revision: 126
Proposed branch: lp:~tvansteenburgh/juju-deployer/fix-git
Merge into: lp:juju-deployer
Diff against target: 209 lines (+147/-5)
4 files modified
deployer/tests/test_charm.py (+142/-1)
deployer/tests/test_guiserver.py (+2/-2)
deployer/tests/test_importer.py (+1/-0)
deployer/vcs.py (+2/-2)
To merge this branch: bzr merge lp:~tvansteenburgh/juju-deployer/fix-git
Reviewer Review Type Date Requested Status
Kapil Thangavelu Approve
Review via email: mp+236330@code.launchpad.net

Description of the change

Fix bugs in Git impl; add tests.

To post a comment you must log in.
Revision history for this message
Kapil Thangavelu (hazmat) wrote :

merged with some minor changes, thanks.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'deployer/tests/test_charm.py'
--- deployer/tests/test_charm.py 2014-09-03 13:17:33 +0000
+++ deployer/tests/test_charm.py 2014-09-29 13:34:03 +0000
@@ -5,6 +5,7 @@
5from deployer.charm import Charm5from deployer.charm import Charm
6from deployer.utils import ErrorExit, yaml_dump6from deployer.utils import ErrorExit, yaml_dump
7from deployer.vcs import Bzr as BaseBzr7from deployer.vcs import Bzr as BaseBzr
8from deployer.vcs import Git as BaseGit
8from .base import Base9from .base import Base
910
1011
@@ -51,7 +52,7 @@
51 branch = update = pull = None52 branch = update = pull = None
5253
5354
54class CharmTest(Base):55class BzrCharmTest(Base):
5556
56 def setUp(self):57 def setUp(self):
57 self.repo_path = d = self.mkdir()58 self.repo_path = d = self.mkdir()
@@ -151,3 +152,143 @@
151 "scratch", self.repo_path, "precise", params)152 "scratch", self.repo_path, "precise", params)
152 self.assertRaises(ErrorExit, charm.fetch)153 self.assertRaises(ErrorExit, charm.fetch)
153 self.assertIn('bzr: ERROR: Not a branch: ', self.output.getvalue())154 self.assertIn('bzr: ERROR: Not a branch: ', self.output.getvalue())
155
156
157class Git(BaseGit):
158
159 def __init__(self, path):
160 super(Git, self).__init__(
161 path, "", logging.getLogger("deployer.repo"))
162
163 def init(self):
164 self._call(
165 ["git", "init", self.path],
166 "Could not initialize repo at %(path)s")
167
168 def write(self, files):
169 for f in files:
170 with open(os.path.join(
171 self.path, f), 'w') as fh:
172 fh.write(files[f])
173 self._call(
174 ["git", "add", f],
175 "Could not add file %s" % f)
176
177 def commit(self, msg):
178 self._call(
179 ["git", "commit", "-m", msg],
180 "Could not commit at %(path)s")
181
182 def revert(self):
183 self._call(
184 ["git", "reset", "--hard"],
185 "Could not revert at %(path)s")
186
187 def tag(self, name):
188 self._call(
189 ["git", "tag", name],
190 "Could not tag at %(path)s")
191
192 branch = update = pull = None
193
194
195class GitCharmTest(Base):
196
197 def setUp(self):
198 self.repo_path = d = self.mkdir()
199 self.series_path = os.path.join(d, "precise")
200 os.mkdir(self.series_path)
201 self.output = self.capture_logging(
202 "deployer.charm", level=logging.DEBUG)
203
204 def setup_vcs_charm(self):
205 self.branch = Git(self.mkdir())
206 self.branch.init()
207 self.branch.write(
208 {'metadata.yaml': yaml_dump({
209 'name': 'couchdb',
210 'summary': 'RESTful document oriented database',
211 'provides': {
212 'db': {
213 'interface': 'couchdb'}}}),
214 'revision': '3'})
215 self.branch.commit('initial')
216 self.branch.write({'revision': '4'})
217 self.branch.commit('next')
218 self.branch.tag('v2')
219 self.branch.write({'revision': '5'})
220 self.branch.commit('next')
221
222 self.charm_data = {
223 "charm": "couchdb",
224 "build": None,
225 "branch": self.branch.path,
226 "rev": None,
227 "charm_url": None,
228 }
229
230 def test_vcs_charm(self):
231 self.setup_vcs_charm()
232 params = dict(self.charm_data)
233 charm = Charm.from_service(
234 "scratch", self.repo_path, "precise", params)
235
236 charm.fetch()
237 self.assertEqual(charm.metadata['name'], 'couchdb')
238 HEAD = charm.vcs.get_cur_rev()
239
240 self.assertFalse(charm.is_modified())
241 with open(os.path.join(charm.path, 'revision'), 'w') as fh:
242 fh.write('0')
243 self.assertTrue(charm.is_modified())
244 Git(charm.path).revert()
245
246 charm.rev = None
247 # Update goes to latest with no revision specified
248 charm.update()
249 self.assertEqual(charm.vcs.get_cur_rev(), HEAD)
250
251 def test_vcs_fetch_with_rev(self):
252 self.setup_vcs_charm()
253 params = dict(self.charm_data)
254 rev2 = self.branch._call(
255 "git rev-parse HEAD~1".split(),
256 self.branch.err_cur_rev,
257 )
258 params['branch'] = '{}@{}'.format(params['branch'], rev2)
259 charm = Charm.from_service(
260 "scratch", self.repo_path, "precise", params)
261 charm.fetch()
262 self.assertEqual(charm.vcs.get_cur_rev(), rev2)
263
264 def test_store_charm(self):
265 pass
266
267 charms_vcs_series = [
268 ({"charm": "local:precise/mongodb",
269 "branch": "lp:charms/precise/couchdb"},
270 'trusty', 'precise/mongodb'),
271 ({"series": "trusty",
272 "charm": "couchdb",
273 "branch": "lp:charms/precise/couchdb"},
274 'precise', 'trusty/couchdb')]
275
276 def test_vcs_charm_with_series(self):
277 for data, dseries, path in self.charms_vcs_series:
278 charm = Charm.from_service(
279 "db", "/tmp", dseries, data)
280 self.assertEqual(
281 charm.path,
282 os.path.join('/tmp', path))
283 self.assertEqual(
284 charm.series_path, os.path.join('/tmp', path.split('/')[0]))
285
286 def test_charm_error(self):
287 branch = self.mkdir()
288 params = {
289 'charm': 'couchdb',
290 'branch': "file://%s" % branch}
291 charm = Charm.from_service(
292 "scratch", self.repo_path, "precise", params)
293 self.assertRaises(ErrorExit, charm.fetch)
294 self.assertIn('bzr: ERROR: Not a branch: ', self.output.getvalue())
154295
=== modified file 'deployer/tests/test_guiserver.py'
--- deployer/tests/test_guiserver.py 2014-02-22 23:11:02 +0000
+++ deployer/tests/test_guiserver.py 2014-09-29 13:34:03 +0000
@@ -27,8 +27,8 @@
27 'deployment', 'description', 'destroy_services', 'diff',27 'deployment', 'description', 'destroy_services', 'diff',
28 'find_service', 'ignore_errors', 'juju_env', 'list_deploys',28 'find_service', 'ignore_errors', 'juju_env', 'list_deploys',
29 'no_local_mods', 'overrides', 'rel_wait', 'retry_count', 'series',29 'no_local_mods', 'overrides', 'rel_wait', 'retry_count', 'series',
30 'terminate_machines', 'timeout', 'update_charms', 'verbose',30 'skip_unit_wait', 'terminate_machines', 'timeout', 'update_charms',
31 'watch'31 'verbose', 'watch'
32 ])32 ])
33 self.assertEqual(expected_keys, set(self.options.__dict__.keys()))33 self.assertEqual(expected_keys, set(self.options.__dict__.keys()))
3434
3535
=== modified file 'deployer/tests/test_importer.py'
--- deployer/tests/test_importer.py 2014-02-22 23:33:57 +0000
+++ deployer/tests/test_importer.py 2014-09-29 13:34:03 +0000
@@ -38,6 +38,7 @@
38 'rel_wait': 60,38 'rel_wait': 60,
39 'retry_count': 0,39 'retry_count': 0,
40 'series': None,40 'series': None,
41 'skip_unit_wait': False,
41 'terminate_machines': False,42 'terminate_machines': False,
42 'timeout': 2700,43 'timeout': 2700,
43 'update_charms': False,44 'update_charms': False,
4445
=== modified file 'deployer/vcs.py'
--- deployer/vcs.py 2014-04-21 22:49:05 +0000
+++ deployer/vcs.py 2014-09-29 13:34:03 +0000
@@ -99,11 +99,11 @@
99 self._call(params, self.err_update)99 self._call(params, self.err_update)
100100
101 def branch(self):101 def branch(self):
102 params = ["git", "clone", "--depth", "1", self.branch]102 params = ["git", "clone", "--depth", "1", self.origin, self.path]
103 self._call(params, self.err_branch, os.path.dirname(self.path))103 self._call(params, self.err_branch, os.path.dirname(self.path))
104104
105 def is_modified(self):105 def is_modified(self):
106 params = ["git", "stat", "-s"]106 params = ["git", "status", "-s"]
107 return bool(self._call(params, self.err_is_mod).strip())107 return bool(self._call(params, self.err_is_mod).strip())
108108
109 def get_origin(self):109 def get_origin(self):

Subscribers

People subscribed via source and target branches