Make worker JSON message case sensitive.

Fixes bug 1091316

It has been decided that we should not change the casing of the
JSON fields for the response that we send back to the API server.

Change-Id: I8c8e3d43cdc98520597381dc7b574a0575c1564f
This commit is contained in:
David Shrewsbury
2012-12-17 12:03:59 -05:00
parent 445496a276
commit 1146335192
2 changed files with 15 additions and 7 deletions

View File

@@ -24,14 +24,13 @@ class LBaaSController(object):
RESPONSE_SUCCESS = "PASS" RESPONSE_SUCCESS = "PASS"
ACTION_FIELD = 'hpcs_action' ACTION_FIELD = 'hpcs_action'
RESPONSE_FIELD = 'hpcs_response' RESPONSE_FIELD = 'hpcs_response'
LBLIST_FIELD = 'loadbalancers' LBLIST_FIELD = 'loadBalancers'
def __init__(self, logger, driver, json_msg): def __init__(self, logger, driver, json_msg):
self.logger = logger self.logger = logger
self.driver = driver self.driver = driver
self.logger.debug("Entered LBaaSController") self.logger.debug("Entered LBaaSController")
# Standardize case on JSON elements self.msg = json_msg
self.msg = dict((k.lower(), v) for k, v in json_msg.iteritems())
def run(self): def run(self):
""" """

View File

@@ -25,10 +25,19 @@ class TestWorkerController(unittest.TestCase):
self.assertIn(c.RESPONSE_FIELD, response) self.assertIn(c.RESPONSE_FIELD, response)
self.assertEquals(response[c.RESPONSE_FIELD], c.RESPONSE_FAILURE) self.assertEquals(response[c.RESPONSE_FIELD], c.RESPONSE_FAILURE)
def testCaseSensitive(self):
msg = {
c.ACTION_FIELD: 'UPDATE',
'LoAdBaLaNcErS': [ { 'protocol': 'http' } ]
}
controller = c(self.logger, self.driver, msg)
response = controller.run()
self.assertIn('badRequest', response)
def testUpdate(self): def testUpdate(self):
msg = { msg = {
c.ACTION_FIELD: 'UPDATE', c.ACTION_FIELD: 'UPDATE',
'loadBalancers': [ c.LBLIST_FIELD: [
{ {
'protocol': 'http', 'protocol': 'http',
'nodes': [ 'nodes': [
@@ -83,7 +92,7 @@ class TestWorkerController(unittest.TestCase):
def testCreateMissingNodes(self): def testCreateMissingNodes(self):
msg = { msg = {
c.ACTION_FIELD: 'UPDATE', c.ACTION_FIELD: 'UPDATE',
'loadBalancers': [ { 'protocol': 'http' } ] c.LBLIST_FIELD: [ { 'protocol': 'http' } ]
} }
controller = c(self.logger, self.driver, msg) controller = c(self.logger, self.driver, msg)
response = controller.run() response = controller.run()
@@ -92,7 +101,7 @@ class TestWorkerController(unittest.TestCase):
def testCreateMissingProto(self): def testCreateMissingProto(self):
msg = { msg = {
c.ACTION_FIELD: 'UPDATE', c.ACTION_FIELD: 'UPDATE',
'loadBalancers': [ c.LBLIST_FIELD: [
{ {
'nodes': [ 'nodes': [
{ {
@@ -110,7 +119,7 @@ class TestWorkerController(unittest.TestCase):
def testBadAlgorithm(self): def testBadAlgorithm(self):
msg = { msg = {
c.ACTION_FIELD: 'UPDATE', c.ACTION_FIELD: 'UPDATE',
'loadBalancers': [ c.LBLIST_FIELD: [
{ {
'protocol': 'http', 'protocol': 'http',
'algorithm': 'BOGUS', 'algorithm': 'BOGUS',