def test_json_payload_list(self): codec = Codec() schema = self.restconf_session.get_root_schema() json_int_payload = '''{ "openconfig-interfaces:interfaces": { "interface": [ { "name": "Loopback10", "config": { "name": "Loopback10" } } ] } } ''' json_bgp_payload = '''{ "openconfig-bgp:bgp": { "global": { "config": { "as": 65172 } } } } ''' payload_list = [json_int_payload, json_bgp_payload] rdn = codec.decode_json_output(schema, payload_list) json_str = codec.encode(rdn, EncodingFormat.JSON, True) self.assertEquals(json_str, json_int_payload + json_bgp_payload)
def test_json_payload_list(self): codec = Codec() schema = self.restconf_session.get_root_schema() json_int_payload = '''{ "openconfig-interfaces:interfaces": { "interface": [ { "name": "Loopback10", "config": { "name": "Loopback10" } } ] } } ''' json_bgp_payload = '''{ "openconfig-bgp:bgp": { "global": { "config": { "as": 65172 } } } } ''' payload_list = [json_int_payload, json_bgp_payload] rdn = codec.decode_json_output(schema, payload_list) json_str = codec.encode(rdn, EncodingFormat.JSON, True) self.assertEqual(json_str, json_int_payload + json_bgp_payload)
def setUpClass(self): self.codec = Codec() self.repo = Repository(get_local_repo_dir()) self.session = gNMISession(self.repo, "127.0.0.1", 50051, "admin", "admin") self.schema = self.session.get_root_schema() self.bgp_json = '' self.int_json = ''
def execute_path(session): codec = Codec() schema = session.get_root_schema() bgp = schema.create_datanode("Cisco-IOS-XR-ipv4-bgp-oper:bgp") xml = codec.encode(bgp, EncodingFormat.XML, True) create_rpc = schema.create_rpc("ydk:read") create_rpc.get_input_node().create_datanode("filter", xml) create_rpc(session)
def setUpClass(cls): cls.nc_session = NetconfSession(cls.hostname, cls.username, cls.password, cls.port, cls.protocol, cls.on_demand, cls.common_cache, cls.timeout) cls.root_schema = cls.nc_session.get_root_schema() cls.codec = Codec()
def setUpClass(self): self.codec = Codec() self.repo = Repository(get_local_repo_dir()) self.session = gNMISession( self.repo, "127.0.0.1", 50051, "admin", "admin") self.schema = self.session.get_root_schema() self.bgp_json = '' self.int_json = ''
def test_create_del_read(self): root_schema = self.restconf_session.get_root_schema() runner = root_schema.create_datanode('ydktest-sanity:runner', '') delete_rpc = root_schema.create_rpc('ydk:delete') codec_service = Codec() json = codec_service.encode(runner, EncodingFormat.JSON, False) delete_rpc.get_input_node().create_datanode('entity', json) delete_rpc(self.restconf_session) runner.create_datanode('ytypes/built-in-t/number8', '3') json = codec_service.encode(runner, EncodingFormat.JSON, False) self.assertNotEqual(json, '') create_rpc = root_schema.create_rpc('ydk:create') create_rpc.get_input_node().create_datanode('entity', json) read_rpc = root_schema.create_rpc('ydk:read') runner_read = root_schema.create_datanode('ydktest-sanity:runner', '') json = codec_service.encode(runner_read, EncodingFormat.JSON, False) self.assertNotEqual(json, '') read_rpc.get_input_node().create_datanode('filter', json) read_result = read_rpc(self.restconf_session) self.assertEqual(read_result is not None, True) runner = root_schema.create_datanode('ydktest-sanity:runner', '') runner.create_datanode('ytypes/built-in-t/number8', '5') json = codec_service.encode(runner, EncodingFormat.JSON, False) self.assertNotEqual(json, '') update_rpc = root_schema.create_rpc('ydk:update') update_rpc.get_input_node().create_datanode('entity', json) update_rpc(self.restconf_session)
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # ------------------------------------------------------------------ from ydk.providers import RestconfServiceProvider from ydk.path import Codec, Repository from ydk.types import EncodingFormat def execute_path(provider, codec): schema = provider.get_root_schema() bgp = schema.create_datanode("openconfig-bgp:bgp") bgp.create_datanode("global/config/as", "65321") runner = schema.create_datanode('ydktest-sanity:runner') runner.create_datanode('ytypes/built-in-t/number8', '12') xml = codec.encode(runner, EncodingFormat.JSON, True) print(xml) create_rpc = schema.create_rpc("ydk:create") create_rpc.get_input_node().create_datanode("entity", xml) create_rpc(provider) if __name__ == "__main__": repo = Repository("/usr/local/share/[email protected]") provider = RestconfServiceProvider(repo, '127.0.0.1', 'admin', 'admin', 12306, EncodingFormat.JSON) codec = Codec() execute_path(provider, codec)
class SanityGnmiSession(unittest.TestCase): @classmethod def setUpClass(self): self.codec = Codec() self.repo = Repository(get_local_repo_dir()) self.session = gNMISession(self.repo, "127.0.0.1", 50051, "admin", "admin") self.schema = self.session.get_root_schema() self.bgp_json = '' self.int_json = '' def test_gnmi_rpc_caps(self): cap_rpc = self.schema.create_rpc("ydk:gnmi-caps") caps = self.session.invoke(cap_rpc) json = self.codec.encode(caps, EncodingFormat.JSON, True) cap_update = ''' { "name": "openconfig-bgp", "organization": "OpenConfig working group", "version": "2016-06-21" },''' self.assertEqual((cap_update in json), True) #print("Server capabilities:\n%s" % json) def _build_configuration(self): # Configure BGP bgp = self.schema.create_datanode("openconfig-bgp:bgp") bgp.create_datanode("global/config/as", "65172") neighbor = bgp.create_datanode( "neighbors/neighbor[neighbor-address='172.16.255.2']") neighbor_address = neighbor.create_datanode("config/neighbor-address", "172.16.255.2") peer_as = neighbor.create_datanode("config/peer-as", "65172") # Configure interface ifc = self.schema.create_datanode("openconfig-interfaces:interfaces") lo10_config = ifc.create_datanode("interface[name='Loopback10']") lo10_config.create_datanode("config/name", 'Loopback10') lo10_config.create_datanode("config/description", 'Test') # Add data-nodes to RPC self.bgp_json = self.codec.encode(bgp, EncodingFormat.JSON, False) self.int_json = self.codec.encode(ifc, EncodingFormat.JSON, False) set_rpc = self.schema.create_rpc("ydk:gnmi-set") set_rpc.get_input_node().create_datanode("replace[alias='bgp']/entity", self.bgp_json) set_rpc.get_input_node().create_datanode("replace[alias='int']/entity", self.int_json) res = self.session.invoke(set_rpc) def _delete_configuration(self): del_rpc = self.schema.create_rpc("ydk:gnmi-set") del_rpc.get_input_node().create_datanode("delete[alias='bgp']/entity", self.bgp_json) del_rpc.get_input_node().create_datanode("delete[alias='int']/entity", self.int_json) res = self.session.invoke(del_rpc) def test_gnmi_rpc_set_get(self): self._build_configuration() # Read configuration bgp_read = self.schema.create_datanode("openconfig-bgp:bgp", "") json_bgp = self.codec.encode(bgp_read, EncodingFormat.JSON, False) int_read = self.schema.create_datanode( "openconfig-interfaces:interfaces", "") json_int = self.codec.encode(int_read, EncodingFormat.JSON, False) read_rpc = self.schema.create_rpc("ydk:gnmi-get") read_rpc.get_input_node().create_datanode("type", "CONFIG") read_rpc.get_input_node().create_datanode( "request[alias='bgp']/entity", json_bgp) read_rpc.get_input_node().create_datanode( "request[alias='int']/entity", json_int) read_result = self.session.invoke(read_rpc) # Delete configuration self._delete_configuration() def test_gnmi_rpc_subscribe(self): self._build_configuration() rpc = self.schema.create_rpc("ydk:gnmi-subscribe") subscription = rpc.get_input_node().create_datanode("subscription", "") subscription.create_datanode("mode", "ONCE") subscription.create_datanode("qos", "10") subscription.create_datanode("encoding", "JSON_IETF") bgp_read = self.schema.create_datanode("openconfig-bgp:bgp", "") bgp_json = self.codec.encode(bgp_read, EncodingFormat.JSON, False) int_read = self.schema.create_datanode( "openconfig-interfaces:interfaces", "") int_json = self.codec.encode(int_read, EncodingFormat.JSON, False) int_subscription = subscription.create_datanode( "subscription-list[alias='int']", "") int_subscription.create_datanode("entity", int_json) int_subscription.create_datanode("subscription-mode", "ON_CHANGE") int_subscription.create_datanode("sample-interval", "10000000") int_subscription.create_datanode("suppress-redundant", "true") int_subscription.create_datanode("heartbeat-interval", "1000000000") bgp_subscription = subscription.create_datanode( "subscription-list[alias='bgp']", "") bgp_subscription.create_datanode("entity", bgp_json) bgp_subscription.create_datanode("sample-interval", "20000000") self.session.subscribe(rpc, gnmi_service_subscribe_callback) # Delete configuration self._delete_configuration()
class SanityGnmiSession(unittest.TestCase): @classmethod def setUpClass(self): self.codec = Codec() self.repo = Repository(get_local_repo_dir()) self.session = gNMISession( self.repo, "127.0.0.1", 50051, "admin", "admin") self.schema = self.session.get_root_schema() self.bgp_json = '' self.int_json = '' def test_gnmi_rpc_caps(self): cap_rpc = self.schema.create_rpc("ydk:gnmi-caps") caps = self.session.invoke(cap_rpc) json = self.codec.encode(caps, EncodingFormat.JSON, True) cap_update = ''' { "name": "openconfig-bgp", "organization": "OpenConfig working group", "version": "2016-06-21" },''' self.assertEqual((cap_update in json), True) #print("Server capabilities:\n%s" % json) def _build_configuration(self): # Configure BGP bgp = self.schema.create_datanode("openconfig-bgp:bgp") bgp.create_datanode("global/config/as", "65172") neighbor = bgp.create_datanode("neighbors/neighbor[neighbor-address='172.16.255.2']") neighbor_address = neighbor.create_datanode("config/neighbor-address", "172.16.255.2") peer_as = neighbor.create_datanode("config/peer-as","65172") # Configure interface ifc = self.schema.create_datanode("openconfig-interfaces:interfaces") lo10_config = ifc.create_datanode("interface[name='Loopback10']") lo10_config.create_datanode("config/name", 'Loopback10') lo10_config.create_datanode("config/description", 'Test') # Add data-nodes to RPC self.bgp_json = self.codec.encode(bgp, EncodingFormat.JSON, False) self.int_json = self.codec.encode(ifc, EncodingFormat.JSON, False) set_rpc = self.schema.create_rpc("ydk:gnmi-set") set_rpc.get_input_node().create_datanode("replace[alias='bgp']/entity", self.bgp_json) set_rpc.get_input_node().create_datanode("replace[alias='int']/entity", self.int_json) res = self.session.invoke(set_rpc) def _delete_configuration(self): del_rpc = self.schema.create_rpc("ydk:gnmi-set") del_rpc.get_input_node().create_datanode("delete[alias='bgp']/entity", self.bgp_json) del_rpc.get_input_node().create_datanode("delete[alias='int']/entity", self.int_json) res = self.session.invoke(del_rpc) def test_gnmi_rpc_set_get(self): self._build_configuration() # Read configuration bgp_read = self.schema.create_datanode("openconfig-bgp:bgp", "") json_bgp = self.codec.encode(bgp_read, EncodingFormat.JSON, False) int_read = self.schema.create_datanode("openconfig-interfaces:interfaces", "") json_int = self.codec.encode(int_read, EncodingFormat.JSON, False) read_rpc = self.schema.create_rpc("ydk:gnmi-get") read_rpc.get_input_node().create_datanode("type", "CONFIG") read_rpc.get_input_node().create_datanode("request[alias='bgp']/entity", json_bgp) read_rpc.get_input_node().create_datanode("request[alias='int']/entity", json_int) read_result = self.session.invoke(read_rpc) # Delete configuration self._delete_configuration() def test_gnmi_rpc_subscribe(self): self._build_configuration() rpc = self.schema.create_rpc("ydk:gnmi-subscribe") subscription = rpc.get_input_node().create_datanode("subscription", "") subscription.create_datanode("mode", "ONCE") subscription.create_datanode("qos", "10") subscription.create_datanode("encoding", "JSON_IETF") bgp_read = self.schema.create_datanode("openconfig-bgp:bgp", "") bgp_json = self.codec.encode(bgp_read, EncodingFormat.JSON, False) int_read = self.schema.create_datanode("openconfig-interfaces:interfaces", "") int_json = self.codec.encode(int_read, EncodingFormat.JSON, False) int_subscription = subscription.create_datanode("subscription-list[alias='int']", "") int_subscription.create_datanode("entity", int_json) int_subscription.create_datanode("subscription-mode", "ON_CHANGE") int_subscription.create_datanode("sample-interval", "10000000") int_subscription.create_datanode("suppress-redundant", "true") int_subscription.create_datanode("heartbeat-interval", "1000000000") bgp_subscription = subscription.create_datanode("subscription-list[alias='bgp']", "") bgp_subscription.create_datanode("entity", bgp_json) bgp_subscription.create_datanode("sample-interval", "20000000") self.session.subscribe(rpc, gnmi_service_subscribe_callback) # Delete configuration self._delete_configuration()