Exemple #1
0
    def test_create_failed_error_status(self):
        cfg.CONF.set_override('action_retry_limit', 0)

        snippet = template_format.parse(pool_template)
        self.stack = utils.parse_stack(snippet)
        pool_create_snippet = {
            'pool': {
                'subnet_id': 'sub123', 'protocol': u'HTTP',
                'name': utils.PhysName(self.stack.name, 'pool'),
                'lb_method': 'ROUND_ROBIN', 'admin_state_up': True}}
        vip_create_snippet = {
            'vip': {
                'protocol': u'HTTP', 'name': 'pool.vip',
                'admin_state_up': True, 'subnet_id': u'sub123',
                'pool_id': '5678', 'protocol_port': 80}}

        self.mock_create.return_value = {'pool': {'id': '5678'}}
        self.mock_create_vip.return_value = {'vip': {'id': 'xyz'}}
        self.mock_show.return_value = {
            'pool': {'status': 'ERROR', 'name': '5678'}}
        resource_defns = self.stack.t.resource_definitions(self.stack)
        rsrc = loadbalancer.Pool(
            'pool', resource_defns['pool'], self.stack)
        error = self.assertRaises(exception.ResourceFailure,
                                  scheduler.TaskRunner(rsrc.create))
        self.assertEqual(
            'ResourceInError: resources.pool: '
            'Went to status ERROR due to "error in pool"',
            six.text_type(error))
        self.assertEqual((rsrc.CREATE, rsrc.FAILED), rsrc.state)
        self.mock_create.assert_called_once_with(pool_create_snippet)
        self.mock_create_vip.assert_called_once_with(vip_create_snippet)
        self.mock_show.assert_called_once_with('5678')
Exemple #2
0
    def test_create_failed_unexpected_vip_status(self):
        snippet = template_format.parse(pool_template)
        self.stack = utils.parse_stack(snippet)
        self.mock_create.return_value = {'pool': {'id': '5678'}}
        self.mock_create_vip.return_value = {'vip': {'id': 'xyz'}}
        self.mock_show.return_value = {
            'pool': {'status': 'ACTIVE', 'name': '5678'}}
        self.mock_show_vip.return_value = {
            'vip': {'status': 'SOMETHING', 'name': 'xyz'}}
        pool_create_snippet = {
            'pool': {
                'subnet_id': 'sub123', 'protocol': u'HTTP',
                'name': utils.PhysName(self.stack.name, 'pool'),
                'lb_method': 'ROUND_ROBIN', 'admin_state_up': True}}
        vip_create_snippet = {
            'vip': {
                'protocol': u'HTTP', 'name': 'pool.vip',
                'admin_state_up': True, 'subnet_id': u'sub123',
                'pool_id': '5678', 'protocol_port': 80}}

        resource_defns = self.stack.t.resource_definitions(self.stack)
        rsrc = loadbalancer.Pool(
            'pool', resource_defns['pool'], self.stack)
        error = self.assertRaises(exception.ResourceFailure,
                                  scheduler.TaskRunner(rsrc.create))
        self.assertEqual('ResourceUnknownStatus: resources.pool: '
                         'Pool creation failed due to '
                         'vip - Unknown status SOMETHING due to "Unknown"',
                         six.text_type(error))
        self.assertEqual((rsrc.CREATE, rsrc.FAILED), rsrc.state)
        self.mock_create.assert_called_once_with(pool_create_snippet)
        self.mock_create_vip.assert_called_once_with(vip_create_snippet)
        self.mock_show.assert_called_once_with('5678')
        self.mock_show_vip.assert_called_once_with('xyz')
Exemple #3
0
    def test_create_with_session_persistence(self):
        snippet = template_format.parse(pool_with_session_persistence_template)
        self.stack = utils.parse_stack(snippet)
        self.mock_create.return_value = {'pool': {'id': '5678'}}
        self.mock_create_vip.return_value = {'vip': {'id': 'xyz'}}
        self.mock_show.return_value = {
            'pool': {'status': 'ACTIVE', 'name': '5678'}}
        self.mock_show_vip.return_value = {
            'vip': {'status': 'ACTIVE', 'name': 'xyz'}}
        pool_create_snippet = {
            'pool': {
                'subnet_id': 'sub123', 'protocol': u'HTTP',
                'name': utils.PhysName(self.stack.name, 'pool'),
                'lb_method': 'ROUND_ROBIN', 'admin_state_up': True}}
        vip_create_snippet = {
            'vip': {
                'protocol': u'HTTP', 'name': 'pool.vip',
                'admin_state_up': True, 'subnet_id': u'sub123',
                'pool_id': '5678', 'protocol_port': 80,
                'session_persistence': {
                    'type': 'APP_COOKIE',
                    'cookie_name': 'cookie'}}}

        resource_defns = self.stack.t.resource_definitions(self.stack)
        rsrc = loadbalancer.Pool(
            'pool', resource_defns['pool'], self.stack)
        scheduler.TaskRunner(rsrc.create)()
        self.assertEqual((rsrc.CREATE, rsrc.COMPLETE), rsrc.state)
        self.mock_create.assert_called_once_with(pool_create_snippet)
        self.mock_create_vip.assert_called_once_with(vip_create_snippet)
        self.mock_show.assert_called_once_with('5678')
        self.mock_show_vip.assert_called_once_with('xyz')
Exemple #4
0
    def create_pool(self, resolve_neutron=True, with_vip_subnet=False):
        if resolve_neutron:
            if with_vip_subnet:
                snippet = template_format.parse(pool_template_with_vip_subnet)
            else:
                snippet = template_format.parse(pool_template)
        else:
            snippet = template_format.parse(pool_template_deprecated)
        self.stack = utils.parse_stack(snippet)
        self.tmpl = snippet
        self.mock_create.return_value = {'pool': {'id': '5678'}}
        self.mock_show.return_value = {'pool': {'status': 'ACTIVE'}}
        self.mock_show_vip.return_value = {'vip': {'status': 'ACTIVE'}}
        self.pool_create_snippet = {
            'pool': {
                'subnet_id': 'sub123', 'protocol': u'HTTP',
                'name': utils.PhysName(self.stack.name, 'pool'),
                'lb_method': 'ROUND_ROBIN', 'admin_state_up': True}}
        self.vip_create_snippet = {
            'vip': {
                'protocol': u'HTTP', 'name': 'pool.vip',
                'admin_state_up': True, 'subnet_id': u'sub123',
                'pool_id': '5678', 'protocol_port': 80}}

        if with_vip_subnet:
            self.stub_SubnetConstraint_validate()
            self.vip_create_snippet['vip']['subnet_id'] = 'sub9999'
        self.mock_create_vip.return_value = {'vip': {'id': 'xyz'}}
        resource_defns = self.stack.t.resource_definitions(self.stack)
        return loadbalancer.Pool(
            'pool', resource_defns['pool'], self.stack)
Exemple #5
0
    def test_create_pool_with_provider(self):
        snippet = template_format.parse(pool_template_with_provider)
        self.stub_ProviderConstraint_validate()
        self.stack = utils.parse_stack(snippet)
        self.mock_create.return_value = {'pool': {'id': '5678'}}
        self.mock_create_vip.return_value = {'vip': {'id': 'xyz'}}
        self.mock_show.return_value = {
            'pool': {'status': 'ACTIVE', 'provider': 'test_prov'}}
        self.mock_show_vip.return_value = {
            'vip': {'status': 'ACTIVE', 'name': 'xyz'}}
        pool_create_snippet = {
            'pool': {
                'subnet_id': 'sub123', 'protocol': u'HTTP',
                'name': utils.PhysName(self.stack.name, 'pool'),
                'lb_method': 'ROUND_ROBIN', 'admin_state_up': True,
                'provider': 'test_prov'}}
        vip_create_snippet = {
            'vip': {
                'protocol': u'HTTP', 'name': 'pool.vip',
                'admin_state_up': True, 'subnet_id': u'sub123',
                'pool_id': '5678', 'protocol_port': 80}}

        resource_defns = self.stack.t.resource_definitions(self.stack)
        rsrc = loadbalancer.Pool(
            'pool', resource_defns['pool'], self.stack)

        scheduler.TaskRunner(rsrc.create)()
        self.assertEqual((rsrc.CREATE, rsrc.COMPLETE), rsrc.state)
        self.assertEqual("test_prov", rsrc.FnGetAtt("provider"))
        self.mock_create.assert_called_once_with(pool_create_snippet)
        self.mock_create_vip.assert_called_once_with(vip_create_snippet)
        self.mock_show_vip.assert_called_once_with('xyz')
        self.mock_show.assert_called_with('5678')
Exemple #6
0
    def test_create_failed(self):
        snippet = template_format.parse(pool_template)
        self.stack = utils.parse_stack(snippet)

        neutronV20.find_resourceid_by_name_or_id(
            mox.IsA(neutronclient.Client),
            'subnet',
            'sub123',
            cmd_resource=None,
        ).MultipleTimes().AndReturn('sub123')

        neutronclient.Client.create_pool({
            'pool': {
                'subnet_id': 'sub123', 'protocol': u'HTTP',
                'name': utils.PhysName(self.stack.name, 'pool'),
                'lb_method': 'ROUND_ROBIN', 'admin_state_up': True}}
        ).AndRaise(exceptions.NeutronClientException())
        self.m.ReplayAll()

        resource_defns = self.stack.t.resource_definitions(self.stack)
        rsrc = loadbalancer.Pool(
            'pool', resource_defns['pool'], self.stack)
        error = self.assertRaises(exception.ResourceFailure,
                                  scheduler.TaskRunner(rsrc.create))
        self.assertEqual(
            'NeutronClientException: resources.pool: '
            'An unknown exception occurred.',
            six.text_type(error))
        self.assertEqual((rsrc.CREATE, rsrc.FAILED), rsrc.state)
        self.m.VerifyAll()
 def test_create_pool_with_provider(self):
     neutronV20.find_resourceid_by_name_or_id(
         mox.IsA(neutronclient.Client),
         'subnet',
         'sub123'
     ).MultipleTimes().AndReturn('sub123')
     neutronclient.Client.create_pool({
         'pool': {
             'subnet_id': 'sub123', 'protocol': u'HTTP',
             'name': utils.PhysName('test_stack', 'pool'),
             'lb_method': 'ROUND_ROBIN', 'admin_state_up': True,
             'provider': 'test_prov'}}
     ).AndReturn({'pool': {'id': '5678'}})
     neutronclient.Client.create_vip({
         'vip': {
             'protocol': u'HTTP', 'name': 'pool.vip',
             'admin_state_up': True, 'subnet_id': u'sub123',
             'pool_id': '5678', 'protocol_port': 80}}
     ).AndReturn({'vip': {'id': 'xyz'}})
     neutronclient.Client.show_pool('5678').MultipleTimes().AndReturn(
         {'pool': {'status': 'ACTIVE', 'provider': 'test_prov'}})
     neutronclient.Client.show_vip('xyz').AndReturn(
         {'vip': {'status': 'ACTIVE'}})
     snippet = template_format.parse(pool_template_with_provider)
     self.stack = utils.parse_stack(snippet)
     resource_defns = self.stack.t.resource_definitions(self.stack)
     rsrc = loadbalancer.Pool(
         'pool', resource_defns['pool'], self.stack)
     self.m.ReplayAll()
     scheduler.TaskRunner(rsrc.create)()
     self.assertEqual((rsrc.CREATE, rsrc.COMPLETE), rsrc.state)
     self.assertEqual("test_prov", rsrc.FnGetAtt("provider"))
     self.m.VerifyAll()
Exemple #8
0
    def test_validation_not_failing_without_session_persistence(self):
        snippet = template_format.parse(pool_template)

        self.stack = utils.parse_stack(snippet)
        resource_defns = self.stack.t.resource_definitions(self.stack)
        resource = loadbalancer.Pool('pool', resource_defns['pool'],
                                     self.stack)
        self.stub_SubnetConstraint_validate()
        self.assertIsNone(resource.validate())
    def test_create_failed_unexpected_vip_status(self):
        snippet = template_format.parse(pool_template)
        self.stack = utils.parse_stack(snippet)

        neutronV20.find_resourceid_by_name_or_id(
            mox.IsA(neutronclient.Client),
            'subnet',
            'sub123',
            cmd_resource=None,
        ).MultipleTimes().AndReturn('sub123')
        neutronclient.Client.create_pool({
            'pool': {
                'subnet_id': 'sub123',
                'protocol': u'HTTP',
                'name': utils.PhysName(self.stack.name, 'pool'),
                'lb_method': 'ROUND_ROBIN',
                'admin_state_up': True
            }
        }).AndReturn({'pool': {
            'id': '5678'
        }})
        neutronclient.Client.create_vip({
            'vip': {
                'protocol': u'HTTP',
                'name': 'pool.vip',
                'admin_state_up': True,
                'subnet_id': u'sub123',
                'pool_id': '5678',
                'protocol_port': 80
            }
        }).AndReturn({'vip': {
            'id': 'xyz'
        }})
        neutronclient.Client.show_pool('5678').MultipleTimes().AndReturn(
            {'pool': {
                'status': 'ACTIVE'
            }})
        neutronclient.Client.show_vip('xyz').AndReturn(
            {'vip': {
                'status': 'SOMETHING',
                'name': 'xyz'
            }})

        resource_defns = self.stack.t.resource_definitions(self.stack)
        rsrc = loadbalancer.Pool('pool', resource_defns['pool'], self.stack)
        self.m.ReplayAll()
        error = self.assertRaises(exception.ResourceFailure,
                                  scheduler.TaskRunner(rsrc.create))
        self.assertEqual(
            'ResourceUnknownStatus: resources.pool: '
            'Pool creation failed due to '
            'vip - Unknown status SOMETHING due to "Unknown"',
            six.text_type(error))
        self.assertEqual((rsrc.CREATE, rsrc.FAILED), rsrc.state)
        self.m.VerifyAll()
    def create_pool(self, resolve_neutron=True, with_vip_subnet=False):
        neutronclient.Client.create_pool({
            'pool': {
                'subnet_id': 'sub123', 'protocol': u'HTTP',
                'name': utils.PhysName('test_stack', 'pool'),
                'lb_method': 'ROUND_ROBIN', 'admin_state_up': True}}
        ).AndReturn({'pool': {'id': '5678'}})
        neutronclient.Client.show_pool('5678').AndReturn(
            {'pool': {'status': 'ACTIVE'}})
        neutronclient.Client.show_vip('xyz').AndReturn(
            {'vip': {'status': 'ACTIVE'}})
        stvipvsn = {
            'vip': {
                'protocol': u'HTTP', 'name': 'pool.vip',
                'admin_state_up': True, 'subnet_id': u'sub9999',
                'pool_id': '5678', 'protocol_port': 80}
        }

        stvippsn = copy.deepcopy(stvipvsn)
        stvippsn['vip']['subnet_id'] = 'sub123'
        self.stub_SubnetConstraint_validate()

        if resolve_neutron and with_vip_subnet:
            neutronV20.find_resourceid_by_name_or_id(
                mox.IsA(neutronclient.Client),
                'subnet',
                'sub123'
            ).AndReturn('sub123')
            neutronV20.find_resourceid_by_name_or_id(
                mox.IsA(neutronclient.Client),
                'subnet',
                'sub9999'
            ).AndReturn('sub9999')
            snippet = template_format.parse(pool_template_with_vip_subnet)
            neutronclient.Client.create_vip(stvipvsn
                                            ).AndReturn({'vip': {'id': 'xyz'}})

        elif resolve_neutron and not with_vip_subnet:
            neutronV20.find_resourceid_by_name_or_id(
                mox.IsA(neutronclient.Client),
                'subnet',
                'sub123'
            ).AndReturn('sub123')
            snippet = template_format.parse(pool_template)
            neutronclient.Client.create_vip(stvippsn
                                            ).AndReturn({'vip': {'id': 'xyz'}})
        else:
            snippet = template_format.parse(pool_template_deprecated)
            neutronclient.Client.create_vip(stvippsn
                                            ).AndReturn({'vip': {'id': 'xyz'}})
        self.stack = utils.parse_stack(snippet)
        resource_defns = self.stack.t.resource_definitions(self.stack)
        return loadbalancer.Pool(
            'pool', resource_defns['pool'], self.stack)
    def test_create_failed_error_status(self):
        cfg.CONF.set_override('action_retry_limit', 0)

        snippet = template_format.parse(pool_template)
        self.stack = utils.parse_stack(snippet)

        neutronV20.find_resourceid_by_name_or_id(
            mox.IsA(neutronclient.Client),
            'subnet',
            'sub123',
            cmd_resource=None,
        ).MultipleTimes().AndReturn('sub123')

        neutronclient.Client.create_pool({
            'pool': {
                'subnet_id': 'sub123',
                'protocol': u'HTTP',
                'name': utils.PhysName(self.stack.name, 'pool'),
                'lb_method': 'ROUND_ROBIN',
                'admin_state_up': True
            }
        }).AndReturn({'pool': {
            'id': '5678'
        }})
        neutronclient.Client.create_vip({
            'vip': {
                'protocol': u'HTTP',
                'name': 'pool.vip',
                'admin_state_up': True,
                'subnet_id': u'sub123',
                'pool_id': '5678',
                'protocol_port': 80
            }
        }).AndReturn({'vip': {
            'id': 'xyz'
        }})
        neutronclient.Client.show_pool('5678').AndReturn(
            {'pool': {
                'status': 'ERROR',
                'name': '5678'
            }})

        resource_defns = self.stack.t.resource_definitions(self.stack)
        rsrc = loadbalancer.Pool('pool', resource_defns['pool'], self.stack)
        self.m.ReplayAll()
        error = self.assertRaises(exception.ResourceFailure,
                                  scheduler.TaskRunner(rsrc.create))
        self.assertEqual(
            'ResourceInError: resources.pool: '
            'Went to status ERROR due to "error in pool"',
            six.text_type(error))
        self.assertEqual((rsrc.CREATE, rsrc.FAILED), rsrc.state)
        self.m.VerifyAll()
    def test_create_with_session_persistence(self):
        snippet = template_format.parse(pool_with_session_persistence_template)
        self.stack = utils.parse_stack(snippet)

        neutronV20.find_resourceid_by_name_or_id(
            mox.IsA(neutronclient.Client),
            'subnet',
            'sub123',
            cmd_resource=None,
        ).MultipleTimes().AndReturn('sub123')
        neutronclient.Client.create_pool({
            'pool': {
                'subnet_id': 'sub123',
                'protocol': u'HTTP',
                'name': utils.PhysName(self.stack.name, 'pool'),
                'lb_method': 'ROUND_ROBIN',
                'admin_state_up': True
            }
        }).AndReturn({'pool': {
            'id': '5678'
        }})
        neutronclient.Client.create_vip({
            'vip': {
                'protocol': u'HTTP',
                'name': 'pool.vip',
                'admin_state_up': True,
                'subnet_id': u'sub123',
                'pool_id': '5678',
                'protocol_port': 80,
                'session_persistence': {
                    'type': 'APP_COOKIE',
                    'cookie_name': 'cookie'
                }
            }
        }).AndReturn({'vip': {
            'id': 'xyz'
        }})
        neutronclient.Client.show_pool('5678').AndReturn(
            {'pool': {
                'status': 'ACTIVE'
            }})
        neutronclient.Client.show_vip('xyz').AndReturn(
            {'vip': {
                'status': 'ACTIVE'
            }})

        resource_defns = self.stack.t.resource_definitions(self.stack)
        rsrc = loadbalancer.Pool('pool', resource_defns['pool'], self.stack)
        self.m.ReplayAll()
        scheduler.TaskRunner(rsrc.create)()
        self.assertEqual((rsrc.CREATE, rsrc.COMPLETE), rsrc.state)
        self.m.VerifyAll()
Exemple #13
0
    def test_properties_are_prepared_for_session_persistence(self):
        snippet = template_format.parse(pool_with_session_persistence_template)
        pool = snippet['resources']['pool']
        persistence = pool['properties']['vip']['session_persistence']

        # change persistence type to HTTP_COOKIE that not require cookie_name
        persistence['type'] = 'HTTP_COOKIE'
        del persistence['cookie_name']

        self.stack = utils.parse_stack(snippet)

        neutronV20.find_resourceid_by_name_or_id(
            mox.IsA(neutronclient.Client),
            'subnet',
            'sub123',
            cmd_resource=None,
        ).MultipleTimes().AndReturn('sub123')

        neutronclient.Client.create_pool({
            'pool': {
                'subnet_id': 'sub123', 'protocol': u'HTTP',
                'name': utils.PhysName(self.stack.name, 'pool'),
                'lb_method': 'ROUND_ROBIN', 'admin_state_up': True}}
        ).AndReturn({'pool': {'id': '5678'}})
        neutronclient.Client.create_vip({
            'vip': {
                'protocol': u'HTTP', 'name': 'pool.vip',
                'admin_state_up': True, 'subnet_id': u'sub123',
                'pool_id': '5678', 'protocol_port': 80,
                'session_persistence': {'type': 'HTTP_COOKIE'}}}
        ).AndReturn({'vip': {'id': 'xyz'}})
        neutronclient.Client.show_pool('5678').AndReturn(
            {'pool': {'status': 'ACTIVE'}})
        neutronclient.Client.show_vip('xyz').AndReturn(
            {'vip': {'status': 'ACTIVE'}})

        resource_defns = self.stack.t.resource_definitions(self.stack)
        resource = loadbalancer.Pool('pool', resource_defns['pool'],
                                     self.stack)

        # assert that properties contain cookie_name property with None value
        persistence = resource.properties['vip']['session_persistence']
        self.assertIn('cookie_name', persistence)
        self.assertIsNone(persistence['cookie_name'])

        self.m.ReplayAll()
        scheduler.TaskRunner(resource.create)()
        self.assertEqual((resource.CREATE, resource.COMPLETE), resource.state)
        self.m.VerifyAll()
Exemple #14
0
    def test_update_monitors(self):
        snippet = template_format.parse(pool_template)
        self.stack = utils.parse_stack(snippet)

        neutronV20.find_resourceid_by_name_or_id(
            mox.IsA(neutronclient.Client),
            'subnet',
            'sub123',
            cmd_resource=None,
        ).MultipleTimes().AndReturn('sub123')
        neutronclient.Client.create_pool({
            'pool': {
                'subnet_id': 'sub123', 'protocol': u'HTTP',
                'name': utils.PhysName(self.stack.name, 'pool'),
                'lb_method': 'ROUND_ROBIN', 'admin_state_up': True}}
        ).AndReturn({'pool': {'id': '5678'}})
        neutronclient.Client.associate_health_monitor(
            '5678', {'health_monitor': {'id': 'mon123'}})
        neutronclient.Client.associate_health_monitor(
            '5678', {'health_monitor': {'id': 'mon456'}})
        neutronclient.Client.create_vip({
            'vip': {
                'protocol': u'HTTP', 'name': 'pool.vip',
                'admin_state_up': True, 'subnet_id': u'sub123',
                'pool_id': '5678', 'protocol_port': 80}}
        ).AndReturn({'vip': {'id': 'xyz'}})
        neutronclient.Client.show_pool('5678').AndReturn(
            {'pool': {'status': 'ACTIVE'}})
        neutronclient.Client.show_vip('xyz').AndReturn(
            {'vip': {'status': 'ACTIVE'}})
        neutronclient.Client.disassociate_health_monitor(
            '5678', 'mon456')
        neutronclient.Client.associate_health_monitor(
            '5678', {'health_monitor': {'id': 'mon789'}})

        snippet['resources']['pool']['properties']['monitors'] = [
            'mon123', 'mon456']
        resource_defns = self.stack.t.resource_definitions(self.stack)
        rsrc = loadbalancer.Pool('pool', resource_defns['pool'], self.stack)
        self.m.ReplayAll()
        scheduler.TaskRunner(rsrc.create)()

        props = snippet['resources']['pool']['properties'].copy()
        props['monitors'] = ['mon123', 'mon789']
        update_template = rsrc.t.freeze(properties=props)
        scheduler.TaskRunner(rsrc.update, update_template)()

        self.m.VerifyAll()
Exemple #15
0
    def test_failing_validation_with_session_persistence(self):
        msg = _('Property cookie_name is required, when '
                'session_persistence type is set to APP_COOKIE.')
        snippet = template_format.parse(pool_with_session_persistence_template)
        pool = snippet['Resources']['pool']
        persistence = pool['Properties']['vip']['session_persistence']

        # When persistence type is set to APP_COOKIE, cookie_name is required
        persistence['type'] = 'APP_COOKIE'
        persistence['cookie_name'] = None

        stack = utils.parse_stack(snippet)
        resource_defns = stack.t.resource_definitions(stack)
        resource = loadbalancer.Pool('pool', resource_defns['pool'], stack)

        error = self.assertRaises(exception.StackValidationFailed,
                                  resource.validate)
        self.assertEqual(msg, six.text_type(error))
Exemple #16
0
    def test_update_monitors(self):
        snippet = template_format.parse(pool_template)
        self.stack = utils.parse_stack(snippet)
        self.mock_create.return_value = {'pool': {'id': '5678'}}
        self.mock_create_vip.return_value = {'vip': {'id': 'xyz'}}
        pool_create_snippet = {
            'pool': {
                'subnet_id': 'sub123', 'protocol': u'HTTP',
                'name': utils.PhysName(self.stack.name, 'pool'),
                'lb_method': 'ROUND_ROBIN', 'admin_state_up': True}}
        vip_create_snippet = {
            'vip': {
                'protocol': u'HTTP', 'name': 'pool.vip',
                'admin_state_up': True, 'subnet_id': u'sub123',
                'pool_id': '5678', 'protocol_port': 80}}

        self.mock_show.return_value = {
            'pool': {'status': 'ACTIVE', 'name': '5678'}}
        self.mock_show_vip.return_value = {
            'vip': {'status': 'ACTIVE', 'name': 'xyz'}}

        snippet['resources']['pool']['properties']['monitors'] = [
            'mon123', 'mon456']
        resource_defns = self.stack.t.resource_definitions(self.stack)
        rsrc = loadbalancer.Pool('pool', resource_defns['pool'], self.stack)
        scheduler.TaskRunner(rsrc.create)()

        props = snippet['resources']['pool']['properties'].copy()
        props['monitors'] = ['mon123', 'mon789']
        update_template = rsrc.t.freeze(properties=props)
        scheduler.TaskRunner(rsrc.update, update_template)()
        associate_calls = [mock.call('5678',
                                     {'health_monitor': {'id': 'mon123'}}),
                           mock.call('5678',
                                     {'health_monitor': {'id': 'mon456'}}),
                           mock.call('5678',
                                     {'health_monitor': {'id': 'mon789'}})]
        self.mock_associate.assert_has_calls(associate_calls)
        self.assertEqual(3, self.mock_associate.call_count)
        self.mock_disassociate.assert_called_once_with('5678', 'mon456')
        self.mock_create.assert_called_once_with(pool_create_snippet)
        self.mock_create_vip.assert_called_once_with(vip_create_snippet)
        self.mock_show.assert_called_once_with('5678')
        self.mock_show_vip.assert_called_once_with('xyz')
Exemple #17
0
    def test_properties_are_prepared_for_session_persistence(self):
        snippet = template_format.parse(pool_with_session_persistence_template)
        pool = snippet['resources']['pool']
        persistence = pool['properties']['vip']['session_persistence']

        # change persistence type to HTTP_COOKIE that not require cookie_name
        persistence['type'] = 'HTTP_COOKIE'
        del persistence['cookie_name']

        self.stack = utils.parse_stack(snippet)

        self.mock_create.return_value = {'pool': {'id': '5678'}}
        self.mock_create_vip.return_value = {'vip': {'id': 'xyz'}}
        self.mock_show.return_value = {
            'pool': {'status': 'ACTIVE', 'name': '5678'}}
        self.mock_show_vip.return_value = {
            'vip': {'status': 'ACTIVE', 'name': 'xyz'}}
        pool_create_snippet = {
            'pool': {
                'subnet_id': 'sub123', 'protocol': u'HTTP',
                'name': utils.PhysName(self.stack.name, 'pool'),
                'lb_method': 'ROUND_ROBIN', 'admin_state_up': True}}
        vip_create_snippet = {
            'vip': {
                'protocol': u'HTTP', 'name': 'pool.vip',
                'admin_state_up': True, 'subnet_id': u'sub123',
                'pool_id': '5678', 'protocol_port': 80,
                'session_persistence': {'type': 'HTTP_COOKIE'}}}

        resource_defns = self.stack.t.resource_definitions(self.stack)
        resource = loadbalancer.Pool('pool', resource_defns['pool'],
                                     self.stack)

        # assert that properties contain cookie_name property with None value
        persistence = resource.properties['vip']['session_persistence']
        self.assertIn('cookie_name', persistence)
        self.assertIsNone(persistence['cookie_name'])

        scheduler.TaskRunner(resource.create)()
        self.assertEqual((resource.CREATE, resource.COMPLETE), resource.state)
        self.mock_create.assert_called_once_with(pool_create_snippet)
        self.mock_create_vip.assert_called_once_with(vip_create_snippet)
        self.mock_show.assert_called_once_with('5678')
        self.mock_show_vip.assert_called_once_with('xyz')
Exemple #18
0
    def test_create_failed(self):
        snippet = template_format.parse(pool_template)
        self.stack = utils.parse_stack(snippet)
        pool_create_snippet = {
            'pool': {
                'subnet_id': 'sub123', 'protocol': u'HTTP',
                'name': utils.PhysName(self.stack.name, 'pool'),
                'lb_method': 'ROUND_ROBIN', 'admin_state_up': True}}

        self.mock_create.side_effect = exceptions.NeutronClientException()
        resource_defns = self.stack.t.resource_definitions(self.stack)
        rsrc = loadbalancer.Pool(
            'pool', resource_defns['pool'], self.stack)
        error = self.assertRaises(exception.ResourceFailure,
                                  scheduler.TaskRunner(rsrc.create))
        self.assertEqual(
            'NeutronClientException: resources.pool: '
            'An unknown exception occurred.',
            six.text_type(error))
        self.assertEqual((rsrc.CREATE, rsrc.FAILED), rsrc.state)
        self.mock_create.assert_called_once_with(pool_create_snippet)