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
=== modified file 'hwpack/hardwarepack.py'
--- hwpack/hardwarepack.py 2010-09-15 19:24:29 +0000
+++ hwpack/hardwarepack.py 2010-10-18 12:34:41 +0000
@@ -15,7 +15,8 @@
1515
16 :ivar name: the name of the hardware pack.16 :ivar name: the name of the hardware pack.
17 :type name: str17 :type name: str
18 :ivar version: the version of the hardware pack.18 :ivar version: the version of the hardware pack. It must not contain white
19 spaces.
19 :type version: str20 :type version: str
20 :ivar origin: the origin of the hardware pack, or None if the origin21 :ivar origin: the origin of the hardware pack, or None if the origin
21 is not known.22 is not known.
@@ -35,6 +36,10 @@
35 See the instance variables for a description of the arguments.36 See the instance variables for a description of the arguments.
36 """37 """
37 self.name = name38 self.name = name
39 if ' ' in version:
40 raise AssertionError(
41 'Hardware pack format version must not contain white '
42 'spaces: "%s"' % version)
38 self.version = version43 self.version = version
39 self.origin = origin44 self.origin = origin
40 self.maintainer = maintainer45 self.maintainer = maintainer
@@ -86,6 +91,7 @@
86 :type FORMAT: str91 :type FORMAT: str
87 """92 """
8893
94 # The format version cannot contain white spaces.
89 FORMAT = "1.0"95 FORMAT = "1.0"
90 FORMAT_FILENAME = "FORMAT"96 FORMAT_FILENAME = "FORMAT"
91 METADATA_FILENAME = "metadata"97 METADATA_FILENAME = "metadata"
9298
=== modified file 'hwpack/tests/test_hardwarepack.py'
--- hwpack/tests/test_hardwarepack.py 2010-09-15 19:24:29 +0000
+++ hwpack/tests/test_hardwarepack.py 2010-10-18 12:34:41 +0000
@@ -18,6 +18,10 @@
18 metadata = Metadata("ahwpack", "3", "armel")18 metadata = Metadata("ahwpack", "3", "armel")
19 self.assertEqual("3", metadata.version)19 self.assertEqual("3", metadata.version)
2020
21 def test_version_with_whitespace(self):
22 self.assertRaises(
23 AssertionError, Metadata, "ahwpack", "3 (with extras)", "armel")
24
21 def test_architecture(self):25 def test_architecture(self):
22 metadata = Metadata("ahwpack", "3", "armel")26 metadata = Metadata("ahwpack", "3", "armel")
23 self.assertEqual("armel", metadata.architecture)27 self.assertEqual("armel", metadata.architecture)
@@ -93,7 +97,7 @@
9397
94 def setUp(self):98 def setUp(self):
95 super(HardwarePackTests, self).setUp()99 super(HardwarePackTests, self).setUp()
96 self.metadata = Metadata("ahwpack", 4, "armel")100 self.metadata = Metadata("ahwpack", "4", "armel")
97101
98 def test_format_is_1_0(self):102 def test_format_is_1_0(self):
99 hwpack = HardwarePack(self.metadata)103 hwpack = HardwarePack(self.metadata)
100104
=== modified file 'linaro-hwpack-install'
--- linaro-hwpack-install 2010-10-14 14:55:00 +0000
+++ linaro-hwpack-install 2010-10-18 12:34:41 +0000
@@ -28,6 +28,7 @@
28INSTALL_LATEST="no"28INSTALL_LATEST="no"
29SOURCES_LIST_FILE="${TEMP_DIR}/sources.list"29SOURCES_LIST_FILE="${TEMP_DIR}/sources.list"
30APT_GET_OPTIONS="Dir::Etc::SourceList=${SOURCES_LIST_FILE}"30APT_GET_OPTIONS="Dir::Etc::SourceList=${SOURCES_LIST_FILE}"
31SUPPORTED_FORMATS="1.0" # A space-separated list of hwpack formats.
3132
32die() {33die() {
33 echo -e "$@"34 echo -e "$@"
@@ -75,6 +76,19 @@
75tar zxf "$HWPACK_TARBALL" -C "$HWPACK_DIR"76tar zxf "$HWPACK_TARBALL" -C "$HWPACK_DIR"
76echo "Done"77echo "Done"
7778
79# Check the format of the hwpack is supported.
80hwpack_format=$(cat ${HWPACK_DIR}/FORMAT)
81supported="false"
82for format in $SUPPORTED_FORMATS; do
83 if [ $hwpack_format == $format ]; then
84 supported="true"
85 break
86 fi
87done
88[ $supported == "true" ] || \
89 die "Unsupported hwpack format: $hwpack_format. "\
90 "Try using a newer version of $(basename $0)."
91
78# Check the architecture of the hwpack matches that of the host system.92# Check the architecture of the hwpack matches that of the host system.
79HWPACK_ARCH=`grep ARCHITECTURE "${HWPACK_DIR}/metadata" | cut -d "=" -f2`93HWPACK_ARCH=`grep ARCHITECTURE "${HWPACK_DIR}/metadata" | cut -d "=" -f2`
80[ "$HWPACK_ARCH" == `dpkg --print-architecture` ] || \94[ "$HWPACK_ARCH" == `dpkg --print-architecture` ] || \

Subscribers

People subscribed via source and target branches