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
1=== modified file 'lava_dispatcher/actions/lava_test_shell.py'
2--- lava_dispatcher/actions/lava_test_shell.py 2013-07-17 09:16:46 +0000
3+++ lava_dispatcher/actions/lava_test_shell.py 2013-07-23 08:14:26 +0000
4@@ -107,13 +107,16 @@
5
6 from datetime import datetime
7 from glob import glob
8+import base64
9 import logging
10 import os
11 import pexpect
12 import pkg_resources
13 import shutil
14 import stat
15+import StringIO
16 import subprocess
17+import tarfile
18 import tempfile
19 import time
20 from uuid import uuid4
21@@ -187,6 +190,37 @@
22 logging.error('Unable to get test definition from bzr\n' + str(e))
23
24
25+def _get_testdef_tar_repo(testdef_repo, tmpdir):
26+ """Extracts the provided encoded tar archive into tmpdir."""
27+ tardir = os.path.join(tmpdir, 'tartestrepo')
28+ temp_tar = os.path.join(tmpdir, "tar-repo.tar")
29+
30+ try:
31+ if not os.path.isdir(tardir):
32+ logging.info("Creating directory to extract the tar archive into.")
33+ os.makedirs(tardir)
34+
35+ encoded_in = StringIO.StringIO(testdef_repo)
36+ decoded_out = StringIO.StringIO()
37+ base64.decode(encoded_in, decoded_out)
38+
39+ # The following two operations can also be done in memory
40+ # using cStringIO.
41+ # At the moment the tar file sent is not big, but that can change.
42+ with open(temp_tar, "w") as write_tar:
43+ write_tar.write(decoded_out.getvalue())
44+
45+ with tarfile.open(temp_tar) as tar:
46+ tar.extractall(path=tardir)
47+ except (OSError, tarfile.TarError) as ex:
48+ logging.error("Error extracting the tar archive.\n" + str(ex))
49+ finally:
50+ # Remove the temporary created tar file after it has been extracted.
51+ if os.path.isfile(temp_tar):
52+ os.unlink(temp_tar)
53+ return tardir
54+
55+
56 def _get_testdef_info(testdef):
57 metadata = {'os': '', 'devices': '', 'environment': ''}
58 metadata['description'] = testdef['metadata'].get('description')
59@@ -255,8 +289,20 @@
60 name = testdef_repo['bzr-repo'].replace('lp:', '').split('/')[-1]
61 info = _bzr_info(testdef_repo['bzr-repo'], repo, name)
62
63+ if 'tar-repo' in testdef_repo:
64+ repo = _get_testdef_tar_repo(testdef_repo['tar-repo'], tmpdir)
65+ # Default info structure, since we need something, but we have
66+ # a tar file in this case.
67+ info = {
68+ "project_name": "Tar archived repository",
69+ "branch_vcs": "tar",
70+ "branch_revision": "0",
71+ "branch_url": repo
72+ }
73+
74 if not repo or not info:
75 logging.debug("Unable to identify specified repository. %s" % testdef_repo)
76+
77 test = testdef_repo.get('testdef', 'lavatest.yaml')
78 with open(os.path.join(repo, test), 'r') as f:
79 logging.info('loading test definition ...')
80@@ -462,13 +508,15 @@
81 'items': {'type': 'object',
82 'properties':
83 {'git-repo': {'type': 'string',
84- 'optional': True},
85- 'bzr-repo': {'type': 'string',
86- 'optional': True},
87- 'revision': {'type': 'string',
88- 'optional': True},
89- 'testdef': {'type': 'string',
90- 'optional': True}
91+ 'optional': True},
92+ 'bzr-repo': {'type': 'string',
93+ 'optional': True},
94+ 'tar-repo': {'type': 'string',
95+ 'optional': True},
96+ 'revision': {'type': 'string',
97+ 'optional': True},
98+ 'testdef': {'type': 'string',
99+ 'optional': True}
100 },
101 'additionalProperties': False},
102 'optional': True

Subscribers

People subscribed via source and target branches