Exemple #1
0
 def test_write_structured_data_with_no_device(self):
     with patch('unified_worker.requests.put') as mock:
         mock.return_value = mock.return_value = MockResponse(
             bytes(json.dumps({}), encoding='utf-8'), 404)
         request = unified_worker.write_structured_data({
             "inputData": {
                 "device_id":
                 "",
                 "uri":
                 "/frinx-openconfig-interfaces:interfaces/interface=Loopback01",
                 "template":
                 "{\"interface\":[{\"name\":\"Loopback01\","
                 "\"config\":{"
                 "\"type\":\"iana-if-type:softwareLoopback\","
                 "\"enabled\":false,"
                 "\"name\":\"Loopback01\"}}]}",
                 "params": {}
             }
         })
         self.assertEqual(request["status"], "FAILED")
         self.assertEqual(
             request["output"]["url"], uniconfig_url_base +
             "/data/network-topology:network-topology/topology=unified/node=/"
             "yang-ext:mount/frinx-openconfig-interfaces:interfaces/interface=Loopback01"
         )
         self.assertEqual(request["output"]["response_code"], 404)
Exemple #2
0
 def test_write_structured_data_with_bad_template(self):
     with patch('unified_worker.requests.put') as mock:
         mock.return_value = MockResponse(
             bytes(json.dumps(bad_input_response), encoding='utf-8'), 400)
         request = unified_worker.write_structured_data({
             "inputData": {
                 "device_id":
                 "xr6",
                 "uri":
                 "/frinx-openconfig-interfaces:interfaces/interface=Loopback01",
                 "template":
                 "{\"interface\":[{\"name\":\"Loopback01\","
                 "\"config\":{"
                 "\"type\":\"iana-if-type:softwareLoopback\","
                 "\"enabled\":false,"
                 "\"name\":\"Loopback01\","
                 "\"prefix\": \"aaa\"}}]}",
                 "params": {}
             }
         })
         self.assertEqual(request["status"], "FAILED")
         self.assertEqual(
             request["output"]["url"], uniconfig_url_base +
             "/data/network-topology:network-topology/topology=unified/node=xr6/"
             "yang-ext:mount/frinx-openconfig-interfaces:interfaces/interface=Loopback01"
         )
         self.assertEqual(request["output"]["response_code"], 400)
         self.assertEqual(
             request["output"]["response_body"]['errors']['error'][0]
             ["error-type"], "protocol")
         self.assertEqual(
             request["output"]["response_body"]['errors']['error'][0]
             ["error-message"],
             "Error parsing input: com.google.common.util.concurrent.UncheckedExecutionException: "
             "java.lang.IllegalStateException: Schema node with name prefix was not found under "
             "(http://frinx.openconfig.net/yang/interfaces?revision=2016-12-22)config."
         )
         self.assertEqual(
             request["output"]["response_body"]['errors']['error'][0]
             ["error-tag"], "malformed-message")