Merge lp://qastaging/~pfalcon/linaro-android-build-tools/validate-build-conf into lp://qastaging/linaro-android-build-tools

Proposed by Paul Sokolovsky
Status: Merged
Merged at revision: 460
Proposed branch: lp://qastaging/~pfalcon/linaro-android-build-tools/validate-build-conf
Merge into: lp://qastaging/linaro-android-build-tools
Diff against target: 309 lines (+237/-24)
4 files modified
node/build (+26/-22)
node/lava-submit (+1/-2)
node/prepare_build_config.py (+114/-0)
tests/test_prepare_build_config.py (+96/-0)
To merge this branch: bzr merge lp://qastaging/~pfalcon/linaro-android-build-tools/validate-build-conf
Reviewer Review Type Date Requested Status
Georgy Redkozubov Approve
Paul Sokolovsky Approve
James Tunnicliffe Pending
Review via email: mp+103118@code.qastaging.launchpad.net

This proposal supersedes a proposal from 2012-04-20.

Description of the change

This implements validation for build config to accommodate restricted Android builds, per teh previous discussion via email. I initially tried to implement that using bash, but it turned out to be waste of time, as various issues to workaround kept popping up. So, instead I rewrote it in Python, which should make it more robust and maintainable.

Fixed issues pointed out by Georgy, more tests.

To post a comment you must log in.
Revision history for this message
Georgy Redkozubov (gesha) wrote : Posted in a previous version of this proposal

At least following 2 errors were found:

1) convert_config_to_shell() takes 1 argument in definition, 2 was given: config = convert_config_to_shell(config_text, get_slave_type())

   Looks like you have mixed up 2 functions, please move get_slave_type() form first to second:
    config = convert_config_to_shell(config_text, get_slave_type())
    try:
        validate_config(config)

2) global name 'cfg' is not defined
     for l in cfg.split("\n"):
   You should use config_text.split("\n") instead

review: Needs Fixing
Revision history for this message
Paul Sokolovsky (pfalcon) wrote : Posted in a previous version of this proposal

Thanks, that definitely shows that more unit tests should be added ;-)

Revision history for this message
James Tunnicliffe (dooferlad) wrote :
Download full text (11.0 KiB)

Hi,

This is a good start and while I have a few comments below, they are
all for small changes that won't take long to make and should
hopefully make maintaining the code easier. I am completely behind
changing as much of the build process into Python so thanks for doing
this!

Could you run the python through the pep8 tool
(http://www.python.org/dev/peps/pep-0008/ for what it is checking).
You certainly have some lines that are too long and I think some
non-standard spacing between classes and functions. The other tool to
help reduce the number of style nags you will get is pyflakes (sudo
apt-get install pep8 pyflakes). While I think the 80 character line
length thing is a pain and being longer would be nice, it is the
standard we code to. I will happily buy you a beer and let you
complain about it at the next Connect if you want. Took me a few rants
to get over!

You could try using PyCharm as your Python editor. It provides real
time feedback on some pep8 and pyflakes errors as well as doing nice
code browsing, auto-completion, debugging and unit test running (among
many other features). We have a license.

Other comments inline.

On 23 April 2012 15:56, Paul Sokolovsky <email address hidden> wrote:

> https://code.launchpad.net/~pfalcon/linaro-android-build-tools/validate-build-conf/+merge/103118

> === added file 'node/prepare_build_config.py'
> --- node/prepare_build_config.py        1970-01-01 00:00:00 +0000
> +++ node/prepare_build_config.py        2012-04-23 14:55:21 +0000
> @@ -0,0 +1,103 @@
> +#!/usr/bin/env python
> +import sys
> +import os
> +import base64
> +import re
> +import pipes
> +
> +
> +SLAVE_TYPE_FILE = "/var/run/build-tools/slave-type"
> +SLAVE_TYPE_RESTRICTED = "Natty Release 64bit Instance Store - private builds"
> +# sf-safe build config is written to this file
> +BUILD_CONFIG_FILE = "/var/run/build-tools/build-config"
> +
> +
> +class BuildConfigMismatchException(Exception):
> +    pass
> +
> +def shell_unquote(s):
> +    # Primitive implementation, we should

Seem to be missing the end of that comment :-)

> +    if s[0] == '"' and s[-1] == '"':
> +        return s[1:-1]
> +    if s[0] == "'" and s[-1] == "'":
> +        return s[1:-1]
> +    return s

This may work better (will cope with whitespace at the beginning and
end of the line):

unquote = re.search("^\s*["'](.*?)["']\s*$", s)

if unquote:
    return unquote s.group(1)

You could do two searches instead of using the character class or a
reference so the second quote matches the first if you wanted.

> +
> +def get_slave_type():
> +    slave_type = ""
> +    try:
> +        slave_type = open(SLAVE_TYPE_FILE).read()
> +    except:
> +        pass
> +    return slave_type

This will close the file for you and avoids the need for the try/except block:

with open(SLAVE_TYPE_FILE) as slave_type_file:
    return slave_type_file.read()

return None

> +def validate_config(config, slave_type):
> +    """Validate various constraints on the config params and overall
> +    environment."""
> +    full_job_name = os.environ.get("JOB_NAME")

os.environ is a dictionary so this will return the value of "JOB_NAME"
or None. Is it worth checking for None? The next li...

452. By Paul Sokolovsky

Import optparse

453. By Paul Sokolovsky

Typo fix

454. By Paul Sokolovsky

Make sure that /var/run/build-tools exists.

455. By Paul Sokolovsky

Handle short string properly.

456. By Paul Sokolovsky

Be sure to base64-decode initial config from jenkins.

Revision history for this message
Paul Sokolovsky (pfalcon) wrote :
Download full text (10.2 KiB)

On Mon, 23 Apr 2012 16:34:17 -0000
James Tunnicliffe <email address hidden> wrote:

> Hi,
>
> This is a good start and while I have a few comments below, they are
> all for small changes that won't take long to make and should
> hopefully make maintaining the code easier. I am completely behind
> changing as much of the build process into Python so thanks for doing
> this!
>
> Could you run the python through the pep8 tool
> (http://www.python.org/dev/peps/pep-0008/ for what it is checking).
> You certainly have some lines that are too long and I think some
> non-standard spacing between classes and functions. The other tool to
> help reduce the number of style nags you will get is pyflakes (sudo
> apt-get install pep8 pyflakes). While I think the 80 character line
> length thing is a pain and being longer would be nice, it is the
> standard we code to.

I already proposed to expand it to 132 chars, don't remember anyone
objecting.

I'll run code thru pep8.

> I will happily buy you a beer and let you
> complain about it at the next Connect if you want. Took me a few rants
> to get over!
>
> You could try using PyCharm as your Python editor. It provides real
> time feedback on some pep8 and pyflakes errors as well as doing nice
> code browsing, auto-completion, debugging and unit test running (among
> many other features). We have a license.
>
> Other comments inline.
>
> On 23 April 2012 15:56, Paul Sokolovsky <email address hidden>
> wrote:
>
> > https://code.launchpad.net/~pfalcon/linaro-android-build-tools/validate-build-conf/+merge/103118
>
> > === added file 'node/prepare_build_config.py'
> > --- node/prepare_build_config.py        1970-01-01 00:00:00 +0000
> > +++ node/prepare_build_config.py        2012-04-23 14:55:21 +0000
> > @@ -0,0 +1,103 @@
> > +#!/usr/bin/env python
> > +import sys
> > +import os
> > +import base64
> > +import re
> > +import pipes
> > +
> > +
> > +SLAVE_TYPE_FILE = "/var/run/build-tools/slave-type"
> > +SLAVE_TYPE_RESTRICTED = "Natty Release 64bit Instance Store -
> > private builds" +# sf-safe build config is written to this file
> > +BUILD_CONFIG_FILE = "/var/run/build-tools/build-config"
> > +
> > +
> > +class BuildConfigMismatchException(Exception):
> > +    pass
> > +
> > +def shell_unquote(s):
> > +    # Primitive implementation, we should
>
> Seem to be missing the end of that comment :-)

Fixed.

>
> > +    if s[0] == '"' and s[-1] == '"':
> > +        return s[1:-1]
> > +    if s[0] == "'" and s[-1] == "'":
> > +        return s[1:-1]
> > +    return s
>
> This may work better (will cope with whitespace at the beginning and
> end of the line):
>
> unquote = re.search("^\s*["'](.*?)["']\s*$", s)
>
> if unquote:
> return unquote s.group(1)
>
> You could do two searches instead of using the character class or a
> reference so the second quote matches the first if you wanted.

Thanks, that code is more easy to grasp, no need to hide the primitive
impl. behind not immediately graspable regexps.

>
> > +
> > +def get_slave_type():
> > +    slave_type = ""
> > +    try:
> > +        slave_type = open(SLAVE_TYPE_FILE).read()
> > +    except:
> > +        pass
> > +    return slave_ty...

457. By Paul Sokolovsky

Fix comment

458. By Paul Sokolovsky

Close file.

Revision history for this message
Paul Sokolovsky (pfalcon) wrote :

Both pep8 --ignore=E501 and pyflakes are ok with the code now (and only minor double-line issues were before).

review: Approve
459. By Paul Sokolovsky

PEP8 double-lining.

Revision history for this message
Paul Sokolovsky (pfalcon) wrote :
460. By Paul Sokolovsky

Wrap comments a bit/fix typos.

461. By Paul Sokolovsky

Update restricted slave name

462. By Paul Sokolovsky

Remove newline from slave type file.

463. By Paul Sokolovsky

[merge] Merge in main branch

Revision history for this message
Georgy Redkozubov (gesha) wrote :

Looks good

review: Approve
Revision history for this message
Paul Sokolovsky (pfalcon) wrote :

Thanks. Verified for both normal and restricted build (https://android-build.linaro.org/builds/~linaro-android-restricted/test-buildconf-validate/#build=3), time to deploy.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
The diff is not available at this time. You can reload the page or download it.

Subscribers

People subscribed via source and target branches