Fix heat ostf-test 'test_autoscaling'

-Autoscaling templates were updated
-Verification that second instance is loaded was changed
(before we counted common number of instances with F17 image and waited until
this number increase, but that's not correct, that's why now we count instances which
belong to test stack and wait for scale-up)

Change-Id: I6c7cecf2f38cb73ef05c6eaea2c958e0cebded5b
Closes-Bug: #1334346
This commit is contained in:
Anastasia Kuznetsova 2014-07-14 18:34:59 +04:00
parent 9863db951a
commit c1b60d4bce
5 changed files with 82 additions and 83 deletions

View File

@ -41,13 +41,13 @@ resources:
CPUAlarmHigh:
type: OS::Heat::CWLiteAlarm
properties:
AlarmDescription: Scale-up if CPU > 90% for 1 minute
AlarmDescription: Scale-up if CPU > 50% for 1 minute
MetricName: CPUUtilization
Namespace: system/linux
Statistic: Average
Period: '60'
Period: '20'
EvaluationPeriods: '1'
Threshold: '90'
Threshold: '50'
AlarmActions:
- {Ref: AScaleUpPolicy}
Dimensions:
@ -57,13 +57,13 @@ resources:
CPUAlarmLow:
type: OS::Heat::CWLiteAlarm
properties:
AlarmDescription: Scale-down if CPU < 50% for 1 minute
AlarmDescription: Scale-down if CPU < 30% for 1 minute
MetricName: CPUUtilization
Namespace: system/linux
Statistic: Average
Period: '60'
Period: '20'
EvaluationPeriods: '1'
Threshold: '50'
Threshold: '30'
AlarmActions:
- {Ref: AScaleDownPolicy}
Dimensions:
@ -79,14 +79,14 @@ resources:
/etc/cfn/cfn-credentials:
content:
Fn::Join:
- ""
- ''
- - AWSAccessKeyId=
- {Ref: AKeys}
- '
'
- AWSSecretKey=
- Fn::GetAtt: [AKeys, SecretAccessKey]
- get_attr: [AKeys, SecretAccessKey]
- '
'
@ -122,22 +122,12 @@ resources:
KeyName: {Ref: KeyName}
SecurityGroups: [{Ref: SecurityGroup}]
UserData:
Fn::Base64:
Fn::Join:
- ''
- - '#!/bin/bash -v
'
- '/opt/aws/bin/cfn-init -s '
- ' -r LaunchConfig '
- '
'
- '# install crontab
'
- 'crontab /tmp/stats-crontab.txt
'
- 'touch /tmp/vm_ready.txt
'
str_replace:
template: |
#!/bin/bash -v
/opt/aws/bin/cfn-init -s $stack_id -r LaunchConfig
# install crontab
crontab /tmp/stats-crontab.txt
touch /tmp/vm_ready.txt
params:
$stack_id: {get_param: "OS::stack_id"}

View File

@ -5,16 +5,12 @@ parameters:
type: string
ImageId:
type: string
network:
type: string
Subnet:
type: string
KeyName:
type: string
SecurityGroup:
type: string
network:
type: string
resources:
CfnUser:
type: AWS::IAM::User
@ -47,13 +43,13 @@ resources:
CPUAlarmHigh:
type: OS::Heat::CWLiteAlarm
properties:
AlarmDescription: Scale-up if CPU > 90% for 1 minute
AlarmDescription: Scale-up if CPU > 50% for 1 minute
MetricName: CPUUtilization
Namespace: system/linux
Statistic: Average
Period: '60'
Period: '20'
EvaluationPeriods: '1'
Threshold: '90'
Threshold: '50'
AlarmActions:
- {Ref: AScaleUpPolicy}
Dimensions:
@ -63,13 +59,13 @@ resources:
CPUAlarmLow:
type: OS::Heat::CWLiteAlarm
properties:
AlarmDescription: Scale-down if CPU < 50% for 1 minute
AlarmDescription: Scale-down if CPU < 30% for 1 minute
MetricName: CPUUtilization
Namespace: system/linux
Statistic: Average
Period: '60'
Period: '20'
EvaluationPeriods: '1'
Threshold: '50'
Threshold: '30'
AlarmActions:
- {Ref: AScaleDownPolicy}
Dimensions:
@ -87,10 +83,15 @@ resources:
Fn::Join:
- ''
- - AWSAccessKeyId=
- '{Ref: AKeys}'
-
- {Ref: AKeys}
- '
'
- AWSSecretKey=
- 'Fn::GetAtt: [AKeys, SecretAccessKey]'
- get_attr: [AKeys, SecretAccessKey]
- '
'
mode: '000400'
owner: root
group: root
@ -98,15 +99,22 @@ resources:
content:
Fn::Join:
- ''
- - MAIL=""
-
- '* * * * * /opt/aws/bin/cfn-push-stats --watch'
- '{Ref: CPUAlarmHigh}'
- '--cpu-util'
-
- '* * * * * /opt/aws/bin/cfn-push-stats --watch'
- '{Ref: CPUAlarmLow}'
- ' --cpu-util'
- - 'MAIL=""
'
- '
'
- '* * * * * /opt/aws/bin/cfn-push-stats --watch '
- {Ref: CPUAlarmHigh}
- ' --cpu-util
'
- '* * * * * /opt/aws/bin/cfn-push-stats --watch '
- {Ref: CPUAlarmLow}
- ' --cpu-util
'
mode: '000600'
owner: root
group: root
@ -116,9 +124,12 @@ resources:
KeyName: {Ref: KeyName}
SecurityGroups: [{Ref: SecurityGroup}]
UserData:
Fn::Base64: |
#!/bin/bash -v
/opt/aws/bin/cfn-init -s -r LaunchConfig
# install crontab
crontab /tmp/stats-crontab.txt
touch /tmp/vm_ready.txt
str_replace:
template: |
#!/bin/bash -v
/opt/aws/bin/cfn-init -s $stack_id -r LaunchConfig
# install crontab
crontab /tmp/stats-crontab.txt
touch /tmp/vm_ready.txt
params:
$stack_id: {get_param: "OS::stack_id"}

View File

@ -132,29 +132,23 @@ class HeatBaseTest(fuel_health.nmanager.NovaNetworkScenarioTest,
return image_name in [i.name for i in
self.compute_client.images.list()]
def _find_heat_image_id(self, image_name):
image_id = [i.id for i in self.compute_client.images.list()
if i.name == image_name]
return image_id
def _wait_for_autoscaling(self, exp_count,
timeout, interval):
img_id = self._find_heat_image_id('F17-x86_64-cfntools')[0]
timeout, interval, reduced_stack_name):
LOG.info('expected count is {0}'.format(exp_count))
def count_instances():
def count_instances(reduced_stack_name):
res = []
_list = self.compute_client.servers.list()
for i in _list:
details = self.compute_client.servers.get(server=i)
LOG.info('instance details is {0}'.format(details.image))
if details.image['id'] == img_id:
res.append(i)
for server in _list:
LOG.info('instance name is {0}'.format(server.name))
if server.name.startswith(reduced_stack_name):
res.append(server)
LOG.info('!!! current res is {0}'.format(res))
return len(res) == exp_count
return fuel_health.test.call_until_true(
count_instances, timeout, interval)
count_instances, timeout, interval, reduced_stack_name)
def _wait_for_cloudinit(self, conn_string, timeout, interval):
"""

View File

@ -43,7 +43,7 @@ class BaseTestCase(unittest2.TestCase,
cls.config = config.FuelConfig()
def call_until_true(func, duration, sleep_for):
def call_until_true(func, duration, sleep_for, arg=None):
"""
Call the given function until it returns True (and return True) or
until the specified duration (in seconds) elapses (and return
@ -58,7 +58,10 @@ def call_until_true(func, duration, sleep_for):
now = time.time()
timeout = now + duration
while now < timeout:
if func():
if arg:
if func(arg):
return True
elif func():
return True
LOG.debug("Sleeping for %d seconds", sleep_for)
time.sleep(sleep_for)

View File

@ -260,7 +260,6 @@ class HeatSmokeTests(heatmanager.HeatBaseTest):
}
if 'neutron' in self.config.network.network_provider:
parameters['Subnet'] = self._get_subnet_id()
parameters['network'] = self._get_net_uuid()[0]
template = self._load_template('heat_autoscaling_template.yaml')
else:
template = self._load_template('heat_autoscale_nova.yaml')
@ -277,17 +276,19 @@ class HeatSmokeTests(heatmanager.HeatBaseTest):
"stack status becoming 'CREATE_COMPLETE'",
stack.id, 'CREATE_COMPLETE', 600, 15)
reduced_stack_name = '{0}-{1}'.format(
stack.stack_name[:2], stack.stack_name[-4:])
# find just created instance
instance_list = self.compute_client.servers.list()
LOG.info('servers list is {0}'.format(instance_list))
img_id = self._find_heat_image_id('F17-x86_64-cfntools')[0]
LOG.info('expected img_id is {0}'.format(img_id))
LOG.info('expected img_name starts with {0}'.format(
reduced_stack_name))
for i in instance_list:
details = self.compute_client.servers.get(server=i)
LOG.info('instance details is {0}'.format(details.image))
if details.image['id'] == img_id:
self.instance.append(i)
for server in instance_list:
LOG.info('instance name is {0}'.format(server.name))
if server.name.startswith(reduced_stack_name):
self.instance.append(server)
if not self.instance:
self.fail("Failed step: 7 Instance for the {0} stack "
@ -315,23 +316,23 @@ class HeatSmokeTests(heatmanager.HeatBaseTest):
"loading VM CPU",
vm_connection)
self.verify(180,
self.verify(300,
self._wait_for_autoscaling, 12,
"Stack failed to launch the 2nd instance "
"per autoscaling alarm.",
"launching the new instance per autoscaling alarm",
len(instance_list) + 1, 180, 10)
len(self.instance) + 1, 300, 10, reduced_stack_name)
self.verify(180, self._release_vm_cpu, 13,
"Cannot kill the process on VM to turn CPU load off.",
"turning off VM CPU load",
vm_connection)
self.verify(500, self._wait_for_autoscaling, 14,
self.verify(300, self._wait_for_autoscaling, 14,
"Stack failed to terminate the 2nd instance "
"per autoscaling alarm.",
"terminating the 2nd instance per autoscaling alarm",
len(instance_list), 300, 10)
len(self.instance), 300, 10, reduced_stack_name)
# delete private key file
self.verify(10, self._delete_key_file, 15,