Skip to content

Commit d733160

Browse files
committed
Fix: zapper_iot must define test_data issue
We default use test_data username/password, while test_data is not defined fallback to use provision_data username/password but just "ubunut"/"ubuntu" Signed-off-by: ChunAn Wu <an.wu@canonical.com>
1 parent accf330 commit d733160

2 files changed

Lines changed: 74 additions & 3 deletions

File tree

device-connectors/src/testflinger_device_connectors/devices/zapper_iot/__init__.py

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,25 @@ def _validate_configuration(
3838
"""Validate the job config and data and prepare the arguments
3939
for the Zapper `provision` API.
4040
"""
41+
# We prefer using username/password in provision_plan
42+
# while username/password are not defined in test_data
43+
provision_plan = self.job_data["provision_data"].get("provision_plan")
44+
if provision_plan:
45+
try:
46+
default_uname = provision_plan["config"]["username"]
47+
default_password = provision_plan["config"]["password"]
48+
except (ValueError, KeyError):
49+
default_uname = "ubuntu"
50+
default_password = "ubuntu"
51+
else:
52+
default_uname = "ubuntu"
53+
default_password = "ubuntu"
54+
4155
username = self.job_data.get("test_data", {}).get(
42-
"test_username", "ubuntu"
56+
"test_username", default_uname
4357
)
4458
password = self.job_data.get("test_data", {}).get(
45-
"test_password", "ubuntu"
59+
"test_password", default_password
4660
)
4761
ubuntu_sso_email = self.job_data["provision_data"].get(
4862
"ubuntu_sso_email"

device-connectors/src/testflinger_device_connectors/devices/zapper_iot/tests/test_zapper_iot.py

Lines changed: 58 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ def test_validate_configuration_ubuntu_sso_email(self):
5858
self.assertEqual(args, ())
5959
self.assertDictEqual(kwargs, expected)
6060

61-
def test_validate_configuration_provision_plan(self):
61+
def test_validate_configuration_provision_plan_without_test_data(self):
6262
"""Test the function validates a custom test plan
6363
when provided.
6464
"""
@@ -85,6 +85,63 @@ def test_validate_configuration_provision_plan(self):
8585

8686
args, kwargs = device._validate_configuration()
8787

88+
expected = {
89+
"username": "admin",
90+
"password": "admin",
91+
"custom_provision_plan": {
92+
"config": {
93+
"project_name": "name",
94+
"username": "admin", # this gets overridden
95+
"password": "admin",
96+
"serial_console": {
97+
"port": "/dev/ttySanity1",
98+
"baud_rate": 115200,
99+
},
100+
"network": "eth0",
101+
},
102+
"run_stage": [
103+
{"initial_login": {"method": "system-user"}},
104+
],
105+
},
106+
"urls": [],
107+
"preset": None,
108+
"preset_kwargs": None,
109+
}
110+
self.maxDiff = None
111+
self.assertEqual(args, ())
112+
self.assertDictEqual(expected, kwargs)
113+
114+
def test_validate_configuration_provision_plan_with_test_data(self):
115+
"""Test the function validates a custom test plan
116+
when provided.
117+
"""
118+
device = DeviceConnector({})
119+
device.job_data = {
120+
"provision_data": {
121+
"provision_plan": {
122+
"config": {
123+
"project_name": "name",
124+
"username": "admin",
125+
"password": "admin",
126+
"serial_console": {
127+
"port": "/dev/ttySanity1",
128+
"baud_rate": 115200,
129+
},
130+
"network": "eth0",
131+
},
132+
"run_stage": [
133+
{"initial_login": {"method": "system-user"}},
134+
],
135+
}
136+
},
137+
"test_data": {
138+
"test_username": "ubuntu",
139+
"test_password": "ubuntu",
140+
},
141+
}
142+
143+
args, kwargs = device._validate_configuration()
144+
88145
expected = {
89146
"username": "ubuntu",
90147
"password": "ubuntu",

0 commit comments

Comments
 (0)