From c756e719899d9ff6885f9a98dbe9877f0192ce4a Mon Sep 17 00:00:00 2001 From: ricolin Date: Thu, 6 Apr 2017 22:50:10 +0800 Subject: [PATCH] Add test for basic resources as heat define test A basic scenario test for heat define. Which run some basic resources from core projects. This test should be one of the tests to define whether or not the environment can be defined as enable heat service. Change-Id: Ic3c8301ebc678c066a312d8e472fd4f66ed7298d --- scenario/templates/test_base_resources.yaml | 110 ++++++++++++++++++++ scenario/test_base_resources.py | 73 +++++++++++++ 2 files changed, 183 insertions(+) create mode 100644 scenario/templates/test_base_resources.yaml create mode 100644 scenario/test_base_resources.py diff --git a/scenario/templates/test_base_resources.yaml b/scenario/templates/test_base_resources.yaml new file mode 100644 index 0000000..bff6185 --- /dev/null +++ b/scenario/templates/test_base_resources.yaml @@ -0,0 +1,110 @@ +heat_template_version: 2014-10-16 + +description: > + This HOT template that just defines a single server. + Contains just base features to verify base heat support. + +parameters: + key_name: + type: string + default: key-01 + description: Name of an existing key pair to use for the server + flavor: + type: string + description: Flavor for the server to be created + default: m1.small + constraints: + - custom_constraint: nova.flavor + image: + type: string + description: Image ID or image name to use for the server + constraints: + - custom_constraint: glance.image + vol_size: + type: number + description: The size of the Cinder volume + default: 1 + private_net_name: + type: string + default: private-net-01 + description: Name of private network to be created + private_net_cidr: + type: string + default: 192.168.101.0/24 + description: Private network address (CIDR notation) + private_net_gateway: + type: string + default: 192.168.101.1 + description: Private network gateway address + private_net_pool_start: + type: string + default: 192.168.101.2 + description: Start of private network IP address allocation pool + private_net_pool_end: + type: string + default: 192.168.101.127 + description: End of private network IP address allocation pool + echo_foo: + default: fooooo + type: string + +resources: + private_net: + type: OS::Neutron::Net + properties: + name: { get_param: private_net_name } + + private_subnet: + type: OS::Neutron::Subnet + properties: + network_id: { get_resource: private_net } + cidr: { get_param: private_net_cidr } + gateway_ip: { get_param: private_net_gateway } + allocation_pools: + - start: { get_param: private_net_pool_start } + end: { get_param: private_net_pool_end } + + server_port: + type: OS::Neutron::Port + properties: + network_id: { get_resource: private_net } + fixed_ips: + - subnet_id: { get_resource: private_subnet } + + key: + type: OS::Nova::KeyPair + properties: + name: { get_param: key_name } + + server: + type: OS::Nova::Server + properties: + key_name: { get_resource: key } + image: { get_param: image } + flavor: { get_param: flavor } + networks: + - port: { get_resource: server_port } + user_data: + str_replace: + template: | + #!/bin/bash + echo echo_foo + params: + echo_foo: { get_param: echo_foo } + + vol: + type: OS::Cinder::Volume + properties: + size: { get_param: vol_size } + + vol_att: + type: OS::Cinder::VolumeAttachment + properties: + instance_uuid: { get_resource: server } + volume_id: { get_resource: vol } + mountpoint: /dev/vdb + +outputs: + server_networks: + description: The networks of the deployed server + value: { get_attr: [server, networks] } diff --git a/scenario/test_base_resources.py b/scenario/test_base_resources.py new file mode 100644 index 0000000..80194a0 --- /dev/null +++ b/scenario/test_base_resources.py @@ -0,0 +1,73 @@ +# 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 heat_integrationtests.common import test +from heat_integrationtests.scenario import scenario_base +from heatclient.common import template_utils + + +class BasicResourcesTest(scenario_base.ScenarioTestsBase): + + def setUp(self): + super(BasicResourcesTest, self).setUp() + if not self.conf.image_ref: + raise self.skipException("No image configured to test") + if not self.conf.instance_type: + raise self.skipException("No flavor configured to test") + + def check_stack(self): + sid = self.stack_identifier + # Check that stack were created + self._wait_for_stack_status(sid, 'CREATE_COMPLETE') + server_resource = self.client.resources.get(sid, 'server') + server_id = server_resource.physical_resource_id + server = self.compute_client.servers.get(server_id) + self.assertEqual(server.id, server_id) + + stack = self.client.stacks.get(sid) + + server_networks = self._stack_output(stack, 'server_networks') + self.assertIn(self.private_net_name, server_networks) + + def test_base_resources_integration(self): + """Define test for base resources interation from core porjects + + The alternative scenario is the following: + 1. Create a stack with basic resources from core projects. + 2. Check that all stack resources are created successfully. + 3. Wait for deployment. + 4. Check that stack was created. + 5. Check stack outputs. + """ + + self.private_net_name = test.rand_name('heat-net') + parameters = { + 'key_name': test.rand_name('heat-key'), + 'flavor': self.conf.instance_type, + 'image': self.conf.image_ref, + 'vol_size': self.conf.volume_size, + 'private_net_name': self.private_net_name + } + + env_files, env = template_utils.process_environment_and_files( + self.conf.boot_config_env) + + # Launch stack + self.stack_identifier = self.launch_stack( + template_name='test_base_resources.yaml', + parameters=parameters, + expected_status=None, + environment=env + ) + + # Check stack + self.check_stack()