Dennis Dmitriev | 6f59add | 2016-10-18 13:45:27 +0300 | [diff] [blame] | 1 | # Copyright 2016 Mirantis, Inc. |
| 2 | # |
| 3 | # Licensed under the Apache License, Version 2.0 (the "License"); you may |
| 4 | # not use this file except in compliance with the License. You may obtain |
| 5 | # a copy of the License at |
| 6 | # |
| 7 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | # |
| 9 | # Unless required by applicable law or agreed to in writing, software |
| 10 | # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 11 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| 12 | # License for the specific language governing permissions and limitations |
| 13 | # under the License. |
| 14 | |
| 15 | |
| 16 | class UnexpectedExitCode(Exception): |
| 17 | def __init__(self, command, ec, expected_ec, stdout=None, stderr=None): |
| 18 | """Exception for unexpected exit code after executing shell/ssh command |
| 19 | |
| 20 | :param command: str - executed command |
| 21 | :param ec: int - actual exit code |
| 22 | :param expected_ec: list of integers - expected exit codes |
| 23 | :param stdout: str |
| 24 | :param stderr: str |
| 25 | """ |
| 26 | self.ec = ec |
| 27 | self.expected_ec = expected_ec |
| 28 | self.cmd = command |
| 29 | self.stdout = stdout |
| 30 | self.stderr = stderr |
| 31 | super(UnexpectedExitCode, self).__init__() |
| 32 | |
| 33 | def __str__(self): |
| 34 | message = "Command '{cmd:s}' returned unexpected exit code {code:d}," \ |
| 35 | " while waiting for {exp}".format(cmd=self.cmd, |
| 36 | code=self.ec, |
| 37 | exp=self.expected_ec) |
| 38 | if self.stdout: |
| 39 | message += "stdout: {}\n".format(self.stdout) |
| 40 | if self.stderr: |
| 41 | message += "stderr: {}\n".format(self.stderr) |
| 42 | return message |
| 43 | |
| 44 | |
| 45 | class VariableNotSet(Exception): |
| 46 | def __init__(self, variable_name, expected_value): |
| 47 | self.variable_name = variable_name |
| 48 | self.expected_value = expected_value |
| 49 | super(VariableNotSet, self).__init__() |
| 50 | |
| 51 | def __str__(self): |
| 52 | return "Variable {0} was not set in value {1}".format( |
| 53 | self.variable_name, self.expected_value) |
| 54 | |
| 55 | |
| 56 | class DevopsConfigPathIsNotSet(ValueError): |
| 57 | def __str__(self): |
| 58 | return "Devops config/template path is not set!" |
| 59 | |
| 60 | |
| 61 | class DevopsConfigTypeError(TypeError): |
| 62 | def __init__(self, type_name): |
| 63 | self.type_name = type_name |
| 64 | super(DevopsConfigTypeError, self).__init__() |
| 65 | |
| 66 | def __str__(self): |
| 67 | return "Devops config should be dict instead of {0}".format( |
| 68 | self.type_name |
| 69 | ) |
| 70 | |
| 71 | |
| 72 | class DevopsConfigIsNone(ValueError): |
| 73 | def __str__(self): |
| 74 | return "Devops config is None!" |
| 75 | |
| 76 | |
| 77 | class EnvironmentNameIsNotSet(ValueError): |
| 78 | def __str__(self): |
| 79 | return "Couldn't get environment name!" |
| 80 | |
| 81 | |
| 82 | class EnvironmentDoesNotExist(BaseException): |
| 83 | def __init__(self, env_name): |
| 84 | super(EnvironmentDoesNotExist, self).__init__() |
| 85 | self.env_name = env_name |
| 86 | |
| 87 | def __str__(self): |
| 88 | return "Environment {0} does not exist!".format( |
| 89 | self.env_name |
| 90 | ) |
| 91 | |
| 92 | |
| 93 | class EnvironmentAlreadyExists(BaseException): |
| 94 | def __init__(self, env_name): |
| 95 | super(EnvironmentAlreadyExists, self).__init__() |
| 96 | self.env_name = env_name |
| 97 | |
| 98 | def __str__(self): |
| 99 | return "Environment {0} already exists!".format( |
| 100 | self.env_name |
| 101 | ) |
| 102 | |
| 103 | |
Dennis Dmitriev | f5f2e60 | 2017-11-03 15:36:19 +0200 | [diff] [blame^] | 104 | class EnvironmentWrongStatus(BaseException): |
| 105 | def __init__(self, env_name, env_expected_status, env_actual_status): |
| 106 | super(EnvironmentWrongStatus, self).__init__() |
| 107 | self.env_name = env_name |
| 108 | self.env_expected_status = env_expected_status |
| 109 | self.env_actual_status = env_actual_status |
| 110 | |
| 111 | def __str__(self): |
| 112 | return ("Environment '{0}' has wrong status: " |
| 113 | "expected '{1}', got: '{2}'" |
| 114 | .format(self.env_name, |
| 115 | self.env_expected_status, |
| 116 | self.env_actual_status)) |
| 117 | |
| 118 | |
| 119 | class EnvironmentBadStatus(BaseException): |
| 120 | def __init__(self, env_name, env_expected_status, |
| 121 | env_actual_status, wrong_resources): |
| 122 | super(EnvironmentBadStatus, self).__init__() |
| 123 | self.env_name = env_name |
| 124 | self.env_expected_status = env_expected_status |
| 125 | self.env_actual_status = env_actual_status |
| 126 | self.wrong_resources = wrong_resources |
| 127 | |
| 128 | def __str__(self): |
| 129 | return ("Environment '{0}' has bad status: " |
| 130 | "expected '{1}', got: '{2}'\n{3}" |
| 131 | .format(self.env_name, |
| 132 | self.env_expected_status, |
| 133 | self.env_actual_status, |
| 134 | self.wrong_resources)) |
| 135 | |
| 136 | |
Dennis Dmitriev | 6f59add | 2016-10-18 13:45:27 +0300 | [diff] [blame] | 137 | class EnvironmentSnapshotMissing(BaseException): |
| 138 | def __init__(self, env_name, snapshot_name): |
| 139 | super(EnvironmentSnapshotMissing, self).__init__() |
| 140 | self.env_name = env_name |
| 141 | self.snapshot_name = snapshot_name |
| 142 | |
| 143 | def __str__(self): |
| 144 | return ("Environment '{0}' doesn't have requested snapshot '{1}'! " |
| 145 | "Please create the snapshot manually or erase the environment." |
| 146 | .format(self.env_name, self.snapshot_name)) |
| 147 | |
| 148 | |
| 149 | class EnvironmentIsNotSet(BaseException): |
| 150 | def __str__(self): |
| 151 | return "Environment is not set!" |
| 152 | |
| 153 | |
| 154 | class BaseImageIsNotSet(BaseException): |
| 155 | def __str__(self): |
| 156 | return "Base image for creating VMs is not set!" |
Dennis Dmitriev | 2d643bc | 2017-12-04 12:23:47 +0200 | [diff] [blame] | 157 | |
| 158 | |
| 159 | class SaltPillarError(BaseException): |
| 160 | def __init__(self, minion_id, pillar, message=''): |
| 161 | super(SaltPillarError, self).__init__() |
| 162 | self.minion_id = minion_id |
| 163 | self.pillar = pillar |
| 164 | self.message = message |
| 165 | |
| 166 | def __str__(self): |
| 167 | return ("Salt pillar '{0}' error on minion {1}: {2}" |
| 168 | .format(self.minion_id, self.pillar, self.message)) |
Dennis Dmitriev | 86085b4 | 2018-07-02 14:14:25 +0300 | [diff] [blame] | 169 | |
| 170 | |
| 171 | class EnvironmentNodeIsNotStarted(BaseException): |
| 172 | def __init__(self, node_name, message=''): |
| 173 | super(EnvironmentNodeIsNotStarted, self).__init__() |
| 174 | self.node_name = node_name |
| 175 | self.message = message |
| 176 | |
| 177 | def __str__(self): |
| 178 | return ("Cloud-init failed on node {0} with error: \n{1}" |
| 179 | .format(self.node_name, self.message)) |
Dennis Dmitriev | f5f2e60 | 2017-11-03 15:36:19 +0200 | [diff] [blame^] | 180 | |
| 181 | |
| 182 | class EnvironmentNodeAccessError(BaseException): |
| 183 | def __init__(self, node_name, message=''): |
| 184 | super(EnvironmentNodeAccessError, self).__init__() |
| 185 | self.node_name = node_name |
| 186 | self.message = message |
| 187 | |
| 188 | def __str__(self): |
| 189 | return ("Unable to reach the node {0}: \n{1}" |
| 190 | .format(self.node_name, self.message)) |