Example #1
0
 def setUp(self):
     super(TcpTestCase, self).setUp()
     self.mox = mox.Mox()
     self.load_balancer_id = '123'
     self.uuid = 'lb-uuid-1'
     self.name = 'test-lb-1'
     self.user_id = 'a-fake-user-0'
     self.project_id = 'a-fake-project-0'
     self.protocol = 'tcp'
     self.listen_port = 11000
     self.instance_port = 22
     self.dns_prefix = 'abcdefghij'
     self.config_id = '123'
     self.instance_uuids = ['a-uuid', 'b-uuid', 'c-uuid']
     self.lb_values = {
         'uuid': self.uuid,
         'name': self.name,
         'user_id': self.user_id,
         'project_id': self.project_id,
         'protocol': self.protocol,
         'state': state.CREATING,
         'free': False,
         'dns_prefix': self.dns_prefix,
         'listen_port': self.listen_port,
         'instance_port': self.instance_port,
     }
     self.tmp = copy.deepcopy(self.lb_values)
     self.tmp['id'] = self.load_balancer_id
     self.lb_ref = models.LoadBalancer()
     self.lb_ref.update(self.tmp)
     self.config_values = {
         'load_balancer_id': self.load_balancer_id,
         'balancing_method': 'round_robin',
         'health_check_timeout_ms': 100,
         'health_check_interval_ms': 500,
         'health_check_target_path': '',
         'health_check_healthy_threshold': 3,
         'health_check_unhealthy_threshold': 3,
     }
     self.tmp = copy.deepcopy(self.config_values)
     self.tmp['id'] = self.config_id
     self.config_ref = models.LoadBalancerConfig()
     self.config_ref.update(self.tmp)
     self.create_kwargs = {
         'name': self.name,
         'user_id': self.user_id,
         'tenant_id': self.project_id,
         'protocol': self.protocol,
         'instance_port': self.instance_port,
         'instance_uuids': self.instance_uuids,
         'config': self.config_values,
     }
     self.delete_kwargs = {
         'user_id': self.user_id,
         'tenant_id': self.project_id,
         'protocol': self.protocol,
         'uuid': self.uuid,
     }
     self.ctxt = context.get_context(tenant_id=self.project_id)
Example #2
0
 def setUp(self):
     super(ApiTestCase, self).setUp()
     ##NOTE DISABLE Rabbitmq notification on test
     api.FLAGS.notification_enabled = False
     self.mox = mox.Mox()
     self.project_id = 'a-fake-project-0'
     self.protocol = 'proto-1'
     self.instance_uuids = ['a-uuid', 'b-uuid', 'c-uuid']
     self.http_server_names = ['www.abc.com', 'www.xyz.com']
     self.load_balancer_id = '123'
     self.config_id = '123'
     self.lb_uuid = 'lb-uuid-1'
     self.dns_prefix = 'abcdefghij'
     self.lb = {
         'name': 'test-lb-1',
         'user_id': 'a-fake-user-0',
         'project_id': self.project_id,
         'uuid': self.lb_uuid,
         'protocol': self.protocol,
         'dns_prefix': self.dns_prefix,
         'instance_port': 80,
     }
     self.tmp = copy.deepcopy(self.lb)
     self.tmp['id'] = self.load_balancer_id
     self.lb_ref = models.LoadBalancer()
     self.lb_ref.update(self.tmp)
     self.config = {
         'load_balancer_id': self.load_balancer_id,
         'balancing_method': 'round_robin',
         'health_check_timeout_ms': 100,
         'health_check_interval_ms': 500,
         'health_check_target_path': '/',
         'health_check_healthy_threshold': 0,
         'health_check_unhealthy_threshold': 0,
     }
     self.tmp = copy.deepcopy(self.config)
     self.tmp['id'] = self.config_id
     self.config_ref = models.LoadBalancerConfig()
     self.config_ref.update(self.tmp)
     self.kwargs = {
         'user_id': 'a-fake-user-0',
         'tenant_id': self.project_id,
         'protocol': self.protocol,
         'uuid': self.lb_uuid,
         'all_tenants': True,
     }
     self.all_domains = []
     for name in self.http_server_names:
         self.all_domains.append(models.LoadBalancerDomain(name=name))
     self.context = context.get_context(tenant_id=self.project_id)
Example #3
0
def client_routine(*args, **kwargs):
    LOG.info('nozzle client starting...')

    handler = kwargs['handler']
    broadcast = kwargs['broadcast']
    poller = zmq.Poller()
    poller.register(handler, zmq.POLLIN)

    while True:
        eventlet.sleep(0)
        socks = dict(poller.poll(100))
        if socks.get(handler) == zmq.POLLIN:
            msg_type, msg_uuid, msg_json = handler.recv_multipart()
            response = dict()
            cli_msg = {'code': 200, 'message': 'OK'}
            try:
                msg_body = jsonutils.loads(msg_json)
                LOG.debug("<<<<<<< client: %s" % msg_body)
                method = msg_body['method']
                args = msg_body['args']
                ctxt = context.get_context(**args)
                method_func = getattr(api, method)
                result = method_func(ctxt, **args)
                if result is not None:
                    response.update(result)
                # send request to worker
                try:
                    msg = api.get_msg_to_worker(ctxt, method, **args)
                    if msg is not None:
                        request_msg = jsonutils.dumps(msg)
                        LOG.debug(">>>>>>> worker: %s" % request_msg)
                        broadcast.send_multipart([msg_type, msg_uuid,
                                                  request_msg])
                except Exception:
                    pass
            except Exception as e:
                cli_msg['code'] = 500
                cli_msg['message'] = str(e)
                LOG.exception(cli_msg['message'])
            response.update(cli_msg)
            response_msg = jsonutils.dumps(response)
            LOG.debug(">>>>>>> client: %s" % response_msg)
            handler.send_multipart([msg_type, msg_uuid, response_msg])
Example #4
0
 def setUp(self):
     super(DBApiTestCase, self).setUp()
     engine = get_engine()
     self.connection = engine.connect()
     self.configs = dict()
     self.user_id = 'fake-user-0'
     self.tenant_id = 'fake-project-0'
     self.load_balancer_id = utils.str_uuid()
     self.lb = {
         'id': self.load_balancer_id,
         'user_id': self.user_id,
         'tenant_id': self.tenant_id,
         'free': False,
         'name': 'test-lb-1',
         'state': 'creating',
         'protocol': 'proto-1',
         'dns_prefix': 'abcdefg',
         'listen_port': 80,
         'instance_port': 80,
     }
     self.configs['lb'] = self.lb
     self.config = {
         'load_balancer_id': self.load_balancer_id,
         'balancing_method': 'round_robin',
         'health_check_timeout_ms': 5,
         'health_check_interval_ms': 500,
         'health_check_target_path': '/',
         'health_check_healthy_threshold': 5,
         'health_check_unhealthy_threshold': 3,
     }
     self.configs['config'] = self.config
     self.domain = {
         'load_balancer_id': self.load_balancer_id,
         'name': "www.abc.com",
     }
     self.configs['domains'] = [self.domain]
     self.association = {
         'load_balancer_id': self.load_balancer_id,
         'instance_uuid': 'inst-0',
         'instance_ip': '192.168.1.1',
     }
     self.configs['associations'] = [self.association]
     self.context = context.get_context(self.user_id, self.tenant_id)