Merge lp:~doanac/utah/vcs-dev-relative into lp:utah

Proposed by Andy Doan
Status: Merged
Merged at revision: 955
Proposed branch: lp:~doanac/utah/vcs-dev-relative
Merge into: lp:utah
Diff against target: 225 lines (+63/-57)
3 files modified
utah/client/runner.py (+5/-4)
utah/client/tests/test_vcs_dev.py (+43/-48)
utah/client/vcs.py (+15/-5)
To merge this branch: bzr merge lp:~doanac/utah/vcs-dev-relative
Reviewer Review Type Date Requested Status
Max Brustkern (community) Approve
Review via email: mp+171207@code.launchpad.net

Description of the change

Allows the use of relative paths when using a "dev" as the fetch-method of a runlist

To post a comment you must log in.
Revision history for this message
Max Brustkern (nuclearbob) wrote :

This looks good. If you felt like it, it would be awesome if you could also make the test_vcs_bzr and test_vcs_git scripts not fail to initialize probes as well, since those two are still broken. We can come back to that later, though.

review: Approve
Revision history for this message
Andy Doan (doanac) wrote :

On 06/25/2013 09:41 PM, Max Brustkern wrote:

> If you felt like it, it would be awesome if you could also make the test_vcs_bzr and test_vcs_git scripts not fail to initialize probes as well, since those two are still broken.

I think that should be fixed in trunk already.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'utah/client/runner.py'
2--- utah/client/runner.py 2013-06-19 16:46:28 +0000
3+++ utah/client/runner.py 2013-06-25 03:17:23 +0000
4@@ -410,13 +410,14 @@
5
6 return tests
7
8- def _fetch_suite(self, suite):
9+ def _fetch_suite(self, runlist, suite):
10 name = suite['name']
11 syslog.syslog('Fetching testsuite: {}'.format(name))
12 vcs_handler = create_vcs_handler(
13 suite['fetch_method'],
14 suite['fetch_location'],
15 name,
16+ runlist,
17 )
18 res = timeout(60, retry, vcs_handler.get, name)
19 self.result.add_result(res)
20@@ -464,11 +465,11 @@
21 raise exceptions.UTAHClientError(
22 'Error removing the testsuite {}: {}'.format(name, e))
23
24- def _add_suite(self, suite):
25+ def _add_suite(self, runlist, suite):
26 name = suite['name']
27
28 if name not in self.fetched_suites:
29- if self._fetch_suite(suite):
30+ if self._fetch_suite(runlist, suite):
31 self.fetched_suites.append(name)
32 auto = os.path.join(name, name, 'tslist.auto')
33 if os.path.exists(auto):
34@@ -527,7 +528,7 @@
35 self._clean_suite(name)
36
37 mkdir(name)
38- self._add_suite(suite)
39+ self._add_suite(runlist, suite)
40
41 def get_next_suite(self):
42 """Return the next suite to be run.
43
44=== modified file 'utah/client/tests/test_vcs_dev.py'
45--- utah/client/tests/test_vcs_dev.py 2013-04-05 19:32:58 +0000
46+++ utah/client/tests/test_vcs_dev.py 2013-06-25 03:17:23 +0000
47@@ -18,73 +18,68 @@
48
49 import os
50 import shutil
51+import tempfile
52 import unittest
53
54-from utah.client.common import run_cmd
55 from utah.client.vcs import DevHandler
56
57-
58-DEV_TEST_REPO = "/tmp/utahdevtest"
59-
60-
61-def setUp():
62- """Create a local directory for testing."""
63- # should fail if the repo already exists.
64- os.mkdir(DEV_TEST_REPO)
65-
66- run_cmd("touch test.py", cwd=DEV_TEST_REPO)
67-
68-
69-def tearDown():
70- """Remove the test repo."""
71- # We should only ever get here if the repo was created in setUp().
72- shutil.rmtree(DEV_TEST_REPO)
73+from utah.client.tests.common import ( # NOQA
74+ setUp, # Used by nosetests
75+ tearDown, # Used by nosetests
76+)
77
78
79 class TestDevHandler(unittest.TestCase):
80
81 """Test the dev pseudo-VCS handler."""
82
83+ def setUp(self):
84+ """Create a local directory for testing."""
85+ self.repo = tempfile.mkdtemp()
86+ with open(os.path.join(self.repo, 'test.py'), 'w') as f:
87+ f.write('')
88+ self.dest = tempfile.mkdtemp()
89+
90+ def tearDown(self):
91+ """Remove the test repo."""
92+ shutil.rmtree(self.repo)
93+ shutil.rmtree(self.dest)
94+
95 def test_init(self):
96 """Test the initial setup."""
97- repo = DEV_TEST_REPO
98- dev = DevHandler(repo=repo)
99+ dev = DevHandler(repo=self.repo)
100
101 self.assertIsNotNone(dev)
102- self.assertEqual(dev.repo, repo)
103- self.assertEqual(dev.get_command, "cp -r {} .".format(repo))
104+ self.assertEqual(dev.repo, self.repo)
105+ self.assertEqual(dev.get_command, "cp -r {} .".format(self.repo))
106 self.assertEqual(dev.rev_command, "echo 'DEVELOPMENT'")
107
108- def test_dev_get(self):
109+ def test_dev_get_absolute(self):
110 """Test copying files."""
111- repo = DEV_TEST_REPO
112- dest = "utah-dev"
113- dev = DevHandler(repo=repo, destination=dest)
114- directory = "/tmp"
115- path = os.path.join(directory, dest)
116-
117- self.assertFalse(os.path.exists(path), path)
118-
119- result = dev.get(directory=directory)
120- self.assertEqual(result['returncode'], 0)
121-
122- self.assertTrue(os.path.exists(path), path)
123- shutil.rmtree(path)
124+ dev = DevHandler(repo=self.repo, destination=self.dest)
125+ self.assertEqual(0, len(os.listdir(self.dest)))
126+ result = dev.get(directory=self.dest)
127+ self.assertEqual(result['returncode'], 0)
128+ bname = os.path.basename(self.repo)
129+ self.assertListEqual([bname], os.listdir(self.dest))
130+ d = os.path.join(self.dest, bname)
131+ self.assertListEqual(['test.py'], os.listdir(d))
132+
133+ def test_dev_get_relative(self):
134+ """Test we can copy when passed a relative path."""
135+ runlist = os.path.join(self.repo, 'master.run')
136+ with open(runlist, 'w') as f:
137+ f.write('')
138+
139+ dev = DevHandler(repo='./', destination=self.dest, runlist=runlist)
140+ result = dev.get(directory=self.dest)
141+ self.assertEqual(result['returncode'], 0)
142+ self.assertListEqual(['test.py', 'master.run'], os.listdir(self.dest))
143
144 def test_dev_revision(self):
145 """Test fake revision gathering support."""
146- repo = DEV_TEST_REPO
147- dest = "utah-dev"
148- dev = DevHandler(repo=repo, destination=dest)
149- directory = "/tmp"
150- path = os.path.join(directory, dest)
151-
152- self.assertFalse(os.path.exists(path))
153- result = dev.get(directory=directory)
154+ dev = DevHandler(repo=self.repo, destination=self.dest)
155+ result = dev.get(directory=self.dest)
156 self.assertEqual(result['returncode'], 0)
157- self.assertTrue(os.path.exists(path))
158-
159- result = dev.revision(directory=path)
160-
161- shutil.rmtree(path)
162+ result = dev.revision(directory=self.dest)
163 self.assertEqual(result['returncode'], 0)
164
165=== modified file 'utah/client/vcs.py'
166--- utah/client/vcs.py 2013-06-11 17:12:07 +0000
167+++ utah/client/vcs.py 2013-06-25 03:17:23 +0000
168@@ -15,6 +15,9 @@
169
170 """UTAH client VCS support."""
171
172+import logging
173+import os
174+
175 from utah.client.common import (
176 CMD_TS_FETCH,
177 run_cmd,
178@@ -37,9 +40,10 @@
179
180 """
181
182- def __init__(self, repo, destination=''):
183+ def __init__(self, repo, destination='', runlist=None):
184 self.repo = repo
185 self.destination = destination
186+ self.runlist = runlist
187
188 def get(self, directory=REPO_DEFAULT_DIR):
189 """Execute VCS get command.
190@@ -145,18 +149,23 @@
191
192 """
193
194- def __init__(self, repo, destination=".", **kwargs):
195- super(DevHandler, self).__init__(repo, destination, **kwargs)
196+ def __init__(self, repo, destination=".", runlist=None):
197+ super(DevHandler, self).__init__(repo, destination, runlist)
198+
199+ if self.repo[0] != '/':
200+ logging.debug('using relative path for dev handler')
201+ path = os.path.abspath(runlist)
202+ path = os.path.dirname(path)
203+ self.repo = os.path.join(path, self.repo)
204
205 self.get_command = "cp -r {} {}".format(
206 self.repo,
207 self.destination,
208 )
209-
210 self.rev_command = "echo 'DEVELOPMENT'"
211
212
213-def create_vcs_handler(method, location, destination):
214+def create_vcs_handler(method, location, destination, runlist):
215 """Find an instantiate the proper VCS handler object.
216
217 :return: VCSHandler object
218@@ -166,6 +175,7 @@
219 kwargs = {
220 'repo': location,
221 'destination': destination,
222+ 'runlist': runlist,
223 }
224
225 handlers = {

Subscribers

People subscribed via source and target branches

to all changes: