Test template v3 with parameters
Change-Id: I0c9c588b8233ed2824bc580f94b48b944328119d Story: 2004056 Task: 29446
This commit is contained in:
parent
39cb545f05
commit
9b444b1c41
vitrage_tempest_plugin/tests
api/templates
resources/templates/api
@ -122,7 +122,8 @@ class BaseTemplateTest(BaseVitrageTempest):
|
||||
def _assert_add_result(self, result, status, message):
|
||||
self.assertThat(result, matchers.HasLength(1))
|
||||
self.assertEqual(status, result[0]['status'])
|
||||
self.assertEqual(message, result[0]['status details'])
|
||||
self.assertThat(result[0]['status details'],
|
||||
matchers.StartsWith(message))
|
||||
|
||||
def _compare_template_show(self, api_templates, cli_templates):
|
||||
self.assertThat(api_templates, IsNotEmpty(),
|
||||
|
@ -24,85 +24,115 @@ DEFINITION_TEMPLATE = 'v2_definition_template.yaml'
|
||||
NO_TYPE_TEMPLATE = 'v2_no_type_template.yaml'
|
||||
WITH_PARAMS_TEMPLATE = 'v2_with_params.yaml'
|
||||
|
||||
FAILED_TO_RESOLVE_PARAM = 'Failed to resolve parameter'
|
||||
ERROR_STATUS = 'ERROR'
|
||||
LOADING_STATUS = 'LOADING'
|
||||
TEMPLATE_VALIDATION_OK = 'Template validation is OK'
|
||||
|
||||
class TestTemplatesV2(BaseTemplateTest):
|
||||
|
||||
"""Template test class for Vitrage API tests."""
|
||||
FAILED_TO_RESOLVE_PARAM = 'Failed to resolve parameter'
|
||||
ERROR_STATUS = 'ERROR'
|
||||
LOADING_STATUS = 'LOADING'
|
||||
TEMPLATE_VALIDATION_OK = 'Template validation is OK'
|
||||
class TestTemplatesApis(BaseTemplateTest):
|
||||
|
||||
def tearDown(self):
|
||||
super(TestTemplatesApis, self).tearDown()
|
||||
self._delete_templates()
|
||||
|
||||
def _validate_no_type_templates(self, template_name):
|
||||
path = self.TEST_PATH + template_name
|
||||
validation = self.vitrage_client.template.validate(path=path)
|
||||
self._assert_validate_result(
|
||||
validation, path, negative=True, status_code='')
|
||||
|
||||
def _validate_standard_template(self, template_name):
|
||||
path = self.TEST_PATH + template_name
|
||||
validation = self.vitrage_client.template.validate(path=path)
|
||||
self._assert_validate_result(validation, path)
|
||||
|
||||
def _validate_definition_template(self, template_name):
|
||||
path = self.TEST_PATH + template_name
|
||||
validation = self.vitrage_client.template.validate(path=path)
|
||||
self._assert_validate_result(validation, path)
|
||||
|
||||
def _validate_with_missing_parameters(self, template_name):
|
||||
path = self.TEST_PATH + template_name
|
||||
validation = self.vitrage_client.template.validate(path=path)
|
||||
self._assert_validate_result(
|
||||
validation, path, negative=True, status_code=163)
|
||||
|
||||
def _validate_with_missing_parameter(self, template_name):
|
||||
path = self.TEST_PATH + template_name
|
||||
params = {'template_name': 'My template 1',
|
||||
'new_state': 'SUBOPTIMAL'}
|
||||
validation = \
|
||||
self.vitrage_client.template.validate(path=path, params=params)
|
||||
self._assert_validate_result(
|
||||
validation, path, negative=True, status_code=163)
|
||||
|
||||
def _validate_with_parameters(self, template_name):
|
||||
path = self.TEST_PATH + template_name
|
||||
params = {'template_name': 'My template 1',
|
||||
'alarm_type': 'Monitor1',
|
||||
'alarm_name': 'My alarm',
|
||||
'new_state': 'SUBOPTIMAL'}
|
||||
validation = \
|
||||
self.vitrage_client.template.validate(path=path, params=params)
|
||||
self._assert_validate_result(validation, path)
|
||||
|
||||
def _add_with_missing_parameters(self, template_name):
|
||||
path = self.TEST_PATH + template_name
|
||||
result = self.vitrage_client.template.add(path=path)
|
||||
self._assert_add_result(result, ERROR_STATUS, FAILED_TO_RESOLVE_PARAM)
|
||||
|
||||
def _add_with_missing_parameter(self, template_name):
|
||||
path = self.TEST_PATH + template_name
|
||||
params = {'template_name': 'My template 1',
|
||||
'new_state': 'SUBOPTIMAL'}
|
||||
result = self.vitrage_client.template.add(path=path, params=params)
|
||||
self._assert_add_result(result, ERROR_STATUS, FAILED_TO_RESOLVE_PARAM)
|
||||
|
||||
def _add_with_parameters(self, template_name):
|
||||
path = self.TEST_PATH + template_name
|
||||
params = {'template_name': 'My template 1',
|
||||
'alarm_type': 'Monitor1',
|
||||
'alarm_name': 'My alarm',
|
||||
'new_state': 'SUBOPTIMAL'}
|
||||
result = self.vitrage_client.template.add(path=path, params=params)
|
||||
self._assert_add_result(result, LOADING_STATUS, TEMPLATE_VALIDATION_OK)
|
||||
|
||||
def _delete_templates(self):
|
||||
templates = self.vitrage_client.template.list()
|
||||
template_ids = [template['uuid'] for template in templates]
|
||||
self.vitrage_client.template.delete(template_ids)
|
||||
|
||||
|
||||
class TestTemplatesV2(TestTemplatesApis):
|
||||
|
||||
def tearDown(self):
|
||||
super(TestTemplatesV2, self).tearDown()
|
||||
self._delete_templates()
|
||||
|
||||
def test_templates_validate_no_type_templates(self):
|
||||
path = self.TEST_PATH + NO_TYPE_TEMPLATE
|
||||
validation = self.vitrage_client.template.validate(path=path)
|
||||
self._assert_validate_result(
|
||||
validation, path, negative=True, status_code='')
|
||||
self._validate_no_type_templates(NO_TYPE_TEMPLATE)
|
||||
|
||||
def test_templates_validate_standard_template(self):
|
||||
path = self.TEST_PATH + EXECUTE_MISTRAL_TEMPLATE
|
||||
validation = self.vitrage_client.template.validate(path=path)
|
||||
self._assert_validate_result(validation, path)
|
||||
self._validate_standard_template(EXECUTE_MISTRAL_TEMPLATE)
|
||||
|
||||
def test_templates_validate_definition_template(self):
|
||||
path = self.TEST_PATH + DEFINITION_TEMPLATE
|
||||
validation = self.vitrage_client.template.validate(path=path)
|
||||
self._assert_validate_result(validation, path)
|
||||
self._validate_definition_template(DEFINITION_TEMPLATE)
|
||||
|
||||
def test_template_validate_with_missing_parameters(self):
|
||||
path = self.TEST_PATH + WITH_PARAMS_TEMPLATE
|
||||
validation = self.vitrage_client.template.validate(path=path)
|
||||
self._assert_validate_result(
|
||||
validation, path, negative=True, status_code=163)
|
||||
self._validate_with_missing_parameters(WITH_PARAMS_TEMPLATE)
|
||||
|
||||
def test_template_validate_with_missing_parameter(self):
|
||||
path = self.TEST_PATH + WITH_PARAMS_TEMPLATE
|
||||
params = {'template_name': 'My template 1',
|
||||
'new_state': 'SUBOPTIMAL'}
|
||||
validation = \
|
||||
self.vitrage_client.template.validate(path=path, params=params)
|
||||
self._assert_validate_result(
|
||||
validation, path, negative=True, status_code=163)
|
||||
self._validate_with_missing_parameter(WITH_PARAMS_TEMPLATE)
|
||||
|
||||
def test_template_validate_with_parameters(self):
|
||||
path = self.TEST_PATH + WITH_PARAMS_TEMPLATE
|
||||
params = {'template_name': 'My template 1',
|
||||
'alarm_type': 'Monitor1',
|
||||
'alarm_name': 'My alarm',
|
||||
'new_state': 'SUBOPTIMAL'}
|
||||
validation = \
|
||||
self.vitrage_client.template.validate(path=path, params=params)
|
||||
self._assert_validate_result(validation, path)
|
||||
self._validate_with_parameters(WITH_PARAMS_TEMPLATE)
|
||||
|
||||
def test_template_add_with_missing_parameters(self):
|
||||
path = self.TEST_PATH + WITH_PARAMS_TEMPLATE
|
||||
result = self.vitrage_client.template.add(path=path)
|
||||
self._assert_add_result(result, self.ERROR_STATUS,
|
||||
self.FAILED_TO_RESOLVE_PARAM)
|
||||
self._add_with_missing_parameters(WITH_PARAMS_TEMPLATE)
|
||||
|
||||
def test_template_add_with_missing_parameter(self):
|
||||
path = self.TEST_PATH + WITH_PARAMS_TEMPLATE
|
||||
params = {'template_name': 'My template 1',
|
||||
'new_state': 'SUBOPTIMAL'}
|
||||
result = self.vitrage_client.template.add(path=path, params=params)
|
||||
self._assert_add_result(result, self.ERROR_STATUS,
|
||||
self.FAILED_TO_RESOLVE_PARAM)
|
||||
self._add_with_missing_parameter(WITH_PARAMS_TEMPLATE)
|
||||
|
||||
def test_template_add_with_parameters(self):
|
||||
path = self.TEST_PATH + WITH_PARAMS_TEMPLATE
|
||||
params = {'template_name': 'My template 1',
|
||||
'alarm_type': 'Monitor1',
|
||||
'alarm_name': 'My alarm',
|
||||
'new_state': 'SUBOPTIMAL'}
|
||||
result = self.vitrage_client.template.add(path=path, params=params)
|
||||
self._assert_add_result(result, self.LOADING_STATUS,
|
||||
self.TEMPLATE_VALIDATION_OK)
|
||||
|
||||
def _delete_templates(self):
|
||||
templates = self.vitrage_client.template.list()
|
||||
template_ids = [template['uuid'] for template in templates]
|
||||
self.vitrage_client.template.delete(template_ids)
|
||||
self._add_with_parameters(WITH_PARAMS_TEMPLATE)
|
||||
|
@ -0,0 +1,43 @@
|
||||
# Copyright 2019 - Nokia
|
||||
#
|
||||
# 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 oslo_log import log as logging
|
||||
|
||||
from vitrage_tempest_plugin.tests.api.templates.test_template_v2 \
|
||||
import TestTemplatesApis
|
||||
|
||||
LOG = logging.getLogger(__name__)
|
||||
|
||||
WITH_PARAMS_TEMPLATE = 'v3_with_params.yaml'
|
||||
|
||||
|
||||
class TestTemplatesV3(TestTemplatesApis):
|
||||
|
||||
def test_template_validate_with_missing_parameters(self):
|
||||
self._validate_with_missing_parameters(WITH_PARAMS_TEMPLATE)
|
||||
|
||||
def test_template_validate_with_missing_parameter(self):
|
||||
self._validate_with_missing_parameter(WITH_PARAMS_TEMPLATE)
|
||||
|
||||
def test_template_validate_with_parameters(self):
|
||||
self._validate_with_parameters(WITH_PARAMS_TEMPLATE)
|
||||
|
||||
def test_template_add_with_missing_parameters(self):
|
||||
self._add_with_missing_parameters(WITH_PARAMS_TEMPLATE)
|
||||
|
||||
def test_template_add_with_missing_parameter(self):
|
||||
self._add_with_missing_parameter(WITH_PARAMS_TEMPLATE)
|
||||
|
||||
def test_template_add_with_parameters(self):
|
||||
self._add_with_parameters(WITH_PARAMS_TEMPLATE)
|
@ -0,0 +1,28 @@
|
||||
metadata:
|
||||
version: 3
|
||||
type: standard
|
||||
name: get_param(template_name)
|
||||
description: template with parameters
|
||||
parameters:
|
||||
template_name:
|
||||
description: the name of the template
|
||||
default: template_with_params
|
||||
alarm_type:
|
||||
description: the type of the alarm
|
||||
alarm_name:
|
||||
new_state:
|
||||
default: ERROR
|
||||
entities:
|
||||
alarm:
|
||||
category: ALARM
|
||||
type: get_param(alarm_type)
|
||||
name: get_param(alarm_name)
|
||||
host:
|
||||
category: RESOURCE
|
||||
type: nova.host
|
||||
scenarios:
|
||||
- condition: alarm [on] host
|
||||
actions:
|
||||
- set_state:
|
||||
state: get_param(new_state)
|
||||
target: host
|
Loading…
x
Reference in New Issue
Block a user