Skip to content

Commit 47048c3

Browse files
committed
chore: fix linting issues (canonical#470)
1 parent 23e2d0b commit 47048c3

File tree

8 files changed

+221
-154
lines changed

8 files changed

+221
-154
lines changed

examples/oracle/oracle-cluster-demo.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,13 @@
77

88
import pycloudlib
99

10+
1011
def demo_cluster(
1112
availability_domain: str = None,
1213
compartment_id: str = None,
1314
vcn_name: str = None,
1415
):
1516
"""Show example of using the OCI library to launch a cluster instance and ping between them."""
16-
1717
with pycloudlib.OCI(
1818
"pycl-oracle-cluster-demo",
1919
availability_domain=availability_domain,
@@ -37,6 +37,7 @@ def demo_cluster(
3737
else:
3838
print(f"Successfully pinged {private_ip} from {instance.private_ip}")
3939

40+
4041
if __name__ == "__main__":
4142
logging.basicConfig(level=logging.DEBUG)
4243
if len(sys.argv) != 3:

examples/oracle/oracle-example-cluster-test.py

Lines changed: 121 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -2,37 +2,37 @@
22
# This file is part of pycloudlib. See LICENSE file for license information.
33
"""Basic examples of various lifecycle with an OCI instance."""
44

5-
from datetime import datetime
6-
import json
75
import logging
8-
import sys
6+
import threading
97
import time
8+
from datetime import datetime
9+
from typing import Generator
1010

1111
import pytest
1212

1313
import pycloudlib
1414
from pycloudlib.oci.instance import OciInstance
15-
from typing import Generator
16-
import logging
17-
import threading
1815

1916
logger = logging.getLogger(__name__)
2017

21-
EXISTING_INSTANCE_IDS = [
18+
EXISTING_INSTANCE_IDS: list[str] = [
2219
# add the OCIDs of the instances you want to use for testing here
2320
]
2421

22+
2523
# change this to either "class" or "module" as you see fit
2624
@pytest.fixture(scope="module")
2725
def cluster() -> Generator[list[OciInstance], None, None]:
2826
"""
29-
Launch a cluster of BM instances and yield them.
30-
"""
27+
Launch a cluster of BM instances.
3128
29+
Yields:
30+
list[OciInstance]: The created or retrieved cluster instances.
31+
"""
3232
with pycloudlib.OCI(
3333
"pycl-oracle-cluster-test",
3434
# use the already created "mofed-vcn" for cluster testing
35-
vcn_name="mofed-vcn" # THIS WILL OVERRIDE THE VCN_NAME IN THE CONFIG FILE
35+
vcn_name="mofed-vcn", # THIS WILL OVERRIDE THE VCN_NAME IN THE CONFIG FILE
3636
) as client:
3737
if EXISTING_INSTANCE_IDS:
3838
instances = [client.get_instance(instance_id) for instance_id in EXISTING_INSTANCE_IDS]
@@ -42,33 +42,49 @@ def cluster() -> Generator[list[OciInstance], None, None]:
4242
# so once this function returns, the instances are ready
4343
instances = client.create_compute_cluster(
4444
# if you create a custom image, specify its OCID here
45-
image_id=client.released_image("noble"),
45+
image_id=client.released_image("noble"),
4646
instance_count=2,
4747
)
4848
yield instances
4949

5050

5151
class TestOracleClusterBasic:
52-
def test_basic_ping_on_private_ips(self, cluster: list[OciInstance]):
52+
"""Test basic functionalities of Oracle Cluster."""
53+
54+
def test_basic_ping_on_private_ips(self, cluster: list[OciInstance]): # pylint: disable=W0621
5355
"""
54-
Verifies that the instances in the cluster can reach each other on their private IPs.
56+
Test that cluster instances can ping each other on private IPs.
57+
58+
Args:
59+
cluster (list[OciInstance]): Instances in the cluster.
5560
"""
5661
# get the private ips of the instances
5762
private_ips = [instance.private_ip for instance in cluster]
5863
# try to ping each instance from each other instance at their private ip
5964
for instance in cluster:
6065
for private_ip in private_ips:
6166
if private_ip != instance.private_ip:
62-
logger.info(f"Pinging {private_ip} from {instance.private_ip}")
67+
logger.info("Pinging %s from %s", private_ip, instance.private_ip)
6368
# ping once with a timeout of 5 seconds
6469
r = instance.execute(f"ping -c 1 -W 5 {private_ip}")
6570
assert r.ok, f"Failed to ping {private_ip} from {instance.private_ip}"
66-
logger.info(f"Successfully pinged {private_ip} from {instance.private_ip}")
71+
logger.info("Successfully pinged %s from %s", private_ip, instance.private_ip)
6772

6873

6974
def setup_mofed_iptables_rules(instance: OciInstance):
75+
"""
76+
Set up IPTABLES rules for RDMA usage.
77+
78+
Args:
79+
instance (OciInstance): Target instance to configure.
80+
81+
Returns:
82+
OciInstance: The same instance after configuration.
83+
"""
7084
# Update the cloud.cfg file to set preserve_hostname to true
71-
instance.execute("sed -i 's/preserve_hostname: false/preserve_hostname: true/' /etc/cloud/cloud.cfg")
85+
instance.execute(
86+
"sed -i 's/preserve_hostname: false/preserve_hostname: true/' /etc/cloud/cloud.cfg"
87+
)
7288
# Backup the existing iptables rules
7389
backup_file = f"/etc/iptables/rules.v4.bak.{datetime.now().strftime('%F-%T')}"
7490
instance.execute(f"cp -v /etc/iptables/rules.v4 {backup_file}")
@@ -101,23 +117,31 @@ def setup_mofed_iptables_rules(instance: OciInstance):
101117

102118

103119
def ensure_image_is_rdma_ready(instance: OciInstance):
120+
"""
121+
Check if the image supports RDMA.
122+
123+
Args:
124+
instance (OciInstance): The instance to verify.
125+
"""
104126
r = instance.execute("ibstatus")
105127
if not r.stdout or not r.ok:
106128
logger.info("Infiniband status: %s", r.stdout + "\n" + r.stderr)
107129
pytest.skip("The image beiing used is not RDMA ready")
108130

109131

110132
class TestOracleClusterRdma:
133+
"""Test RDMA functionalities of Oracle Cluster."""
134+
111135
@pytest.fixture(scope="class")
112-
def mofed_cluster(self, cluster: list[OciInstance]) -> Generator[list[OciInstance], None, None]:
136+
def mofed_cluster(
137+
self,
138+
cluster: list[OciInstance], # pylint: disable=W0621
139+
) -> Generator[list[OciInstance], None, None]:
113140
"""
114-
Custom fixture to configure the instances in the cluster for RDMA testing.
115-
116-
This fixture will:
117-
- Ensure the image being used is RDMA ready
118-
- Create a secondary VNIC on the private subnet for each instance in the cluster
119-
- Configure the secondary VNIC for RDMA usage
120-
- Set up the necessary iptables rules for RDMA usage on each instance's secondary NIC
141+
Configure cluster for RDMA testing.
142+
143+
Yields:
144+
list[OciInstance]: RDMA-ready cluster instances.
121145
"""
122146
ensure_image_is_rdma_ready(cluster[0])
123147
for instance in cluster:
@@ -130,38 +154,54 @@ def mofed_cluster(self, cluster: list[OciInstance]) -> Generator[list[OciInstanc
130154
# create a secondary VNIC on the 2nd vnic on the private subnet for RDMA usage
131155
instance.add_network_interface(
132156
nic_index=1,
133-
subnet_name="private subnet-mofed-vcn", # use the private subnet for mofed testing
157+
subnet_name="private subnet-mofed-vcn", # use the private subnet for mofed testing
134158
)
135159
instance.configure_secondary_vnic()
136160
setup_mofed_iptables_rules(instance)
137-
161+
138162
yield cluster
139-
140-
def test_basic_ping_on_new_rdma_ips(
141-
self,
142-
mofed_cluster: list[OciInstance],
143-
):
144-
# get the private ips of the instances
163+
164+
def test_basic_ping_on_new_rdma_ips(self, mofed_cluster: list[OciInstance]):
165+
"""
166+
Test ping on RDMA-enabled private IPs.
167+
168+
Args:
169+
mofed_cluster (list[OciInstance]): RDMA-enabled cluster instances.
170+
"""
171+
# get the private ips of the instances that are on the same RDMA-enabled subnet
145172
rdma_ips = [instance.secondary_vnic_private_ip for instance in mofed_cluster]
146-
# try to ping each instance from each other instance at their private ip
173+
147174
for instance in mofed_cluster:
148175
for rdma_ip in rdma_ips:
149176
if rdma_ip != instance.secondary_vnic_private_ip:
150-
logger.info(f"Pinging {rdma_ip} from {instance.secondary_vnic_private_ip}")
151-
# ping once with a timeout of 5 seconds
177+
logger.info(
178+
"Pinging %s from %s",
179+
rdma_ip,
180+
instance.secondary_vnic_private_ip,
181+
)
182+
# ping once with a timeout of 5 seconds so it doesn't hang
152183
r = instance.execute(f"ping -c 1 -W 5 {rdma_ip}")
153-
assert r.ok, f"Failed to ping {rdma_ip} from {instance.secondary_vnic_private_ip}"
154-
logger.info(f"Successfully pinged {rdma_ip} from {instance.secondary_vnic_private_ip}")
155-
156-
def test_rping(
157-
self,
158-
mofed_cluster: list[OciInstance],
159-
):
184+
assert (
185+
r.ok
186+
), f"Failed to ping {rdma_ip} from {instance.secondary_vnic_private_ip}"
187+
logger.info(
188+
"Successfully pinged %s from %s",
189+
rdma_ip,
190+
instance.secondary_vnic_private_ip,
191+
)
192+
193+
def test_rping(self, mofed_cluster: list[OciInstance]):
194+
"""
195+
Test rping between two instances.
196+
197+
Args:
198+
mofed_cluster (list[OciInstance]): RDMA-enabled cluster instances
199+
"""
160200
server_instance = mofed_cluster[0]
161201
client_instance = mofed_cluster[1]
162202

163203
def start_server():
164-
# start the rping server on the first instance
204+
"""Start the rping server on the "server_instance"."""
165205
server_instance.execute(f"rping -s -a {server_instance.secondary_vnic_private_ip} -v &")
166206

167207
server_thread = threading.Thread(target=start_server)
@@ -170,74 +210,88 @@ def start_server():
170210
# Wait for rping server to start
171211
time.sleep(5)
172212
# start the rping client on the second instance (only send 10 packets so it doesn't hang)
173-
r = client_instance.execute(f"rping -c -a {server_instance.secondary_vnic_private_ip} -C 10 -v")
213+
r = client_instance.execute(
214+
f"rping -c -a {server_instance.secondary_vnic_private_ip} -C 10 -v"
215+
)
174216
logger.info("rping output: %s", r.stdout)
175217
assert r.ok, "Failed to run rping"
176218

177-
def test_ucmatose(
178-
self,
179-
mofed_cluster: list[OciInstance],
180-
):
219+
def test_ucmatose(self, mofed_cluster: list[OciInstance]):
220+
"""
221+
Test ucmatose connections.
222+
223+
Args:
224+
mofed_cluster (list[OciInstance]): RDMA-enabled cluster instances
225+
"""
181226
server_instance = mofed_cluster[0]
182227
client_instance = mofed_cluster[1]
183228

184229
def start_server():
185-
# start the rping server on the first instance
186-
server_instance.execute(f"ucmatose &")
230+
"""Start the ucmatose server on the "server_instance"."""
231+
server_instance.execute("ucmatose &")
187232

188233
server_thread = threading.Thread(target=start_server)
189234
server_thread.start()
190235

191236
# Wait for server to start
192237
time.sleep(5)
193-
# start the client on the second instance (only send 10 packets so it doesn't hang)
238+
# start the ucmatose client
194239
r = client_instance.execute(f"ucmatose -s {server_instance.secondary_vnic_private_ip}")
195240
logger.info("ucmatose output: %s", r.stdout)
196241
assert r.ok, "Failed to run ucmatose"
197242

198-
def test_ucx_perftest_lat_one_node(
199-
self,
200-
mofed_cluster: list[OciInstance],
201-
):
243+
def test_ucx_perftest_lat_one_node(self, mofed_cluster: list[OciInstance]):
244+
"""
245+
Run ucx_perftest latency on a single node.
246+
247+
Args:
248+
mofed_cluster (list[OciInstance]): RDMA-enabled cluster instances
249+
"""
202250
server_instance = mofed_cluster[0]
203251
# ucx_perftest only works within a single instance on all MOFED stacks right now, so this
204252
# being 0 is intentional. (Will adjust if Oracle provides config info to resolve this)
205253
client_instance = mofed_cluster[0]
206254

207255
def start_server():
208-
# start the rping server on the first instance
209-
server_instance.execute(f"ucx_perftest -c 0 &")
256+
"""Start the ucx_perftest server on the "server_instance"."""
257+
server_instance.execute("ucx_perftest -c 0 &")
210258

211259
server_thread = threading.Thread(target=start_server)
212260
server_thread.start()
213261

214262
# Wait for server to start
215263
time.sleep(5)
216-
# start the client on the second instance (only send 10 packets so it doesn't hang)
217-
r = client_instance.execute(f"ucx_perftest {server_instance.secondary_vnic_private_ip} -t tag_lat -c 1")
264+
# start the ucx_perftest client
265+
r = client_instance.execute(
266+
f"ucx_perftest {server_instance.secondary_vnic_private_ip} -t tag_lat -c 1"
267+
)
218268
logger.info("ucx_perftest output: %s", r.stdout)
219269
assert r.ok, "Failed to run ucx_perftest"
220270

271+
def test_ucx_perftest_bw_one_node(self, mofed_cluster: list[OciInstance]):
272+
"""
273+
Run ucx_perftest bandwidth on a single node.
221274
222-
def test_ucx_perftest_bw_one_node(
223-
self,
224-
mofed_cluster: list[OciInstance],
225-
):
275+
Args:
276+
mofed_cluster (list[OciInstance]): RDMA-enabled cluster instances
277+
"""
226278
server_instance = mofed_cluster[0]
227279
# ucx_perftest only works within a single instance on all MOFED stacks right now, so this
228280
# being 0 is intentional. (Will adjust if Oracle provides config info to resolve this)
229281
client_instance = mofed_cluster[0]
230282

231283
def start_server():
232-
# start the rping server on the first instance
233-
server_instance.execute(f"ucx_perftest -c 0 &")
284+
"""Start the ucx_perftest server on the "server_instance"."""
285+
server_instance.execute("ucx_perftest -c 0 &")
234286

235287
server_thread = threading.Thread(target=start_server)
236288
server_thread.start()
237289

238290
# Wait for server to start
239291
time.sleep(5)
240-
# start the client on the second instance (only send 10 packets so it doesn't hang)
241-
r = client_instance.execute(f"ucx_perftest {server_instance.secondary_vnic_private_ip} -t tag_bw -c 1")
292+
# start the ucx_perftest client
293+
r = client_instance.execute(
294+
f"ucx_perftest {server_instance.secondary_vnic_private_ip} -t tag_bw -c 1"
295+
)
242296
logger.info("ucx_perftest output: %s", r.stdout)
243297
assert r.ok, "Failed to run ucx_perftest"

pycloudlib/instance.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ def __exit__(self, _type, _value, _traceback):
5858
def id(self) -> str:
5959
"""Return instance id."""
6060
raise NotImplementedError
61-
61+
6262
@property
6363
def private_ip(self) -> str:
6464
"""Return instance private ip."""

0 commit comments

Comments
 (0)