Split templates and tests in scenario tests

- Added subdirectory "templates" for storing all templates used in
  scenario tests.
- Added parameter sub_dir for method _load_template.
- Inline template was moved in templates directory from
  test_neutron_autoscaling.

Change-Id: I1acaf1ccc1466cf7ffc2e004eff486f49f4b5928
This commit is contained in:
Sergey Kraynev 2015-02-13 03:03:55 -05:00
parent 9a4a9f48fb
commit b6afc2b831
8 changed files with 67 additions and 64 deletions

View File

@ -179,9 +179,10 @@ class HeatIntegrationTest(testscenarios.WithScenarios,
LOG.debug('Console output for %s', server.id)
LOG.debug(server.get_console_output())
def _load_template(self, base_file, file_name):
def _load_template(self, base_file, file_name, sub_dir=None):
sub_dir = sub_dir or ''
filepath = os.path.join(os.path.dirname(os.path.realpath(base_file)),
file_name)
sub_dir, file_name)
with open(filepath) as f:
return f.read()

View File

@ -0,0 +1,55 @@
heat_template_version: 2014-10-16
description: Auto-scaling Test
parameters:
image_id:
type: string
label: Image ID
description: Image ID from configurations
capacity:
type: string
label: Capacity
description: Auto-scaling group desired capacity
fixed_subnet_name:
type: string
label: fixed subnetwork ID
description: subnetwork ID used for autoscaling
instance_type:
type: string
label: instance_type
description: type of instance to launch
resources:
test_pool:
type: OS::Neutron::Pool
properties:
description: Test Pool
lb_method: ROUND_ROBIN
name: test_pool
protocol: HTTP
subnet: { get_param: fixed_subnet_name }
vip: {
"description": "Test VIP",
"protocol_port": 80,
"name": "test_vip"
}
load_balancer:
type: OS::Neutron::LoadBalancer
properties:
protocol_port: 80
pool_id: { get_resource: test_pool }
launch_config:
type: AWS::AutoScaling::LaunchConfiguration
properties:
ImageId: { get_param: image_id }
InstanceType: { get_param: instance_type }
server_group:
type: AWS::AutoScaling::AutoScalingGroup
properties:
AvailabilityZones : ["nova"]
LaunchConfigurationName : { get_resource : launch_config }
MinSize : 1
MaxSize : 5
DesiredCapacity: { get_param: capacity }
LoadBalancerNames : [ { get_resource : load_balancer } ]

View File

@ -12,64 +12,6 @@
from heat_integrationtests.common import test
test_template = '''
heat_template_version: 2014-10-16
description: Auto-scaling Test
parameters:
image_id:
type: string
label: Image ID
description: Image ID from configurations
capacity:
type: string
label: Capacity
description: Auto-scaling group desired capacity
fixed_subnet_name:
type: string
label: fixed subnetwork ID
description: subnetwork ID used for autoscaling
instance_type:
type: string
label: instance_type
description: type of instance to launch
resources:
test_pool:
type: OS::Neutron::Pool
properties:
description: Test Pool
lb_method: ROUND_ROBIN
name: test_pool
protocol: HTTP
subnet: { get_param: fixed_subnet_name }
vip: {
"description": "Test VIP",
"protocol_port": 80,
"name": "test_vip"
}
load_balancer:
type: OS::Neutron::LoadBalancer
properties:
protocol_port: 80
pool_id: { get_resource: test_pool }
launch_config:
type: AWS::AutoScaling::LaunchConfiguration
properties:
ImageId: { get_param: image_id }
InstanceType: { get_param: instance_type }
server_group:
type: AWS::AutoScaling::AutoScalingGroup
properties:
AvailabilityZones : ["nova"]
LaunchConfigurationName : { get_resource : launch_config }
MinSize : 1
MaxSize : 5
DesiredCapacity: { get_param: capacity }
LoadBalancerNames : [ { get_resource : load_balancer } ]
'''
class NeutronAutoscalingTest(test.HeatIntegrationTest):
"""
@ -106,8 +48,11 @@ class NeutronAutoscalingTest(test.HeatIntegrationTest):
"fixed_subnet_name": self.conf.fixed_subnet_name,
}}
template = self._load_template(__file__,
'test_neutron_autoscaling.yaml',
'templates')
# Create stack
stack_id = self.stack_create(template=test_template,
stack_id = self.stack_create(template=template,
environment=env)
members = self.network_client.list_members()
@ -116,7 +61,7 @@ class NeutronAutoscalingTest(test.HeatIntegrationTest):
# Increase desired capacity and update the stack
env["parameters"]["capacity"] = "2"
self.update_stack(stack_id,
template=test_template,
template=template,
environment=env)
upd_members = self.network_client.list_members()

View File

@ -27,6 +27,7 @@ class CfnInitIntegrationTest(test.HeatIntegrationTest):
raise self.skipException("No image configured to test")
self.client = self.orchestration_client
self.template_name = 'test_server_cfn_init.yaml'
self.sub_dir = 'templates'
def assign_keypair(self):
self.stack_name = self._stack_rand_name()
@ -48,7 +49,8 @@ class CfnInitIntegrationTest(test.HeatIntegrationTest):
}
# create the stack
self.template = self._load_template(__file__, self.template_name)
self.template = self._load_template(__file__, self.template_name,
self.sub_dir)
self.client.stacks.create(
stack_name=self.stack_name,
template=self.template,

View File

@ -56,7 +56,7 @@ class VolumeBackupRestoreIntegrationTest(test.HeatIntegrationTest):
# TODO(shardy): refactor this into a generic base-class helper
net = self._get_default_network()
stack_name = self._stack_rand_name()
template = self._load_template(__file__, template_name)
template = self._load_template(__file__, template_name, 'templates')
parameters = {'key_name': self.keypair_name,
'instance_type': self.conf.instance_type,
'image_id': self.conf.minimal_image_ref,