| Dario Faccin | 989602b | 2023-06-20 16:12:29 +0200 | [diff] [blame] | 1 | ####################################################################################### |
| 2 | # Copyright ETSI Contributors and Others. |
| 3 | # |
| 4 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | # you may not use this file except in compliance with the License. |
| 6 | # You may obtain a copy of the License at |
| 7 | # |
| 8 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | # |
| 10 | # Unless required by applicable law or agreed to in writing, software |
| 11 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or |
| 13 | # implied. |
| 14 | # See the License for the specific language governing permissions and |
| 15 | # limitations under the License. |
| 16 | ####################################################################################### |
| 17 | |
| 18 | from dataclasses import dataclass |
| 19 | |
| 20 | from osm_common.dbbase import DbBase |
| 21 | from osm_common.temporal.activities.base import BaseActivity |
| 22 | from osm_common.temporal.dataclasses_common import CharmInfo, VduComputeConstraints |
| 23 | |
| 24 | |
| 25 | class TestVimConnectivity(BaseActivity): |
| 26 | """Validates the credentials by attempting to connect to the given Juju Controller. |
| 27 | |
| 28 | Collaborators: |
| 29 | Juju Controller: Connect only |
| 30 | |
| 31 | Raises (Retryable): |
| 32 | ApplicationError If any of password, cacert, cloud_credentials is invalid |
| 33 | or Juju controller is not reachable |
| 34 | |
| 35 | Activity Lifecycle: |
| 36 | This activity should complete relatively quickly (in a few seconds). |
| 37 | However, it would be reasonable to wait more than 72 seconds (network timeout) |
| 38 | incase there are network issues. |
| 39 | |
| 40 | This activity will not report a heartbeat due to its |
| 41 | short-running nature. |
| 42 | |
| 43 | It is recommended, although not necessary to implement a |
| 44 | back-off strategy for this activity, as it will naturally block |
| 45 | and wait on each connection attempt. |
| 46 | """ |
| 47 | |
| 48 | @dataclass |
| 49 | class Input: |
| 50 | """ |
| 51 | Input dataclass for the Test Vim Connectivity Ativity |
| 52 | |
| 53 | Attributes: |
| 54 | ----------- |
| 55 | vim_uuid : str |
| 56 | The UUID of the VIM account as stored in the OSM vim |
| 57 | collection in Mongo |
| 58 | """ |
| 59 | |
| 60 | vim_uuid: str |
| 61 | |
| 62 | def __init__(self, juju_controller): |
| 63 | super().__init__() |
| 64 | self.juju_controller = juju_controller |
| 65 | |
| 66 | async def __call__(self, activity_input: Input) -> None: |
| 67 | raise NotImplementedError() |
| 68 | |
| 69 | |
| 70 | class CreateModel(BaseActivity): |
| 71 | """Connects to Juju Controller. Creates a new model. |
| 72 | |
| 73 | Collaborators: |
| 74 | DB Read: vim_accounts |
| 75 | Juju Controller: Connect and create model. |
| 76 | |
| 77 | Raises (Retryable): |
| 78 | ApplicationError If Juju controller is not reachable. |
| 79 | If the model already exists. |
| 80 | |
| 81 | Activity Lifecycle: |
| 82 | This activity should complete relatively quickly (in a few seconds). |
| 83 | However, it would be reasonable to wait more than 72 seconds (network timeout) |
| 84 | incase there are network issues. |
| 85 | |
| 86 | This activity will not report a heartbeat due to its |
| 87 | short-running nature. |
| 88 | |
| 89 | It is recommended, although not necessary to implement a |
| 90 | back-off strategy for this activity, as it will naturally block |
| 91 | and wait on each connection attempt. |
| 92 | """ |
| 93 | |
| 94 | @dataclass |
| 95 | class Input: |
| 96 | """ |
| 97 | Contains the information related to a model. |
| 98 | |
| 99 | Attributes: |
| 100 | ----------- |
| 101 | vim_uuid : str |
| 102 | The UUID of the VIM as stored in the OSM vim_accounts |
| 103 | collection in Mongo. |
| 104 | |
| 105 | model_name : str |
| 106 | Name of the Juju model used to deploy charms. |
| 107 | """ |
| 108 | |
| 109 | vim_uuid: str |
| 110 | model_name: str |
| 111 | |
| 112 | def __init__(self, db: DbBase, juju_controller): |
| 113 | super().__init__() |
| 114 | self.db: DbBase = db |
| 115 | self.juju_controller = juju_controller |
| 116 | |
| 117 | async def __call__(self, activity_input: Input) -> None: |
| 118 | raise NotImplementedError() |
| 119 | |
| 120 | |
| 121 | class DeployCharm(BaseActivity): |
| 122 | """Deploys a charm. |
| 123 | |
| 124 | Collaborators: |
| 125 | Juju Controller: Connect and deploy charm |
| 126 | |
| 127 | Raises (Retryable): |
| 128 | ApplicationError If Juju controller is not reachable |
| 129 | If application already exists |
| 130 | |
| 131 | Activity Lifecycle: |
| 132 | This activity should complete relatively quickly (in a few seconds). |
| 133 | However, it would be reasonable to wait more than 72 seconds (network timeout) |
| 134 | incase there are network issues. |
| 135 | |
| 136 | This activity will not report a heartbeat due to its |
| 137 | short-running nature. |
| 138 | |
| 139 | It is recommended, although not necessary to implement a |
| 140 | back-off strategy for this activity, as it will naturally block |
| 141 | and wait on each connection attempt. |
| 142 | """ |
| 143 | |
| 144 | @dataclass |
| 145 | class Input: |
| 146 | """ |
| 147 | Input dataclass for workflow that instantiates a VDU. |
| 148 | |
| 149 | vim_uuid: str |
| 150 | |
| 151 | model_name: str |
| 152 | |
| 153 | charm_info : CharmInfo |
| 154 | |
| 155 | constraints: VduComputeConstraints |
| 156 | |
| 157 | cloud: VIM cloud type |
| 158 | |
| 159 | config: Config details of application |
| 160 | """ |
| 161 | |
| 162 | vim_uuid: str |
| 163 | model_name: str |
| 164 | charm_info: CharmInfo |
| 165 | constraints: VduComputeConstraints |
| 166 | cloud: str |
| 167 | config: dict |
| 168 | |
| 169 | def __init__(self, juju_controller): |
| 170 | super().__init__() |
| 171 | self.juju_controller = juju_controller |
| 172 | |
| 173 | async def __call__(self, activity_input: Input) -> None: |
| 174 | raise NotImplementedError() |
| 175 | |
| 176 | |
| 177 | class CheckCharmStatus(BaseActivity): |
| 178 | """Checks the ready status of the charm. This activity will block until the status of |
| 179 | the application is either "active" or "blocked". Additionally, it also blocks until |
| 180 | the workload status of each of its units is also either "active" or "blocked". |
| 181 | |
| 182 | Collaborators: |
| 183 | Juju Controller: Connect to controller and check charm status. |
| 184 | |
| 185 | Raises (Retryable): |
| 186 | ApplicationError If any of password, cacert, cloud_credentials is invalid |
| 187 | or Juju controller is not reachable |
| 188 | |
| 189 | Activity Lifecycle: |
| 190 | This activity will continue indefinitely until the specified charm deployment |
| 191 | has reached a ready state. Heartbeats are performed to ensure this activity |
| 192 | does not time out. |
| 193 | |
| 194 | A start-to-close of something reasonable (such as 5 minutes) should be implemented |
| 195 | at the workflow level and such a timeout shall trigger workflow failure logic. |
| 196 | """ |
| 197 | |
| 198 | @dataclass |
| 199 | class Input: |
| 200 | """ |
| 201 | Input dataclass for checking on a specific charm's deployment |
| 202 | status |
| 203 | |
| 204 | Attributes: |
| 205 | ----------- |
| 206 | vim_uuid : str |
| 207 | The UUID of the VIM as stored in the OSM vim_accounts |
| 208 | collection in Mongo. |
| 209 | |
| 210 | model_name : str |
| 211 | Name of the model to create in Juju. |
| 212 | |
| 213 | application_name : str |
| 214 | Name of the application that the state is going to be |
| 215 | awaited. |
| 216 | |
| 217 | poll_interval : int (optional) |
| 218 | Time, in seconds, to wait between status checks. |
| 219 | """ |
| 220 | |
| 221 | vim_uuid: str |
| 222 | model_name: str |
| 223 | application_name: str |
| 224 | poll_interval: int = 1 |
| 225 | |
| 226 | def __init__(self, juju_controller): |
| 227 | super().__init__() |
| 228 | self.juju_controller = juju_controller |
| 229 | |
| 230 | async def __call__(self, activity_input: Input) -> None: |
| 231 | raise NotImplementedError() |
| Dario Faccin | d32ac8b | 2023-07-03 09:19:34 +0200 | [diff] [blame] | 232 | |
| 233 | |
| 234 | class RemoveCharm(BaseActivity): |
| 235 | """Removes the given charm from the given model. |
| 236 | |
| 237 | Collaborators: |
| 238 | Juju Controller: Connect to controller and check charm status. |
| 239 | |
| 240 | Raises (Retryable): |
| 241 | ApplicationError If any of password, cacert, cloud_credentials is invalid |
| 242 | or Juju controller is not reachable |
| 243 | |
| 244 | Activity Lifecycle: |
| 245 | This activity should complete relatively quickly (in a few seconds). |
| 246 | However, it would be reasonable to wait more than 72 seconds (network timeout) |
| 247 | incase there are network issues. |
| 248 | |
| 249 | This activity will not report a heartbeat due to its |
| 250 | short-running nature. |
| 251 | |
| 252 | It is recommended, although not necessary to implement a |
| 253 | back-off strategy for this activity, as it will naturally block |
| 254 | and wait on each connection attempt. |
| 255 | """ |
| 256 | |
| 257 | @dataclass |
| 258 | class Input: |
| 259 | """ |
| 260 | Input dataclass for checking on a specific charm's removal |
| 261 | status |
| 262 | |
| 263 | Attributes: |
| 264 | ----------- |
| 265 | vim_uuid : str |
| 266 | The UUID of the VIM as stored in the OSM vim_accounts |
| 267 | collection in Mongo. |
| 268 | |
| 269 | model_name : str |
| 270 | Name of the model in Juju where the charm is deployed. |
| 271 | |
| 272 | application_name : str |
| 273 | Name of the application to be removed. |
| 274 | |
| 275 | force_remove : bool |
| 276 | If application has to be forcefully removed. |
| 277 | |
| 278 | """ |
| 279 | |
| 280 | vim_uuid: str |
| 281 | model_name: str |
| 282 | application_name: str |
| 283 | force_remove: bool |
| 284 | |
| 285 | def __init__(self, juju_controller): |
| 286 | super().__init__() |
| 287 | self.juju_controller = juju_controller |
| 288 | |
| 289 | async def __call__(self, activity_input: Input) -> None: |
| 290 | raise NotImplementedError() |
| 291 | |
| 292 | |
| 293 | class CheckCharmIsRemoved(BaseActivity): |
| 294 | """Checks the removal of the charm. This activity will block until the application |
| 295 | is not present in the specified model. |
| 296 | |
| 297 | Collaborators: |
| 298 | Juju Controller: Connect to controller and check charm status. |
| 299 | |
| 300 | Raises (Retryable): |
| 301 | ApplicationError If any of password, cacert, cloud_credentials is invalid |
| 302 | or Juju controller is not reachable |
| 303 | |
| 304 | Activity Lifecycle: |
| 305 | This activity will continue indefinitely until the specified charm is removed. |
| 306 | Heartbeats are performed to ensure this activity does not time out. |
| 307 | |
| 308 | A start-to-close of something reasonable (such as 5 minutes) should be implemented |
| 309 | at the workflow level and such a timeout shall trigger workflow failure logic. |
| 310 | """ |
| 311 | |
| 312 | @dataclass |
| 313 | class Input: |
| 314 | """ |
| 315 | Input dataclass for checking on a specific charm's removal |
| 316 | status |
| 317 | |
| 318 | Attributes: |
| 319 | ----------- |
| 320 | vim_uuid : str |
| 321 | The UUID of the VIM as stored in the OSM vim_accounts |
| 322 | collection in Mongo. |
| 323 | |
| 324 | model_name : str |
| 325 | Name of the model in Juju where the charm is deployed. |
| 326 | |
| 327 | application_name : str |
| 328 | Name of the application whose removal is going to be |
| 329 | awaited. |
| 330 | |
| 331 | poll_interval : int (optional) |
| 332 | Time, in seconds, to wait between status checks. |
| 333 | """ |
| 334 | |
| 335 | vim_uuid: str |
| 336 | model_name: str |
| 337 | application_name: str |
| 338 | poll_interval: int = 1 |
| 339 | |
| 340 | def __init__(self, juju_controller): |
| 341 | super().__init__() |
| 342 | self.juju_controller = juju_controller |
| 343 | |
| 344 | async def __call__(self, activity_input: Input) -> None: |
| 345 | raise NotImplementedError() |