Skip to content

Commit 159d1d9

Browse files
p3rf Teamcopybara-github
authored andcommitted
resolve unsoundness caused by pytype.
PiperOrigin-RevId: 840944874
1 parent 32599d3 commit 159d1d9

File tree

5 files changed

+37
-10
lines changed

5 files changed

+37
-10
lines changed

perfkitbenchmarker/archive.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,10 @@ def ArchiveRun(
6969
)
7070
p = subprocess.Popen(cmd, stdin=subprocess.PIPE)
7171

72-
with p.stdin:
73-
with tarfile.open(mode='w:gz', fileobj=p.stdin) as tar:
74-
tar.add(run_temp_directory, os.path.basename(run_temp_directory))
72+
if p.stdin is not None:
73+
with p.stdin:
74+
with tarfile.open(mode='w:gz', fileobj=p.stdin) as tar:
75+
tar.add(run_temp_directory, os.path.basename(run_temp_directory))
7576

7677
status = p.wait()
7778
if status:

perfkitbenchmarker/dpb_service.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -549,6 +549,10 @@ def _InitializeMetadata(self) -> None:
549549
def _CreateDependencies(self):
550550
"""Creates a bucket to use with the cluster."""
551551
if self.manage_bucket:
552+
if self.storage_service is None:
553+
raise ValueError(
554+
'storage_service is None. Initialize before use.'
555+
)
552556
self.storage_service.MakeBucket(self.bucket)
553557

554558
def _Create(self):
@@ -558,6 +562,10 @@ def _Create(self):
558562
def _DeleteDependencies(self):
559563
"""Deletes the bucket used with the cluster."""
560564
if self.manage_bucket:
565+
if self.storage_service is None:
566+
raise ValueError(
567+
'storage_service is None. Initialize before use.'
568+
)
561569
self.storage_service.DeleteBucket(self.bucket)
562570

563571
def _Delete(self):
@@ -932,6 +940,10 @@ def SubmitJob(
932940
cmd_list += job_arguments
933941
cmd_string = ' '.join(cmd_list)
934942

943+
if self.leader is None:
944+
raise JobSubmissionError(
945+
'Cannot submit job as leader VM is not initialized.'
946+
)
935947
start_time = datetime.datetime.now()
936948
try:
937949
stdout, stderr = self.leader.RobustRemoteCommand(cmd_string)
@@ -1027,6 +1039,10 @@ def SubmitJob(
10271039
job_type=job_type,
10281040
properties=properties,
10291041
)
1042+
if self.leader is None:
1043+
raise JobSubmissionError(
1044+
'Cannot submit job as leader VM is not initialized.'
1045+
)
10301046
start_time = datetime.datetime.now()
10311047
try:
10321048
stdout, _ = self.leader.RobustRemoteCommand(' '.join(cmd))

perfkitbenchmarker/providers/alicloud/ali_network.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -346,16 +346,22 @@ def Create(self):
346346
self.security_group = AliSecurityGroup(
347347
self.name, self.region, use_vpc=True, vpc_id=self.vpc.id
348348
)
349-
self.security_group.Create()
349+
if self.security_group is not None:
350+
self.security_group.Create()
350351
else:
351-
self.security_group.Create()
352+
if self.security_group is not None:
353+
self.security_group.Create()
352354

353355
def Delete(self):
354356
"""Deletes the network."""
355357
if self.use_vpc:
356-
self.security_group.Delete()
357-
self.vswitch.Delete()
358-
self.security_group.Delete()
358+
if self.security_group is not None:
359+
self.security_group.Delete()
360+
if self.vswitch is not None:
361+
self.vswitch.Delete()
362+
if self.security_group is not None:
363+
self.security_group.Delete()
359364
self.vpc.Delete()
360365
else:
361-
self.security_group.Delete()
366+
if self.security_group is not None:
367+
self.security_group.Delete()

perfkitbenchmarker/scripts/messaging_service_scripts/common/e2e/latency_runner.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,9 @@ def run_phase(self, number_of_messages: int, message_size: int):
143143
return asyncio.run(self._async_run_phase(number_of_messages))
144144

145145
async def _wait_until_received(self, seq: int) -> protocol.ReceptionReport:
146+
assert self._receiver is not None, (
147+
f'Receiver is not initialized. Message sequence: {seq}.'
148+
)
146149
while True:
147150
report = await self._receiver.receive()
148151
self._record_message_reception(report)

perfkitbenchmarker/scripts/messaging_service_scripts/common/e2e/main_process.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ async def stop(self, timeout: Optional[float] = None):
6262
Args:
6363
timeout: Timeout in seconds. Defaults to BaseWorker.DEFAULT_TIMEOUT.
6464
"""
65+
assert self.subprocess is not None, 'stop() called before start()'
6566
try:
6667
self.subprocess.terminate()
6768
await self._join_subprocess(timeout)
@@ -89,7 +90,7 @@ async def _read_subprocess_output(
8990
async def _join_subprocess(self, timeout=None):
9091
timeout = self.DEFAULT_TIMEOUT if timeout is None else timeout
9192
deadline = time.time() + timeout
92-
while self.subprocess.exitcode is None:
93+
while self.subprocess and self.subprocess.exitcode is None:
9394
await asyncio.sleep(self.SLEEP_TIME)
9495
if time.time() > deadline:
9596
raise errors.EndToEnd.SubprocessTimeoutError

0 commit comments

Comments
 (0)