What are deviations?

Overview

Not all devices faithfully support features defined in standard yang models. For a particular device, it could support only part of features or the feature it supported varies from the standard module. The YANG language defines the deviation statement to indicate such a thing. For example, using a deviation statement in cisco-xr-openconfig-telemetry-deviations.yang, the netconf server can indicate that the openconfig_telemetry.TelemetrySystem.Subscriptions.Dynamic.Subscription container of the openconfig_telemetry model is not supported.

deviation /oc-telemetry:telemetry-system/oc-telemetry:subscriptions/oc-telemetry:dynamic/oc-telemetry:subscription {
  deviate not-supported;
}

How to use deviation with YDK

When using YDK to program a device which has some unsupported features, YDK will raise error before sending payload to device. For instance, if the device advertises via a deviation that it does not support the subscription node as shown above, an error will be raised.

We can try to configure a dynamic subscription with the below app.

 1from ydk.models.openconfig.openconfig_telemetry import TelemetrySystem
 2
 3telemetry = TelemetrySystem()
 4s = telemetry.subscriptions.dynamic.Subscription()
 5s.subscription_id = 123
 6s.state.subscription_id = 123
 7telemetry.subscriptions.dynamic.subscription.append(s)
 8
 9# Call the CRUD create on the top-level telemetry object
10# (assuming you have already instantiated the service and provider)
11crud.create(provider, telemetry)

The above app results in the below errors logged and exception being raised because of the deviation which is active on the subscription node.

 12017-11-08 21:26:58,543 - ydk - ERROR - Data is invalid according to the yang model. Error details: Schema node not found. Path: 'subscription'
 22017-11-08 21:26:58,543 - ydk - ERROR - Invalid path: subscription[subscription-id='123']
 3
 4  File "/Users/lib/python3.6/site-packages/ydk/errors/error_handler.py", line 112, in helper
 5    return func(self, provider, entity, *args, **kwargs)
 6  File "/Users/lib/python3.6/site-packages/ydk/services/crud_service.py", line 30, in create
 7    return self._crud.create(provider, entity)
 8  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/contextlib.py", line 99, in __exit__
 9    self.gen.throw(type, value, traceback)
10  File "/Users/lib/python3.6/site-packages/ydk/errors/error_handler.py", line 82, in handle_runtime_error
11    _raise(_exc)
12  File "/Users/lib/python3.6/site-packages/ydk/errors/error_handler.py", line 54, in _raise
13    exec("raise exc from None")
14  File "<string>", line 1, in <module>
15ydk.errors.YModelError:  Invalid path: subscription[subscription-id='123'] : Schema node not found.. Path: subscription