Exemplo n.º 1
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))
Exemplo n.º 2
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)
Exemplo n.º 3
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']
                                                },
                                                metadata={},
                                                deletion_policy='Delete')

        group._lb_reload()
        mock_members.assert_called_once_with(group, exclude=[])
        lb.update.assert_called_once_with(expected)
    def test_timeout_exception(self):
        self.stub_ImageConstraint_validate()
        self.stub_KeypairConstraint_validate()
        self.stub_FlavorConstraint_validate()
        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._group_data().size = mock.Mock(return_value=12)
        group.get_size = mock.Mock(return_value=12)
        self.assertRaises(ValueError, group._replace, 10, 1, 14 * 60)
 def setUp(self):
     super(TestInstanceGroup, self).setUp()
     t = template_format.parse(inline_templates.as_template)
     self.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, self.stack)
    def setUp(self):
        super(InstanceGroupWithNestedStack, self).setUp()
        t = template_format.parse(inline_templates.as_template)
        self.stack = utils.parse_stack(t, params=inline_templates.as_params)
        self.create_launch_config(t, self.stack)
        wsg_props = self.stack['WebServerGroup'].t._properties
        self.defn = rsrc_defn.ResourceDefinition(
            'asg', 'OS::Heat::InstanceGroup',
            {'Size': 2, 'AvailabilityZones': ['zoneb'],
             'LaunchConfigurationName': wsg_props['LaunchConfigurationName']})
        self.group = instgrp.InstanceGroup('asg', self.defn, self.stack)

        self.group._lb_reload = mock.Mock()
        self.group.update_with_template = mock.Mock()
        self.group.check_update_complete = mock.Mock()
Exemplo n.º 7
0
    def setUp(self):
        super(ReplaceTest, self).setUp()
        t = template_format.parse(inline_templates.as_template)
        self.stack = utils.parse_stack(t, params=inline_templates.as_params)
        lc = self.create_launch_config(t, self.stack)
        lcid = lc.FnGetRefId()
        self.defn = rsrc_defn.ResourceDefinition(
            'asg', 'OS::Heat::InstanceGroup',
            {'Size': 2, 'AvailabilityZones': ['zoneb'],
             'LaunchConfigurationName': lcid})
        self.group = instgrp.InstanceGroup('asg', self.defn, self.stack)

        self.group._lb_reload = mock.Mock()
        self.group.update_with_template = mock.Mock()
        self.group.check_update_complete = mock.Mock()
        self.group._nested = self.get_fake_nested_stack()
Exemplo n.º 8
0
    def test_members(self):
        self.patchobject(neutron.NeutronClientPlugin,
                         'has_extension',
                         return_value=True)

        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)

        mocks = self.setup_mocks(group, ['aaaa', 'bbb'])
        expected = rsrc_defn.ResourceDefinition('ElasticLoadBalancer',
                                                'OS::Neutron::LoadBalancer', {
                                                    'protocol_port': 8080,
                                                    'members': ['aaaa', 'bbb']
                                                })

        group._lb_reload()
        self.check_mocks(group, mocks)
        lb.update.assert_called_once_with(expected)