Skip to contentSkip to conversation

pygrub: Fix regression from c/s d1b93ea, attempt 2

RFC PATCH In review Andrew Cooper 4 participants 15 messages Nov 17, 2014 – Nov 25, 2014

lore
Share & tools
lore
#0 lore raw

RFC PATCH 1/1 pygrub: Fix regression from c/s d1b93ea, attempt 2

c/s d1b93ea causes substantial functional regressions in pygrub's ability to parse bootloader configuration files.

c/s d1b93ea itself changed an an interface which previously used exclusively integers, to using strings in the case of a grub configuration with explicit default set, along with changing the code calling the interface to require a string. The default value for "default" remained as an integer.

As a result, any Extlinux or Lilo configuration (which drives this interface exclusively with integers), or Grub configuration which doesn't explicitly declare a default will die with an AttributeError when attempting to call "self.cf.default.isdigit()" where "default" is an integer.

Sadly, this AttributeError gets swallowed by the blanket ignore in the loop which searches partitions for valid bootloader configurations, causing the issue to be reported as "Unable to find partition containing kernel"

This patch attempts to fix the issue by altering all parts of this interface to use strings, as opposed to integers.

CC Ian Campbell <[email protected]>
CC Ian Jackson <[email protected]>
CC Wei Liu <[email protected]>
CC Konrad Rzeszutek Wilk <[email protected]>
CC Boris Ostrovsky <[email protected]>

---

This patch is RFC because, while I have dev tested and proved that it unwedges the specific senario I encountered, I have not yet tested that it contines to boot all other PV guests.

As for 4.5-ness, this is a must-fix as far as I am concerned

Either:
1) Revert d1b93ea (original bad changeset) and 4ee393f (attempt 1 to fix)
2) Take this patch in addition which hopefully fixes the regressions

---
 tools/pygrub/src/ExtLinuxConf.py |    6 +++---
 tools/pygrub/src/GrubConf.py     |    7 ++-----
 tools/pygrub/src/LiloConf.py     |    6 +++---
 3 files changed, 8 insertions(+), 11 deletions(-)
tools/pygrub/src/ExtLinuxConf.py +3 -3
index 510099b..e70fca6 100644
@@ -123,7 +123,7 @@ class ExtLinuxConfigFile(object):
         self.filename = fn
         self.images = []
         self.timeout = -1
-        self._default = 0
+        self._default = "0"
 
         if fn is not None:
             self.parse()
@@ -191,8 +191,8 @@ class ExtLinuxConfigFile(object):
     def _get_default(self):
         for i in range(len(self.images)):
             if self.images[i].title == self._default:
-                return i
-        return 0
+                return str(i)
+        return "0"
     def _set_default(self, val):
         self._default = val
     default = property(_get_default, _set_default)
tools/pygrub/src/GrubConf.py +2 -5
index dea7044..645b6e2 100644
@@ -170,7 +170,7 @@ class _GrubConfigFile(object):
         self.filename = fn
         self.images = []
         self.timeout = -1
-        self._default = 0
+        self._default = "0"
         self.passwordAccess = True
         self.passExc = None
 
@@ -229,12 +229,9 @@ class _GrubConfigFile(object):
         return self._default
     def _set_default(self, val):
         if val == "saved":
-            self._default = 0
+            self._default = "0"
         else:
             self._default = val
-
-        if self._default < 0:
-            raise ValueError, "default must be positive number"
     default = property(_get_default, _set_default)
 
     def set_splash(self, val):
tools/pygrub/src/LiloConf.py +3 -3
index 2cb649f..53411e6 100644
@@ -89,7 +89,7 @@ class LiloConfigFile(object):
         self.filename = fn
         self.images = []
         self.timeout = -1
-        self._default = 0
+        self._default = "0"
 
         if fn is not None:
             self.parse()
@@ -156,8 +156,8 @@ class LiloConfigFile(object):
     def _get_default(self):
         for i in range(len(self.images)):
             if self.images[i].title == self._default:
-                return i
-        return 0
+                return str(i)
+        return "0"
     def _set_default(self, val):
         self._default = val
     default = property(_get_default, _set_default)
Signature · 1 line
1.7.10.4
#1 lore raw
Quoted 82 lines · Andrew Cooper

c/s d1b93ea causes substantial functional regressions in pygrub's ability to parse bootloader configuration files.

c/s d1b93ea itself changed an an interface which previously used exclusively integers, to using strings in the case of a grub configuration with explicit default set, along with changing the code calling the interface to require a string. The default value for "default" remained as an integer.

As a result, any Extlinux or Lilo configuration (which drives this interface exclusively with integers), or Grub configuration which doesn't explicitly declare a default will die with an AttributeError when attempting to call "self.cf.default.isdigit()" where "default" is an integer.

Sadly, this AttributeError gets swallowed by the blanket ignore in the loop which searches partitions for valid bootloader configurations, causing the issue to be reported as "Unable to find partition containing kernel"

This patch attempts to fix the issue by altering all parts of this interface to use strings, as opposed to integers.

CC Ian Campbell <[email protected]>
CC Ian Jackson <[email protected]>
CC Wei Liu <[email protected]>
CC Konrad Rzeszutek Wilk <[email protected]>
CC Boris Ostrovsky <[email protected]>

---

This patch is RFC because, while I have dev tested and proved that it unwedges the specific senario I encountered, I have not yet tested that it contines to boot all other PV guests.

As for 4.5-ness, this is a must-fix as far as I am concerned

Either:
1) Revert d1b93ea (original bad changeset) and 4ee393f (attempt 1 to fix)
2) Take this patch in addition which hopefully fixes the regressions

---
  tools/pygrub/src/ExtLinuxConf.py |    6 +++---
  tools/pygrub/src/GrubConf.py     |    7 ++-----
  tools/pygrub/src/LiloConf.py     |    6 +++---
  3 files changed, 8 insertions(+), 11 deletions(-)
tools/pygrub/src/ExtLinuxConf.py +3 -3
index 510099b..e70fca6 100644
@@ -123,7 +123,7 @@ class ExtLinuxConfigFile(object):
          self.filename = fn
          self.images = []
          self.timeout = -1
-        self._default = 0
+        self._default = "0"
 
          if fn is not None:
              self.parse()
@@ -191,8 +191,8 @@ class ExtLinuxConfigFile(object):
      def _get_default(self):
          for i in range(len(self.images)):
              if self.images[i].title == self._default:
-                return i
-        return 0
+                return str(i)
+        return "0"
      def _set_default(self, val):
          self._default = val
      default = property(_get_default, _set_default)
tools/pygrub/src/GrubConf.py +1 -1
index dea7044..645b6e2 100644
@@ -170,7 +170,7 @@ class _GrubConfigFile(object):
          self.filename = fn
          self.images = []
          self.timeout = -1
-        self._default = 0
+        self._default = "0"
          self.passwordAccess = True
          self.passExc = None
 

tools/pygrub/src/GrubConf.py class _GrubConfigFile(object): · line 234

Quoted 7 lines
tools/pygrub/src/GrubConf.py +1 -1
@@ -229,12 +229,9 @@ class _GrubConfigFile(object):
          return self._default
      def _set_default(self, val):
          if val == "saved":
-            self._default = 0
+            self._default = "0"
          else:
              self._default = val

If we are using strings-only value, should this also be str(val)? Here and elsewhere. (My python skills are highly questionable so I don't know whether this would be needed).

Other than that, I tested this with a few grub2 configurations and it worked fine.

-boris

Quoted 30 lines
tools/pygrub/src/GrubConf.py +0 -3
-
-        if self._default < 0:
-            raise ValueError, "default must be positive number"
      default = property(_get_default, _set_default)
 
      def set_splash(self, val):
tools/pygrub/src/LiloConf.py +3 -3
index 2cb649f..53411e6 100644
@@ -89,7 +89,7 @@ class LiloConfigFile(object):
          self.filename = fn
          self.images = []
          self.timeout = -1
-        self._default = 0
+        self._default = "0"
 
          if fn is not None:
              self.parse()
@@ -156,8 +156,8 @@ class LiloConfigFile(object):
      def _get_default(self):
          for i in range(len(self.images)):
              if self.images[i].title == self._default:
-                return i
-        return 0
+                return str(i)
+        return "0"
      def _set_default(self, val):
          self._default = val
      default = property(_get_default, _set_default)
#2 lore raw
Quoted 107 lines · Boris Ostrovsky
Quoted 97 lines · Andrew Cooper

c/s d1b93ea causes substantial functional regressions in pygrub's ability to
parse bootloader configuration files.

c/s d1b93ea itself changed an an interface which previously used exclusively
integers, to using strings in the case of a grub configuration with explicit
default set, along with changing the code calling the interface to require a
string. The default value for "default" remained as an integer.

As a result, any Extlinux or Lilo configuration (which drives this interface
exclusively with integers), or Grub configuration which doesn't explicitly
declare a default will die with an AttributeError when attempting to call
"self.cf.default.isdigit()" where "default" is an integer.

Sadly, this AttributeError gets swallowed by the blanket ignore in the loop
which searches partitions for valid bootloader configurations, causing the
issue to be reported as "Unable to find partition containing kernel"

This patch attempts to fix the issue by altering all parts of this interface
to use strings, as opposed to integers.

CC Ian Campbell <[email protected]>
CC Ian Jackson <[email protected]>
CC Wei Liu <[email protected]>
CC Konrad Rzeszutek Wilk <[email protected]>
CC Boris Ostrovsky <[email protected]>

---

This patch is RFC because, while I have dev tested and proved that it unwedges
the specific senario I encountered, I have not yet tested that it contines to
boot all other PV guests.

As for 4.5-ness, this is a must-fix as far as I am concerned

Either:
1) Revert d1b93ea (original bad changeset) and 4ee393f (attempt 1
to fix)
2) Take this patch in addition which hopefully fixes the regressions

---
  tools/pygrub/src/ExtLinuxConf.py |    6 +++---
  tools/pygrub/src/GrubConf.py     |    7 ++-----
  tools/pygrub/src/LiloConf.py     |    6 +++---
  3 files changed, 8 insertions(+), 11 deletions(-)
tools/pygrub/src/ExtLinuxConf.py +3 -3
index 510099b..e70fca6 100644
@@ -123,7 +123,7 @@ class ExtLinuxConfigFile(object):
          self.filename = fn
          self.images = []
          self.timeout = -1
-        self._default = 0
+        self._default = "0"
            if fn is not None:
              self.parse()
@@ -191,8 +191,8 @@ class ExtLinuxConfigFile(object):
      def _get_default(self):
          for i in range(len(self.images)):
              if self.images[i].title == self._default:
-                return i
-        return 0
+                return str(i)
+        return "0"
      def _set_default(self, val):
          self._default = val
      default = property(_get_default, _set_default)
tools/pygrub/src/GrubConf.py +1 -1
index dea7044..645b6e2 100644
@@ -170,7 +170,7 @@ class _GrubConfigFile(object):
          self.filename = fn
          self.images = []
          self.timeout = -1
-        self._default = 0
+        self._default = "0"
          self.passwordAccess = True
          self.passExc = None
  @@ -229,12 +229,9 @@ class _GrubConfigFile(object):

return self._default
def _set_default(self, val):
if val == "saved":

tools/pygrub/src/GrubConf.py class _GrubConfigFile(object): · line 234

Quoted 4 lines
tools/pygrub/src/GrubConf.py +1 -1
-            self._default = 0
+            self._default = "0"
          else:
              self._default = val

If we are using strings-only value, should this also be str(val)? Here and elsewhere. (My python skills are highly questionable so I don't know whether this would be needed).

Quoted 2 lines

Other than that, I tested this with a few grub2 configurations and it worked fine.

I believe not, as _set_default() is unconditionally called with val as a string, in all config parsers.

Observe that you switched int(val) -> val in your original change.

~Andrew

#3 lore raw
In reply to Andrew Cooper
Quoted 2 lines · Andrew Cooper

c/s d1b93ea causes substantial functional regressions in pygrub's ability to parse bootloader configuration files.

Please can you and Boris both provide examples of (ideally real-world) configuration files which exhibit these failures as patches against tools/pygrub/examples/.

Boris, in your case I mean the one which caused you to write the original patch, which I should have remembered to ask for at the time.

Andy, in your case it would make sense to include at least one in this patch I think.

Ian.

#4 lore raw
Quoted 7 lines · Ian Campbell
Quoted 2 lines · Andrew Cooper

c/s d1b93ea causes substantial functional regressions in pygrub's ability to parse bootloader configuration files.

Please can you and Boris both provide examples of (ideally real-world) configuration files which exhibit these failures as patches against tools/pygrub/examples/.

Quoted 8 lines

Boris, in your case I mean the one which caused you to write the original patch, which I should have remembered to ask for at the time.

Andy, in your case it would make sense to include at least one in this patch I think.

Ian.

examples/ doesn't help. The parsers themselves don't exhibit the bug. It is only when pygrub itself attempts to interact with the parsed config does the issue exhibits itself.

I would have provided an example if it would have helped.

~Andrew

#5 lore raw
Quoted 10 lines · Andrew Cooper
Quoted 9 lines · Ian Campbell
Quoted 2 lines · Andrew Cooper

c/s d1b93ea causes substantial functional regressions in pygrub's ability to parse bootloader configuration files.

Please can you and Boris both provide examples of (ideally real-world) configuration files which exhibit these failures as patches against tools/pygrub/examples/.

Boris, in your case I mean the one which caused you to write the original patch, which I should have remembered to ask for at the time.

I wanted to be able to parse grub2's default values set as strings, such as

set default="Fedora, with Xen xen and Linux 3.17.0-rc3"

or, for submenus

set default="Advanced options for Fedora (with Xen
hypervisor)>Fedora, with Xen xen and Linux 3.17.0-rc3"

Original pygrub would not be able to understand the string and default to zero.

-boris

Quoted 13 lines
Quoted 6 lines

Andy, in your case it would make sense to include at least one in this patch I think.

Ian.

examples/ doesn't help. The parsers themselves don't exhibit the bug. It is only when pygrub itself attempts to interact with the parsed config does the issue exhibits itself.

I would have provided an example if it would have helped.

~Andrew

#6 lore raw
In reply to Andrew Cooper
Quoted 13 lines · Andrew Cooper

c/s d1b93ea causes substantial functional regressions in pygrub's ability to parse bootloader configuration files.

c/s d1b93ea itself changed an an interface which previously used exclusively integers, to using strings in the case of a grub configuration with explicit default set, along with changing the code calling the interface to require a string. The default value for "default" remained as an integer.

As a result, any Extlinux or Lilo configuration (which drives this interface exclusively with integers), or Grub configuration which doesn't explicitly declare a default will die with an AttributeError when attempting to call "self.cf.default.isdigit()" where "default" is an integer.

Quoted 6 lines

Sadly, this AttributeError gets swallowed by the blanket ignore in the loop which searches partitions for valid bootloader configurations, causing the issue to be reported as "Unable to find partition containing kernel"

This patch attempts to fix the issue by altering all parts of this interface to use strings, as opposed to integers.

Would it be less invasive at this point in the release to have the place where this stuff is used do isinstance(s, str) and isinstance(s, int)?

Also, in run_grub sel can be set to g.cf.default and then:

    if sel == -1:
        print "No kernel image selected!"
        sys.exit(1)

I can't see where the -1 comes from though, and you aren't changing any -1 into "-1", so maybe something more subtle is going on there.

Ian.

#7 lore raw
Quoted 14 lines · Ian Campbell
Quoted 13 lines · Andrew Cooper

c/s d1b93ea causes substantial functional regressions in pygrub's ability to parse bootloader configuration files.

c/s d1b93ea itself changed an an interface which previously used exclusively integers, to using strings in the case of a grub configuration with explicit default set, along with changing the code calling the interface to require a string. The default value for "default" remained as an integer.

As a result, any Extlinux or Lilo configuration (which drives this interface exclusively with integers), or Grub configuration which doesn't explicitly declare a default will die with an AttributeError when attempting to call "self.cf.default.isdigit()" where "default" is an integer.

Quoted 8 lines
Quoted 6 lines

Sadly, this AttributeError gets swallowed by the blanket ignore in the loop which searches partitions for valid bootloader configurations, causing the issue to be reported as "Unable to find partition containing kernel"

This patch attempts to fix the issue by altering all parts of this interface to use strings, as opposed to integers.

Would it be less invasive at this point in the release to have the place where this stuff is used do isinstance(s, str) and isinstance(s, int)?

It would be BaseString not str, but I am fairly sure the classes have altered through Py2's history. I would not be any more confident with that as a solution as trying to correctly to start with.

By far the least risky option at this point would be to revert the two identified commits in the comments of the original patch.

Quoted 12 lines

Also, in run_grub sel can be set to g.cf.default and then:

    if sel == -1:
        print "No kernel image selected!"
        sys.exit(1)

I can't see where the -1 comes from though, and you aren't changing any -1 into "-1", so maybe something more subtle is going on there.

Ian.

sel comes either from g.image_index() which strictly is an integer, or pulled out of the loop immediately preceding and strictly an integer.

I can't however find anything which could cause it to have the value -1. All error paths I can spot use 0 instead and load the first entry.

~Andrew

#8 lore raw
Quoted 19 lines · Andrew Cooper
Quoted 18 lines · Ian Campbell
Quoted 17 lines · Andrew Cooper

c/s d1b93ea causes substantial functional regressions in pygrub's ability to parse bootloader configuration files.

c/s d1b93ea itself changed an an interface which previously used exclusively integers, to using strings in the case of a grub configuration with explicit default set, along with changing the code calling the interface to require a string. The default value for "default" remained as an integer.

As a result, any Extlinux or Lilo configuration (which drives this interface exclusively with integers), or Grub configuration which doesn't explicitly declare a default will die with an AttributeError when attempting to call "self.cf.default.isdigit()" where "default" is an integer.

Sadly, this AttributeError gets swallowed by the blanket ignore in the loop which searches partitions for valid bootloader configurations, causing the issue to be reported as "Unable to find partition containing kernel"

Quoted 8 lines
Quoted 4 lines
Quoted 2 lines

This patch attempts to fix the issue by altering all parts of this interface to use strings, as opposed to integers.

Would it be less invasive at this point in the release to have the place where this stuff is used do isinstance(s, str) and isinstance(s, int)?

It would be BaseString not str, but I am fairly sure the classes have altered through Py2's history. I would not be any more confident with that as a solution as trying to correctly to start with.

Actually isinstance(s, basestring) is what the webpage I was looking at said, but I cut-n-pasted the wrong thing.

But regardless could it not do something like:
if !isinstance(foo.cf.default, int):
blah = int(foo.cf.default)
elif foo.cf.default.isdigit():
blah = whatever

and avoid the confusion about what is/isn't a string class while still fixing the issue?

Quoted 2 lines

sel comes either from g.image_index() which strictly is an integer, or pulled out of the loop immediately preceding and strictly an integer.

Ah, good.

Quoted 5 lines

I can't however find anything which could cause it to have the value -1. All error paths I can spot use 0 instead and load the first entry.

~Andrew

#9 lore raw
Quoted 24 lines · Ian Campbell
Quoted 23 lines · Andrew Cooper
Quoted 22 lines · Ian Campbell
Quoted 13 lines · Andrew Cooper

c/s d1b93ea causes substantial functional regressions in pygrub's ability to parse bootloader configuration files.

c/s d1b93ea itself changed an an interface which previously used exclusively integers, to using strings in the case of a grub configuration with explicit default set, along with changing the code calling the interface to require a string. The default value for "default" remained as an integer.

As a result, any Extlinux or Lilo configuration (which drives this interface exclusively with integers), or Grub configuration which doesn't explicitly declare a default will die with an AttributeError when attempting to call "self.cf.default.isdigit()" where "default" is an integer.

Quoted 6 lines

Sadly, this AttributeError gets swallowed by the blanket ignore in the loop which searches partitions for valid bootloader configurations, causing the issue to be reported as "Unable to find partition containing kernel"

This patch attempts to fix the issue by altering all parts of this interface to use strings, as opposed to integers.

Would it be less invasive at this point in the release to have the place where this stuff is used do isinstance(s, str) and isinstance(s, int)?

Quoted 8 lines
Quoted 3 lines

It would be BaseString not str, but I am fairly sure the classes have altered through Py2's history. I would not be any more confident with that as a solution as trying to correctly to start with.

Actually isinstance(s, basestring) is what the webpage I was looking at said, but I cut-n-pasted the wrong thing.

But regardless could it not do something like:
if !isinstance(foo.cf.default, int):

I think it would be the other way around, e.g. (not tested):

tools/pygrub/src/pygrub +3 -1
index aa7e562..7250f45 100644
@@ -457,7 +457,9 @@ class Grub:
         self.cf.parse(buf)
 
     def image_index(self):
-        if self.cf.default.isdigit():
+        if isinstance(self.cf.default, int)
+            sel = self.cf.default
+        elif if self.cf.default.isdigit():
             sel = int(self.cf.default)
         else:
             # We don't fully support submenus. Look for the leaf value in

but yes, this looks less intrusive (assuming this the only place where we'd hit this error).

-boris

Quoted 17 lines

blah = int(foo.cf.default)
elif foo.cf.default.isdigit():
blah = whatever

and avoid the confusion about what is/isn't a string class while still fixing the issue?

Quoted 2 lines

sel comes either from g.image_index() which strictly is an integer, or pulled out of the loop immediately preceding and strictly an integer.

Ah, good.

Quoted 5 lines

I can't however find anything which could cause it to have the value -1. All error paths I can spot use 0 instead and load the first entry.

~Andrew

#10 lore raw
Quoted 64 lines · Boris Ostrovsky
Quoted 35 lines · Ian Campbell
Quoted 34 lines · Andrew Cooper
Quoted 33 lines · Ian Campbell
Quoted 26 lines · Andrew Cooper

c/s d1b93ea causes substantial functional regressions in pygrub's ability to
parse bootloader configuration files.

c/s d1b93ea itself changed an an interface which previously used exclusively
integers, to using strings in the case of a grub configuration with explicit
default set, along with changing the code calling the interface to require a
string. The default value for "default" remained as an integer.

As a result, any Extlinux or Lilo configuration (which drives this interface
exclusively with integers), or Grub configuration which doesn't explicitly
declare a default will die with an AttributeError when attempting to call
"self.cf.default.isdigit()" where "default" is an integer.

Sadly, this AttributeError gets swallowed by the blanket ignore in the loop
which searches partitions for valid bootloader configurations, causing the
issue to be reported as "Unable to find partition containing kernel"

Quoted 3 lines

This patch attempts to fix the issue by altering all parts of this interface
to use strings, as opposed to integers.

Would it be less invasive at this point in the release to have the place
where this stuff is used do isinstance(s, str) and isinstance(s, int)?

Quoted 8 lines
Quoted 3 lines

It would be BaseString not str, but I am fairly sure the classes have altered through Py2's history. I would not be any more confident with that as a solution as trying to correctly to start with.

Actually isinstance(s, basestring) is what the webpage I was looking at said, but I cut-n-pasted the wrong thing.

But regardless could it not do something like:
if !isinstance(foo.cf.default, int):

I think it would be the other way around, e.g. (not tested):

tools/pygrub/src/pygrub +3 -1
index aa7e562..7250f45 100644
@@ -457,7 +457,9 @@ class Grub:
         self.cf.parse(buf)
 
     def image_index(self):
-        if self.cf.default.isdigit():
+        if isinstance(self.cf.default, int)
+            sel = self.cf.default
+        elif if self.cf.default.isdigit():
             sel = int(self.cf.default)
         else:
             # We don't fully support submenus. Look for the leaf

value in

Quoted 3 lines

but yes, this looks less intrusive (assuming this the only place where we'd hit this error).

That does look plausibly like it would fix the issue.

However, I can't help but feeing that this is hacking around a broken patch in the first place.

~Andrew

#11 lore raw
Quoted 65 lines · Andrew Cooper
Quoted 64 lines · Boris Ostrovsky
Quoted 35 lines · Ian Campbell
Quoted 34 lines · Andrew Cooper
Quoted 33 lines · Ian Campbell
Quoted 26 lines · Andrew Cooper

c/s d1b93ea causes substantial functional regressions in pygrub's ability to
parse bootloader configuration files.

c/s d1b93ea itself changed an an interface which previously used exclusively
integers, to using strings in the case of a grub configuration with explicit
default set, along with changing the code calling the interface to require a
string. The default value for "default" remained as an integer.

As a result, any Extlinux or Lilo configuration (which drives this interface
exclusively with integers), or Grub configuration which doesn't explicitly
declare a default will die with an AttributeError when attempting to call
"self.cf.default.isdigit()" where "default" is an integer.

Sadly, this AttributeError gets swallowed by the blanket ignore in the loop
which searches partitions for valid bootloader configurations, causing the
issue to be reported as "Unable to find partition containing kernel"

Quoted 3 lines

This patch attempts to fix the issue by altering all parts of this interface
to use strings, as opposed to integers.

Would it be less invasive at this point in the release to have the place
where this stuff is used do isinstance(s, str) and isinstance(s, int)?

Quoted 8 lines
Quoted 3 lines

It would be BaseString not str, but I am fairly sure the classes have altered through Py2's history. I would not be any more confident with that as a solution as trying to correctly to start with.

Actually isinstance(s, basestring) is what the webpage I was looking at said, but I cut-n-pasted the wrong thing.

But regardless could it not do something like:
if !isinstance(foo.cf.default, int):

I think it would be the other way around, e.g. (not tested):

tools/pygrub/src/pygrub +3 -1
index aa7e562..7250f45 100644
@@ -457,7 +457,9 @@ class Grub:
         self.cf.parse(buf)
 
     def image_index(self):
-        if self.cf.default.isdigit():
+        if isinstance(self.cf.default, int)
+            sel = self.cf.default
+        elif if self.cf.default.isdigit():
             sel = int(self.cf.default)
         else:
             # We don't fully support submenus. Look for the leaf

value in

Quoted 8 lines
Quoted 3 lines

but yes, this looks less intrusive (assuming this the only place where we'd hit this error).

That does look plausibly like it would fix the issue.

However, I can't help but feeing that this is hacking around a broken patch in the first place.

I cannot think of a reason you would ever feel that way! <surreptitiously checks the roll of Xen 4.5 band-aid>

We know that the existing patches work fine for a host of Fedora families (15->21) (thought I need to double check that the testing framework that we have is using pygrub and not pvgrub), SLESs and RHEL5s, and OL6s.

The ones that I am worried about are the ExtLinux and such which I didn't realize would use 'pygrub'.

Thought I just remembered a bug with OL7 grub entries - that is if you go in the interactive menu things broke down. Boris, do you remember if that was fixed or just 'deferred'?

Quoted 2 lines

~Andrew

#12 lore raw
Quoted 12 lines · Konrad Rzeszutek Wilk
Quoted 4 lines · Andrew Cooper

That does look plausibly like it would fix the issue.

However, I can't help but feeing that this is hacking around a broken patch in the first place.

I cannot think of a reason you would ever feel that way! <surreptitiously checks the roll of Xen 4.5 band-aid>

We know that the existing patches work fine for a host of Fedora families (15->21) (thought I need to double check that the testing framework that we have is using pygrub and not pvgrub), SLESs and RHEL5s, and OL6s.

Quoted 6 lines

The ones that I am worried about are the ExtLinux and such which I didn't realize would use 'pygrub'.

Thought I just remembered a bug with OL7 grub entries - that is if you go in the interactive menu things broke down. Boris, do you remember if that was fixed or just 'deferred'?

The only bug that I remember that had to do pygrub and OL7 was the fact that pygrub cannot parse grubenv (and therefore it's not really OL7-specific).

We decided not to fix it.

-boris

#13 lore raw
In reply to Andrew Cooper
Quoted 65 lines · Andrew Cooper
Quoted 64 lines · Boris Ostrovsky
Quoted 35 lines · Ian Campbell
Quoted 34 lines · Andrew Cooper
Quoted 33 lines · Ian Campbell
Quoted 26 lines · Andrew Cooper

c/s d1b93ea causes substantial functional regressions in pygrub's ability to
parse bootloader configuration files.

c/s d1b93ea itself changed an an interface which previously used exclusively
integers, to using strings in the case of a grub configuration with explicit
default set, along with changing the code calling the interface to require a
string. The default value for "default" remained as an integer.

As a result, any Extlinux or Lilo configuration (which drives this interface
exclusively with integers), or Grub configuration which doesn't explicitly
declare a default will die with an AttributeError when attempting to call
"self.cf.default.isdigit()" where "default" is an integer.

Sadly, this AttributeError gets swallowed by the blanket ignore in the loop
which searches partitions for valid bootloader configurations, causing the
issue to be reported as "Unable to find partition containing kernel"

Quoted 3 lines

This patch attempts to fix the issue by altering all parts of this interface
to use strings, as opposed to integers.

Would it be less invasive at this point in the release to have the place
where this stuff is used do isinstance(s, str) and isinstance(s, int)?

Quoted 8 lines
Quoted 3 lines

It would be BaseString not str, but I am fairly sure the classes have altered through Py2's history. I would not be any more confident with that as a solution as trying to correctly to start with.

Actually isinstance(s, basestring) is what the webpage I was looking at said, but I cut-n-pasted the wrong thing.

But regardless could it not do something like:
if !isinstance(foo.cf.default, int):

I think it would be the other way around, e.g. (not tested):

tools/pygrub/src/pygrub +3 -1
index aa7e562..7250f45 100644
@@ -457,7 +457,9 @@ class Grub:
         self.cf.parse(buf)
 
     def image_index(self):
-        if self.cf.default.isdigit():
+        if isinstance(self.cf.default, int)
+            sel = self.cf.default
+        elif if self.cf.default.isdigit():
             sel = int(self.cf.default)
         else:
             # We don't fully support submenus. Look for the leaf

value in

Quoted 5 lines
Quoted 3 lines

but yes, this looks less intrusive (assuming this the only place where we'd hit this error).

That does look plausibly like it would fix the issue.

Is someone going to resubmit a patch along these lines then?

Ian

#14 lore raw
Quoted 65 lines · Ian Campbell
Quoted 64 lines · Andrew Cooper
Quoted 63 lines · Boris Ostrovsky
Quoted 35 lines · Ian Campbell
Quoted 34 lines · Andrew Cooper
Quoted 33 lines · Ian Campbell
Quoted 26 lines · Andrew Cooper

c/s d1b93ea causes substantial functional regressions in pygrub's ability to
parse bootloader configuration files.

c/s d1b93ea itself changed an an interface which previously used exclusively
integers, to using strings in the case of a grub configuration with explicit
default set, along with changing the code calling the interface to require a
string. The default value for "default" remained as an integer.

As a result, any Extlinux or Lilo configuration (which drives this interface
exclusively with integers), or Grub configuration which doesn't explicitly
declare a default will die with an AttributeError when attempting to call
"self.cf.default.isdigit()" where "default" is an integer.

Sadly, this AttributeError gets swallowed by the blanket ignore in the loop
which searches partitions for valid bootloader configurations, causing the
issue to be reported as "Unable to find partition containing kernel"

Quoted 3 lines

This patch attempts to fix the issue by altering all parts of this interface
to use strings, as opposed to integers.

Would it be less invasive at this point in the release to have the place
where this stuff is used do isinstance(s, str) and isinstance(s, int)?

Quoted 8 lines
Quoted 3 lines

It would be BaseString not str, but I am fairly sure the classes have altered through Py2's history. I would not be any more confident with that as a solution as trying to correctly to start with.

Actually isinstance(s, basestring) is what the webpage I was looking at said, but I cut-n-pasted the wrong thing.

But regardless could it not do something like:
if !isinstance(foo.cf.default, int):

I think it would be the other way around, e.g. (not tested):

tools/pygrub/src/pygrub +3 -1
index aa7e562..7250f45 100644
@@ -457,7 +457,9 @@ class Grub:
         self.cf.parse(buf)
 
     def image_index(self):
-        if self.cf.default.isdigit():
+        if isinstance(self.cf.default, int)
+            sel = self.cf.default
+        elif if self.cf.default.isdigit():
             sel = int(self.cf.default)
         else:
             # We don't fully support submenus. Look for the leaf

value in

Quoted 9 lines
Quoted 4 lines
Quoted 3 lines

but yes, this looks less intrusive (assuming this the only place where we'd hit this error).

That does look plausibly like it would fix the issue.

Is someone going to resubmit a patch along these lines then?

Ian

Unless you are NAKing my original patch, no.

That is untested, and IMO only a gross hack around the complete type brokenness introduced by d1b93ea.

I still firmly believe that my patch is the proper solution, which brings all the types back in line.

~Andrew