Return variables in response on Network Device create
If a user creates a network device and also passes variables during the create process the variables get created but are not present in the response. This patch fixes that by adding variables in response for a create calls on network devices when variable was in the create request body. Change-Id: Id9818d5c30a9a0c17039191335f1b75525003a3d Closes-Bug: 1675087
This commit is contained in:
parent
6eaa61ccc0
commit
1e1e8da171
|
@ -105,6 +105,10 @@ class NetworkDevices(base.Resource):
|
|||
json = util.copy_project_id_into_json(context, request_data)
|
||||
obj = dbapi.network_devices_create(context, json)
|
||||
device = jsonutils.to_primitive(obj)
|
||||
if 'variables' in json:
|
||||
device["variables"] = jsonutils.to_primitive(obj.variables)
|
||||
else:
|
||||
device["variables"] = {}
|
||||
|
||||
utils.add_up_link(context, device)
|
||||
|
||||
|
|
|
@ -173,7 +173,7 @@ NETWORKS_LIST2 = [NETWORK1, NETWORK2, NETWORK3]
|
|||
|
||||
|
||||
class NetworkDevice():
|
||||
def __init__(self, id, name, project_id, region_id, device_type,
|
||||
def __init__(self, id, name, project_id, cloud_id, region_id, device_type,
|
||||
ip_address, variables, labels=None, cell_id=None,
|
||||
parent_id=None):
|
||||
self.name = name
|
||||
|
@ -185,6 +185,7 @@ class NetworkDevice():
|
|||
self.variables = variables
|
||||
self.resolved = copy.copy(variables)
|
||||
self.labels = labels
|
||||
self.cloud_id = cloud_id
|
||||
self.cell_id = cell_id
|
||||
self.parent_id = parent_id
|
||||
|
||||
|
@ -192,10 +193,12 @@ class NetworkDevice():
|
|||
return iter(self.__dict__.items())
|
||||
|
||||
|
||||
NETWORK_DEVICE1 = NetworkDevice(1, "NetDevices1", 1, 1, "Server", "10.10.0.1",
|
||||
NETWORK_DEVICE1 = NetworkDevice(1, "NetDevices1", 1, 1, 1, "Server",
|
||||
"10.10.0.1",
|
||||
{"key1": "value1", "key2": "value2"},
|
||||
labels=["a", "b"])
|
||||
NETWORK_DEVICE2 = NetworkDevice(2, "NetDevices2", 1, 2, "Server", "10.10.0.2",
|
||||
NETWORK_DEVICE2 = NetworkDevice(2, "NetDevices2", 1, 1, 2, "Server",
|
||||
"10.10.0.2",
|
||||
{"key1": "value1", "key2": "value2"},
|
||||
labels=["a", "b"])
|
||||
|
||||
|
|
|
@ -1592,6 +1592,25 @@ class APIV1NetworkDevicesTest(APIV1Test):
|
|||
"http://localhost/v1/network-devices/1"
|
||||
)
|
||||
|
||||
@mock.patch.object(dbapi, 'network_devices_create')
|
||||
def test_create_network_devices_returns_netdev_obj(self, mock_devices):
|
||||
mock_devices.return_value = fake_resources.NETWORK_DEVICE1
|
||||
data = {'name': 'NetDevices1', 'region_id': 1, 'cloud_id': 1,
|
||||
'device_type': 'Server', 'ip_address': '10.10.0.1',
|
||||
'variables': {"key1": "value1", "key2": "value2"}}
|
||||
expected_result = copy.deepcopy(data)
|
||||
expected_result.update({
|
||||
'id': 1,
|
||||
'project_id': 1,
|
||||
'cell_id': None,
|
||||
'parent_id': None,
|
||||
'links': [{'href': 'http://localhost/v1/regions/1', 'rel': 'up'}],
|
||||
})
|
||||
resp = self.post('/v1/network-devices', data=data)
|
||||
|
||||
self.assertEqual(201, resp.status_code)
|
||||
self.assertEqual(expected_result, resp.json)
|
||||
|
||||
@mock.patch.object(dbapi, 'network_devices_create')
|
||||
def test_create_netdevices_with_invalid_data(self, mock_devices):
|
||||
mock_devices.return_value = None
|
||||
|
|
Loading…
Reference in New Issue