def test_update_load_balancer_http_servers(self): kwargs = copy.deepcopy(self.delete_kwargs) new_http_servers = ['www.abc.com', 'www.123.com'] kwargs['http_server_names'] = new_http_servers self.mox.StubOutWithMock(utils, 'get_all_domain_names') self.mox.StubOutWithMock(db, 'load_balancer_get_by_uuid') self.mox.StubOutWithMock(db, 'load_balancer_domain_create') self.mox.StubOutWithMock(db, 'load_balancer_domain_destroy') self.mox.StubOutWithMock(db, 'load_balancer_update_state') load_balancer_ref = self.lb_ref for index, domain in enumerate(self.http_server_names): domain_values = { 'id': index + 1, 'load_balancer_id': load_balancer_ref.id, 'name': domain, } domain_ref = models.LoadBalancerDomain() domain_ref.update(domain_values) load_balancer_ref.domains.append(domain_ref) db.load_balancer_get_by_uuid( self.ctxt, self.uuid).AndReturn(load_balancer_ref) utils.get_all_domain_names().AndReturn(list()) old_http_servers = map(lambda x: x['name'], load_balancer_ref.domains) need_deleted_domains = filter(lambda x: x not in new_http_servers, old_http_servers) need_created_domains = filter(lambda x: x not in old_http_servers, new_http_servers) for domain in load_balancer_ref.domains: if domain.name in need_deleted_domains: db.load_balancer_domain_destroy( self.ctxt, domain.id).AndReturn(None) for domain in need_created_domains: domain_values = { 'load_balancer_id': load_balancer_ref.id, 'name': domain, } db.load_balancer_domain_create( self.ctxt, domain_values).AndReturn(None) db.load_balancer_update_state( self.ctxt, self.uuid, state.UPDATING).AndReturn(None) self.mox.ReplayAll() r = http.update_load_balancer_http_servers(self.ctxt, **kwargs) self.mox.VerifyAll() self.assertRaises(r, None)
def test_create_load_balancer(self): def _raise_exception(*args): raise exception.LoadBalancerNotFoundByName( load_balancer_name=self.create_kwargs['name']) self.mox.StubOutWithMock(utils, 'get_all_domain_names') self.mox.StubOutWithMock(utils, 'str_uuid') self.mox.StubOutWithMock(utils, 'gen_dns_prefix') self.mox.StubOutWithMock(db, 'load_balancer_get_by_name') self.mox.StubOutWithMock(db, 'load_balancer_create') self.mox.StubOutWithMock(db, 'load_balancer_config_create') self.mox.StubOutWithMock(db, 'load_balancer_domain_create') self.mox.StubOutWithMock( db, 'load_balancer_instance_association_create') db.load_balancer_get_by_name( self.ctxt, self.create_kwargs['name']).WithSideEffects( _raise_exception).AndReturn(None) utils.get_all_domain_names().AndReturn(list()) utils.str_uuid().AndReturn(self.uuid) utils.gen_dns_prefix().AndReturn(self.dns_prefix) db.load_balancer_create(self.ctxt, self.lb).AndReturn(self.lb_ref) db.load_balancer_config_create( self.ctxt, self.config).AndReturn(self.config_ref) for index, domain in enumerate(self.http_server_names): domain_values = { 'load_balancer_id': self.load_balancer_id, 'name': domain, } self.tmp = copy.deepcopy(domain_values) self.tmp['id'] = index + 1 domain_ref = models.LoadBalancerDomain() domain_ref.update(self.tmp) db.load_balancer_domain_create( self.ctxt, domain_values).AndReturn(domain_ref) for uuid in self.create_kwargs['instance_uuids']: association_values = { 'load_balancer_id': self.load_balancer_id, 'instance_uuid': uuid, } association_ref = models.LoadBalancerInstanceAssociation() association_ref.update(association_values) db.load_balancer_instance_association_create( self.ctxt, association_values).AndReturn(association_ref) self.mox.ReplayAll() r = http.create_load_balancer(self.ctxt, **self.create_kwargs) self.mox.VerifyAll() self.assertEqual(r, {'data': {'uuid': self.uuid}})
'load_balancer_id': load_balancer_ref.id, 'balancing_method': config['balancing_method'], 'health_check_timeout_ms': config['health_check_timeout_ms'], 'health_check_interval_ms': config['health_check_interval_ms'], 'health_check_target_path': config['health_check_target_path'], 'health_check_healthy_threshold': 0, 'health_check_unhealthy_threshold': 0, } config_ref = db.load_balancer_config_create(context, config_values) # binding domains for domain in kwargs['http_server_names']: domain_values = { 'load_balancer_id': load_balancer_ref.id, 'name': domain, } domain_ref = db.load_balancer_domain_create(context, domain_values) inserted_domains.append(domain_ref.id) # binding instances for uuid in kwargs['instance_uuids']: association = { 'load_balancer_id': load_balancer_ref.id, 'instance_uuid': uuid, } db.load_balancer_instance_association_create(context, association) associated_instances.append(uuid) except Exception, exp: if load_balancer_ref: for instance_uuid in associated_instances: db.load_balancer_instance_association_destroy( context, load_balancer_ref.id, instance_uuid) for domain_id in inserted_domains: