Keun Soo Yim | b293fdb | 2016-09-21 16:03:44 -0700 | [diff] [blame] | 1 | #!/usr/bin/env python |
| 2 | # |
| 3 | # Copyright 2016 - The Android Open Source Project |
| 4 | # |
| 5 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | # you may not use this file except in compliance with the License. |
| 7 | # You may obtain a copy of the License at |
| 8 | # |
| 9 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | # |
| 11 | # Unless required by applicable law or agreed to in writing, software |
| 12 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | # See the License for the specific language governing permissions and |
| 15 | # limitations under the License. |
Keun Soo Yim | b293fdb | 2016-09-21 16:03:44 -0700 | [diff] [blame] | 16 | """Define errors that are raised by the driver.""" |
| 17 | |
Keun Soo Yim | b293fdb | 2016-09-21 16:03:44 -0700 | [diff] [blame] | 18 | HTTP_NOT_FOUND_CODE = 404 |
| 19 | |
| 20 | |
| 21 | class DriverError(Exception): |
| 22 | """Base Android Gce driver exception.""" |
| 23 | |
| 24 | |
| 25 | class ConfigError(DriverError): |
| 26 | """Error related to config.""" |
| 27 | |
| 28 | |
| 29 | class CommandArgError(DriverError): |
| 30 | """Error related to command line args.""" |
| 31 | |
| 32 | |
| 33 | class GceOperationTimeoutError(DriverError): |
| 34 | """Error raised when a GCE operation timedout.""" |
| 35 | |
| 36 | |
| 37 | class HttpError(DriverError): |
| 38 | """Error related to http requests.""" |
| 39 | |
| 40 | def __init__(self, code, message): |
| 41 | self.code = code |
| 42 | super(HttpError, self).__init__(message) |
| 43 | |
| 44 | @staticmethod |
| 45 | def CreateFromHttpError(http_error): |
| 46 | """Create from an apiclient.errors.HttpError. |
| 47 | |
| 48 | Parse the error code from apiclient.errors.HttpError |
| 49 | and create an instance of HttpError from this module |
| 50 | that has the error code. |
| 51 | |
| 52 | Args: |
| 53 | http_error: An apiclient.errors.HttpError instance. |
| 54 | |
| 55 | Returns: |
| 56 | An HttpError instance from this module. |
| 57 | """ |
| 58 | return HttpError(http_error.resp.status, str(http_error)) |
| 59 | |
| 60 | |
| 61 | class ResourceNotFoundError(HttpError): |
| 62 | """Error raised when a resource is not found.""" |
| 63 | |
| 64 | |
| 65 | class InvalidVirtualDeviceIpError(DriverError): |
| 66 | """Invalid virtual device's IP is set. |
| 67 | |
| 68 | Raise this when the virtual device's IP of an AVD instance is invalid. |
| 69 | """ |
| 70 | |
| 71 | |
Keun Soo Yim | b293fdb | 2016-09-21 16:03:44 -0700 | [diff] [blame] | 72 | class HasRetriableRequestsError(DriverError): |
| 73 | """Raised when some retriable requests fail in a batch execution.""" |
| 74 | |
| 75 | |
xingdai | 147a978 | 2018-08-01 17:13:51 -0700 | [diff] [blame] | 76 | class AuthenticationError(DriverError): |
Keun Soo Yim | b293fdb | 2016-09-21 16:03:44 -0700 | [diff] [blame] | 77 | """Raised when authentication fails.""" |
Kevin Cheng | b596388 | 2018-05-09 00:06:27 -0700 | [diff] [blame] | 78 | |
| 79 | |
| 80 | class DeviceBootError(DriverError): |
herbertxue | 769e1b7 | 2018-05-17 08:27:48 +0000 | [diff] [blame] | 81 | """To catch device boot errors.""" |
Kevin Cheng | b596388 | 2018-05-09 00:06:27 -0700 | [diff] [blame] | 82 | |
| 83 | |
Kevin Cheng | 1f582bc | 2018-10-02 10:37:02 -0700 | [diff] [blame] | 84 | class NoSubnetwork(DriverError): |
| 85 | """When there is no subnetwork for the GCE.""" |
| 86 | |
| 87 | |
Kevin Cheng | b596388 | 2018-05-09 00:06:27 -0700 | [diff] [blame] | 88 | class DeviceBootTimeoutError(DeviceBootError): |
herbertxue | 769e1b7 | 2018-05-17 08:27:48 +0000 | [diff] [blame] | 89 | """Raised when an AVD defice failed to boot within timeout.""" |
herbertxue | 0cf6cef | 2018-07-03 21:57:48 +0800 | [diff] [blame] | 90 | |
| 91 | |
| 92 | class SetupError(Exception): |
| 93 | """Base Setup cmd exception.""" |
| 94 | |
| 95 | |
| 96 | class OSTypeError(SetupError): |
| 97 | """Error related to OS type.""" |
| 98 | |
| 99 | |
| 100 | class NoGoogleSDKDetected(SetupError): |
| 101 | """Can't find the SDK path.""" |