Anton Samoylov | 28ad4fa | 2018-10-02 14:45:41 +0400 | [diff] [blame] | 1 | #!/usr/bin/python |
| 2 | # Copyright 2018 Mirantis, Inc. |
| 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 implied. |
| 13 | # See the License for the specific language governing permissions and |
| 14 | # limitations under the License. |
| 15 | ''' |
| 16 | Verification of Contrail services states |
| 17 | ''' |
| 18 | |
| 19 | |
| 20 | def __virtual__(): |
| 21 | ''' |
| 22 | Load Contrail Health state module |
| 23 | ''' |
| 24 | return 'contrail_health' |
| 25 | |
| 26 | |
| 27 | def services_health(name, healthy_states=None, extra_states_map=None): |
| 28 | services_states = __salt__['contrail_health.get_services_status']() |
| 29 | |
| 30 | healthy_states = healthy_states or ['active'] |
| 31 | extra_states_map = extra_states_map or {} |
| 32 | |
| 33 | if services_states: |
| 34 | |
| 35 | nonhealthy_services = [] |
| 36 | |
| 37 | for service_name, state in services_states.items(): |
| 38 | if (state not in healthy_states and |
| 39 | state not in extra_states_map.get(service_name, [])): |
| 40 | nonhealthy_services.append(service_name) |
| 41 | |
| 42 | if nonhealthy_services: |
| 43 | comment = ("The following services didn't pass health check:\n" + |
| 44 | "\n".join(nonhealthy_services)) |
| 45 | result = False |
| 46 | else: |
| 47 | comment = ("All contrail services have health state:\n" + |
| 48 | "\n".join(services_states.keys())) |
| 49 | result = True |
| 50 | |
| 51 | else: |
Anton Samoylov | 7a8d83c | 2018-10-11 12:33:36 +0400 | [diff] [blame^] | 52 | comment = ("Contrail services states could not be verified.\n" |
Anton Samoylov | 28ad4fa | 2018-10-02 14:45:41 +0400 | [diff] [blame] | 53 | "If contrail services are working inside container(s) " |
| 54 | "(starting from version 4.0), please check " |
| 55 | "that related container(s) is (are) started.") |
| 56 | result = False |
| 57 | |
| 58 | return {'name': name, 'changes': {}, 'comment': comment, 'result': result} |