From 0951799e7038c1428e82d5082fb49ae1818b00e4 Mon Sep 17 00:00:00 2001 From: Zane Bitter Date: Wed, 22 Jun 2016 20:40:46 +0200 Subject: [PATCH] Unit tests: add a test resource that takes multiple steps All of the current test resource types complete in a single step (i.e. have no check_*_complete() methods). In order to test longer-running resources, add a resource type in which the number of steps can be specified as a property. Change-Id: Ia894efa3207130a187032f2f667c096dee883aea --- heat/tests/common.py | 2 ++ heat/tests/generic_resource.py | 37 ++++++++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+) diff --git a/heat/tests/common.py b/heat/tests/common.py index 4dbd50370b..2e631ff60b 100644 --- a/heat/tests/common.py +++ b/heat/tests/common.py @@ -141,6 +141,8 @@ class HeatTestCase(testscenarios.WithScenarios, def register_test_resources(self): resource._register_class('GenericResourceType', generic_rsrc.GenericResource) + resource._register_class('MultiStepResourceType', + generic_rsrc.MultiStepResource) resource._register_class('ResWithShowAttrType', generic_rsrc.ResWithShowAttr) resource._register_class('SignalResourceType', diff --git a/heat/tests/generic_resource.py b/heat/tests/generic_resource.py index 889e856169..9032d5c692 100644 --- a/heat/tests/generic_resource.py +++ b/heat/tests/generic_resource.py @@ -78,6 +78,43 @@ class CancellableResource(GenericResource): self.type()) +class MultiStepResource(GenericResource): + properties_schema = { + 'create_steps': properties.Schema(properties.Schema.INTEGER, + default=2), + 'update_steps': properties.Schema(properties.Schema.INTEGER, + default=2, update_allowed=True), + 'delete_steps': properties.Schema(properties.Schema.INTEGER, + default=2, update_allowed=True), + } + + def handle_create(self): + super(MultiStepResource, self).handle_create() + return [None] * self.properties['create_steps'] + + def check_create_complete(self, cookie): + cookie.pop() + return not cookie + + def handle_update(self, json_snippet, tmpl_diff, prop_diff): + super(MultiStepResource, self).handle_update(json_snippet, + tmpl_diff, + prop_diff) + return [None] * self.properties['update_steps'] + + def check_update_complete(self, cookie): + cookie.pop() + return not cookie + + def handle_delete(self): + super(MultiStepResource, self).handle_delete() + return [None] * self.properties['delete_steps'] + + def check_delete_complete(self, cookie): + cookie.pop() + return not cookie + + class ResWithShowAttr(GenericResource): def _show_resource(self): return {'foo': self.name,