This is merely a historical archive of years 2008-2021, before the migration to mailman3.
A maintained and still updated list archive can be found at https://lists.osmocom.org/hyperkitty/list/gerrit-log@lists.osmocom.org/.
Pau Espin Pedrol gerrit-no-reply at lists.osmocom.orgHello Harald Welte, Jenkins Builder, I'd like you to reexamine a change. Please visit https://gerrit.osmocom.org/7167 to look at the new patch set (#2). Introduce PowerSupply interface and PowerSupplySispm File powersupply.py defines the interface to be used by child classes implementing it. It also provides helpers to allocate a child class based on configuration provided ('type' field). File powersupply_sispm.py is an implementation using pysispm [1], as it's the one used to control the programmable power socket we have right now. This kind of class will be used in later commits by Nanobts class, as we want to poweroff the Nanobts completelly when not in use. Using it requires the following extra dependencies: $ apt-get install python3-usb $ pip3 install pysispm Related: OS#3040 [1] https://github.com/xypron/pysispm Change-Id: I981c260eca1a61657147e6d83b4226618088223c --- A src/osmo_gsm_tester/powersupply.py A src/osmo_gsm_tester/powersupply_sispm.py 2 files changed, 144 insertions(+), 0 deletions(-) git pull ssh://gerrit.osmocom.org:29418/osmo-gsm-tester refs/changes/67/7167/2 diff --git a/src/osmo_gsm_tester/powersupply.py b/src/osmo_gsm_tester/powersupply.py new file mode 100644 index 0000000..69dd51b --- /dev/null +++ b/src/osmo_gsm_tester/powersupply.py @@ -0,0 +1,69 @@ +# osmo_gsm_tester: class defining a Power Supply object +# +# Copyright (C) 2018 by sysmocom - s.f.m.c. GmbH +# +# Author: Pau Espin Pedrol <pespin at sysmocom.de> +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. + +from abc import ABCMeta, abstractmethod +from . import log, event_loop + +class PowerSupply(log.Origin, metaclass=ABCMeta): + +############## +# PROTECTED +############## + def __init__(self, conf, name): + super().__init__(log.C_RUN, name) + self.conf = conf + +######################## +# PUBLIC - INTERNAL API +######################## + @abstractmethod + def powered(self): + 'Get whether the device is powered on or off' + pass + + @abstractmethod + def power_set(self, onoff): + 'Turn on (onoff=True) or off (onof=False) the device' + pass + + def power_cycle(self, sleep=0): + 'Turns off the device, waits N.N seconds, then turn on the device' + self.power_set(False) + event_loop.sleep(self, sleep) + self.power_set(True) + + +from . import powersupply_sispm + +KNOWN_PWSUPPLY_TYPES = { + 'sispm' : powersupply_sispm.PowerSupplySispm, +} + +def register_type(name, clazz): + KNOWN_PWSUPPLY_TYPES[name] = clazz + +def get_instance_by_type(pwsupply_type, pwsupply_opt): + obj = KNOWN_PWSUPPLY_TYPES.get(pwsupply_type, None) + if not obj: + raise log.Error('PowerSupply type not supported:', pwsupply_type) + return obj(pwsupply_opt) + + + +# vim: expandtab tabstop=4 shiftwidth=4 diff --git a/src/osmo_gsm_tester/powersupply_sispm.py b/src/osmo_gsm_tester/powersupply_sispm.py new file mode 100644 index 0000000..3bc6c29 --- /dev/null +++ b/src/osmo_gsm_tester/powersupply_sispm.py @@ -0,0 +1,75 @@ +# osmo_gsm_tester: class defining a Power Supply object +# +# Copyright (C) 2018 by sysmocom - s.f.m.c. GmbH +# +# Author: Pau Espin Pedrol <pespin at sysmocom.de> +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. + +import sispm + +from . import log +from .powersupply import PowerSupply + +class PowerSupplySispm(PowerSupply): + + device = None + +############## +# PROTECTED +############## + def __init__(self, conf): + super().__init__(conf, 'sispm') + mydevid = conf.get('device', None) + if mydevid is None: + raise log.Error('No "device" attribute provided in supply conf!') + self.set_name('sispm-'+mydevid) + myport = conf.get('port', None) + if myport is None: + raise log.Error('No "port" attribute provided in power_supply conf!') + if not int(myport): + raise log.Error('Wrong non numeric "port" attribute provided in power_supply conf!') + self.port = int(myport) + + devices = sispm.connect() + for d in devices: + did = sispm.getid(d) + self.dbg('detected device:', did) + if did == mydevid: + self.device = d + dmin = sispm.getminport(d) + dmax = sispm.getmaxport(d) + self.dbg('found matching device: %s min=%d max=%d' % (did, dmin, dmax)) + if dmin > self.port or dmax < self.port: + raise log.Error('Out of range "port" attribute provided in power_supply conf!') + + +######################## +# PUBLIC - INTERNAL API +######################## + def powered(self): + 'Get whether the device is powered on or off' + return sispm.getstatus(self.device, self.port) + + def power_set(self, onoff): + 'Turn on (onoff=True) or off (onof=False) the device' + if onoff: + self.dbg('switchon') + sispm.switchon(self.device, self.port) + else: + self.dbg('switchoff') + sispm.switchoff(self.device, self.port) + + +# vim: expandtab tabstop=4 shiftwidth=4 -- To view, visit https://gerrit.osmocom.org/7167 To unsubscribe, visit https://gerrit.osmocom.org/settings Gerrit-MessageType: newpatchset Gerrit-Change-Id: I981c260eca1a61657147e6d83b4226618088223c Gerrit-PatchSet: 2 Gerrit-Project: osmo-gsm-tester Gerrit-Branch: master Gerrit-Owner: Pau Espin Pedrol <pespin at sysmocom.de> Gerrit-Reviewer: Harald Welte <laforge at gnumonks.org> Gerrit-Reviewer: Jenkins Builder