summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJenkins <jenkins@review.openstack.org>2017-06-19 15:37:39 +0000
committerGerrit Code Review <review@openstack.org>2017-06-19 15:37:39 +0000
commit8e6ecebcf9b9f3dd3091af9b71923156fcfa9ff3 (patch)
tree81b8f5153d0b8604cfb137d2943356c67b72cd53
parent0b608b2e6aa2f87b22310884a3a2e2dcc2025afc (diff)
parentb419de723d2192a9e2842f925f8fec3a857d0c84 (diff)
Merge "Add stack health check validation"
-rw-r--r--releasenotes/notes/stack-health-validation-c2174bc5f0bd585e.yaml8
-rw-r--r--tripleo_validations/inventory.py4
-rw-r--r--tripleo_validations/tests/test_inventory.py12
-rw-r--r--validations/lookup_plugins/stack_resources.py54
-rw-r--r--validations/stack-health.yaml17
5 files changed, 93 insertions, 2 deletions
diff --git a/releasenotes/notes/stack-health-validation-c2174bc5f0bd585e.yaml b/releasenotes/notes/stack-health-validation-c2174bc5f0bd585e.yaml
new file mode 100644
index 0000000..fe49ce9
--- /dev/null
+++ b/releasenotes/notes/stack-health-validation-c2174bc5f0bd585e.yaml
@@ -0,0 +1,8 @@
1---
2features:
3 - |
4 New validation to check the health of the current stack; to be run before
5 an update or upgrade.
6 - |
7 New lookup plugin to access the current stack's resources in Ansible
8 playbooks.
diff --git a/tripleo_validations/inventory.py b/tripleo_validations/inventory.py
index ea71b1a..be357a7 100644
--- a/tripleo_validations/inventory.py
+++ b/tripleo_validations/inventory.py
@@ -109,8 +109,12 @@ class TripleoInventory(object):
109 'hosts': ['localhost'], 109 'hosts': ['localhost'],
110 'vars': { 110 'vars': {
111 'ansible_connection': 'local', 111 'ansible_connection': 'local',
112 'auth_url': self.configs.auth_url,
113 'cacert': self.configs.cacert,
112 'os_auth_token': self.session.get_token(), 114 'os_auth_token': self.session.get_token(),
113 'plan': self.configs.plan, 115 'plan': self.configs.plan,
116 'project_name': self.configs.project_name,
117 'username': self.configs.username,
114 }, 118 },
115 } 119 }
116 } 120 }
diff --git a/tripleo_validations/tests/test_inventory.py b/tripleo_validations/tests/test_inventory.py
index 85221e3..e38f3d2 100644
--- a/tripleo_validations/tests/test_inventory.py
+++ b/tripleo_validations/tests/test_inventory.py
@@ -95,6 +95,10 @@ class TestInventory(base.TestCase):
95 95
96 self.configs = MagicMock() 96 self.configs = MagicMock()
97 self.configs.plan = self.plan_name 97 self.configs.plan = self.plan_name
98 self.configs.auth_url = 'xyz://keystone.local'
99 self.configs.cacert = 'acacert'
100 self.configs.project_name = 'admin'
101 self.configs.username = 'admin'
98 102
99 self.session = MagicMock() 103 self.session = MagicMock()
100 self.session.get_token.return_value = 'atoken' 104 self.session.get_token.return_value = 'atoken'
@@ -168,11 +172,13 @@ class TestInventory(base.TestCase):
168 'undercloud': { 172 'undercloud': {
169 'hosts': ['localhost'], 173 'hosts': ['localhost'],
170 'vars': {'ansible_connection': 'local', 174 'vars': {'ansible_connection': 'local',
175 'auth_url': 'xyz://keystone.local',
176 'cacert': 'acacert',
171 'os_auth_token': 'atoken', 177 'os_auth_token': 'atoken',
172 'overcloud_keystone_url': 'xyz://keystone', 178 'overcloud_keystone_url': 'xyz://keystone',
173 'overcloud_admin_password': 'theadminpw', 179 'overcloud_admin_password': 'theadminpw',
174 'plan': 'overcloud', 180 'plan': 'overcloud',
175 'undercloud_swift_url': 'anendpoint', 181 'project_name': 'admin',
176 'undercloud_service_list': [ 182 'undercloud_service_list': [
177 'openstack-nova-compute', 183 'openstack-nova-compute',
178 'openstack-nova-api', 184 'openstack-nova-api',
@@ -186,7 +192,9 @@ class TestInventory(base.TestCase):
186 'openstack-glance-api', 192 'openstack-glance-api',
187 'openstack-mistral-engine', 193 'openstack-mistral-engine',
188 'openstack-mistral-api.service', 194 'openstack-mistral-api.service',
189 'openstack-glance-api'], }}} 195 'openstack-glance-api'],
196 'undercloud_swift_url': 'anendpoint',
197 'username': 'admin'}}}
190 inv_list = self.inventory.list() 198 inv_list = self.inventory.list()
191 for k in expected: 199 for k in expected:
192 self.assertEqual(expected[k], inv_list[k]) 200 self.assertEqual(expected[k], inv_list[k])
diff --git a/validations/lookup_plugins/stack_resources.py b/validations/lookup_plugins/stack_resources.py
new file mode 100644
index 0000000..813b77c
--- /dev/null
+++ b/validations/lookup_plugins/stack_resources.py
@@ -0,0 +1,54 @@
1#!/usr/bin/env python
2
3# Copyright 2017 Red Hat, Inc.
4# All Rights Reserved.
5#
6# Licensed under the Apache License, Version 2.0 (the "License"); you may
7# not use this file except in compliance with the License. You may obtain
8# a copy of the License at
9#
10# http://www.apache.org/licenses/LICENSE-2.0
11#
12# Unless required by applicable law or agreed to in writing, software
13# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
14# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
15# License for the specific language governing permissions and limitations
16# under the License.
17
18
19from ansible.plugins.lookup import LookupBase
20from heatclient import client as heat_client
21
22from tripleo_validations.utils import get_auth_session
23
24
25class LookupModule(LookupBase):
26
27 def run(self, terms, variables=None, **kwargs):
28 """Returns the current plan's stack resources.
29
30 :return: A list of dicts
31 """
32 ret = []
33 session = get_auth_session(variables['auth_url'],
34 variables['username'],
35 variables['project_name'],
36 auth_token=variables['os_auth_token'],
37 cacert=variables['cacert'])
38
39 hclient = heat_client.Client('1', session=session)
40 resource_list = hclient.resources.list(variables['plan'])
41 for resource in resource_list:
42 ret.append(dict(
43 resource_name=resource.resource_name,
44 resource_status=resource.resource_status,
45 logical_resource_id=resource.logical_resource_id,
46 links=resource.links,
47 creation_time=resource.creation_time,
48 resource_status_reason=resource.resource_status_reason,
49 updated_time=resource.updated_time,
50 required_by=resource.required_by,
51 physical_resource_id=resource.physical_resource_id,
52 resource_type=resource.resource_type
53 ))
54 return ret
diff --git a/validations/stack-health.yaml b/validations/stack-health.yaml
new file mode 100644
index 0000000..1cd9214
--- /dev/null
+++ b/validations/stack-health.yaml
@@ -0,0 +1,17 @@
1---
2- hosts: undercloud
3 vars:
4 metadata:
5 name: Stack Health Check
6 description: >
7 Check if all stack resources are in a *_COMPLETE state before starting
8 an upgrade.
9 groups:
10 - pre-upgrade
11 tasks:
12 - name: Check stack resource statuses
13 assert:
14 that:
15 - "'_COMPLETE' in item.resource_status"
16 msg: "Health check failed for resource {{ item.resource_name }} with status: {{ item.resource_status }}"
17 with_items: "{{ lookup('stack_resources', wantlist=True) }}"