Merge "Add stack health check validation"
This commit is contained in:
commit
8e6ecebcf9
|
@ -0,0 +1,8 @@
|
|||
---
|
||||
features:
|
||||
- |
|
||||
New validation to check the health of the current stack; to be run before
|
||||
an update or upgrade.
|
||||
- |
|
||||
New lookup plugin to access the current stack's resources in Ansible
|
||||
playbooks.
|
|
@ -109,8 +109,12 @@ class TripleoInventory(object):
|
|||
'hosts': ['localhost'],
|
||||
'vars': {
|
||||
'ansible_connection': 'local',
|
||||
'auth_url': self.configs.auth_url,
|
||||
'cacert': self.configs.cacert,
|
||||
'os_auth_token': self.session.get_token(),
|
||||
'plan': self.configs.plan,
|
||||
'project_name': self.configs.project_name,
|
||||
'username': self.configs.username,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
|
|
@ -95,6 +95,10 @@ class TestInventory(base.TestCase):
|
|||
|
||||
self.configs = MagicMock()
|
||||
self.configs.plan = self.plan_name
|
||||
self.configs.auth_url = 'xyz://keystone.local'
|
||||
self.configs.cacert = 'acacert'
|
||||
self.configs.project_name = 'admin'
|
||||
self.configs.username = 'admin'
|
||||
|
||||
self.session = MagicMock()
|
||||
self.session.get_token.return_value = 'atoken'
|
||||
|
@ -168,11 +172,13 @@ class TestInventory(base.TestCase):
|
|||
'undercloud': {
|
||||
'hosts': ['localhost'],
|
||||
'vars': {'ansible_connection': 'local',
|
||||
'auth_url': 'xyz://keystone.local',
|
||||
'cacert': 'acacert',
|
||||
'os_auth_token': 'atoken',
|
||||
'overcloud_keystone_url': 'xyz://keystone',
|
||||
'overcloud_admin_password': 'theadminpw',
|
||||
'plan': 'overcloud',
|
||||
'undercloud_swift_url': 'anendpoint',
|
||||
'project_name': 'admin',
|
||||
'undercloud_service_list': [
|
||||
'openstack-nova-compute',
|
||||
'openstack-nova-api',
|
||||
|
@ -186,7 +192,9 @@ class TestInventory(base.TestCase):
|
|||
'openstack-glance-api',
|
||||
'openstack-mistral-engine',
|
||||
'openstack-mistral-api.service',
|
||||
'openstack-glance-api'], }}}
|
||||
'openstack-glance-api'],
|
||||
'undercloud_swift_url': 'anendpoint',
|
||||
'username': 'admin'}}}
|
||||
inv_list = self.inventory.list()
|
||||
for k in expected:
|
||||
self.assertEqual(expected[k], inv_list[k])
|
||||
|
|
|
@ -0,0 +1,54 @@
|
|||
#!/usr/bin/env python
|
||||
|
||||
# Copyright 2017 Red Hat, Inc.
|
||||
# All Rights Reserved.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
# not use this file except in compliance with the License. You may obtain
|
||||
# a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
|
||||
from ansible.plugins.lookup import LookupBase
|
||||
from heatclient import client as heat_client
|
||||
|
||||
from tripleo_validations.utils import get_auth_session
|
||||
|
||||
|
||||
class LookupModule(LookupBase):
|
||||
|
||||
def run(self, terms, variables=None, **kwargs):
|
||||
"""Returns the current plan's stack resources.
|
||||
|
||||
:return: A list of dicts
|
||||
"""
|
||||
ret = []
|
||||
session = get_auth_session(variables['auth_url'],
|
||||
variables['username'],
|
||||
variables['project_name'],
|
||||
auth_token=variables['os_auth_token'],
|
||||
cacert=variables['cacert'])
|
||||
|
||||
hclient = heat_client.Client('1', session=session)
|
||||
resource_list = hclient.resources.list(variables['plan'])
|
||||
for resource in resource_list:
|
||||
ret.append(dict(
|
||||
resource_name=resource.resource_name,
|
||||
resource_status=resource.resource_status,
|
||||
logical_resource_id=resource.logical_resource_id,
|
||||
links=resource.links,
|
||||
creation_time=resource.creation_time,
|
||||
resource_status_reason=resource.resource_status_reason,
|
||||
updated_time=resource.updated_time,
|
||||
required_by=resource.required_by,
|
||||
physical_resource_id=resource.physical_resource_id,
|
||||
resource_type=resource.resource_type
|
||||
))
|
||||
return ret
|
|
@ -0,0 +1,17 @@
|
|||
---
|
||||
- hosts: undercloud
|
||||
vars:
|
||||
metadata:
|
||||
name: Stack Health Check
|
||||
description: >
|
||||
Check if all stack resources are in a *_COMPLETE state before starting
|
||||
an upgrade.
|
||||
groups:
|
||||
- pre-upgrade
|
||||
tasks:
|
||||
- name: Check stack resource statuses
|
||||
assert:
|
||||
that:
|
||||
- "'_COMPLETE' in item.resource_status"
|
||||
msg: "Health check failed for resource {{ item.resource_name }} with status: {{ item.resource_status }}"
|
||||
with_items: "{{ lookup('stack_resources', wantlist=True) }}"
|
Loading…
Reference in New Issue