Commit f01edd65 authored by Antoine Kaufmann's avatar Antoine Kaufmann Committed by Antoine Kaufmann
Browse files

orchestration: fix overly broad exceptions being raised (#53)

This uses somewhat more specific exception types instead of just Exception()
everywhere. Makes pylint happy.
parent 753ba0b1
...@@ -20,6 +20,7 @@ ...@@ -20,6 +20,7 @@
# TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE # TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
# SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. # SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
import errno
import json import json
import os import os
import pathlib import pathlib
...@@ -43,7 +44,7 @@ with open(log_file, 'r', encoding='utf-8') as log: ...@@ -43,7 +44,7 @@ with open(log_file, 'r', encoding='utf-8') as log:
outdir = '/'.join(list(p.parts)[0:-1]) + tooutdir outdir = '/'.join(list(p.parts)[0:-1]) + tooutdir
if not os.path.exists(outdir): if not os.path.exists(outdir):
raise Exception('no such directory') raise FileNotFoundError(errno.ENOENT, os.strerror(errno.ENOENT), outdir)
start_end_path = os.path.join(outdir, 'start_end.txt') start_end_path = os.path.join(outdir, 'start_end.txt')
......
...@@ -212,7 +212,7 @@ class SimpleComponent(Component): ...@@ -212,7 +212,7 @@ class SimpleComponent(Component):
if self.verbose: if self.verbose:
print(self.label, 'TERMINATED:', rc, flush=True) print(self.label, 'TERMINATED:', rc, flush=True)
if not self.canfail and rc != 0: if not self.canfail and rc != 0:
raise Exception('Command Failed: ' + str(self.cmd_parts)) raise RuntimeError('Command Failed: ' + str(self.cmd_parts))
class SimpleRemoteComponent(SimpleComponent): class SimpleRemoteComponent(SimpleComponent):
......
...@@ -69,7 +69,7 @@ class Experiment(object): ...@@ -69,7 +69,7 @@ class Experiment(object):
"""Add a host simulator to the experiment.""" """Add a host simulator to the experiment."""
for h in self.hosts: for h in self.hosts:
if h.name == sim.name: if h.name == sim.name:
raise Exception('Duplicate host name') raise ValueError('Duplicate host name')
self.hosts.append(sim) self.hosts.append(sim)
def add_nic(self, sim: tp.Union[NICSim, I40eMultiNIC]): def add_nic(self, sim: tp.Union[NICSim, I40eMultiNIC]):
...@@ -80,14 +80,14 @@ class Experiment(object): ...@@ -80,14 +80,14 @@ class Experiment(object):
"""Add a PCIe device simulator to the experiment.""" """Add a PCIe device simulator to the experiment."""
for d in self.pcidevs: for d in self.pcidevs:
if d.name == sim.name: if d.name == sim.name:
raise Exception('Duplicate pcidev name') raise ValueError('Duplicate pcidev name')
self.pcidevs.append(sim) self.pcidevs.append(sim)
def add_network(self, sim: NetSim): def add_network(self, sim: NetSim):
"""Add a network simulator to the experiment.""" """Add a network simulator to the experiment."""
for n in self.networks: for n in self.networks:
if n.name == sim.name: if n.name == sim.name:
raise Exception('Duplicate net name') raise ValueError('Duplicate net name')
self.networks.append(sim) self.networks.append(sim)
def all_simulators(self): def all_simulators(self):
......
...@@ -108,10 +108,10 @@ class LocalParallelRuntime(Runtime): ...@@ -108,10 +108,10 @@ class LocalParallelRuntime(Runtime):
def add_run(self, run: Run): def add_run(self, run: Run):
if run.experiment.resreq_cores() > self.cores: if run.experiment.resreq_cores() > self.cores:
raise Exception('Not enough cores available for run') raise RuntimeError('Not enough cores available for run')
if self.mem is not None and run.experiment.resreq_mem() > self.mem: if self.mem is not None and run.experiment.resreq_mem() > self.mem:
raise Exception('Not enough memory available for run') raise RuntimeError('Not enough memory available for run')
if run.prereq is None: if run.prereq is None:
self.runs_noprereq.append(run) self.runs_noprereq.append(run)
......
...@@ -110,7 +110,7 @@ class SlurmRuntime(Runtime): ...@@ -110,7 +110,7 @@ class SlurmRuntime(Runtime):
result = stream.close() result = stream.close()
if result is not None: if result is not None:
raise Exception('running sbatch failed') raise RuntimeError('running sbatch failed')
m = jid_re.search(output) m = jid_re.search(output)
run.job_id = int(m.group(1)) run.job_id = int(m.group(1))
......
...@@ -306,7 +306,7 @@ class QemuHost(HostSim): ...@@ -306,7 +306,7 @@ class QemuHost(HostSim):
elif unit.lower() == 'mhz': elif unit.lower() == 'mhz':
base = 3 base = 3
else: else:
raise Exception('cpu frequency specified in unsupported unit') raise ValueError('cpu frequency specified in unsupported unit')
num = float(self.cpu_freq[:-3]) num = float(self.cpu_freq[:-3])
shift = base - int(math.ceil(math.log(num, 2))) shift = base - int(math.ceil(math.log(num, 2)))
...@@ -610,7 +610,7 @@ class NS3SequencerNet(NetSim): ...@@ -610,7 +610,7 @@ class NS3SequencerNet(NetSim):
elif 'sequencer' in n.name: elif 'sequencer' in n.name:
ports += '--ServerPort=' + s + ' ' ports += '--ServerPort=' + s + ' '
else: else:
raise Exception('Wrong NIC type') raise KeyError('Wrong NIC type')
cmd = ( cmd = (
f'{env.repodir}/sims/external/ns-3' f'{env.repodir}/sims/external/ns-3'
f'/cosim-run.sh sequencer sequencer-single-switch-example' f'/cosim-run.sh sequencer sequencer-single-switch-example'
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment