Esempio n. 1
0
 def test_update_lb_0(self, *mocks):
     """No exception"""
     api.update_lb(self.conf, self.lb_id, self.lb_body, async=False)
     for mock in mocks:
         self.assertTrue(mock.called)
     mocks[3].assert_called_with(self.conf, self.lb_id,
             {'status': "ACTIVE"})
Esempio n. 2
0
 def test_update_lb_2(self, *mocks):
     """Exception"""
     mocks[4].return_value = Exception
     with self.assertRaises(Exception):
         api.update_lb(self.conf, self.lb_id, self.lb_body, async=False)
         mocks[3].assert_called_with(self.conf, self.lb_id,
             {'status': "ERROR"})
Esempio n. 3
0
 def test_update_lb_nothing(self,
                            mock_loadbalancer_get,
                            mock_loadbalancer_update,
                            *mock_funcs):
     lb_body = {'name': 'fakenewname'}
     mock_loadbalancer_get.return_value = {
         'id': self.lb_id,
         'device_id': 'fakedeviceid',
         'name': 'fakename',
         'algorithm': 'FAKE_ALGO0',
         'protocol': 'FAKE_PROTO0',
     }
     mock_loadbalancer_update.return_value = lb_ref = {
         'id': self.lb_id,
         'device_id': 'fakedeviceid',
         'name': 'fakenewname',
         'algorithm': 'FAKE_ALGO0',
         'protocol': 'FAKE_PROTO0',
     }
     sf_ref = {'id': 'fakesfid'}
     api.update_lb(self.conf, 'faketenantid', self.lb_id, lb_body,
                   async=False)
     mock_loadbalancer_get.assert_called_once_with(self.conf, self.lb_id,
                                                   tenant_id='faketenantid')
     for mock_func in mock_funcs:
         mock_func.assert_has_calls([])
 def test_update_lb_0(self, *mocks):
     """No exception"""
     resp = api.update_lb(self.conf, self.lb_id, self.lb_body,
                          async=False)
     for mock in mocks:
         self.assertTrue(mock.called)
     mocks[0].assert_called_once_with(self.conf,
                                      mocks[1].return_value['device_id'])
     mocks[1].assert_called_once_with(self.conf, self.lb_id)
     mocks[2].assert_called_once_with(mocks[1].return_value, self.lb_body)
     mocks[3].assert_called_with(self.conf, self.lb_id,
             {'status': "ACTIVE"})
     with mocks[0].return_value.request_context() as ctx:
         mocks[4].assert_called_once_with(ctx, mocks[1].return_value,
                                          mocks[3].return_value)
     self.assertEqual(resp, None)
Esempio n. 5
0
 def update(self, req, **args):
     logger.debug("Got update request. Request: %s", req)
     core_api.update_lb(self.conf, args['id'], args['body'])
     return {'loadbalancers': "OK"}
Esempio n. 6
0
 def test_update_lb_0(self, mock_driver, mock_api, mock_bal):
     """No exception, key.lower!='algorithm'"""
     api.update_lb(self.conf, self.lb_id, self.lb_body_0, async=False)
     self.assertFalse(mock_api.called)
Esempio n. 7
0
 def test_update_lb_2(self, mock_driver, mock_bal):
     """exception"""
     mock_driver.return_value = None
     api.update_lb(self.conf, self.lb_id, self.lb_body, async=False)
     self.assertTrue(mock_driver.called)
Esempio n. 8
0
 def update(self, req, id, body):
     LOG.debug("Got update request. Request: %s", req)
     core_api.update_lb(self.conf, id, body)
     return {'loadbalancer': {'id': id}}
Esempio n. 9
0
    def test_update_lb(self,
                       mock_get_device_driver,
                       mock_sticky_get_all_by_sf_id,
                       mock_probe_get_all_by_sf_id,
                       mock_server_get_all_by_sf_id,
                       mock_virtualserver_update,
                       mock_virtualserver_get_all_by_sf_id,
                       mock_predictor_update,
                       mock_predictor_get_by_sf_id,
                       mock_serverfarm_get_all_by_lb_id,
                       mock_loadbalancer_update,
                       mock_loadbalancer_get,
                       mock_create_loadbalancer,
                       mock_delete_loadbalancer,
                       mock_reschedule):
        lb_body = {'algorithm': 'FAKE_ALGO1', 'protocol': 'FAKE_PROTO1'}
        mock_loadbalancer_get.return_value = {
            'id': self.lb_id,
            'device_id': 'fakedeviceid',
            'name': 'fakename',
            'algorithm': 'FAKE_ALGO0',
            'protocol': 'FAKE_PROTO0',
        }
        mock_loadbalancer_update.return_value = lb_ref = {
            'id': self.lb_id,
            'device_id': 'fakedeviceid',
            'name': 'fakename',
            'algorithm': 'FAKE_ALGO1',
            'protocol': 'FAKE_PROTO1',
        }
        mock_reschedule.return_value = {'id': 'fakedeviceid'}
        sf_ref = {'id': 'fakesfid'}
        mock_serverfarm_get_all_by_lb_id.return_value = [sf_ref]
        predictor_ref = {'id': 'fakepredid'}
        mock_predictor_get_by_sf_id.return_value = predictor_ref
        vip_ref = {'id': 'fakevipid', 'extra': {'protocol': 'FAKE_PROTO0'}}
        mock_virtualserver_get_all_by_sf_id.return_value = [vip_ref]
        mock_servers = mock_server_get_all_by_sf_id.return_value
        mock_probes = mock_probe_get_all_by_sf_id.return_value
        mock_stickies = mock_sticky_get_all_by_sf_id.return_value
        mock_device_driver = mock_get_device_driver.return_value
        api.update_lb(self.conf, 'faketenantid', self.lb_id, lb_body,
                      async=False)
        mock_loadbalancer_get.assert_called_once_with(self.conf, self.lb_id,
                                                      tenant_id='faketenantid')
        mock_serverfarm_get_all_by_lb_id.assert_called_once_with(self.conf,
                                                                 self.lb_id)
        mock_predictor_get_by_sf_id.assert_called_once_with(self.conf,
                                                            sf_ref['id'])
        mock_predictor_update.assert_called_once_with(self.conf,
            predictor_ref['id'], {'type': 'FAKE_ALGO1'})
        mock_virtualserver_get_all_by_sf_id.assert_called_once_with(self.conf,
                                                            sf_ref['id'])
        mock_virtualserver_update.assert_called_once_with(self.conf,
            vip_ref['id'], {'id': 'fakevipid',
                            'extra': {'protocol': 'FAKE_PROTO1'}})
        for mock_func in [mock_server_get_all_by_sf_id,
                          mock_probe_get_all_by_sf_id,
                          mock_sticky_get_all_by_sf_id]:
            mock_func.assert_called_once_with(self.conf, sf_ref['id'])
        mock_get_device_driver.assert_called_once_with(self.conf,
                                                       lb_ref['device_id'])
        mock_loadbalancer_update.assert_has_calls([
            mock.call(self.conf, self.lb_id, lb_ref),
            mock.call(self.conf, self.lb_id, {'status': 'ACTIVE'}),
        ])

        # reschedule returns another device
        mock_reschedule.return_value = {'id': 'anotherdeviceid'}
        mock_loadbalancer_update.reset_mock()
        mock_loadbalancer_get.return_value['algorithm'] = 'FAKE_ALGO0'
        api.update_lb(self.conf, 'faketenantid', self.lb_id, lb_body,
                      async=False)
        mock_loadbalancer_update.assert_has_calls([
            mock.call(self.conf, self.lb_id, lb_ref),
            mock.call(self.conf, self.lb_id, {'device_id': 'anotherdeviceid'}),
            mock.call(self.conf, self.lb_id, {'status': 'ACTIVE'}),
        ])