From 23c5d564f6eeeed5c81c8d23e4edd846a9c3ea55 Mon Sep 17 00:00:00 2001
From: lukken <lukken@astron.nl>
Date: Wed, 18 Aug 2021 12:04:18 +0000
Subject: [PATCH] L2SS-240: Split basic integration tasks out across files

---
 .gitlab-ci.yml                                |  3 ++
 devices/integration_test/README.md            | 15 +++++++--
 devices/integration_test/client/__init__.py   |  0
 .../integration_test/client/test_apsct_sim.py | 33 +++++++++++++++++++
 .../integration_test/client/test_sdptr_sim.py | 32 ++++++++++++++++++
 devices/integration_test/devices/__init__.py  |  0
 .../devices/test_device_apsct.py              | 27 +++++++++++++++
 .../test_device_sdp.py}                       | 10 +++---
 8 files changed, 113 insertions(+), 7 deletions(-)
 create mode 100644 devices/integration_test/client/__init__.py
 create mode 100644 devices/integration_test/client/test_apsct_sim.py
 create mode 100644 devices/integration_test/client/test_sdptr_sim.py
 create mode 100644 devices/integration_test/devices/__init__.py
 create mode 100644 devices/integration_test/devices/test_device_apsct.py
 rename devices/integration_test/{test_device.py => devices/test_device_sdp.py} (51%)

diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index a8130f21e..e4fab6713 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -37,10 +37,13 @@ unit_test:
     - tox -e py37
 integration_test:
   stage: integration-tests
+  allow_failure: true
   services:
     - name: docker:20.10.8-dind
   variables:
     DOCKER_TLS_CERTDIR: "/certs"
+# Everything below does not work currently, we need a privileged container
+# that can run the dind service
   before_script:
     - sudo apt update
     - sudo apt install -y docker.io
diff --git a/devices/integration_test/README.md b/devices/integration_test/README.md
index 9bf4efee9..55c42d3df 100644
--- a/devices/integration_test/README.md
+++ b/devices/integration_test/README.md
@@ -1,6 +1,4 @@
-# Integration tests
-
-**Warning running these tests will make changes to your local system**
+# Integration Tests
 
 ## Approach
 
@@ -9,10 +7,21 @@ container will be build by the makefiles but should only be started by the
 dedicated integration test script. This script will ensure that other containers
 are running and are in the required state.
 
+[comment]: <> (#TODO&#40;Corne&#41;: Change pypcc-sim name to apsct-sim name once changed!)
+
 * Launch pypcc-sim and sdptr-sim simulators.
 * Reconfigure dsconfig to use these simulators.
 * Create and start the integration-test container.
 
+## Running
+
+**Warning running these tests will make changes to your local system!**
+
+```shell
+source bootstrap/etc/lofar20rc.sh
+$LOFAR20_DIR/sbin/run_integration_test.sh
+```
+
 ## Limitations
 
 Our makefile will always launch the new container upon creation, resulting in
diff --git a/devices/integration_test/client/__init__.py b/devices/integration_test/client/__init__.py
new file mode 100644
index 000000000..e69de29bb
diff --git a/devices/integration_test/client/test_apsct_sim.py b/devices/integration_test/client/test_apsct_sim.py
new file mode 100644
index 000000000..775c34cd2
--- /dev/null
+++ b/devices/integration_test/client/test_apsct_sim.py
@@ -0,0 +1,33 @@
+# -*- coding: utf-8 -*-
+#
+# This file is part of the LOFAR 2.0 Station Software
+#
+#
+#
+# Distributed under the terms of the APACHE license.
+# See LICENSE.txt for more info.
+
+from opcua import Client
+
+from integration_test import base
+
+
+class TestAPSCTSim(base.IntegrationTestCase):
+
+    def setUp(self):
+        super(TestAPSCTSim, self).setUp()
+
+    def test_opcua_connection(self):
+        """Check if we can connect to apsct-sim"""
+
+        #TODO(Corne): Replace to APSCT name once simulator name has changed
+        client = Client("opc.tcp://pypcc-sim:4842")
+        root_node = None
+
+        try:
+            client.connect()
+            root_node = client.get_root_node()
+        finally:
+            client.disconnect()
+
+        self.assertNotEqual(None, root_node)
diff --git a/devices/integration_test/client/test_sdptr_sim.py b/devices/integration_test/client/test_sdptr_sim.py
new file mode 100644
index 000000000..3ba48e7d7
--- /dev/null
+++ b/devices/integration_test/client/test_sdptr_sim.py
@@ -0,0 +1,32 @@
+# -*- coding: utf-8 -*-
+#
+# This file is part of the LOFAR 2.0 Station Software
+#
+#
+#
+# Distributed under the terms of the APACHE license.
+# See LICENSE.txt for more info.
+
+from opcua import Client
+
+from integration_test import base
+
+
+class TestSDPTRSim(base.IntegrationTestCase):
+
+    def setUp(self):
+        super(TestSDPTRSim, self).setUp()
+
+    def test_opcua_connection(self):
+        """Check if we can connect to sdptr-sim"""
+
+        client = Client("opc.tcp://sdptr-sim:4840")
+        root_node = None
+
+        try:
+            client.connect()
+            root_node = client.get_root_node()
+        finally:
+            client.disconnect()
+
+        self.assertNotEqual(None, root_node)
diff --git a/devices/integration_test/devices/__init__.py b/devices/integration_test/devices/__init__.py
new file mode 100644
index 000000000..e69de29bb
diff --git a/devices/integration_test/devices/test_device_apsct.py b/devices/integration_test/devices/test_device_apsct.py
new file mode 100644
index 000000000..f26bdd26e
--- /dev/null
+++ b/devices/integration_test/devices/test_device_apsct.py
@@ -0,0 +1,27 @@
+# -*- coding: utf-8 -*-
+#
+# This file is part of the LOFAR 2.0 Station Software
+#
+#
+#
+# Distributed under the terms of the APACHE license.
+# See LICENSE.txt for more info.
+
+from tango import DeviceProxy
+from tango._tango import DevState
+
+from integration_test import base
+
+
+class TestDeviceAPSCT(base.IntegrationTestCase):
+
+    def setUp(self):
+        super(TestDeviceAPSCT, self).setUp()
+
+    def test_device_proxy_apsct(self):
+        """Test if we can successfully create a DeviceProxy and fetch state"""
+
+        #TODO(Corne): Change name to APSCT once ready
+        d = DeviceProxy("LTS/PCC/1")
+
+        self.assertEqual(DevState.OFF, d.state())
diff --git a/devices/integration_test/test_device.py b/devices/integration_test/devices/test_device_sdp.py
similarity index 51%
rename from devices/integration_test/test_device.py
rename to devices/integration_test/devices/test_device_sdp.py
index 036280823..89a30acca 100644
--- a/devices/integration_test/test_device.py
+++ b/devices/integration_test/devices/test_device_sdp.py
@@ -8,17 +8,19 @@
 # See LICENSE.txt for more info.
 
 from tango import DeviceProxy
+from tango._tango import DevState
 
 from integration_test import base
 
 
-class TestDevice(base.IntegrationTestCase):
+class TestDeviceSDP(base.IntegrationTestCase):
 
     def setUp(self):
-        super(TestDevice, self).setUp()
+        super(TestDeviceSDP, self).setUp()
 
+    def test_device_proxy_sdp(self):
+        """Test if we can successfully create a DeviceProxy and fetch state"""
 
-    def test_device(self):
         d = DeviceProxy("LTS/SDP/1")
 
-        self.assertEqual("ON", d.state())
+        self.assertEqual(DevState.OFF, d.state())
-- 
GitLab