Skip to contentSkip to conversation

package/python-ncclient: new package

PATCH In review Vincent Cruz 2 participants 3 messages Apr 14

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 package/python-ncclient: new package

From: Vincent Jardin <[email protected]>

ncclient is a Python library for NETCONF clients. It facilitates client-side scripting and application development around NETCONF.

https://github.com/ncclient/ncclient

---
Changes v1 -> v2:
- Bump version to 0.7.1
- Add test

---
 DEVELOPERS                                    |  1 +
 package/Config.in                             |  1 +
 package/python-ncclient/Config.in             | 13 +++++++
 package/python-ncclient/python-ncclient.hash  |  5 +++
 package/python-ncclient/python-ncclient.mk    | 17 ++++++++
 .../tests/package/sample_python_ncclient.py   | 19 +++++++++
 .../tests/package/test_python_ncclient.py     | 39 +++++++++++++++++++
 .../rootfs-overlay/root/add_root.xml          | 35 +++++++++++++++++
 8 files changed, 130 insertions(+)
 create mode 100644 package/python-ncclient/Config.in
 create mode 100644 package/python-ncclient/python-ncclient.hash
 create mode 100644 package/python-ncclient/python-ncclient.mk
 create mode 100644 support/testing/tests/package/sample_python_ncclient.py
 create mode 100644 support/testing/tests/package/test_python_ncclient.py
 create mode 100644 support/testing/tests/package/test_python_ncclient/rootfs-overlay/root/add_root.xml
DEVELOPERS +1 -0
index 1ad64e876e..4a4a25e2c8 100644
@@ -3369,6 +3369,7 @@ F:	package/dpdk/
 F:	package/libecoli/
 F:	package/libnss-ato/
 F:	package/libyang-cpp/
+F:	package/python-ncclient/
 F:	package/sysrepo-cpp/
 
 N:	Vincent Prince <[email protected]>
package/Config.in +1 -0
index 71501cea53..4eeac53563 100644
@@ -1250,6 +1250,7 @@ menu "External python modules"
 	source "package/python-mwscrape2slob/Config.in"
 	source "package/python-mypy/Config.in"
 	source "package/python-mypy-extensions/Config.in"
+	source "package/python-ncclient/Config.in"
 	source "package/python-nested-dict/Config.in"
 	source "package/python-netaddr/Config.in"
 	source "package/python-netifaces/Config.in"
package/python-ncclient/Config.in new file +13 -0
new file mode 100644
index 0000000000..7cad899ca2
@@ -0,0 +1,13 @@
+config BR2_PACKAGE_PYTHON_NCCLIENT
+	bool "python-ncclient"
+	depends on BR2_PACKAGE_HOST_RUSTC_TARGET_ARCH_SUPPORTS # python-paramiko
+	select BR2_PACKAGE_PYTHON3_PYEXPAT # runtimeq
+	select BR2_PACKAGE_PYTHON_LXML # runtime
+	select BR2_PACKAGE_PYTHON_PARAMIKO # runtime
+	select BR2_PACKAGE_PYTHON_SIX # runtime
+	help
+	  ncclient is a Python library for NETCONF clients. It
+	  facilitates client-side scripting and application
+	  development around NETCONF.
+
+	  https://github.com/ncclient/ncclient
package/python-ncclient/python-ncclient.hash new file +5 -0
new file mode 100644
index 0000000000..5901cb0ddc
@@ -0,0 +1,5 @@
+# From https://pypi.org/pypi/ncclient/0.7.1/json
+sha256  60dabb6ac1a2d84fbc3349cb104ef7d0c5d12cf8eee43fefc715410d70410ddc  ncclient-0.7.1.tar.gz
+
+# Locally computed
+sha256  cfc7749b96f63bd31c3c42b5c471bf756814053e847c10f3eb003417bc523d30  LICENSE
package/python-ncclient/python-ncclient.mk new file +17 -0
new file mode 100644
index 0000000000..36223e835a
@@ -0,0 +1,17 @@
+################################################################################
+#
+# python-ncclient
+#
+################################################################################
+
+PYTHON_NCCLIENT_VERSION = 0.7.1
+PYTHON_NCCLIENT_SOURCE = ncclient-$(PYTHON_NCCLIENT_VERSION).tar.gz
+PYTHON_NCCLIENT_SITE = https://files.pythonhosted.org/packages/source/n/ncclient
+
+PYTHON_NCCLIENT_LICENSE = Apache-2.0
+PYTHON_NCCLIENT_LICENSE_FILES = LICENSE
+
+PYTHON_NCCLIENT_SETUP_TYPE = hatch
+PYTHON_NCCLIENT_DEPENDENCIES = host-python-hatch-vcs
+
+$(eval $(python-package))
support/testing/tests/package/sample_python_ncclient.py new file +19 -0
new file mode 100644
index 0000000000..cfd4e260e8
@@ -0,0 +1,19 @@
+import os
+from ncclient import manager
+
+filter = """
+<filter xmlns="urn:ietf:params:xml:ns:netconf:base:1.0">
+    <netconf-state xmlns="urn:ietf:params:xml:ns:yang:ietf-netconf-monitoring">
+        <sessions/>
+    </netconf-state>
+</filter>
+"""
+
+with manager.connect(host='localhost',
+                     port=830,
+                     username=os.getenv("USER"),
+                     key_filename='/root/.ssh/dummy_key',
+                     hostkey_verify=False,
+                     allow_agent=False,
+                     look_for_keys=False) as m:
+    print(m.get(filter=filter).data_xml)
support/testing/tests/package/test_python_ncclient.py new file +39 -0
new file mode 100644
index 0000000000..ca77b2080c
@@ -0,0 +1,39 @@
+import os
+import infra
+from xml.etree import ElementTree
+from tests.package.test_python import TestPythonPackageBase
+
+
+class TestPythonNCClient(TestPythonPackageBase):
+    rootfs_overlay = infra.filepath("tests/package/test_python_ncclient/rootfs-overlay")
+
+    __test__ = True
+    config = TestPythonPackageBase.config + \
+        f"""
+        BR2_INSTALL_LIBSTDCPP=y
+        BR2_PACKAGE_OPENSSH=y
+        BR2_PACKAGE_NETOPEER2=y
+        BR2_PACKAGE_NETOPEER2_CLI=y
+        BR2_PACKAGE_PYTHON3=y
+        BR2_PACKAGE_PYTHON_NCCLIENT=y
+        BR2_ROOTFS_OVERLAY="{rootfs_overlay}"
+        """
+    sample_scripts = ["tests/package/sample_python_ncclient.py"]
+
+    def test_run(self):
+        self.login()
+        self.check_sample_scripts_exist()
+
+        self.assertRunOk('mkdir -p /root/.ssh')
+        self.assertRunOk('ssh-keygen -t ed25519 -f /root/.ssh/dummy_key -N ""')
+        self.assertRunOk('cat /root/.ssh/dummy_key.pub > /root/.ssh/authorized_keys')
+
+        self.assertRunOk('sysrepocfg -f xml -I ./add_root.xml -d running -m ietf-netconf-server')
+
+        cmd = "%s %s" % (self.interpreter, os.path.basename(self.sample_scripts[0]))
+        output, exit_code = self.emulator.run(cmd, timeout=15)
+        self.assertEqual(exit_code, 0)
+
+        tree = ElementTree.fromstringlist(output)
+        self.assertEqual(tree.tag, '{urn:ietf:params:xml:ns:netconf:base:1.0}data')
+        self.assertEqual(tree.find('.//{*}username').text, 'root')
support/testing/tests/package/test_python_ncclient/rootfs-overlay/root/add_root.xml new file +35 -0
new file mode 100644
index 0000000000..4f48be2483
@@ -0,0 +1,35 @@
+<?xml version="1.0"?>
+<netconf-server xmlns="urn:ietf:params:xml:ns:yang:ietf-netconf-server">
+  <listen>
+    <endpoints>
+      <endpoint>
+        <name>default-ssh</name>
+        <ssh>
+          <tcp-server-parameters>
+            <local-address>0.0.0.0</local-address>
+          </tcp-server-parameters>
+          <ssh-server-parameters>
+            <server-identity>
+              <host-key>
+                <name>default-key</name>
+                <public-key>
+                  <central-keystore-reference>genkey</central-keystore-reference>
+                </public-key>
+              </host-key>
+            </server-identity>
+            <client-authentication>
+              <users>
+                <user>
+                  <name>root</name>
+                  <public-keys>
+                    <use-system-keys xmlns="urn:cesnet:libnetconf2-netconf-server"/>
+                  </public-keys>
+                </user>
+              </users>
+            </client-authentication>
+          </ssh-server-parameters>
+        </ssh>
+      </endpoint>
+    </endpoints>
+  </listen>
+</netconf-server>
Signature · 6 lines
2.51.0

_______________________________________________
buildroot mailing list
[email protected]
https://lists.buildroot.org/mailman/listinfo/buildroot
#1 lore raw

Hi Vincent,

Nice to get an update of this serie with related basic tests.

Quoted 6 lines

ncclient is a Python library for NETCONF clients. It facilitates client-side scripting and application development around NETCONF.

https://github.com/ncclient/ncclient

Can you share the buildroot build ci with those running properly ?

thanks,
Vincent
_______________________________________________
buildroot mailing list
[email protected]
https://lists.buildroot.org/mailman/listinfo/buildroot