Merge lp:~salgado/linaro-image-tools/check-hwpack-format into lp:linaro-image-tools/11.11

Proposed by Guilherme Salgado
Status: Merged
Merged at revision: 166
Proposed branch: lp:~salgado/linaro-image-tools/check-hwpack-format
Merge into: lp:linaro-image-tools/11.11
Diff against target: 88 lines (+26/-2)
3 files modified
hwpack/hardwarepack.py (+7/-1)
hwpack/tests/test_hardwarepack.py (+5/-1)
linaro-hwpack-install (+14/-0)
To merge this branch: bzr merge lp:~salgado/linaro-image-tools/check-hwpack-format
Reviewer Review Type Date Requested Status
James Westby (community) Needs Fixing
Review via email: mp+37749@code.launchpad.net

Description of the change

Check that the hwpack's format is supported before trying to do anything with
it.

Fixes bug 638322

To post a comment you must log in.
Revision history for this message
James Westby (james-w) wrote :

Hi,

Looks good to me. I just wonder what

for format in $SUPPORTED_FORMATS; do

requires SUPPORTED_FORMATS to be set to when there are multiple. Does
space-separated work, or does it need to be newline-separated?

Maybe want to put a hint about trying a newer linaro-hwpack-install
script in the error message?

Thanks,

James

review: Approve
Revision history for this message
Guilherme Salgado (salgado) wrote :

On Fri, 2010-10-08 at 02:16 +0000, James Westby wrote:
> Review: Approve
> Hi,
>
> Looks good to me. I just wonder what
>
> for format in $SUPPORTED_FORMATS; do
>
> requires SUPPORTED_FORMATS to be set to when there are multiple. Does
> space-separated work, or does it need to be newline-separated?

By default it will work with space/tab/newline separated values as
that's the default value for $IFS, but now I'm wondering if it's ok to
rely on that or if we should explicitly set it to whatever we want
(space, in this case) around the for loop.

>
> Maybe want to put a hint about trying a newer linaro-hwpack-install
> script in the error message?

That sounds like a good idea; I'll do it.

135. By Guilherme Salgado

Tell users to try a newer hwpack-install script when the format is not supported

136. By Guilherme Salgado

Ensure the format version of hwpacks don't contain white spaces as that is not necessary and could break linaro-hwpack-install

Revision history for this message
Guilherme Salgado (salgado) wrote :

James, r136 has that change we discussed on IRC to make sure white space is not used in the format version of hwpacks. Please let me know if that's ok and I'll (finally) merge this

Revision history for this message
James Westby (james-w) wrote :

The version you are checking there is the version, not that format version.

However, it is a good check to have anyway :-)

I think an AssertionError at build time if the self.FORMAT contains whitespace
would be good too.

Sorry for the delay in getting back to you on this.

Thanks,

James

review: Needs Fixing
Revision history for this message
Guilherme Salgado (salgado) wrote :

You mean something like

=== modified file 'hwpack/builder.py'
--- hwpack/builder.py 2010-09-14 18:09:01 +0000
+++ hwpack/builder.py 2010-11-05 17:20:13 +0000
@@ -31,6 +31,9 @@
             metadata = Metadata.from_config(
                 self.config, self.version, architecture)
             hwpack = HardwarePack(metadata)
+ if ' ' in hwpack.FORMAT:
+ raise AssertionError(
+ 'Format version cannot have white spaces')
             sources = self.config.sources
             hwpack.add_apt_sources(sources)
             fetcher = PackageFetcher(

?

There's something about it that feels unnatural to me. Maybe it's the
fact that we're asserting on a class variable, or maybe it's because the
HardwarePack was just created and the fact that we have to assert right
after that kind of means we don't have a good contract (as we don't
really know what we'll get back).

I wouldn't feel that way if we made FORMAT a private attribute (_FORMAT)
and created a property which asserts it has no space before returning.
But that sounds like overkill to me as the FORMAT is really a constant
that should not be changed unless you really know what you're doing.

Maybe we could have just a test asserting that HardwarePack.FORMAT has
no spaces?

Revision history for this message
James Westby (james-w) wrote :

> You mean something like
>
> === modified file 'hwpack/builder.py'
> --- hwpack/builder.py 2010-09-14 18:09:01 +0000
> +++ hwpack/builder.py 2010-11-05 17:20:13 +0000
> @@ -31,6 +31,9 @@
> metadata = Metadata.from_config(
> self.config, self.version, architecture)
> hwpack = HardwarePack(metadata)
> + if ' ' in hwpack.FORMAT:
> + raise AssertionError(
> + 'Format version cannot have white spaces')
> sources = self.config.sources
> hwpack.add_apt_sources(sources)
> fetcher = PackageFetcher(
>
> ?
>
> There's something about it that feels unnatural to me. Maybe it's the
> fact that we're asserting on a class variable, or maybe it's because the
> HardwarePack was just created and the fact that we have to assert right
> after that kind of means we don't have a good contract (as we don't
> really know what we'll get back).
>
> I wouldn't feel that way if we made FORMAT a private attribute (_FORMAT)
> and created a property which asserts it has no space before returning.
> But that sounds like overkill to me as the FORMAT is really a constant
> that should not be changed unless you really know what you're doing.

Right, my concern is the separation between when you change this, and the
actual affect that is has. You can change the FORMAT, and then happily build
hwpacks and not realise the mistake until you go and try and enable that format
in hwpack-install and try and install the hwpack.

Given that you are likely to do both together, and shouldn't be pushing out
hwpacks without testing, I don't think this is that big of a deal, so I'm
happy to leave out this change.

> Maybe we could have just a test asserting that HardwarePack.FORMAT has
> no spaces?

That would work too.

Thanks,

James

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'hwpack/hardwarepack.py'
2--- hwpack/hardwarepack.py 2010-09-15 19:24:29 +0000
3+++ hwpack/hardwarepack.py 2010-10-18 12:34:41 +0000
4@@ -15,7 +15,8 @@
5
6 :ivar name: the name of the hardware pack.
7 :type name: str
8- :ivar version: the version of the hardware pack.
9+ :ivar version: the version of the hardware pack. It must not contain white
10+ spaces.
11 :type version: str
12 :ivar origin: the origin of the hardware pack, or None if the origin
13 is not known.
14@@ -35,6 +36,10 @@
15 See the instance variables for a description of the arguments.
16 """
17 self.name = name
18+ if ' ' in version:
19+ raise AssertionError(
20+ 'Hardware pack format version must not contain white '
21+ 'spaces: "%s"' % version)
22 self.version = version
23 self.origin = origin
24 self.maintainer = maintainer
25@@ -86,6 +91,7 @@
26 :type FORMAT: str
27 """
28
29+ # The format version cannot contain white spaces.
30 FORMAT = "1.0"
31 FORMAT_FILENAME = "FORMAT"
32 METADATA_FILENAME = "metadata"
33
34=== modified file 'hwpack/tests/test_hardwarepack.py'
35--- hwpack/tests/test_hardwarepack.py 2010-09-15 19:24:29 +0000
36+++ hwpack/tests/test_hardwarepack.py 2010-10-18 12:34:41 +0000
37@@ -18,6 +18,10 @@
38 metadata = Metadata("ahwpack", "3", "armel")
39 self.assertEqual("3", metadata.version)
40
41+ def test_version_with_whitespace(self):
42+ self.assertRaises(
43+ AssertionError, Metadata, "ahwpack", "3 (with extras)", "armel")
44+
45 def test_architecture(self):
46 metadata = Metadata("ahwpack", "3", "armel")
47 self.assertEqual("armel", metadata.architecture)
48@@ -93,7 +97,7 @@
49
50 def setUp(self):
51 super(HardwarePackTests, self).setUp()
52- self.metadata = Metadata("ahwpack", 4, "armel")
53+ self.metadata = Metadata("ahwpack", "4", "armel")
54
55 def test_format_is_1_0(self):
56 hwpack = HardwarePack(self.metadata)
57
58=== modified file 'linaro-hwpack-install'
59--- linaro-hwpack-install 2010-10-14 14:55:00 +0000
60+++ linaro-hwpack-install 2010-10-18 12:34:41 +0000
61@@ -28,6 +28,7 @@
62 INSTALL_LATEST="no"
63 SOURCES_LIST_FILE="${TEMP_DIR}/sources.list"
64 APT_GET_OPTIONS="Dir::Etc::SourceList=${SOURCES_LIST_FILE}"
65+SUPPORTED_FORMATS="1.0" # A space-separated list of hwpack formats.
66
67 die() {
68 echo -e "$@"
69@@ -75,6 +76,19 @@
70 tar zxf "$HWPACK_TARBALL" -C "$HWPACK_DIR"
71 echo "Done"
72
73+# Check the format of the hwpack is supported.
74+hwpack_format=$(cat ${HWPACK_DIR}/FORMAT)
75+supported="false"
76+for format in $SUPPORTED_FORMATS; do
77+ if [ $hwpack_format == $format ]; then
78+ supported="true"
79+ break
80+ fi
81+done
82+[ $supported == "true" ] || \
83+ die "Unsupported hwpack format: $hwpack_format. "\
84+ "Try using a newer version of $(basename $0)."
85+
86 # Check the architecture of the hwpack matches that of the host system.
87 HWPACK_ARCH=`grep ARCHITECTURE "${HWPACK_DIR}/metadata" | cut -d "=" -f2`
88 [ "$HWPACK_ARCH" == `dpkg --print-architecture` ] || \

Subscribers

People subscribed via source and target branches