Package up2date_client :: Module up2dateErrors
[hide private]
[frames] | no frames]

Source Code for Module up2date_client.up2dateErrors

  1  # 
  2  # Client code for Update Agent 
  3  # Copyright (c) 1999--2016 Red Hat, Inc.  Distributed under GPLv2. 
  4  # 
  5  # Author: Preston Brown <pbrown@redhat.com> 
  6  #         Adrian Likins <alikins@redhat.com 
  7  #         Cristian Gafton <gafton@redhat.com> 
  8  # 
  9  # 
 10  # In addition, as a special exception, the copyright holders give 
 11  # permission to link the code of portions of this program with the 
 12  # OpenSSL library under certain conditions as described in each 
 13  # individual source file, and distribute linked combinations 
 14  # including the two. 
 15  # You must obey the GNU General Public License in all respects 
 16  # for all of the code used other than OpenSSL.  If you modify 
 17  # file(s) with this exception, you may extend this exception to your 
 18  # version of the file(s), but you are not obligated to do so.  If you 
 19  # do not wish to do so, delete this exception statement from your 
 20  # version.  If you delete this exception statement from all source 
 21  # files in the program, then also delete it here. 
 22   
 23  import gettext 
 24  t = gettext.translation('rhn-client-tools', fallback=True) 
 25  # Python 3 translations don't have a ugettext method 
 26  if not hasattr(t, 'ugettext'): 
 27      t.ugettext = t.gettext 
 28  _ = t.ugettext 
 29  import OpenSSL 
 30  from platform import dist 
 31  from rhn.i18n import ustr 
 32  from up2date_client import config 
 33  from up2date_client import up2dateLog 
 34  from up2date_client.pkgplatform import getPlatform 
 35   
 36  import sys 
 37  sys.path = sys.path[1:] + sys.path[:1] 
 38   
 39  try: 
 40      from yum.Errors import YumBaseError as PmBaseError 
 41  except ImportError: 
 42      try: 
 43          from dnf.exceptions import Error as PmBaseError 
 44      except ImportError: 
45 - class PmBaseError(Exception):
46 - def __init__(self, errmsg):
47 self.value = errmsg
48 - def __getattr__(self, name):
49 raise AttributeError(_("class %s has no attribute '%s'") % (self.__class__.__name__, name))
50 - def __setattr__(self, name, value):
51 if name in ['errmsg', 'value']: 52 self.__dict__['value'] = value 53 else: 54 self.__dict__[name] = value
55 56
57 -class Error(PmBaseError):
58 """base class for errors""" 59 premsg = ''
60 - def __init__(self, errmsg):
61 errmsg = ustr(errmsg) 62 PmBaseError.__init__(self, errmsg) 63 self.value = 'rhn-plugin: ' + self.premsg + errmsg 64 self.log = up2dateLog.initLog()
65
66 - def __repr__(self):
67 self.log.log_me(self.value) 68 return self.value
69
70 - def __getattr__(self, name):
71 """ Spacewalk backend still use errmsg, let have errmsg as alias to value """ 72 if name == 'errmsg': 73 return self.value 74 else: 75 if hasattr(PmBaseError, '__getattr__'): 76 # rhel5 has no __getattribute__() 77 return PmBaseError.__getattr__(self, name) 78 else: 79 if name in self.__dict__: 80 return self.__dict__[name] 81 else: 82 raise AttributeError(_("class %s has no attribute '%s'") % (self.__class__.__name__, name))
83
84 - def __setattr__(self, name, value):
85 """ Spacewalk backend still use errmsg, let have errmsg as alias to value """ 86 if name == 'errmsg': 87 self.__dict__['value'] = value 88 else: 89 if hasattr(PmBaseError, '__setattr__'): 90 # rhel5 has no __setattr__() 91 PmBaseError.__setattr__(self, name, value) 92 else: 93 self.__dict__[name] = value
94
95 -class DebAndSuseRepoError(Error):
96 pass
97 98 try: 99 from yum.Errors import RepoError 100 except ImportError: 101 try: 102 from dnf.exceptions import RepoError 103 except ImportError: 104 RepoError = DebAndSuseRepoError 105 106
107 -class RpmError(Error):
108 """rpm itself raised an error condition""" 109 premsg = _("RPM error. The message was:\n")
110
111 -class RhnServerException(Error):
112 pass
113
114 -class PasswordError(RhnServerException):
115 """Raise when the server responds with that a password is incorrect""" 116 premsg = _("Password error. The message was:\n")
117
118 -class DependencyError(Error):
119 """Raise when a rpm transaction set has a dependency error""" 120 premsg = _("RPM dependency error. The message was:\n")
121 - def __init__(self, msg, deps=None):
122 Error.__init__(self, msg) 123 # just tag on the whole deps tuple, so we have plenty of info 124 # to play with 125 self.deps = deps
126 127
128 -class CommunicationError(RhnServerException):
129 """Indicates a problem doing xml-rpc http communication with the server""" 130 premsg = _("Error communicating with server. "\ 131 "The message was:\n")
132
133 -class FileNotFoundError(Error):
134 """ 135 Raise when a package or header that is requested returns 136 a 404 error code""" 137 premsg = _("File Not Found: \n")
138 139
140 -class DelayError(RhnServerException):
141 """ 142 Raise when the expected response from a xml-rpc call 143 exceeds a timeout""" 144 premsg = _("Delay error from server. The message was:\n")
145
146 -class RpmRemoveError(Error):
147 """ 148 Raise when we can't remove a package for some reason 149 (failed deps, etc)"""
150 - def __init__(self, args):
151 Error.__init__(self, "") 152 self.args = args 153 for key in self.args.keys(): 154 self.args[key] = ustr(self.args[key]) 155 self.value = self.value + "%s failed because of %s\n" % ( 156 key, self.args[key]) 157 self.data = self.args
158 - def __repr__(self):
159 return self.value
160
161 -class NoLogError(Error):
162 - def __init__(self, msg):
163 msg = ustr(msg) 164 self.value = self.premsg + msg
165
166 - def __repr__(self):
167 return self.value
168
169 -class AbuseError(Error):
170 pass
171
172 -class AuthenticationTicketError(NoLogError, RhnServerException):
173 pass
174
175 -class AuthenticationError(NoLogError):
176 pass
177
178 -class ValidationError(NoLogError, RhnServerException):
179 """indicates an error during server input validation""" 180 premsg = _("Error validating data at server:\n")
181
182 -class InvalidRegistrationNumberError(ValidationError):
183 pass
184
185 -class RegistrationDeniedError(RhnServerException):
186 - def __init__(self):
188
189 - def __repr__(self):
190 return self.value
191
192 - def changeExplanation(self):
193 return _(""" 194 Red Hat Network Classic is not supported. 195 To register with Red Hat Subscription Management please run: 196 197 subscription-manager register --auto-attach 198 199 Get more information at access.redhat.com/knowledge 200 """)
201
202 -class InvalidProductRegistrationError(NoLogError):
203 """indicates an error during server input validation""" 204 premsg = _("The installation number is invalid")
205
206 -class OemInfoFileError(NoLogError):
207 premsg = _("Error parsing the oemInfo file at field:\n")
208
209 -class NoBaseChannelError(NoLogError, RhnServerException):
210 """No valid base channel was found for this system""" 211 pass
212
213 -class UnknownMethodException(NoLogError, RhnServerException):
214 pass
215
216 -class RhnUuidUniquenessError(NoLogError, RhnServerException):
217 pass
218
219 -class ServerCapabilityError(Error):
220 - def __init__(self, msg, errorlist=None):
221 Error.__init__(self, msg) 222 self.errorlist = [] 223 if errorlist: 224 self.errorlist=errorlist
225
226 - def __repr__(self):
227 return self.value
228
229 -class NoChannelsError(NoLogError):
230 pass
231
232 -class NetworkError(Error):
233 """ some generic network error occurred, e.g. connection reset by peer """ 234 premsg = _("Network error: ")
235
236 -class SSLCertificateVerifyFailedError(RepoError, Error):
237 - def __init__(self):
238 # Need to override __init__ because the base class requires a message arg 239 # and this exception shouldn't. 240 up2dateConfig = config.initUp2dateConfig() 241 certFile = up2dateConfig['sslCACert'] 242 f = open(certFile, "r") 243 buf = f.read() 244 f.close() 245 tempCert = OpenSSL.crypto.load_certificate(OpenSSL.crypto.FILETYPE_PEM, buf) 246 if tempCert.has_expired(): 247 RepoError.__init__(self ,"The certificate %s is expired. Please ensure you have the correct" 248 " certificate and your system time is correct." % certFile) 249 else: 250 RepoError.__init__(self, "The SSL certificate failed verification.")
251 252 __getattr__ = Error.__getattr__
253
254 -class SSLCertificateFileNotFound(Error):
255 pass
256 257
258 -class AuthenticationOrAccountCreationError(ValidationError):
259 """Class that can represent different things depending on context: 260 While logging in with an existing user it represents a username or password 261 being incorrect. 262 While creating a new account, it represents the username already being 263 taken or the user not being allowed to create an account. 264 Optimally these different things would be different exceptions, but there 265 are single fault codes the server can return to the client that can mean 266 more than one of them so we have no way of knowing which is actually 267 intended. 268 269 """ 270 pass
271
272 -class NotEntitlingError(Error):
273 pass
274
275 -class InvalidProtocolError(Error):
276 pass
277
278 -class UnableToCreateUser(NoLogError):
279 pass
280
281 -class ActivationKeyUsageLimitError(NoLogError):
282 pass
283
284 -class LoginMinLengthError(NoLogError):
285 pass
286
287 -class PasswordMinLengthError(NoLogError):
288 pass
289
290 -class PasswordMaxLengthError(NoLogError):
291 pass
292 293
294 -class InsuffMgmntEntsError(RhnServerException):
295 - def __init__(self, msg ):
297
298 - def __repr__(self):
299 return self.value
300
301 - def changeExplanation(self, msg):
302 newExpln = _(""" 303 Your organization does not have enough Management entitlements to register this 304 system to Red Hat Satellite. Please notify your organization administrator of this error. 305 You should be able to register this system after your organization frees existing 306 or purchases additional entitlements. Additional entitlements may be purchased by your 307 organization administrator by logging into Red Hat Network Classic and visiting 308 the 'Subscription Management' page in the 'Your RHN' section of RHN. 309 310 A common cause of this error code is due to having mistakenly setup an 311 Activation Key which is set as the universal default. If an activation key is set 312 on the account as a universal default, you can disable this key and retry to avoid 313 requiring a Management entitlement.""") 314 term = "Explanation:" 315 loc = msg.rindex(term) + len(term) 316 return msg[:loc] + newExpln
317
318 -class NoSystemIdError(NoLogError):
319 pass
320
321 -class InvalidRedirectionError(NoLogError):
322 """ Raise when redirect requests could'nt return a package""" 323 pass
324