Example #1
0
    def test_members(self):
        t = template_format.parse(inline_templates.as_template)
        t['Resources']['ElasticLoadBalancer'] = {
            'Type': 'OS::Neutron::LoadBalancer',
            'Properties': {
                'protocol_port': 8080,
            }
        }
        stack = utils.parse_stack(t)

        lb = stack['ElasticLoadBalancer']
        lb.update = mock.Mock(return_value=None)

        defn = rsrc_defn.ResourceDefinition(
            'asg', 'OS::Heat::InstanceGroup',
            {'Size': 2,
             'AvailabilityZones': ['zoneb'],
             "LaunchConfigurationName": "LaunchConfig",
             "LoadBalancerNames": ["ElasticLoadBalancer"]})
        group = instgrp.InstanceGroup('asg', defn, stack)

        mock_members = self.patchobject(grouputils, 'get_member_refids')
        mock_members.return_value = ['aaaa', 'bbb']
        expected = rsrc_defn.ResourceDefinition(
            'ElasticLoadBalancer',
            'OS::Neutron::LoadBalancer',
            {'protocol_port': 8080,
             'members': ['aaaa', 'bbb']})

        group._lb_reload()
        mock_members.assert_called_once_with(group, exclude=[])
        lb.update.assert_called_once_with(expected)
Example #2
0
    def test_lb_reload_invalid_resource(self):
        t = template_format.parse(inline_templates.as_template)
        t['Resources']['ElasticLoadBalancer'] = {
            'Type': 'AWS::EC2::Volume',
            'Properties': {
                'AvailabilityZone': 'nova'
            }
        }
        stack = utils.parse_stack(t)

        lb = stack['ElasticLoadBalancer']
        lb.update = mock.Mock(return_value=None)

        defn = rsrc_defn.ResourceDefinition(
            'asg', 'OS::Heat::InstanceGroup',
            {'Size': 2,
             'AvailabilityZones': ['zoneb'],
             "LaunchConfigurationName": "LaunchConfig",
             "LoadBalancerNames": ["ElasticLoadBalancer"]})
        group = instgrp.InstanceGroup('asg', defn, stack)

        mock_members = self.patchobject(grouputils, 'get_member_refids')
        mock_members.return_value = ['aaaa', 'bbb']

        error = self.assertRaises(exception.Error,
                                  group._lb_reload)
        self.assertEqual(
            "Unsupported resource 'ElasticLoadBalancer' in "
            "LoadBalancerNames",
            six.text_type(error))
Example #3
0
    def test_Instances(self):
        t = template_format.parse(inline_templates.as_template)
        stack = utils.parse_stack(t)
        lb = stack['ElasticLoadBalancer']
        lb.update = mock.Mock(return_value=None)

        defn = rsrc_defn.ResourceDefinition(
            'asg', 'OS::Heat::InstanceGroup',
            {'Size': 2,
             'AvailabilityZones': ['zoneb'],
             "LaunchConfigurationName": "LaunchConfig",
             "LoadBalancerNames": ["ElasticLoadBalancer"]})
        group = instgrp.InstanceGroup('asg', defn, stack)

        mock_members = self.patchobject(grouputils, 'get_member_refids')
        mock_members.return_value = ['aaaa', 'bbb']
        expected = rsrc_defn.ResourceDefinition(
            'ElasticLoadBalancer',
            'AWS::ElasticLoadBalancing::LoadBalancer',
            {'Instances': ['aaaa', 'bbb'],
             'Listeners': [{'InstancePort': u'80',
                            'LoadBalancerPort': u'80',
                            'Protocol': 'HTTP'}],
             'AvailabilityZones': ['nova']})

        group._lb_reload()
        mock_members.assert_called_once_with(group, exclude=[])
        lb.update.assert_called_once_with(expected)
Example #4
0
 def setUp(self):
     super(TestInstanceGroup, self).setUp()
     t = template_format.parse(inline_templates.as_template)
     stack = utils.parse_stack(t, params=inline_templates.as_params)
     self.defn = rsrc_defn.ResourceDefinition(
         'asg', 'OS::Heat::InstanceGroup',
         {'Size': 2, 'AvailabilityZones': ['zoneb'],
          'LaunchConfigurationName': 'config'})
     self.instance_group = instgrp.InstanceGroup('asg',
                                                 self.defn, stack)
    def test_timeout_exception(self):
        t = template_format.parse(ig_tmpl_with_updt_policy)
        stack = utils.parse_stack(t)

        defn = rsrc_defn.ResourceDefinition(
            'asg', 'OS::Heat::InstanceGroup', {
                'Size': 2,
                'AvailabilityZones': ['zoneb'],
                "LaunchConfigurationName": "LaunchConfig",
                "LoadBalancerNames": ["ElasticLoadBalancer"]
            })

        # the following test, effective_capacity is 12
        # batch_count = (effective_capacity + batch_size -1)//batch_size
        # = (12 + 2 - 1)//2 = 6
        # if (batch_count - 1)* pause_time > stack.time_out, to raise error
        # (6 - 1)*14*60 > 3600, so to raise error

        group = instgrp.InstanceGroup('asg', defn, stack)
        group.nested = mock.MagicMock(return_value=range(12))
        self.assertRaises(ValueError, group._replace, 10, 1, 14 * 60)