spacecmd/src/lib/activationkey.py | 17 +++++++++++++----
spacecmd/src/lib/configchannel.py | 20 +++++++++++++++++---
spacecmd/src/lib/kickstart.py | 7 ++++++-
spacecmd/src/lib/utils.py | 9 ++++++---
4 files changed, 42 insertions(+), 11 deletions(-)
New commits:
commit b72099109cc6212ada8e98bc9028f4dc40e71f5d
Author: Steven Hardy <shardy(a)redhat.com>
Date: Thu May 24 15:30:25 2012 +0100
spacecmd bugfix : kickstart_getcontents fix character encoding error
The API can return characters in the rendered kickstart which can't
be rendered by the default ascii encoder, encoding UTF8 aligns with
the API and works around the problem.
Signed-off-by: Steven Hardy <shardy(a)redhat.com>
diff --git a/spacecmd/src/lib/kickstart.py b/spacecmd/src/lib/kickstart.py
index ef622ec..4f23eb0 100644
--- a/spacecmd/src/lib/kickstart.py
+++ b/spacecmd/src/lib/kickstart.py
@@ -479,7 +479,12 @@ def do_kickstart_getcontents(self, args):
kickstart = self.kickstart_getcontents(profile)
if kickstart:
- print kickstart
+ # We try to encode the output as UTF8, which is what we expect from
+ # the API. This avoids "'ascii' codec can't encode
character" errors
+ try:
+ print kickstart.encode('UTF8')
+ except:
+ print kickstart
####################
commit dc9b54b6dbc6f18b045d584f9e9289788f1a04bc
Author: Steven Hardy <shardy(a)redhat.com>
Date: Thu May 24 14:26:11 2012 +0100
spacecmd bugfix: activationkey_import don't add empty package/group lists
Don't attempt to add empty lists of packages or groups to the activationkey
Signed-off-by: Steven Hardy <shardy(a)redhat.com>
diff --git a/spacecmd/src/lib/activationkey.py b/spacecmd/src/lib/activationkey.py
index 2c28615..904c59c 100644
--- a/spacecmd/src/lib/activationkey.py
+++ b/spacecmd/src/lib/activationkey.py
@@ -1197,12 +1197,15 @@ def import_activationkey_fromdetails(self, keydetails):
grp)
gids.append(grpdetails.get('id'))
- logging.debug("Adding groups %s to key %s" % (gids, newkey))
- self.client.activationkey.addServerGroups(self.session, newkey, gids)
+ if gids:
+ logging.debug("Adding groups %s to key %s" % (gids, newkey))
+ self.client.activationkey.addServerGroups(self.session, newkey,
+ gids)
# Finally add the package list
- self.client.activationkey.addPackages(self.session, newkey, \
- keydetails['packages'])
+ if keydetails['packages']:
+ self.client.activationkey.addPackages(self.session, newkey,
+ keydetails['packages'])
return True
commit dd78914c9ca44c2056d08f41bca07ed2ae890562
Author: Steven Hardy <shardy(a)redhat.com>
Date: Thu May 24 14:17:39 2012 +0100
spacecmd bugfix : fix activationkey_import when no base-channel specified
815118 - activationkey_import fails when no base channel is set
This fix maintains the existing json format and maps json "none" to
and empty string which is what the API expects for default base-channel
Signed-off-by: Steven Hardy <shardy(a)redhat.com>
diff --git a/spacecmd/src/lib/activationkey.py b/spacecmd/src/lib/activationkey.py
index 41406ee..2c28615 100644
--- a/spacecmd/src/lib/activationkey.py
+++ b/spacecmd/src/lib/activationkey.py
@@ -1145,6 +1145,12 @@ def import_activationkey_fromdetails(self, keydetails):
logging.debug("Found key %s, importing as %s" % \
(keydetails['key'], keyname))
+ # Channel label must be an empty-string for "RHN Satellite Default"
+ # The export to json maps this to a unicode string "none"
+ # To avoid changing the json format now, just fix it up here...
+ if keydetails['base_channel_label'] == "none":
+ keydetails['base_channel_label'] = ''
+
if keydetails['usage_limit'] != 0:
newkey = self.client.activationkey.create(self.session,
keyname,
commit 3dfd65d8b0a98e9a6ada67d537522469c9dc94db
Author: Steven Hardy <shardy(a)redhat.com>
Date: Thu May 24 13:51:10 2012 +0100
spacecmd bugfix : Fix reference to non-existent variable
json_read_from_file refers to verbose in the exception handler, we should
just print the error message whenever we hit an exception
Signed-off-by: Steven Hardy <shardy(a)redhat.com>
diff --git a/spacecmd/src/lib/utils.py b/spacecmd/src/lib/utils.py
index 21f6c92..1cee588 100644
--- a/spacecmd/src/lib/utils.py
+++ b/spacecmd/src/lib/utils.py
@@ -631,8 +631,7 @@ def json_read_from_file(filename):
except:
print "could not read in data from %s" % filename
except IOError, E:
- if verbose:
- print "could not open file %s for reading, check permissions?" %
filename
+ print "could not open file %s for reading, check permissions?" %
filename
return None
commit 760b2bde82d5ca5b2170166c0fbe84d8fe631e08
Author: Steven Hardy <shardy(a)redhat.com>
Date: Thu May 24 12:01:26 2012 +0100
spacecmd bugfix : improve configchannel_export operation on old API versions
configchannel_export fails to export anything on the satellite 5.3 API version
when certain problematic files are encountered. This modification should make
a "best effort" to export on early API versions, while still working
as-before
on more recent, less broken API versions.
Signed-off-by: Steven Hardy <shardy(a)redhat.com>
diff --git a/spacecmd/src/lib/configchannel.py b/spacecmd/src/lib/configchannel.py
index 9a27d04..642e6b4 100644
--- a/spacecmd/src/lib/configchannel.py
+++ b/spacecmd/src/lib/configchannel.py
@@ -801,9 +801,23 @@ def export_configchannel_getdetails(self, channel):
files = self.client.configchannel.listFiles(self.session, channel)
details['files'] = []
paths = [f['path'] for f in files]
- logging.debug("Found files %s for %s" % (paths, channel))
- fileinfo = self.client.configchannel.lookupFileInfo(self.session, \
- channel, paths)
+ fileinfo = []
+ # Some versions of the API blow up when lookupFileInfo is asked to
+ # return details of files containing non-XML-valid characters.
+ # later API versions simply return empty file contents, but to
+ # ensure the least-bad operation with older (sat 5.3) API versions
+ # we can iterate over each file, then we just error on individual files
+ # instead of failing to export anything at all...
+ for p in paths:
+ logging.debug("Found file %s for %s" % (p, channel))
+ try:
+ pinfo = self.client.configchannel.lookupFileInfo(self.session,
+ channel, [ p ])
+ if len(pinfo):
+ fileinfo.append(pinfo[0])
+ except:
+ logging.error("Failed to get details for file %s from %s"
+ % (p, channel))
# Now we strip the datetime fields from the Info structs, as they
# are not JSON serializable with the default encoder, and we don't
# need them on import anyway
commit b0fb505f60a23cfc6f1025c0515872d6a1dfcaba
Author: Steven Hardy <shardy(a)redhat.com>
Date: Thu May 24 11:12:52 2012 +0100
spacecmd bugfix : *diff functions allow python 2.4 compatibility
Modify get_normalized_text implementation so it works with python 2.4
for compatibility with EL5 satellite deployments
Signed-off-by: Steven Hardy <shardy(a)redhat.com>
diff --git a/spacecmd/src/lib/utils.py b/spacecmd/src/lib/utils.py
index c9d4c4a..21f6c92 100644
--- a/spacecmd/src/lib/utils.py
+++ b/spacecmd/src/lib/utils.py
@@ -710,7 +710,11 @@ def get_normalized_text( text, replacedict=None, excludes=None ):
if text:
for string in text:
for line in string.split( "\n" ):
- if not excludes or not line.startswith( tuple(excludes) ):
+ if not excludes:
+ normalized_text.append( replace( line, replacedict ) )
+ # We do it this way instead of passing a tuple to
+ # line.startswith to allow compatibility with python 2.4
+ elif not [ e for e in excludes if line.startswith(e) ]:
normalized_text.append( replace( line, replacedict ) )
else:
logging.debug( "excluding line: " + line )