예제 #1
0
def register_devices():
    """."""
    tango_db = tango.Database()
    logging.info("Registering devices!")

    device_info = tango.DbDevInfo()

    device_class = 'TestDevice1'

    # Name of device (/server?) class.
    device_info._class = device_class

    # Name of server instance
    device_info.server = "{}/1".format(device_class)

    # Generate names and add devices to the database.
    start_time = time.time()
    num_devices = 1
    for index in range(num_devices):
        device_info.name = 'test/1/{:03d}'.format(index)
        tango_db.add_device(device_info)

    # Set properties
    tango_db.put_class_property(device_class, dict(version='1.0.0'))
    print('elapsed = {}'.format(time.time() - start_time))
def _declare_devices(db, devices, clazz, server):
    for device in devices:
        info = tango.DbDevInfo()
        info._class = clazz
        info.server = server
        info.name = device
        db.add_device(info)
    def __init__(self, methodName):
        """ constructor

        :param methodName: name of the test method
        """

        PyBenchmarkTargetDeviceTest.__init__(self, methodName)
        self.instance = 'TEST'
        self.device = 'test/javabenchmarktarget/000'
        self.new_device_info_benchmark = tango.DbDevInfo()
        self.new_device_info_benchmark._class = "JavaBenchmarkTarget"
        self.new_device_info_benchmark.server = "JavaBenchmarkTarget/%s" % \
                                                self.instance
        self.new_device_info_benchmark.name = self.device
        self.proxy = None

        # home = expanduser("~")
        # serverfile = "%s/DeviceServers/JavaBenchmarkTarget" % home
        # if os.path.isfile(serverfile):
        self._startserver = \
            "cd ../JavaBenchmarkTarget; " \
            "CLASSPATH=/usr/share/java/JTango.jar:" \
            "./target/JavaBenchmarkTarget-1.0.jar:$CLASSPATH ; " \
            "export CLASSPATH; . /etc/tangorc; export TANGO_HOST; " \
            "java  org.tango.javabenchmarktarget.JavaBenchmarkTarget %s &" % \
            (self.instance)
        # else:
        #     self._startserver = "JavaBenchmarkTarget %s &" % self.instance
        self._grepserver = \
            "ps -ef | " \
            "grep 'JavaBenchmarkTarget %s' | grep -v grep" % (self.instance)
예제 #4
0
def __recreate_axes(server_name,
                    manager_dev_name,
                    axis_names,
                    dev_map,
                    db=None):
    db = db or tango.Database()

    curr_axes = {}

    for dev_class, dev_names in dev_map.items():
        if not dev_class.startswith('BlissAxis_'):
            continue
        for dev_name in dev_names:
            curr_axis_name = dev_name.rsplit("/", 1)[-1]

            try:
                get_axis(curr_axis_name)
            except:
                elog.info("Error instantiating %s (%s):" %
                          (curr_axis_name, dev_name))
                traceback.print_exc()
            curr_axes[curr_axis_name] = dev_name, dev_class

    axis_names_set = set(axis_names)
    curr_axis_names_set = set(curr_axes)
    new_axis_names = axis_names_set.difference(curr_axis_names_set)
    old_axis_names = curr_axis_names_set.difference(axis_names_set)

    domain, family, member = manager_dev_name.split('/', 2)

    # remove old axes
    for axis_name in old_axis_names:
        dev_name, klass_name = curr_axes[axis_name]
        elog.debug('removing old axis %s (%s)' % (dev_name, axis_name))
        db.delete_device(dev_name)

    # add new axes
    for axis_name in new_axis_names:
        dev_name = "%s/%s_%s/%s" % (domain, family, member, axis_name)
        info = tango.DbDevInfo()
        info.server = server_name
        info._class = 'BlissAxis_' + axis_name
        info.name = dev_name
        elog.debug('adding new axis %s (%s)' % (dev_name, axis_name))
        db.add_device(info)
        # try to create alias if it doesn't exist yet
        try:
            db.get_device_alias(axis_name)
        except tango.DevFailed:
            elog.debug('registering alias for %s (%s)' % (dev_name, axis_name))
            db.put_device_alias(dev_name, axis_name)

    axes, tango_classes = [], []
    for axis_name in axis_names_set:
        axis = get_axis(axis_name)
        axes.append(axis)
        tango_class = __create_tango_axis_class(axis)
        tango_classes.append(tango_class)

    return axes, tango_classes
    def __init__(self, methodName):
        """ constructor

        :param methodName: name of the test method
        """
        unittest.TestCase.__init__(self, methodName)
        self.instance = 'TEST'
        self.device = 'test/pybenchmarktarget/000'
        self.new_device_info_benchmark = tango.DbDevInfo()
        self.new_device_info_benchmark._class = "PyBenchmarkTarget"
        self.new_device_info_benchmark.server = "PyBenchmarkTarget/%s" % \
                                                self.instance
        self.new_device_info_benchmark.name = self.device
        self.proxy = None

        if PY3:
            if os.path.isdir("./PyBenchmarkTarget"):
                self._startserver = \
                    "python3 ./PyBenchmarkTarget %s &" % self.instance
            else:
                self._startserver = \
                    "python3 PyBenchmarkTarget %s &" % self.instance
        else:
            if os.path.isdir("./PyBenchmarkTarget"):
                self._startserver = \
                    "python2 ./PyBenchmarkTarget %s &" % self.instance
            else:
                self._startserver = \
                    "python2 PyBenchmarkTarget %s &" % self.instance
        self._grepserver = \
            "ps -ef | grep 'PyBenchmarkTarget %s' | grep -v grep" % \
            self.instance
예제 #6
0
 def add(self):
     """Add instances of the device to the DB"""
     dev_info = tango.DbDevInfo()
     dev_info.server = self._server
     dev_info._class = self._class
     for i in range(self._count):
         dev_info.name = self._name_string.format(i)
         self.db.add_device(dev_info)
예제 #7
0
def register():
    """."""
    db = tango.Database()
    device_info = tango.DbDevInfo()

    device_info.server = 'TestDeviceServer/1'
    device_info.name = 'test/test_device/0'
    device_info._class = 'TestDevice1'
    db.add_device(device_info)
예제 #8
0
def register_server(db=None):
    if db is None:
        db = tango.Database()

    server_name, instance_name, server_instance = get_server_info()

    domain = os.environ.get('BEAMLINENAME', 'bliss')
    dev_name = '{0}/BlissAxisManager/{1}'.format(domain, instance_name)
    elog.info(" registering new server: %s" % dev_name)
    info = tango.DbDevInfo()
    info.server = server_instance
    info._class = 'BlissAxisManager'
    info.name = dev_name
    db.add_device(info)
예제 #9
0
def register(num_devices):
    """."""
    db = tango.Database()
    device_info = tango.DbDevInfo()

    device_info.server = 'TestDeviceServer/1'
    device_info._class = 'TestDevice1'

    start_time = time.time()
    for device_id in range(num_devices):
        device_info.name = 'test/test_device/{:05d}'.format(device_id)
        db.add_device(device_info)
    elapsed = time.time() - start_time
    print('- Register devices: {:.4f} s ({:.4f} s/device)'.format(
        elapsed, elapsed / num_devices))
예제 #10
0
def register(num_devices):
    """."""
    db = tango.Database()
    device_info = tango.DbDevInfo()

    device_info.server = 'TestDeviceServer/1'
    device_info._class = 'TestDevice'

    start_time = time.time()
    for device_id in range(num_devices):
        device_info.name = 'test/test_device/{:05d}'.format(device_id)
        db.add_device(device_info)
    elapsed = time.time() - start_time
    file = open('results.txt', 'a')
    file.write('{},{},{}'.format(num_devices, elapsed, elapsed / num_devices))
    print('- Register devices: {:.4f} s ({:.4f} s/device)'.format(
        elapsed, elapsed / num_devices))
예제 #11
0
    def register(self,
                 device_class=None,
                 server_instance=None,
                 target_device=None,
                 host=None,
                 stop=True):
        """create device

        :param device_class: device class
        :type device_class: :obj:`str`
        :param server_instance: server instance
        :type server_instance: :obj:`str`
        :param target_device: target device
        :type target_device: :obj:`str`
        :param host: host name
        :type host: :obj:`str`
        :param stop: mark server to be stopped
        :type stop: :obj:`bool`
        """

        servers = self.__db.get_server_list(server_instance).value_string
        devices = self.__db.get_device_exported_for_class(
            device_class).value_string
        new_device = tango.DbDevInfo()
        new_device._class = device_class
        new_device.server = server_instance
        new_device.name = target_device
        if not servers:
            if target_device in devices:
                raise Exception("Device %s exists in different server" %
                                device_class)
            self.__db.add_device(new_device)
            self.__db.add_server(new_device.server, new_device)
            if stop:
                self.__registered_servers.append(new_device.server)
                self.__registered_devices.append(target_device)
        else:
            if target_device not in devices:
                self.__db.add_device(new_device)
                if stop:
                    self.__registered_devices.append(target_device)
            else:
                pass
예제 #12
0
# 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.
#

##
# configure tango for testing the WienerMpodLvHvCtrl device server
##

import tango

db = tango.Database()

## register the tango device "mpod_hv_module_test/hv/1"
dev_info = tango.DbDevInfo()
dev_info.server = 'WienerMpodHvModule/mpod_hv_module_test'
dev_info._class = 'WienerMpodHvModule'
dev_info.name = 'mpod_hv_module_test/hv/1'
db.add_device(dev_info)

## this is the new device
test_device = tango.DeviceProxy('mpod_hv_module_test/hv/1')

## define the nqme of the corresponding WienerMpodLvHvCtrl device
dat = tango.DbDatum()
dat.name = 'WienerMpodLvHvCtrlDevice'
dat.value_string.append('mpod_test/mpod/1')
test_device.put_property(dat)

## define the nqme of the corresponding WienerMpodLvHvCtrl deviceslot index in the MPOD crate
예제 #13
0
def recreate_bliss(server_name,
                   manager_dev_name,
                   temp_names,
                   dev_map,
                   db=None):
    db = db or tango.Database()
    config = get_config()
    curr_temps = {}
    for dev_class, dev_names in dev_map.items():
        if not dev_class.startswith('BlissInput_') and \
           not dev_class.startswith('BlissOutput_') and \
           not dev_class.startswith('BlissLoop_'):
            continue
        for dev_name in dev_names:
            curr_temp_name = dev_name.rsplit("/", 1)[-1]

            try:
                config.get(curr_temp_name)
            except:
                elog.info("Error instantiating %s (%s):" %
                          (curr_temp_name, dev_name))
                traceback.print_exc()
            curr_temps[curr_temp_name] = dev_name, dev_class

    temp_names_set = set(temp_names)
    curr_temp_names_set = set(curr_temps)
    new_temp_names = temp_names_set.difference(curr_temp_names_set)
    old_temp_names = curr_temp_names_set.difference(temp_names_set)

    domain, family, member = manager_dev_name.split('/', 2)

    # remove old temps
    for temp_name in old_temp_names:
        dev_name, klass_name = curr_temps[temp_name]
        elog.debug('removing old temp %s (%s)' % (dev_name, temp_name))
        db.delete_device(dev_name)

    # add new temps
    for temp_name in new_temp_names:
        temp = config.get(temp_name)
        temp_type = __get_type_name(temp)
        dev_name = "%s/%s_%s/%s" % (domain, family, member, temp_name)
        info = tango.DbDevInfo()
        info.server = server_name
        info._class = 'Bliss%s_%s' % (temp_type, temp_name)
        info.name = dev_name
        elog.debug('adding new temp %s (%s)' % (dev_name, temp_name))
        db.add_device(info)
        # try to create alias if it doesn't exist yet
        try:
            db.get_device_alias(temp_name)
        except tango.DevFailed:
            elog.debug('registering alias for %s (%s)' % (dev_name, temp_name))
            db.put_device_alias(dev_name, temp_name)

    temps, tango_classes = [], []
    for temp_name in temp_names_set:
        temp = config.get(temp_name)
        temp_type = __get_type_name(temp)
        temps.append(temp)
        tango_base_class = globals()['Bliss' + temp_type]
        tango_class = __create_tango_class(temp, tango_base_class)
        tango_classes.append(tango_class)

    return temps, tango_classes
예제 #14
0
def recreate(db=None, new_server=False, typ='inputs'):
    global dev_map
    #    import pdb; pdb.set_trace()
    if db is None:
        db = tango.Database()

    # some io definitions.
    if typ == 'inputs':
        classname = 'BlissInput'
        classmsg = 'input'
    elif typ == 'outputs':
        classname = 'BlissOutput'
        classmsg = 'output'
    elif typ == 'ctrl_loops':
        classname = 'BlissLoop'
        classmsg = 'loop'
    else:
        print "Type %s not recognized. Exiting" % typ
        sys.exit(255)

    server_name, instance_name, server_instance = get_server_info()

    registered_servers = set(db.get_instance_name_list('BlissTempManager'))

    # check if server exists in database. If not, create it.
    if instance_name not in registered_servers:
        if new_server:
            register_server(db=db)
        else:
            print "The device server %s is not defined in database. " \
                "Exiting!" % server_instance
            print "hint: start with '-n' to create a new one automatically"
            sys.exit(255)

    dev_map = get_devices_from_server(db=db)

    io_names = get_server_io_names(typ=typ)

    # gather info about current io registered in database and
    # new io from config

    curr_ios = {}
    for dev_class, dev_names in dev_map.items():
        if not dev_class.startswith(classname):
            continue
        for dev_name in dev_names:
            curr_io_name = dev_name.rsplit("/", 1)[-1]
            curr_ios[curr_io_name] = dev_name, dev_class

    io_names_set = set(io_names)
    curr_io_names_set = set(curr_ios)
    new_io_names = io_names_set.difference(curr_io_names_set)
    old_io_names = curr_io_names_set.difference(io_names_set)

    domain = os.environ.get('BEAMLINENAME', 'bliss')
    family = 'temperature'
    member = instance_name

    # remove old io
    for io_name in old_io_names:
        dev_name, klass_name = curr_ios[io_name]
        elog.debug('removing old %s %s (%s)' % (classmsg, dev_name, io_name))
        db.delete_device(dev_name)

    # add new io
    for io_name in new_io_names:
        dev_name = "%s/%s_%s/%s" % (domain, family, member, io_name)
        info = tango.DbDevInfo()
        info.server = server_instance
        info._class = "%s_%s" % (classname, io_name)
        info.name = dev_name
        elog.debug('adding new %s %s (%s)' % (classmsg, dev_name, io_name))
        db.add_device(info)
        # try to create alias if it doesn't exist yet
        try:
            db.get_device_alias(io_name)
        except tango.DevFailed:
            elog.debug('registering alias for %s (%s)' % (dev_name, io_name))
            db.put_device_alias(dev_name, io_name)

    cfg = get_config()
    io_objs, tango_classes = [], []
    for io_name in curr_io_names_set:
        io_obj = cfg.get(io_name)
        io_objs.append(io_obj)
        tango_base_class = globals()[classname]
        tango_class = __create_tango_class(io_obj, tango_base_class)
        tango_classes.append(tango_class)

    return io_objs, tango_classes