def test_subtree_explicit_ns_query_elm(): select = etree.fromstring(""" <foo:interfaces xmlns:foo="urn:test:mock"> <foo:interface> <foo:name>Ethernet0/0</foo:name> <foo:state/> </foo:interface> </foo:interfaces> """) logger.info("Connecting to 127.0.0.1 port %d", NC_PORT) session = client.NetconfSSHSession("127.0.0.1", password="******", port=NC_PORT, debug=NC_DEBUG) cmptree = etree.fromstring(""" <data xmlns="urn:ietf:params:xml:ns:netconf:base:1.0"> <interfaces xmlns="urn:test:mock"> <interface> <name>Ethernet0/0</name> <state>down</state> </interface> </interfaces> </data>""") results = session.get(select) assert (xml_eq(results, cmptree))
def test_get_config(): tmp = NamedTemporaryFile("r") main([ "--user", getpass.getuser(), "--password=admin", "--host=127.0.0.1", "--port", str(NC_PORT), "--get-config", "--outfile", tmp.name ]) result = etree.fromstring(tmp.read()) cmptree = etree.fromstring(""" <nc:data xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0"> <t:interfaces xmlns:t="urn:test:mock"> <t:interface> <t:name>Ethernet0/0</t:name> <t:shutdown>true</t:shutdown> </t:interface> <t:interface> <t:name>Ethernet0/1</t:name> <t:shutdown>false</t:shutdown> </t:interface> <t:interface> <t:name>FastEthernet1/0</t:name> <t:shutdown>false</t:shutdown> </t:interface> <t:interface> <t:name>FastEthernet1/1</t:name> <t:shutdown>false</t:shutdown> <t:name>GigabitEthernet2/0</t:name> <t:shutdown>false</t:shutdown> </t:interface> </t:interfaces> </nc:data> """) assert (xml_eq(result, cmptree))
def test_get_subtree(): select = "<foo:interfaces xmlns:foo='urn:test:mock'><foo:interface><foo:name>AutoInterface0/0</foo:name></foo:interface></foo:interfaces>" tmp = NamedTemporaryFile("r") main([ "--user", getpass.getuser(), "--password=admin", "--host=127.0.0.1", "--port", str(NC_PORT), "--get", select, "--outfile", tmp.name, "--namespaces", "foo=urn:test:mock", ]) result = etree.fromstring(tmp.read()) cmptree = etree.fromstring(""" <nc:data xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0"> <t:interfaces xmlns:t="urn:test:mock"> <t:interface> <t:name>AutoInterface0/0</t:name> <t:shutdown>false</t:shutdown> <t:state>up</t:state> </t:interface> </t:interfaces> </nc:data> """) assert (xml_eq(result, cmptree))
def test_get_config(): session = netconf.client.NetconfSSHSession("127.0.0.1", username=getpass.getuser(), password="******", port=NC_PORT, debug=NC_DEBUG) result = session.get_config() cmptree = etree.fromstring(""" <nc:data xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0"> <t:interfaces xmlns:t="urn:test:mock"> <t:interface> <t:name>Ethernet0/0</t:name> <t:shutdown>true</t:shutdown> </t:interface> <t:interface> <t:name>Ethernet0/1</t:name> <t:shutdown>false</t:shutdown> </t:interface> <t:interface> <t:name>FastEthernet1/0</t:name> <t:shutdown>false</t:shutdown> </t:interface> <t:interface> <t:name>FastEthernet1/1</t:name> <t:shutdown>false</t:shutdown> <t:name>GigabitEthernet2/0</t:name> <t:shutdown>false</t:shutdown> </t:interface> </t:interfaces> </nc:data> """) assert (xml_eq(result, cmptree))
def test_xpath_config_query(): select = "/t:interfaces/t:interface[t:name='Ethernet0/1']" logger.info("Connecting to 127.0.0.1 port %d", NC_PORT) session = client.NetconfSSHSession("127.0.0.1", password="******", port=NC_PORT, debug=NC_DEBUG) cmptree = etree.fromstring(""" <data xmlns="urn:ietf:params:xml:ns:netconf:base:1.0"> <interfaces xmlns="urn:test:mock"> <interface> <name>Ethernet0/1</name> <shutdown>false</shutdown> </interface> </interfaces> </data>""") results = session.get_config("running", select) assert (xml_eq(results, cmptree))
def test_xpath_query(caplog): select = "/t:interfaces/t:interface[t:name='Ethernet0/0']/t:shutdown" caplog.set_level(logging.DEBUG) logger.info("Connecting to 127.0.0.1 port %d", NC_PORT) session = client.NetconfSSHSession("127.0.0.1", password="******", port=NC_PORT, debug=NC_DEBUG) cmptree = etree.fromstring(""" <data xmlns="urn:ietf:params:xml:ns:netconf:base:1.0"> <interfaces xmlns="urn:test:mock"> <interface> <shutdown>true</shutdown> </interface> </interfaces> </data>""") results = session.get(select) assert (xml_eq(results, cmptree))