Merge lp:~milo/lava-dispatcher/tar-repo into lp:lava-dispatcher

Proposed by Milo Casagrande
Status: Merged
Merged at revision: 640
Proposed branch: lp:~milo/lava-dispatcher/tar-repo
Merge into: lp:lava-dispatcher
Diff against target: 102 lines (+55/-7)
1 file modified
lava_dispatcher/actions/lava_test_shell.py (+55/-7)
To merge this branch: bzr merge lp:~milo/lava-dispatcher/tar-repo
Reviewer Review Type Date Requested Status
Antonio Terceiro Approve
Review via email: mp+175274@code.launchpad.net

Description of the change

Added support to the dispatcher for tar-repo: a base64-encoded string of the content of a tar file.
This is necessary in order to support ongoing work on lava-tool (LAVA-15 card).

To post a comment you must log in.
lp:~milo/lava-dispatcher/tar-repo updated
639. By Milo Casagrande

Fixed problem with extract directory and tar file.

640. By Milo Casagrande

Fixed typo.

Revision history for this message
Milo Casagrande (milo) wrote :

I pushed new changes to fix a couple of problems found while running jobs.

lp:~milo/lava-dispatcher/tar-repo updated
641. By Milo Casagrande

Use 0 instead of nil for tar revision.

642. By Milo Casagrande

Merged from trunk, fixed conflicts.

643. By Milo Casagrande

Fixed PEP8 problem from previous merge.

Revision history for this message
Antonio Terceiro (terceiro) wrote :
Download full text (4.6 KiB)

Hi Milo,

This looks nice. I have a few comments to be addressed.

 review needs-fixing

> === modified file 'lava_dispatcher/actions/lava_test_shell.py'
> --- lava_dispatcher/actions/lava_test_shell.py 2013-07-17 09:16:46 +0000
> +++ lava_dispatcher/actions/lava_test_shell.py 2013-07-22 13:39:27 +0000
> @@ -107,13 +107,16 @@
>
> from datetime import datetime
> from glob import glob
> +import base64
> import logging
> import os
> import pexpect
> import pkg_resources
> import shutil
> import stat
> +import StringIO
> import subprocess
> +import tarfile
> import tempfile
> import time
> from uuid import uuid4
> @@ -187,6 +190,37 @@
> logging.error('Unable to get test definition from bzr\n' + str(e))
>
>
> +def _get_testdef_tar_repo(testdef_repo, tmpdir):
> + """Extracts the provided encoded tar archive into tmpdir."""
> + tardir = os.path.join(tmpdir, 'tartestrepo')
> + temp_tar = os.path.join(tmpdir, "tar-repo.tar")
> +
> + try:
> + if not os.path.isdir(tardir):
> + logging.info("Creating directory to extract the tar archive into.")
> + os.makedirs(tardir)
> +
> + encoded_in = StringIO.StringIO(testdef_repo)
> + decoded_out = StringIO.StringIO()
> + base64.decode(encoded_in, decoded_out)
> +
> + # The following two operations can also be done in memory
> + # using cStringIO.
> + # At the moment the tar file sent is not big, but that can change.
> + with open(temp_tar, "w") as write_tar:
> + write_tar.write(decoded_out.getvalue())
> +
> + with tarfile.open(temp_tar) as tar:
> + tar.extractall(path=tardir)
> + except Exception as ex:

can we capture a more specific type of exception here? otherwise we may be
masking random exceptions that might happen above.

> + logging.error("Error extracting the tar archive.\n" + str(ex))
> + finally:
> + # Remove the temporary created tar file after it has been extracted.
> + if os.path.isfile(temp_tar):
> + os.unlink(temp_tar)
> + return tardir
> +
> +
> def _get_testdef_info(testdef):
> metadata = {'os': '', 'devices': '', 'environment': ''}
> metadata['description'] = testdef['metadata'].get('description')
> @@ -255,8 +289,20 @@
> name = testdef_repo['bzr-repo'].replace('lp:', '').split('/')[-1]
> info = _bzr_info(testdef_repo['bzr-repo'], repo, name)
>
> + if 'tar-repo' in testdef_repo:
> + repo = _get_testdef_tar_repo(testdef_repo['tar-repo'], tmpdir)
> + # Default info structure, since we need something, but we have
> + # a tar file in this case.
> + info = {
> + "project_name": "Tar archived repository",
> + "branch_vcs": "tar",
> + "branch_revision": "0",
> + "branch_url": repo
> + }
> +
> if not repo or not info:
> logging.debug("Unable to identify specified repository. %s" % testdef_repo)
> +
> test = testdef_repo.get('testdef', 'lavatest.yaml')
> with open(os.path.join(repo, test), 'r') as f:
> logging....

Read more...

review: Needs Fixing
lp:~milo/lava-dispatcher/tar-repo updated
644. By Milo Casagrande

Added more specific exceptions.

Revision history for this message
Milo Casagrande (milo) wrote :

Hi Antonio,

thanks for looking into it.

On Mon, Jul 22, 2013 at 11:46 PM, Antonio Terceiro
<email address hidden> wrote:
>
>> +def _get_testdef_tar_repo(testdef_repo, tmpdir):
>> + """Extracts the provided encoded tar archive into tmpdir."""
>> + tardir = os.path.join(tmpdir, 'tartestrepo')
>> + temp_tar = os.path.join(tmpdir, "tar-repo.tar")
>> +
>> + try:
>> + if not os.path.isdir(tardir):
>> + logging.info("Creating directory to extract the tar archive into.")
>> + os.makedirs(tardir)
>> +
>> + encoded_in = StringIO.StringIO(testdef_repo)
>> + decoded_out = StringIO.StringIO()
>> + base64.decode(encoded_in, decoded_out)
>> +
>> + # The following two operations can also be done in memory
>> + # using cStringIO.
>> + # At the moment the tar file sent is not big, but that can change.
>> + with open(temp_tar, "w") as write_tar:
>> + write_tar.write(decoded_out.getvalue())
>> +
>> + with tarfile.open(temp_tar) as tar:
>> + tar.extractall(path=tardir)
>> + except Exception as ex:
>
> can we capture a more specific type of exception here? otherwise we may be
> masking random exceptions that might happen above.

Fixed now, I used: (OSError, tarfile.TarError) to catch possible
errors with both open() and tarfile.open().

>> {'git-repo': {'type': 'string',
>> - 'optional': True},
>> - 'bzr-repo': {'type': 'string',
>> - 'optional': True},
>> - 'revision': {'type': 'string',
>> - 'optional': True},
>> - 'testdef': {'type': 'string',
>> - 'optional': True}
>> + 'optional': True},
>> + 'bzr-repo': {'type': 'string',
>> + 'optional': True},
>> + 'tar-repo': {'type': 'string',
>> + 'optional': True},
>> + 'revision': {'type': 'string',
>> + 'optional': True},
>> + 'testdef': {'type': 'string',
>> + 'optional': True}
>
> I think this indentation here got changed with a recent PEP8-related merge so
> that this will not merge cleanly, please check.

I merged from trunk and cleaned up, it should be OK.
Ciao.

--
Milo Casagrande | Automation Engineer
Linaro.org <www.linaro.org> │ Open source software for ARM SoCs

Revision history for this message
Antonio Terceiro (terceiro) wrote :

On Tue, Jul 23, 2013 at 08:31:32AM -0000, Milo Casagrande wrote:
> >> + with tarfile.open(temp_tar) as tar:
> >> + tar.extractall(path=tardir)
> >> + except Exception as ex:
> >
> > can we capture a more specific type of exception here? otherwise we may be
> > masking random exceptions that might happen above.
>
> Fixed now, I used: (OSError, tarfile.TarError) to catch possible
> errors with both open() and tarfile.open().

cool

 review approve

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'lava_dispatcher/actions/lava_test_shell.py'
--- lava_dispatcher/actions/lava_test_shell.py 2013-07-17 09:16:46 +0000
+++ lava_dispatcher/actions/lava_test_shell.py 2013-07-23 08:14:26 +0000
@@ -107,13 +107,16 @@
107107
108from datetime import datetime108from datetime import datetime
109from glob import glob109from glob import glob
110import base64
110import logging111import logging
111import os112import os
112import pexpect113import pexpect
113import pkg_resources114import pkg_resources
114import shutil115import shutil
115import stat116import stat
117import StringIO
116import subprocess118import subprocess
119import tarfile
117import tempfile120import tempfile
118import time121import time
119from uuid import uuid4122from uuid import uuid4
@@ -187,6 +190,37 @@
187 logging.error('Unable to get test definition from bzr\n' + str(e))190 logging.error('Unable to get test definition from bzr\n' + str(e))
188191
189192
193def _get_testdef_tar_repo(testdef_repo, tmpdir):
194 """Extracts the provided encoded tar archive into tmpdir."""
195 tardir = os.path.join(tmpdir, 'tartestrepo')
196 temp_tar = os.path.join(tmpdir, "tar-repo.tar")
197
198 try:
199 if not os.path.isdir(tardir):
200 logging.info("Creating directory to extract the tar archive into.")
201 os.makedirs(tardir)
202
203 encoded_in = StringIO.StringIO(testdef_repo)
204 decoded_out = StringIO.StringIO()
205 base64.decode(encoded_in, decoded_out)
206
207 # The following two operations can also be done in memory
208 # using cStringIO.
209 # At the moment the tar file sent is not big, but that can change.
210 with open(temp_tar, "w") as write_tar:
211 write_tar.write(decoded_out.getvalue())
212
213 with tarfile.open(temp_tar) as tar:
214 tar.extractall(path=tardir)
215 except (OSError, tarfile.TarError) as ex:
216 logging.error("Error extracting the tar archive.\n" + str(ex))
217 finally:
218 # Remove the temporary created tar file after it has been extracted.
219 if os.path.isfile(temp_tar):
220 os.unlink(temp_tar)
221 return tardir
222
223
190def _get_testdef_info(testdef):224def _get_testdef_info(testdef):
191 metadata = {'os': '', 'devices': '', 'environment': ''}225 metadata = {'os': '', 'devices': '', 'environment': ''}
192 metadata['description'] = testdef['metadata'].get('description')226 metadata['description'] = testdef['metadata'].get('description')
@@ -255,8 +289,20 @@
255 name = testdef_repo['bzr-repo'].replace('lp:', '').split('/')[-1]289 name = testdef_repo['bzr-repo'].replace('lp:', '').split('/')[-1]
256 info = _bzr_info(testdef_repo['bzr-repo'], repo, name)290 info = _bzr_info(testdef_repo['bzr-repo'], repo, name)
257291
292 if 'tar-repo' in testdef_repo:
293 repo = _get_testdef_tar_repo(testdef_repo['tar-repo'], tmpdir)
294 # Default info structure, since we need something, but we have
295 # a tar file in this case.
296 info = {
297 "project_name": "Tar archived repository",
298 "branch_vcs": "tar",
299 "branch_revision": "0",
300 "branch_url": repo
301 }
302
258 if not repo or not info:303 if not repo or not info:
259 logging.debug("Unable to identify specified repository. %s" % testdef_repo)304 logging.debug("Unable to identify specified repository. %s" % testdef_repo)
305
260 test = testdef_repo.get('testdef', 'lavatest.yaml')306 test = testdef_repo.get('testdef', 'lavatest.yaml')
261 with open(os.path.join(repo, test), 'r') as f:307 with open(os.path.join(repo, test), 'r') as f:
262 logging.info('loading test definition ...')308 logging.info('loading test definition ...')
@@ -462,13 +508,15 @@
462 'items': {'type': 'object',508 'items': {'type': 'object',
463 'properties':509 'properties':
464 {'git-repo': {'type': 'string',510 {'git-repo': {'type': 'string',
465 'optional': True},511 'optional': True},
466 'bzr-repo': {'type': 'string',512 'bzr-repo': {'type': 'string',
467 'optional': True},513 'optional': True},
468 'revision': {'type': 'string',514 'tar-repo': {'type': 'string',
469 'optional': True},515 'optional': True},
470 'testdef': {'type': 'string',516 'revision': {'type': 'string',
471 'optional': True}517 'optional': True},
518 'testdef': {'type': 'string',
519 'optional': True}
472 },520 },
473 'additionalProperties': False},521 'additionalProperties': False},
474 'optional': True522 'optional': True

Subscribers

People subscribed via source and target branches