Uncommented request processing, fixed tests
This commit is contained in:
parent
acd0cb07d6
commit
45b791e341
@ -178,10 +178,22 @@ def get_params(request):
|
||||
params['reason'] = int(params['reason'])
|
||||
if 'vm_uuids' in params:
|
||||
params['vm_uuids'] = params['vm_uuids'].split(',')
|
||||
print params
|
||||
return params
|
||||
|
||||
|
||||
@contract
|
||||
def get_remote_addr(request):
|
||||
""" Return the IP address of the client.
|
||||
|
||||
:param request: A Bottle request object.
|
||||
:type request: *
|
||||
|
||||
:return: The IP address of the remote client.
|
||||
:rtype: str
|
||||
"""
|
||||
return bottle.request.remote_addr
|
||||
|
||||
|
||||
@bottle.put('/')
|
||||
def service():
|
||||
params = get_params(bottle.request)
|
||||
@ -190,24 +202,24 @@ def service():
|
||||
state['state']['hashed_password'],
|
||||
params)
|
||||
log.info('Received a request from %s: %s',
|
||||
bottle.request.remote_addr,
|
||||
get_remote_addr(bottle.request),
|
||||
str(params))
|
||||
# try:
|
||||
# if params['reason'] == 0:
|
||||
# log.info('Processing an underload of a host %s', params['host'])
|
||||
# execute_underload(
|
||||
# state['config'],
|
||||
# state['state'],
|
||||
# params['host'])
|
||||
# else:
|
||||
# log.info('Processing an overload, VMs: %s', str(params['vm_uuids']))
|
||||
# execute_overload(
|
||||
# state['config'],
|
||||
# state['state'],
|
||||
# params['vm_uuids'])
|
||||
# except:
|
||||
# log.exception('Exception during request processing:')
|
||||
# raise
|
||||
try:
|
||||
if params['reason'] == 0:
|
||||
log.info('Processing an underload of a host %s', params['host'])
|
||||
execute_underload(
|
||||
state['config'],
|
||||
state['state'],
|
||||
params['host'])
|
||||
else:
|
||||
log.info('Processing an overload, VMs: %s', str(params['vm_uuids']))
|
||||
execute_overload(
|
||||
state['config'],
|
||||
state['state'],
|
||||
params['vm_uuids'])
|
||||
except:
|
||||
log.exception('Exception during request processing:')
|
||||
raise
|
||||
|
||||
|
||||
@bottle.route('/', method='ANY')
|
||||
|
@ -121,13 +121,13 @@ class GlobalManager(TestCase):
|
||||
'global_manager_port': 8080}
|
||||
paths = [manager.DEFAILT_CONFIG_PATH, manager.CONFIG_PATH]
|
||||
fields = manager.REQUIRED_FIELDS
|
||||
when(manager).read_and_validate_config(paths, fields). \
|
||||
and_return(config)#.once()
|
||||
expect(manager).read_and_validate_config(paths, fields). \
|
||||
and_return(config).once()
|
||||
expect(common).init_logging('dir', 'global-manager.log', 2).once()
|
||||
when(manager).init_state(config). \
|
||||
and_return(state)#.once()
|
||||
when(bottle).app().and_return(app)#.once()
|
||||
when(bottle).run(host='localhost', port=8080)#.once()
|
||||
expect(manager).init_state(config). \
|
||||
and_return(state).once()
|
||||
expect(bottle).app().and_return(app).once()
|
||||
expect(bottle).run(host='localhost', port=8080).once()
|
||||
manager.start()
|
||||
|
||||
def test_init_state(self):
|
||||
@ -165,26 +165,28 @@ class GlobalManager(TestCase):
|
||||
app.state = {'state': state,
|
||||
'config': config}
|
||||
|
||||
# with MockTransaction:
|
||||
# params = {'reason': 0,
|
||||
# 'host': 'host'}
|
||||
# expect(manager).get_params(Any).and_return(params).once()
|
||||
# expect(bottle).app().and_return(app).once()
|
||||
# expect(manager).validate_params('user', 'password', params). \
|
||||
# and_return(True).once()
|
||||
# expect(manager).execute_underload(config, state, 'host').once()
|
||||
# manager.service()
|
||||
with MockTransaction:
|
||||
params = {'reason': 0,
|
||||
'host': 'host'}
|
||||
expect(manager).get_params(Any).and_return(params).once()
|
||||
expect(manager).get_remote_addr(Any).and_return('addr').once()
|
||||
expect(bottle).app().and_return(app).once()
|
||||
expect(manager).validate_params('user', 'password', params). \
|
||||
and_return(True).once()
|
||||
expect(manager).execute_underload(config, state, 'host').once()
|
||||
manager.service()
|
||||
|
||||
# with MockTransaction:
|
||||
# params = {'reason': 1,
|
||||
# 'vm_uuids': 'vm_uuids'}
|
||||
# expect(manager).get_params(Any).and_return(params).once()
|
||||
# expect(bottle).app().and_return(app).once()
|
||||
# expect(manager).validate_params('user', 'password', params). \
|
||||
# and_return(True).once()
|
||||
# expect(manager).execute_overload(config, state, 'vm_uuids'). \
|
||||
# once()
|
||||
# manager.service()
|
||||
with MockTransaction:
|
||||
params = {'reason': 1,
|
||||
'vm_uuids': 'vm_uuids'}
|
||||
expect(manager).get_params(Any).and_return(params).once()
|
||||
expect(manager).get_remote_addr(Any).and_return('addr').once()
|
||||
expect(bottle).app().and_return(app).once()
|
||||
expect(manager).validate_params('user', 'password', params). \
|
||||
and_return(True).once()
|
||||
expect(manager).execute_overload(config, state, 'vm_uuids'). \
|
||||
once()
|
||||
manager.service()
|
||||
|
||||
@qc(20)
|
||||
def vms_by_host(
|
||||
|
Loading…
x
Reference in New Issue
Block a user