Skip to content

Commit b3001b3

Browse files
juturupavankumarCQ Bot
authored andcommitted
[Honeydew] New Affordance ABC with is_supported()
Updated some of the existing affordance ABCs to inherit from this newly created "Affordance" class. In subsequent CLs, * Update rest of the affordnaces ABCs to inherit from this "Affordance" class. * Introduce "Transport" ABC with is_supprted() and update transport ABCs to inherit from this Bug: 377585143 Change-Id: Ice40d2a1e32ac64bedf4869890776ec0d8615bcc Reviewed-on: https://fuchsia-review.googlesource.com/c/fuchsia/+/1151733 Reviewed-by: Sam Balana <[email protected]> Reviewed-by: Kevin Cho <[email protected]> Commit-Queue: Pavan Kumar Juturu <[email protected]>
1 parent 437be43 commit b3001b3

File tree

16 files changed

+126
-45
lines changed

16 files changed

+126
-45
lines changed

src/testing/end_to_end/honeydew/BUILD.gn

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ python_library("honeydew_no_testonly") {
3232
sources = [
3333
"__init__.py",
3434
"affordances/__init__.py",
35+
"affordances/affordance.py",
3536
"affordances/connectivity/wlan/__init__.py",
3637
"affordances/connectivity/wlan/utils/errors.py",
3738
"affordances/connectivity/wlan/utils/types.py",
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# Copyright 2024 The Fuchsia Authors. All rights reserved.
2+
# Use of this source code is governed by a BSD-style license that can be
3+
# found in the LICENSE file.
4+
"""Abstract base class for Honeydew affordance."""
5+
6+
import abc
7+
8+
9+
class Affordance(abc.ABC):
10+
"""Abstract base class for Honeydew affordance.
11+
12+
Every Honeydew affordance contract should inherit from this class and thus required to implement
13+
the methods defined in this class.
14+
"""
15+
16+
@abc.abstractmethod
17+
def verify_supported(self) -> None:
18+
"""Verifies that affordance implementation is supported by the Fuchsia device.
19+
20+
This method should be called in every affordance implementation's `__init__()` so that if an
21+
affordance is used on a Fuchsia device that does not support it, it will raise
22+
NotSupportedError.
23+
24+
Raises:
25+
NotSupportedError: If affordance is not supported.
26+
"""

src/testing/end_to_end/honeydew/honeydew/affordances/connectivity/wlan/wlan/tests/unit_tests/wlan_using_fc_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ def tearDown(self) -> None:
207207
super().tearDown()
208208

209209
def test_verify_supported(self) -> None:
210-
"""Test if _verify_supported works."""
210+
"""Test if verify_supported() works."""
211211
self.ffx_transport_obj.run.return_value = ""
212212
with self.assertRaises(NotSupportedError):
213213
self.wlan_obj = wlan_using_fc.Wlan(

src/testing/end_to_end/honeydew/honeydew/affordances/connectivity/wlan/wlan/wlan.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
import abc
77

8+
from honeydew.affordances import affordance
89
from honeydew.affordances.connectivity.wlan.utils.types import (
910
Authentication,
1011
BssDescription,
@@ -15,7 +16,7 @@
1516
)
1617

1718

18-
class Wlan(abc.ABC):
19+
class Wlan(affordance.Affordance):
1920
"""Abstract base class for Wlan driver affordance."""
2021

2122
# List all the public methods

src/testing/end_to_end/honeydew/honeydew/affordances/connectivity/wlan/wlan/wlan_using_fc.py

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -71,13 +71,16 @@ def __init__(
7171
reboot_affordance: Object that implements RebootCapableDevice.
7272
fuchsia_device_close: Object that implements FuchsiaDeviceClose.
7373
"""
74-
super().__init__()
75-
self._verify_supported(device_name, ffx)
74+
AsyncAdapter.__init__(self)
7675

76+
self._device_name: str = device_name
77+
self._ffx: ffx_transport.FFX = ffx
7778
self._fc_transport = fuchsia_controller
7879
self._reboot_affordance = reboot_affordance
7980
self._fuchsia_device_close = fuchsia_device_close
8081

82+
self.verify_supported()
83+
8184
self._connect_proxy()
8285
self._reboot_affordance.register_for_on_device_boot(self._connect_proxy)
8386

@@ -94,29 +97,29 @@ def close(self) -> None:
9497
self.loop().run_forever() # Handle pending tasks
9598
self.loop().close()
9699

97-
def _verify_supported(self, device: str, ffx: ffx_transport.FFX) -> None:
98-
"""Check if WLAN is supported on the DUT.
100+
def verify_supported(self) -> None:
101+
"""Verifies that the WLAN affordance using FuchsiaController is supported by the Fuchsia
102+
device.
99103
100-
Args:
101-
device: Device name returned by `ffx target list`.
102-
ffx: FFX transport
104+
This method should be called in `__init__()` so that if this affordance was called on a
105+
Fuchsia device that does not support it, it will raise NotSupportedError.
103106
104107
Raises:
105-
NotSupportedError: A required component capability is not available.
108+
NotSupportedError: If affordance is not supported.
106109
"""
107110
for capability in _REQUIRED_CAPABILITIES:
108111
# TODO(http://b/359342196): This is a maintenance burden; find a
109112
# better way to detect FIDL component capabilities.
110-
if capability not in ffx.run(
113+
if capability not in self._ffx.run(
111114
["component", "capability", capability]
112115
):
113116
_LOGGER.warning(
114117
"All available WLAN component capabilities:\n%s",
115-
ffx.run(["component", "capability", "fuchsia.wlan"]),
118+
self._ffx.run(["component", "capability", "fuchsia.wlan"]),
116119
)
117120
raise errors.NotSupportedError(
118121
f'Component capability "{capability}" not exposed by device '
119-
f"{device}; this build of Fuchsia does not support the "
122+
f"{self._device_name}; this build of Fuchsia does not support the "
120123
"WLAN FC affordance."
121124
)
122125

src/testing/end_to_end/honeydew/honeydew/affordances/connectivity/wlan/wlan/wlan_using_sl4f.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,21 @@ def __init__(self, device_name: str, sl4f: SL4F) -> None:
8282
self._name: str = device_name
8383
self._sl4f: SL4F = sl4f
8484

85+
self.verify_supported()
86+
8587
# List all the public methods
88+
def verify_supported(self) -> None:
89+
"""Verifies that the WLAN affordance using SL4F is supported by the Fuchsia device.
90+
91+
This method should be called in `__init__()` so that if this affordance was called on a
92+
Fuchsia device that does not support it, it will raise NotSupportedError.
93+
94+
Raises:
95+
NotSupportedError: If affordance is not supported.
96+
"""
97+
# TODO(http://b/377585939): To Be Implemented
98+
return
99+
86100
def connect(
87101
self,
88102
ssid: str,

src/testing/end_to_end/honeydew/honeydew/affordances/connectivity/wlan/wlan_policy/tests/unit_tests/wlan_policy_using_fc_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ def get_listener(updates: Channel) -> None:
216216
yield client_listener_proxy
217217

218218
def test_verify_supported(self) -> None:
219-
"""Test if _verify_supported works."""
219+
"""Test if verify_supported works."""
220220
self.ffx_transport_obj.run.return_value = ""
221221

222222
with self.assertRaises(NotSupportedError):

src/testing/end_to_end/honeydew/honeydew/affordances/connectivity/wlan/wlan_policy/wlan_policy.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
import abc
77

8+
from honeydew.affordances import affordance
89
from honeydew.affordances.connectivity.wlan.utils.types import (
910
ClientStateSummary,
1011
NetworkConfig,
@@ -13,7 +14,7 @@
1314
)
1415

1516

16-
class WlanPolicy(abc.ABC):
17+
class WlanPolicy(affordance.Affordance):
1718
"""Abstract base class for WlanPolicy affordance."""
1819

1920
# List all the public methods

src/testing/end_to_end/honeydew/honeydew/affordances/connectivity/wlan/wlan_policy/wlan_policy_using_fc.py

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ class ClientControllerState:
111111

112112

113113
class WlanPolicy(AsyncAdapter, wlan_policy.WlanPolicy):
114-
"""WLAN affordance implemented with Fuchsia Controller."""
114+
"""WlanPolicy affordance implemented with Fuchsia Controller."""
115115

116116
def __init__(
117117
self,
@@ -121,7 +121,7 @@ def __init__(
121121
reboot_affordance: affordances_capable.RebootCapableDevice,
122122
fuchsia_device_close: affordances_capable.FuchsiaDeviceClose,
123123
) -> None:
124-
"""Create a WLAN Policy Fuchsia Controller affordance.
124+
"""Create a WlanPolicy Fuchsia Controller affordance.
125125
126126
Args:
127127
device_name: Device name returned by `ffx target list`.
@@ -131,13 +131,16 @@ def __init__(
131131
fuchsia_device_close: Object that implements FuchsiaDeviceClose.
132132
"""
133133
super().__init__()
134-
self._verify_supported(device_name, ffx)
135134

135+
self._device_name: str = device_name
136+
self._ffx: ffx_transport.FFX = ffx
136137
self._fc_transport = fuchsia_controller
137138
self._reboot_affordance = reboot_affordance
138139
self._fuchsia_device_close = fuchsia_device_close
139140
self._client_controller: ClientControllerState | None = None
140141

142+
self.verify_supported()
143+
141144
self._connect_proxy()
142145
self._reboot_affordance.register_for_on_device_boot(self._connect_proxy)
143146

@@ -164,29 +167,29 @@ def _close(self) -> None:
164167
self.loop().run_forever() # Handle pending tasks
165168
self.loop().close()
166169

167-
def _verify_supported(self, device: str, ffx: ffx_transport.FFX) -> None:
168-
"""Check if WLAN Policy is supported on the DUT.
170+
def verify_supported(self) -> None:
171+
"""Verifies that the WlanPolicy affordance using FuchsiaController is supported by the
172+
Fuchsia device.
169173
170-
Args:
171-
device: Device name returned by `ffx target list`.
172-
ffx: FFX transport
174+
This method should be called in `__init__()` so that if this affordance was called on a
175+
Fuchsia device that does not support it, it will raise NotSupportedError.
173176
174177
Raises:
175-
NotSupportedError: A required component capability is not available.
178+
NotSupportedError: If affordance is not supported.
176179
"""
177180
for capability in _REQUIRED_CAPABILITIES:
178181
# TODO(http://b/359342196): This is a maintenance burden; find a
179182
# better way to detect FIDL component capabilities.
180-
if capability not in ffx.run(
183+
if capability not in self._ffx.run(
181184
["component", "capability", capability]
182185
):
183186
_LOGGER.warning(
184187
"All available WLAN component capabilities:\n%s",
185-
ffx.run(["component", "capability", "fuchsia.wlan"]),
188+
self._ffx.run(["component", "capability", "fuchsia.wlan"]),
186189
)
187190
raise errors.NotSupportedError(
188191
f'Component capability "{capability}" not exposed by device '
189-
f"{device}; this build of Fuchsia does not support the "
192+
f"{self._device_name}; this build of Fuchsia does not support the "
190193
"WLAN FC affordance."
191194
)
192195

src/testing/end_to_end/honeydew/honeydew/affordances/connectivity/wlan/wlan_policy/wlan_policy_using_sl4f.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,21 @@ def __init__(self, device_name: str, sl4f: SL4F) -> None:
5858
self._name: str = device_name
5959
self._sl4f: SL4F = sl4f
6060

61+
self.verify_supported()
62+
6163
# List all the public methods
64+
def verify_supported(self) -> None:
65+
"""Verifies that the WlanPolicy affordance using SL4F is supported by the Fuchsia device.
66+
67+
This method should be called in `__init__()` so that if this affordance was called on a
68+
Fuchsia device that does not support it, it will raise NotSupportedError.
69+
70+
Raises:
71+
NotSupportedError: If affordance is not supported.
72+
"""
73+
# TODO(http://b/377585939): To Be Implemented
74+
return
75+
6276
def connect(
6377
self, target_ssid: str, security_type: SecurityType
6478
) -> RequestStatus:

0 commit comments

Comments
 (0)