def test_sticky_get_all(self): values = get_fake_sticky('1') st1 = db_api.sticky_create(self.conf, values) st2 = db_api.sticky_create(self.conf, values) stickies = [dict(sticky.iteritems()) for sticky in db_api.sticky_get_all(self.conf)] self.assertEqual(stickies, [dict(st.iteritems()) for st in [st1, st2]])
def test_sticky_destroy_by_sf_id(self): values = get_fake_sticky('1') sticky_ref1 = db_api.sticky_create(self.conf, values) values = get_fake_sticky('2') sticky_ref2 = db_api.sticky_create(self.conf, values) db_api.sticky_destroy_by_sf_id(self.conf, '1') stickies = db_api.sticky_get_all(self.conf) self.assertEqual(len(stickies), 1)
def test_sticky_destroy_by_sf_id(self): values = get_fake_sticky("1") sticky_ref1 = db_api.sticky_create(self.conf, values) values = get_fake_sticky("2") sticky_ref2 = db_api.sticky_create(self.conf, values) db_api.sticky_destroy_by_sf_id(self.conf, "1") stickies = db_api.sticky_get_all(self.conf) self.assertEqual([dict(sticky_ref2.iteritems())], [dict(st.iteritems()) for st in stickies])
def test_sticky_get_all_by_sf_id(self): values = get_fake_sticky('1') st1 = db_api.sticky_create(self.conf, values) values = get_fake_sticky('2') st2 = db_api.sticky_create(self.conf, values) stickies1 = db_api.sticky_get_all_by_sf_id(self.conf, '1') stickies2 = db_api.sticky_get_all_by_sf_id(self.conf, '2') self.assertEqual(len(stickies1), 1) self.assertEqual(stickies1[0]['id'], st1['id']) self.assertEqual(len(stickies2), 1) self.assertEqual(stickies2[0]['id'], st2['id'])
def test_sticky_get_all_by_sf_id(self): values = get_fake_sticky('1') st1 = db_api.sticky_create(self.conf, values) values = get_fake_sticky('2') st2 = db_api.sticky_create(self.conf, values) stickies1 = db_api.sticky_get_all_by_sf_id(self.conf, '1') stickies2 = db_api.sticky_get_all_by_sf_id(self.conf, '2') self.assertEqual(len(stickies1), 1) self.assertEqual(dict(st1.iteritems()), dict(stickies1[0].iteritems())) self.assertEqual(len(stickies2), 1) self.assertEqual(dict(st2.iteritems()), dict(stickies2[0].iteritems()))
def test_sticky_create(self): values = get_fake_sticky('1') sticky_ref = db_api.sticky_create(self.conf, values) sticky = dict(sticky_ref.iteritems()) self.assertIsNotNone(sticky['id']) values['id'] = sticky['id'] self.assertEqual(sticky, values)
def test_sticky_destroy(self): values = get_fake_sticky('1') sticky = db_api.sticky_create(self.conf, values) db_api.sticky_destroy(self.conf, sticky['id']) with self.assertRaises(exception.StickyNotFound) as cm: db_api.sticky_get(self.conf, sticky['id']) err = cm.exception self.assertEqual(err.kwargs, {'sticky_id': sticky['id']})
def lb_add_sticky(conf, lb_id, st): logger.debug("Got new sticky description %s" % st) if st['persistenceType'] is None: return lb = db_api.loadbalancer_get(conf, lb_id) sf = db_api.serverfarm_get_all_by_lb_id(conf, lb_id)[0] values = db_api.sticky_pack_extra(st) values['sf_id'] = sf['id'] sticky_ref = db_api.sticky_create(conf, values) device_driver = drivers.get_device_driver(conf, lb['device_id']) with device_driver.request_context() as ctx: commands.add_sticky_to_loadbalancer(ctx, lb, sticky_ref) return db_api.unpack_extra(sticky_ref)
def test_sticky_update(self): values = get_fake_sticky('1') sticky_ref = db_api.sticky_create(self.conf, values) update = {'name': 'test', 'extra': {'cookieName': 'testHTTPCookie', 'enableInsert': True, 'browserExpire': False, 'offset': False, 'length': 1000, 'secondaryName': 'cookie'}} sticky_ref = db_api.sticky_update(self.conf, sticky_ref['id'], update) sticky = dict(sticky_ref.iteritems()) values.update(update) self.assertIsNotNone(sticky['id']) values['id'] = sticky['id'] self.assertEqual(sticky, values)
def test_sticky_update(self): values = get_fake_sticky("1") sticky_ref = db_api.sticky_create(self.conf, values) update = { "name": "test", "extra": { "cookieName": "testHTTPCookie", "enableInsert": True, "browserExpire": False, "offset": False, "length": 1000, "secondaryName": "cookie", }, } sticky_ref = db_api.sticky_update(self.conf, sticky_ref["id"], update) sticky = dict(sticky_ref.iteritems()) values.update(update) self.assertIsNotNone(sticky["id"]) values["id"] = sticky["id"] self.assertEqual(sticky, values)
def test_sticky_get(self): values = get_fake_sticky('1') sticky_ref1 = db_api.sticky_create(self.conf, values) sticky_ref2 = db_api.sticky_get(self.conf, sticky_ref1['id']) self.assertEqual(dict(sticky_ref1.iteritems()), dict(sticky_ref2.iteritems()))
def test_sticky_get_all(self): values = get_fake_sticky('1') db_api.sticky_create(self.conf, values) db_api.sticky_create(self.conf, values) stickies = db_api.sticky_get_all(self.conf) self.assertEqual(len(stickies), 2)
def test_sticky_get_with_tenant_fails(self): lb_id, sf_id = self._create_lb_and_sf('1', 'tenant1') sticky_ref = db_api.sticky_create(self.conf, get_fake_sticky(sf_id)) with self.assertRaises(exception.StickyNotFound): db_api.sticky_get(self.conf, sticky_ref['id'], tenant_id='tenant2')
def savetoDB(self): try: lb_ref = db_api.loadbalancer_update(self.conf, self.lb['id'], self.lb) except exception.LoadBalancerNotFound: lb_ref = db_api.loadbalancer_create(self.conf, self.lb) self.sf['lb_id'] = lb_ref['id'] try: sf_ref = db_api.serverfarm_update(self.conf, self.sf['id'], self.sf) except exception.ServerFarmNotFound: sf_ref = db_api.serverfarm_create(self.conf, self.sf) self.sf._predictor['sf_id'] = sf_ref['id'] try: db_api.predictor_update(self.conf, self.sf._predictor['id'], self.sf._predictor) except exception.PredictorNotFound: db_api.predictor_create(self.conf, self.sf._predictor) stickies = self.sf._sticky vips = [] self.sf = sf_ref self.sf._rservers = [] self.sf._probes = [] self.sf._sticky = [] for rs in self.rs: rs['sf_id'] = sf_ref['id'] try: rs_ref = db_api.server_update(self.conf, rs['id'], rs) except exception.ServerNotFound: rs_ref = db_api.server_create(self.conf, rs) self.sf._rservers.append(rs_ref) for pr in self.probes: pr['sf_id'] = sf_ref['id'] try: pr_ref = db_api.probe_update(self.conf, pr['id'], pr) except exception.ProbeNotFound: pr_ref = db_api.probe_create(self.conf, pr) self.sf._probes.append(pr_ref) for vip in self.vips: vip['sf_id'] = sf_ref['id'] vip['lb_id'] = lb_ref['id'] try: vip_ref = db_api.virtualserver_update(self.conf, vip['id'], vip) except exception.VirtualServerNotFound: vip_ref = db_api.virtualserver_create(self.conf, vip) vips.append(vip_ref) for st in stickies: st['sf_id'] = sf_ref['id'] try: st_ref = db_api.sticky_update(self.conf, st['id'], st) except exception.StickyNotFound: st_ref = db_api.sticky_create(self.conf, st) self.sf._sticky.append(st_ref) self.rs = self.sf._rservers self.probes = self.sf._probes self.vips = vips