Fix attempt to access not existed network group id key in input data
Code of NetworkGroupValidator.validate_network_group utilize 'id' key (id of the network group being operated on) so its absence will lead to KeyError exception when the data is not present in payload of the request, e.g. when user updates certain attributes of the network group using fuel-client. This patch fixes described problem. Change-Id: Ida494738ce5d61a6eec20bfa815923c9da6a7d56 Closes-Bug: #1500308
This commit is contained in:
parent
f7dac02379
commit
d04674c391
|
@ -52,7 +52,6 @@ class NetworkConfigurationValidator(BasicValidator):
|
|||
|
||||
@classmethod
|
||||
def validate_network_group(cls, ng_data, ng_db, cluster):
|
||||
net_id = ng_data['id']
|
||||
cidr = ng_data.get('cidr', ng_db.cidr)
|
||||
ip_ranges = ng_data.get(
|
||||
'ip_ranges',
|
||||
|
@ -78,14 +77,14 @@ class NetworkConfigurationValidator(BasicValidator):
|
|||
if not ip_ranges and notation == consts.NETWORK_NOTATION.ip_ranges:
|
||||
raise errors.InvalidData(
|
||||
"No IP ranges were specified for network "
|
||||
"{0}".format(net_id))
|
||||
"{0}".format(ng_db.id))
|
||||
|
||||
if notation in (consts.NETWORK_NOTATION.cidr,
|
||||
consts.NETWORK_NOTATION.ip_ranges):
|
||||
if not cidr and not ng_db.cidr:
|
||||
raise errors.InvalidData(
|
||||
"No CIDR was specified for network "
|
||||
"{0}".format(net_id))
|
||||
"{0}".format(ng_db.id))
|
||||
if cluster.is_locked and cls._check_for_ip_conflicts(
|
||||
ng_data, cluster, notation, use_gateway):
|
||||
|
||||
|
|
|
@ -327,6 +327,23 @@ class TestHandlers(BaseIntegrationTest):
|
|||
resp = self.env._update_network_group(new_ng, expect_errors=False)
|
||||
self.assertEqual(200, resp.status_code)
|
||||
|
||||
def test_update_doesnt_require_id_in_data(self):
|
||||
ng_id = self.env._create_network_group(name='test').json_body['id']
|
||||
|
||||
update_data = {'name': 'test2'}
|
||||
|
||||
update_resp = self.app.put(
|
||||
reverse(
|
||||
'NetworkGroupHandler',
|
||||
kwargs={'obj_id': ng_id}
|
||||
),
|
||||
jsonutils.dumps(update_data),
|
||||
headers=self.default_headers
|
||||
)
|
||||
|
||||
self.assertEqual(200, update_resp.status_code)
|
||||
self.assertEqual(update_resp.json_body['name'], 'test2')
|
||||
|
||||
def test_invalid_group_id_on_creation(self):
|
||||
resp = self.env._create_network_group(expect_errors=True, group_id=-1)
|
||||
self.assertEqual(400, resp.status_code)
|
||||
|
|
Loading…
Reference in New Issue