Skip to content

Commit 70331cd

Browse files
authored
Merge pull request #3712 from reubenmiller/feat-system-test-setup-improvements
test: refactor test setup
2 parents 4b02fbf + fcc2009 commit 70331cd

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+227
-725
lines changed

tests/RobotFramework/libraries/ThinEdgeIO/ThinEdgeIO.py

Lines changed: 107 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,65 @@ def register_certificate(
192192
if certificate.is_self_signed and certificate.thumbprint:
193193
self._certificates[certificate.thumbprint] = common_name or device.get_id()
194194

195+
@keyword("Register Device With Cumulocity CA")
196+
def register_device_with_cumulocity_ca(
197+
self,
198+
external_id: str,
199+
external_type: str = "c8y_Serial",
200+
name: Optional[str] = None,
201+
device_type: str = "thin-edge.io",
202+
device_name: Optional[str] = None,
203+
**kwargs,
204+
):
205+
"""Register a device with Cumulocity using the Cumulocity Certificate Authority feature
206+
207+
Examples:
208+
209+
| Register Device With Cumulocity CA | external_id=tedge001 |
210+
| Register Device With Cumulocity CA | external_id=tedge001 | name=Custom Tedge 0001 |
211+
"""
212+
credentials = c8y_lib.device_mgmt.registration.bulk_register_with_ca(
213+
external_id=external_id,
214+
external_type=external_type,
215+
name=name,
216+
device_type=device_type,
217+
)
218+
219+
self.execute_command(
220+
f"""tedge config set c8y.url '{credentials.url}' && tedge cert download c8y --device-id '{external_id}' --one-time-password '{credentials.one_time_password}' --retry-every 5s --max-timeout 60s""",
221+
device_name=device_name,
222+
)
223+
224+
@keyword("Register Device With Self-Signed Certificate")
225+
def register_device_with_self_signed_certificate(
226+
self,
227+
external_id: str,
228+
device_name: Optional[str] = None,
229+
auto_registration_enabled: bool = True,
230+
**kwargs,
231+
):
232+
"""Register a device with Cumulocity using a self-signed certificate. The self-signed
233+
certificate is updated
234+
235+
Examples:
236+
237+
| Register Device With Self-Signed Certificate | external_id=tedge001 |
238+
"""
239+
domain = c8y_lib.get_domain()
240+
self.execute_command(
241+
f"tedge config set c8y.url '{domain}' && tedge cert create --device-id '{external_id}'"
242+
)
243+
pem_contents = self.execute_command(
244+
'cat "$(tedge config get device.cert_path)"'
245+
)
246+
c8y_lib.upload_trusted_certificate(
247+
name=external_id,
248+
pem_cert=pem_contents,
249+
auto_registration_enabled=auto_registration_enabled,
250+
ignore_duplicate=True,
251+
)
252+
self.register_certificate(common_name=external_id, device_name=device_name)
253+
195254
@keyword("Get Debian Architecture")
196255
def get_debian_architecture(self):
197256
"""Get the debian architecture"""
@@ -690,18 +749,62 @@ def _assert_health_status(
690749
def setup(
691750
self,
692751
skip_bootstrap: Optional[bool] = None,
752+
bootstrap_args: Optional[str] = None,
693753
cleanup: Optional[bool] = None,
694754
adapter: Optional[str] = None,
695755
env_file: str = ".env",
696-
wait_for_healthy: bool = True,
756+
register: bool = True,
757+
register_using: str = "c8y-ca",
758+
connect: bool = True,
697759
**adaptor_config,
698760
) -> str:
761+
"""_summary_
762+
763+
Args:
764+
skip_bootstrap (bool, optional): Don't run the bootstrap script. Defaults to None
765+
bootstrap_args (str, optional): Additional arguments to be passed to the bootstrap
766+
command. Defaults to None.
767+
cleanup (bool, optional): Should the cleanup be run or not. Defaults to None
768+
adapter (str, optional): Type of adapter to use, e.g. ssh, docker etc. Defaults to None
769+
**adaptor_config: Additional configuration that is passed to the adapter. It will override
770+
any existing settings.
771+
772+
env_file (str, optional): dotenv file to pass to the adapter. Defaults to ".env".
773+
register (bool, optional): Register the device with Cumulocity. Defaults to True.
774+
register_using (str, optional): Registration method. Defaults to "c8y-ca".
775+
connect (bool, optional): Connect the mapper to Cumulocity. Defaults to True.
776+
777+
Raises:
778+
ValueError: Invalid 'register_using'
779+
780+
Returns:
781+
str: Serial number
782+
"""
699783
serial_sn = super().setup(
700-
skip_bootstrap, cleanup, adapter, env_file=env_file, **adaptor_config
784+
skip_bootstrap=skip_bootstrap,
785+
bootstrap_args=bootstrap_args,
786+
cleanup=cleanup,
787+
adapter=adapter,
788+
env_file=env_file,
789+
**adaptor_config,
701790
)
702791

703-
if not skip_bootstrap and wait_for_healthy:
704-
self.assert_service_health_status_up("tedge-mapper-c8y")
792+
if not skip_bootstrap:
793+
if register:
794+
if register_using == "c8y-ca":
795+
self.register_device_with_cumulocity_ca(external_id=serial_sn)
796+
elif register_using == "self-signed":
797+
self.register_device_with_self_signed_certificate(
798+
external_id=serial_sn
799+
)
800+
else:
801+
raise ValueError(
802+
"Invalid 'register_using' value. Supported values: [c8y-ca, self-signed]"
803+
)
804+
805+
if connect:
806+
self.tedge_connect("c8y")
807+
705808
return serial_sn
706809

707810
def _assert_mqtt_topic_messages(
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
robotframework-devicelibrary[docker] @ git+https://github.com/thin-edge/robotframework-devicelibrary.git@1.20.0
1+
robotframework-devicelibrary[docker] @ git+https://github.com/thin-edge/robotframework-devicelibrary.git@1.21.1
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
robotframework-devicelibrary[local] @ git+https://github.com/thin-edge/robotframework-devicelibrary.git@1.20.0
1+
robotframework-devicelibrary[local] @ git+https://github.com/thin-edge/robotframework-devicelibrary.git@1.21.1
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
robotframework-devicelibrary[ssh] @ git+https://github.com/thin-edge/robotframework-devicelibrary.git@1.20.0
1+
robotframework-devicelibrary[ssh] @ git+https://github.com/thin-edge/robotframework-devicelibrary.git@1.21.1
22
robotframework-sshlibrary~=3.8.0

tests/RobotFramework/requirements/requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
paho-mqtt~=1.6.1
22
python-dotenv~=1.0.0
33
robotframework~=7.0.0
4-
robotframework-c8y @ git+https://github.com/thin-edge/robotframework-c8y.git@0.45.0
4+
robotframework-c8y @ git+https://github.com/thin-edge/robotframework-c8y.git@0.46.2
55
robotframework-aws @ git+https://github.com/thin-edge/robotframework-aws.git@0.0.10
66
robotframework-debuglibrary~=2.5.0
77
robotframework-jsonlibrary~=0.5

tests/RobotFramework/tests/config_management/inotify_crate.robot

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,7 @@ ${toml} SEPARATOR=\n
2626

2727
*** Test Cases ***
2828
Configuration types should be detected on file change (without restarting service)
29-
${DEVICE_SN}= Setup skip_bootstrap=True
30-
Execute Command /setup/bootstrap.sh 2>&1
29+
${DEVICE_SN}= Setup
3130
Device Should Exist ${DEVICE_SN}
3231

3332
${supported_configs}= Should Support Configurations tedge-configuration-plugin includes=True

tests/RobotFramework/tests/configuration/tedge_configuration.robot

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,16 @@ Test Tags theme:configuration known-issue
1212
*** Test Cases ***
1313
Startup with invalid system.toml
1414
Skip msg=Known issue. tedge does not startup if the system.toml file contains invalid toml content
15-
Setup skip_bootstrap=True
16-
Execute Command test -f ./bootstrap.sh && ./bootstrap.sh --no-connect || true
15+
Setup connect=${False}
1716
${DEVICE_SN}= Execute Command tedge config get device.id
1817
Execute Command cmd=echo -n "[new-section]\ntest = invalid" > /etc/tedge/system.toml
19-
Execute Command test -f ./bootstrap.sh && ./bootstrap.sh --no-install || true
18+
Execute Command cmd=tedge connect c8y
2019
Device Should Exist ${DEVICE_SN}
2120

2221
Startup with invalid tedge.toml
2322
Skip msg=Known issue. tedge does not startup if the tedge.toml file contains invalid toml content
24-
Setup skip_bootstrap=True
25-
Execute Command test -f ./bootstrap.sh && ./bootstrap.sh --no-connect || true
23+
Setup connect=${False}
2624
${DEVICE_SN}= Execute Command tedge config get device.id
2725
Execute Command cmd=echo -n "[new-section]\ntest = invalid" > /etc/tedge/tedge.toml
28-
Execute Command test -f ./bootstrap.sh && ./bootstrap.sh --no-install || true
26+
Execute Command cmd=tedge connect c8y
2927
Device Should Exist ${DEVICE_SN}

tests/RobotFramework/tests/cumulocity/availability/c8y_required_availability.robot

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ Test Tags theme:c8y theme:monitoring
1111

1212
*** Test Cases ***
1313
c8y_RequiredAvailability is set by default to an hour
14-
Execute Command ./bootstrap.sh
14+
Execute Command tedge connect c8y
1515

1616
# Main
1717
Device Should Exist ${DEVICE_SN}
@@ -23,9 +23,8 @@ c8y_RequiredAvailability is set by default to an hour
2323

2424
c8y_RequiredAvailability is set with custom value
2525
# Set tedge config value before connecting
26-
Execute Command ./bootstrap.sh --no-bootstrap --no-connect
2726
Execute Command sudo tedge config set c8y.availability.interval 0
28-
Execute Command ./bootstrap.sh --no-install
27+
Execute Command tedge connect c8y
2928

3029
# Main
3130
Device Should Exist ${DEVICE_SN}
@@ -37,9 +36,8 @@ c8y_RequiredAvailability is set with custom value
3736

3837
c8y_RequiredAvailability is not set when disabled
3938
# Set tedge config value before connecting
40-
Execute Command ./bootstrap.sh --no-bootstrap --no-connect
4139
Execute Command sudo tedge config set c8y.availability.enable false
42-
Execute Command ./bootstrap.sh --no-install
40+
Execute Command tedge connect c8y
4341

4442
# Main
4543
Device Should Exist ${DEVICE_SN}
@@ -52,7 +50,7 @@ c8y_RequiredAvailability is not set when disabled
5250

5351
*** Keywords ***
5452
Test Setup
55-
${DEVICE_SN}= Setup skip_bootstrap=True
53+
${DEVICE_SN}= Setup connect=${False}
5654
Set Test Variable $DEVICE_SN
5755

5856
${CHILD_SN}= Get Random Name

tests/RobotFramework/tests/cumulocity/availability/heartbeat.robot

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -106,17 +106,16 @@ Child heartbeat is sent based on the custom health topic status
106106

107107
*** Keywords ***
108108
Test Setup
109-
${DEVICE_SN}= Setup skip_bootstrap=True
109+
${DEVICE_SN}= Setup connect=${False}
110110
Set Test Variable $DEVICE_SN
111111

112112
${CHILD_SN}= Get Random Name
113113
Set Test Variable $CHILD_SN
114114
Set Test Variable $CHILD_XID ${DEVICE_SN}:device:${CHILD_SN}
115115

116116
# Set tedge config value before connecting
117-
Execute Command ./bootstrap.sh --no-bootstrap --no-connect
118117
Execute Command sudo tedge config set c8y.availability.interval 1m
119-
Execute Command ./bootstrap.sh --no-install
118+
Execute Command tedge connect c8y
120119

121120
Device Should Exist ${DEVICE_SN}
122121

tests/RobotFramework/tests/cumulocity/bootstrap.robot

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,11 @@ Test Teardown Get Logs
1010
*** Test Cases ***
1111
No unexpected child devices created with service autostart
1212
[Tags] \#2584
13-
${DEVICE_SN}= Setup skip_bootstrap=True
14-
Execute Command test -f ./bootstrap.sh && ./bootstrap.sh --no-connect || true
13+
${DEVICE_SN}= Setup connect=${False}
1514
Execute Command systemctl start mosquitto
1615
Execute Command systemctl start tedge-agent
1716
Execute Command systemctl start tedge-mapper-c8y
18-
Execute Command test -f ./bootstrap.sh && ./bootstrap.sh --no-install --no-secure || true
17+
Execute Command tedge connect c8y
1918
Device Should Exist ${DEVICE_SN}
2019

2120
# wait for messages to be processed
@@ -66,12 +65,11 @@ Mapper restart does not alter device hierarchy
6665

6766
Mapper started early does not miss supported operations
6867
[Tags] \#2689
69-
${DEVICE_SN}= Setup skip_bootstrap=True
70-
Execute Command test -f ./bootstrap.sh && ./bootstrap.sh --no-bootstrap --no-connect --no-secure || true
68+
${DEVICE_SN}= Setup connect=${False}
7169
Execute Command systemctl start mosquitto
7270
Execute Command systemctl start tedge-agent
7371
Execute Command systemctl start tedge-mapper-c8y
74-
Execute Command test -f ./bootstrap.sh && ./bootstrap.sh --no-install --no-secure || true
72+
Execute Command tedge connect c8y
7573
Device Should Exist ${DEVICE_SN}
7674

7775
# Assert that there are no child devices present.

0 commit comments

Comments
 (0)