~ubuntu-branches/ubuntu/trusty/heat/trusty-security

« back to all changes in this revision

Viewing changes to heat/tests/test_engine_service.py

  • Committer: Package Import Robot
  • Author(s): James Page
  • Date: 2013-10-12 16:53:03 UTC
  • mfrom: (1.1.6)
  • Revision ID: package-import@ubuntu.com-20131012165303-0sc41ujl3luuu56q
Tags: 2013.2~rc2-0ubuntu1
New upstream release candidate (LP: #1239156).

Show diffs side-by-side

added added

removed removed

Lines of Context:
24
24
 
25
25
from heat.engine import environment
26
26
from heat.common import exception
 
27
from heat.common import urlfetch
27
28
from heat.tests.v1_1 import fakes
28
29
import heat.rpc.api as engine_api
29
30
import heat.db.api as db_api
69
70
}
70
71
'''
71
72
 
 
73
nested_alarm_template = '''
 
74
HeatTemplateFormatVersion: '2012-12-12'
 
75
Resources:
 
76
  the_nested:
 
77
    Type: AWS::CloudFormation::Stack
 
78
    Properties:
 
79
      TemplateURL: https://server.test/alarm.template
 
80
'''
 
81
 
72
82
alarm_template = '''
73
83
{
74
84
  "AWSTemplateFormatVersion" : "2010-09-09",
941
951
 
942
952
        self.m.VerifyAll()
943
953
 
944
 
    @stack_context('service_event_list_deleted_resource_test_stack')
 
954
    @stack_context('event_list_deleted_stack')
945
955
    def test_stack_event_list_deleted_resource(self):
946
956
        rsrs._register_class('GenericResourceType',
947
957
                             generic_rsrc.GenericResource)
1341
1351
                          self.eng.describe_stack_resources,
1342
1352
                          self.ctx, non_exist_identifier, 'WebServer')
1343
1353
 
1344
 
    @stack_context('service_find_physical_resource_test_stack')
 
1354
    @stack_context('find_phys_res_stack')
1345
1355
    def test_find_physical_resource(self):
1346
1356
        resources = self.eng.describe_stack_resources(self.ctx,
1347
1357
                                                      self.stack.identifier(),
1533
1543
                         self.eng.stg[stack.id].threads)
1534
1544
        self.stack.delete()
1535
1545
 
 
1546
    def test_periodic_watch_task_created_nested(self):
 
1547
        self.m.StubOutWithMock(urlfetch, 'get')
 
1548
        urlfetch.get('https://server.test/alarm.template').MultipleTimes().\
 
1549
            AndReturn(alarm_template)
 
1550
        self.m.ReplayAll()
 
1551
 
 
1552
        stack = get_stack('period_watch_task_created_nested',
 
1553
                          utils.dummy_context(),
 
1554
                          nested_alarm_template)
 
1555
        self.stack = stack
 
1556
        self.m.ReplayAll()
 
1557
        stack.store()
 
1558
        stack.create()
 
1559
        self.eng.stg[stack.id] = DummyThreadGroup()
 
1560
        self.eng._start_watch_task(stack.id, self.ctx)
 
1561
        self.assertEqual([self.eng._periodic_watcher_task],
 
1562
                         self.eng.stg[stack.id].threads)
 
1563
        self.stack.delete()
 
1564
 
1536
1565
    @stack_context('service_show_watch_test_stack', False)
1537
1566
    @utils.wr_delete_after
1538
1567
    def test_show_watch(self):
1548
1577
                u'MetricName': u'ServiceFailure'}
1549
1578
        self.wr = []
1550
1579
        self.wr.append(watchrule.WatchRule(context=self.ctx,
1551
 
                                           watch_name='HttpFailureAlarm',
 
1580
                                           watch_name='show_watch_1',
1552
1581
                                           rule=rule,
1553
1582
                                           watch_data=[],
1554
1583
                                           stack_id=self.stack.id,
1556
1585
        self.wr[0].store()
1557
1586
 
1558
1587
        self.wr.append(watchrule.WatchRule(context=self.ctx,
1559
 
                                           watch_name='AnotherWatch',
 
1588
                                           watch_name='show_watch_2',
1560
1589
                                           rule=rule,
1561
1590
                                           watch_data=[],
1562
1591
                                           stack_id=self.stack.id,
1563
1592
                                           state='NORMAL'))
1564
1593
        self.wr[1].store()
1565
1594
 
1566
 
        # watch_name=None should return both watches
 
1595
        # watch_name=None should return all watches
1567
1596
        result = self.eng.show_watch(self.ctx, watch_name=None)
1568
 
        self.assertEqual(2, len(result))
1569
 
 
1570
 
        # watch_name="HttpFailureAlarm" should return only one
1571
 
        result = self.eng.show_watch(self.ctx, watch_name="HttpFailureAlarm")
1572
 
        self.assertEqual(1, len(result))
 
1597
        result_names = [r.get('name') for r in result]
 
1598
        self.assertIn('show_watch_1', result_names)
 
1599
        self.assertIn('show_watch_2', result_names)
 
1600
 
 
1601
        result = self.eng.show_watch(self.ctx, watch_name="show_watch_1")
 
1602
        self.assertEqual(1, len(result))
 
1603
        self.assertIn('name', result[0])
 
1604
        self.assertEqual('show_watch_1', result[0]['name'])
 
1605
 
 
1606
        result = self.eng.show_watch(self.ctx, watch_name="show_watch_2")
 
1607
        self.assertEqual(1, len(result))
 
1608
        self.assertIn('name', result[0])
 
1609
        self.assertEqual('show_watch_2', result[0]['name'])
1573
1610
 
1574
1611
        self.assertRaises(exception.WatchRuleNotFound,
1575
1612
                          self.eng.show_watch,
1593
1630
                u'Threshold': u'2',
1594
1631
                u'MetricName': u'ServiceFailure'}
1595
1632
        self.wr = watchrule.WatchRule(context=self.ctx,
1596
 
                                      watch_name='HttpFailureAlarm',
 
1633
                                      watch_name='show_watch_metric_1',
1597
1634
                                      rule=rule,
1598
1635
                                      watch_data=[],
1599
1636
                                      stack_id=self.stack.id,
1601
1638
        self.wr.store()
1602
1639
 
1603
1640
        # And add a metric datapoint
1604
 
        watch = db_api.watch_rule_get_by_name(self.ctx, "HttpFailureAlarm")
 
1641
        watch = db_api.watch_rule_get_by_name(self.ctx, 'show_watch_metric_1')
1605
1642
        self.assertNotEqual(watch, None)
1606
1643
        values = {'watch_rule_id': watch.id,
1607
1644
                  'data': {u'Namespace': u'system/linux',