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
1=== modified file 'deployer/tests/test_charm.py'
2--- deployer/tests/test_charm.py 2014-09-03 13:17:33 +0000
3+++ deployer/tests/test_charm.py 2014-09-29 13:34:03 +0000
4@@ -5,6 +5,7 @@
5 from deployer.charm import Charm
6 from deployer.utils import ErrorExit, yaml_dump
7 from deployer.vcs import Bzr as BaseBzr
8+from deployer.vcs import Git as BaseGit
9 from .base import Base
10
11
12@@ -51,7 +52,7 @@
13 branch = update = pull = None
14
15
16-class CharmTest(Base):
17+class BzrCharmTest(Base):
18
19 def setUp(self):
20 self.repo_path = d = self.mkdir()
21@@ -151,3 +152,143 @@
22 "scratch", self.repo_path, "precise", params)
23 self.assertRaises(ErrorExit, charm.fetch)
24 self.assertIn('bzr: ERROR: Not a branch: ', self.output.getvalue())
25+
26+
27+class Git(BaseGit):
28+
29+ def __init__(self, path):
30+ super(Git, self).__init__(
31+ path, "", logging.getLogger("deployer.repo"))
32+
33+ def init(self):
34+ self._call(
35+ ["git", "init", self.path],
36+ "Could not initialize repo at %(path)s")
37+
38+ def write(self, files):
39+ for f in files:
40+ with open(os.path.join(
41+ self.path, f), 'w') as fh:
42+ fh.write(files[f])
43+ self._call(
44+ ["git", "add", f],
45+ "Could not add file %s" % f)
46+
47+ def commit(self, msg):
48+ self._call(
49+ ["git", "commit", "-m", msg],
50+ "Could not commit at %(path)s")
51+
52+ def revert(self):
53+ self._call(
54+ ["git", "reset", "--hard"],
55+ "Could not revert at %(path)s")
56+
57+ def tag(self, name):
58+ self._call(
59+ ["git", "tag", name],
60+ "Could not tag at %(path)s")
61+
62+ branch = update = pull = None
63+
64+
65+class GitCharmTest(Base):
66+
67+ def setUp(self):
68+ self.repo_path = d = self.mkdir()
69+ self.series_path = os.path.join(d, "precise")
70+ os.mkdir(self.series_path)
71+ self.output = self.capture_logging(
72+ "deployer.charm", level=logging.DEBUG)
73+
74+ def setup_vcs_charm(self):
75+ self.branch = Git(self.mkdir())
76+ self.branch.init()
77+ self.branch.write(
78+ {'metadata.yaml': yaml_dump({
79+ 'name': 'couchdb',
80+ 'summary': 'RESTful document oriented database',
81+ 'provides': {
82+ 'db': {
83+ 'interface': 'couchdb'}}}),
84+ 'revision': '3'})
85+ self.branch.commit('initial')
86+ self.branch.write({'revision': '4'})
87+ self.branch.commit('next')
88+ self.branch.tag('v2')
89+ self.branch.write({'revision': '5'})
90+ self.branch.commit('next')
91+
92+ self.charm_data = {
93+ "charm": "couchdb",
94+ "build": None,
95+ "branch": self.branch.path,
96+ "rev": None,
97+ "charm_url": None,
98+ }
99+
100+ def test_vcs_charm(self):
101+ self.setup_vcs_charm()
102+ params = dict(self.charm_data)
103+ charm = Charm.from_service(
104+ "scratch", self.repo_path, "precise", params)
105+
106+ charm.fetch()
107+ self.assertEqual(charm.metadata['name'], 'couchdb')
108+ HEAD = charm.vcs.get_cur_rev()
109+
110+ self.assertFalse(charm.is_modified())
111+ with open(os.path.join(charm.path, 'revision'), 'w') as fh:
112+ fh.write('0')
113+ self.assertTrue(charm.is_modified())
114+ Git(charm.path).revert()
115+
116+ charm.rev = None
117+ # Update goes to latest with no revision specified
118+ charm.update()
119+ self.assertEqual(charm.vcs.get_cur_rev(), HEAD)
120+
121+ def test_vcs_fetch_with_rev(self):
122+ self.setup_vcs_charm()
123+ params = dict(self.charm_data)
124+ rev2 = self.branch._call(
125+ "git rev-parse HEAD~1".split(),
126+ self.branch.err_cur_rev,
127+ )
128+ params['branch'] = '{}@{}'.format(params['branch'], rev2)
129+ charm = Charm.from_service(
130+ "scratch", self.repo_path, "precise", params)
131+ charm.fetch()
132+ self.assertEqual(charm.vcs.get_cur_rev(), rev2)
133+
134+ def test_store_charm(self):
135+ pass
136+
137+ charms_vcs_series = [
138+ ({"charm": "local:precise/mongodb",
139+ "branch": "lp:charms/precise/couchdb"},
140+ 'trusty', 'precise/mongodb'),
141+ ({"series": "trusty",
142+ "charm": "couchdb",
143+ "branch": "lp:charms/precise/couchdb"},
144+ 'precise', 'trusty/couchdb')]
145+
146+ def test_vcs_charm_with_series(self):
147+ for data, dseries, path in self.charms_vcs_series:
148+ charm = Charm.from_service(
149+ "db", "/tmp", dseries, data)
150+ self.assertEqual(
151+ charm.path,
152+ os.path.join('/tmp', path))
153+ self.assertEqual(
154+ charm.series_path, os.path.join('/tmp', path.split('/')[0]))
155+
156+ def test_charm_error(self):
157+ branch = self.mkdir()
158+ params = {
159+ 'charm': 'couchdb',
160+ 'branch': "file://%s" % branch}
161+ charm = Charm.from_service(
162+ "scratch", self.repo_path, "precise", params)
163+ self.assertRaises(ErrorExit, charm.fetch)
164+ self.assertIn('bzr: ERROR: Not a branch: ', self.output.getvalue())
165
166=== modified file 'deployer/tests/test_guiserver.py'
167--- deployer/tests/test_guiserver.py 2014-02-22 23:11:02 +0000
168+++ deployer/tests/test_guiserver.py 2014-09-29 13:34:03 +0000
169@@ -27,8 +27,8 @@
170 'deployment', 'description', 'destroy_services', 'diff',
171 'find_service', 'ignore_errors', 'juju_env', 'list_deploys',
172 'no_local_mods', 'overrides', 'rel_wait', 'retry_count', 'series',
173- 'terminate_machines', 'timeout', 'update_charms', 'verbose',
174- 'watch'
175+ 'skip_unit_wait', 'terminate_machines', 'timeout', 'update_charms',
176+ 'verbose', 'watch'
177 ])
178 self.assertEqual(expected_keys, set(self.options.__dict__.keys()))
179
180
181=== modified file 'deployer/tests/test_importer.py'
182--- deployer/tests/test_importer.py 2014-02-22 23:33:57 +0000
183+++ deployer/tests/test_importer.py 2014-09-29 13:34:03 +0000
184@@ -38,6 +38,7 @@
185 'rel_wait': 60,
186 'retry_count': 0,
187 'series': None,
188+ 'skip_unit_wait': False,
189 'terminate_machines': False,
190 'timeout': 2700,
191 'update_charms': False,
192
193=== modified file 'deployer/vcs.py'
194--- deployer/vcs.py 2014-04-21 22:49:05 +0000
195+++ deployer/vcs.py 2014-09-29 13:34:03 +0000
196@@ -99,11 +99,11 @@
197 self._call(params, self.err_update)
198
199 def branch(self):
200- params = ["git", "clone", "--depth", "1", self.branch]
201+ params = ["git", "clone", "--depth", "1", self.origin, self.path]
202 self._call(params, self.err_branch, os.path.dirname(self.path))
203
204 def is_modified(self):
205- params = ["git", "stat", "-s"]
206+ params = ["git", "status", "-s"]
207 return bool(self._call(params, self.err_is_mod).strip())
208
209 def get_origin(self):

Subscribers

People subscribed via source and target branches