Example #1
0
def initPvGroups():
    for k, v in sorted(pvgroups.items()):
        __file = '/'.join(
            (os.path.abspath(os.path.dirname(__file__)), 'pvs', v[0]))
        if os.path.exists(__file):
            if os.path.isfile(__file):
                pvlist = None
                try:
                    f = open(__file, 'r')
                    pvlist = f.read()
                    pvlist = pvlist.split('\n')
                    if len(pvlist[len(pvlist) - 1]) == 0:
                        pvlist = pvlist[:-1]
                    savePvGroup(conn, k, func=v[1])
                    saveGroupPvs(conn, k, pvlist)


#                    results = retrieveGroupPvs(conn, pvgroup_id[0])
                finally:
                    if f:
                        f.close()
                print('finished saving {0}'.format(v[0]))
            else:
                print("""pv list file ({0}) is not a file.""".format(v[0]))
        else:
            print("""pv list file ({0}) does not exist.""".format(v[0]))
Example #2
0
    def savePvGroups(self):        
        for k,v in sorted(pvgroups.items()):
            __file = "/".join((self.__filepath, v[0]))
            if os.path.exists(__file): 
                if os.path.isfile(__file):
#                    pvlist = None
                    try:
                        # remove all empty lines
                        with open(__file) as f_in:
                            lines = filter(None, (line.strip() for line in f_in))
#                        f = open(__file, 'r')
#                        pvlist = f.read()
#                        pvlist = pvlist.split('\n')
#                        if len(pvlist[len(pvlist)-1]) == 0:
#                            pvlist = pvlist[:-1]
                        if len(lines) > 0:
                            savePvGroup(self.conn, k, func=v[1])
                            saveGroupPvs(self.conn, k, lines)
                    finally:
                        if f_in:
                            f_in.close()
                    print ('Finished saving pvs in {0}'.format(v[0]))
                else:
                    raise Exception ("""PV list ({0}) is not a file.""".format(v[0]))
            else:
                raise Exception ("""Can not find pv list file ({0})""".format(v[0]))
def savePvGroups(json, basedir):
    for group in json:
        pvgname = group[u'name']
        pvgdesc = group[u'description']
        pv_file = group[u'pvlist']
        pvlist = []
        with open(os.path.join(basedir, pv_file)) as file:
            for line in file:
                pvlist.append(line.strip())
    __sqlitedb__ = os.environ["MASAR_SQLITE_DB"]
    with masarsqlite.connect(__sqlitedb__) as conn:
        savePvGroup(conn, pvgname, func=pvgdesc)
        saveGroupPvs(conn, pvgname, pvlist)
        conn.commit()
def SQLITE_DB_TEST_SETUP():
    # DB SETUP
    __sqlitedb__ = os.environ["MASAR_SQLITE_DB"]
    try:
        conn = sqlite3.connect(__sqlitedb__)
        cur = conn.cursor()
        __sql__ = None
        if __sql__ is None:
            from pymasarsqlite.db.masarsqlite import SQL
        else:
            sqlfile = open(__sql__)
            SQL = sqlfile.read()
        if SQL is None:
            print('SQLite script is empty. Cannot create SQLite db.')
            raise IOError('SQLite script is empty. Cannot create SQLite db.')
        else:
            cur.executescript(SQL)
            cur.execute("PRAGMA main.page_size= 4096;")
            cur.execute("PRAGMA main.default_cache_size= 10000;")
            cur.execute("PRAGMA main.locking_mode=EXCLUSIVE;")
            cur.execute("PRAGMA main.synchronous=NORMAL;")
            cur.execute("PRAGMA main.journal_mode=WAL;")
            cur.execute("PRAGMA main.temp_store = MEMORY;")

        cur.execute('select name from sqlite_master where type=\'table\'')
        masarconf = 'SR_All_20140421'
        servicename = 'masar'

        pvgname = 'masarpvgroup'
        pvgdesc = 'this is my new pv group for masar service with same group name'
        pvs = [
            "masarExample0000", "masarExample0001", "masarExampleBoUninit",
            "masarExampleMbboUninit", "masarExample0002", "masarExample0003",
            "masarExample0004", "masarExampleCharArray",
            "masarExampleShortArray", "masarExampleLongArray",
            "masarExampleStringArray", "masarExampleFloatArray",
            "masarExampleDoubleArray", "masarExampleMbboUninitTest"
        ]
        res = savePvGroup(conn, pvgname, func=pvgdesc)
        res = saveGroupPvs(conn, pvgname, pvs)
        pvgroups = retrievePvGroups(conn)
        saveService(conn, servicename, desc='test desc')
        saveServiceConfig(conn,
                          servicename,
                          masarconf,
                          system='SR',
                          status='active',
                          configversion=20140420,
                          configdesc='test desc')

        res = saveServicePvGroup(conn, masarconf, [pvgname])
        pvlist = retrieveServiceConfigPVs(conn,
                                          masarconf,
                                          servicename=servicename)
        results = retrieveServiceConfigs(conn, servicename, masarconf)
        conn.commit()
        conn.close()
    except sqlite3.Error, e:
        print("Error %s:" % e.args[0])
        raise
def SQLITE_DB_TEST_SETUP():
    # DB SETUP
    __sqlitedb__ = os.environ["MASAR_SQLITE_DB"]
    try:
        conn = sqlite3.connect(__sqlitedb__)
        cur = conn.cursor()
        __sql__ = None
        if __sql__ is None:
            from pymasarsqlite.db.masarsqlite import SQL
        else:
            sqlfile = open(__sql__)
            SQL = sqlfile.read()
        if SQL is None:
            print ('SQLite script is empty. Cannot create SQLite db.')
            raise IOError('SQLite script is empty. Cannot create SQLite db.')
        else:
            cur.executescript(SQL)
            cur.execute("PRAGMA main.page_size= 4096;")
            cur.execute("PRAGMA main.default_cache_size= 10000;")
            cur.execute("PRAGMA main.locking_mode=EXCLUSIVE;")
            cur.execute("PRAGMA main.synchronous=NORMAL;")
            cur.execute("PRAGMA main.journal_mode=WAL;")
            cur.execute("PRAGMA main.temp_store = MEMORY;")

        cur.execute('select name from sqlite_master where type=\'table\'')
        masarconf = 'SR_All_20140421'
        servicename = 'masar'

        pvgname = 'masarpvgroup'
        pvgdesc = 'this is my new pv group for masar service with same group name'
        pvs = ["masarExample0000",
               "masarExample0001",
               "masarExampleBoUninit",
               "masarExampleMbboUninit",
               "masarExample0002",
               "masarExample0003",
               "masarExample0004",
               "masarExampleCharArray",
               "masarExampleShortArray",
               "masarExampleLongArray",
               "masarExampleStringArray",
               "masarExampleFloatArray",
               "masarExampleDoubleArray",
               "masarExampleMbboUninitTest"]
        res = savePvGroup(conn, pvgname, func=pvgdesc)
        res = saveGroupPvs(conn, pvgname, pvs)
        pvgroups = retrievePvGroups(conn)
        saveService(conn, servicename, desc='test desc')
        saveServiceConfig(conn, servicename, masarconf, system='SR', status='active',
                          configversion=20140420, configdesc='test desc')

        res = saveServicePvGroup(conn, masarconf, [pvgname])
        pvlist = retrieveServiceConfigPVs(conn, masarconf, servicename=servicename)
        results = retrieveServiceConfigs(conn, servicename, masarconf)
        conn.commit()
        conn.close()
    except sqlite3.Error, e:
        print ("Error %s:" % e.args[0])
        raise
def savePvGroups(json):
    for group in json:
        pvgname = group[u'name']
        pvgdesc = group[u'description']
        pv_file = group[u'pvlist']
        pvlist = []
        if os.path.exists(pv_file):
            with open(pv_file) as file:
                for line in file:
                    pvlist.append(line.strip())
        else:
            print "Pvlist file: " + str(pv_file) + " does not exist."
            # file not found
    __sqlitedb__ = os.environ["MASAR_SQLITE_DB"]
    with sqlite3.connect(__sqlitedb__) as conn:
        savePvGroup(conn, pvgname, func=pvgdesc)
        saveGroupPvs(conn, pvgname, pvlist)
        conn.commit()
Example #7
0
def initPvGroups():        
    for k,v in sorted(pvgroups.items()):
        __file = '/'.join((os.path.abspath(os.path.dirname(__file__)), 'pvs', v[0]))
        if os.path.exists(__file): 
            if os.path.isfile(__file):
                pvlist = None
                try:
                    f = open(__file, 'r')
                    pvlist = f.read()
                    pvlist = pvlist.split('\n')
                    if len(pvlist[len(pvlist)-1]) == 0:
                        pvlist = pvlist[:-1]
                    savePvGroup(conn, k, func=v[1])
                    saveGroupPvs(conn, k, pvlist)
#                    results = retrieveGroupPvs(conn, pvgroup_id[0])
                finally:
                    if f:
                        f.close()
                print ('finished saving {0}'.format(v[0]))
            else:
                print ("""pv list file ({0}) is not a file.""".format(v[0]))
        else:
            print ("""pv list file ({0}) does not exist.""".format(v[0]))
    def testMultiGroup(self):
        # DB SETUP
        __sqlitedb__ = os.environ["MASAR_SQLITE_DB"]
        try:
            conn = sqlite3.connect(__sqlitedb__)
            pvgname1 = 'masarpvgroup1'
            pvgdesc1 = 'this is my new pv group for masar service with same group name'
            pvs1 = ["masarExample0000",
                    "masarExample0001",
                    "masarExampleBoUninit",
                    "masarExampleMbboUninit",
                    "masarExample0002",
                    "masarExample0003",
                    "masarExampleFloatArray",
                    "masarExample0004"]
            res1 = savePvGroup(conn, pvgname1, func=pvgdesc1)
            res1 = saveGroupPvs(conn, pvgname1, pvs1)
            pvgname2 = 'masarpvgroup2'
            pvgdesc2 = 'this is my new pv group for masar service with same group name'
            pvs2 = ["masarExample0000",
                    "masarExample0001",
                    "masarExample0002",
                    "masarExample0004",
                    "masarExampleCharArray",
                    "masarExampleShortArray",
                    "masarExampleLongArray",
                    "masarExampleStringArray",
                    "masarExampleFloatArray",
                    "masarExampleDoubleArray",
                    "masarExampleMbboUninitTest"]
            res2 = savePvGroup(conn, pvgname2, func=pvgdesc2)
            res2 = saveGroupPvs(conn, pvgname2, pvs2)
            pvgroups = retrievePvGroups(conn)
            self.assertEqual(pvgroups[0][1], "masarpvgroup")
            self.assertEqual(pvgroups[1][1], "masarpvgroup1")
            self.assertEqual(pvgroups[2][1], "masarpvgroup2")
            pvgroups = retrieveGroupPvs(conn, 2)
            self.assertEqual(pvgroups[0][0], "masarExample0000")
            self.assertEqual(pvgroups[1][0], "masarExample0001")
            self.assertEqual(pvgroups[2][0], "masarExampleBoUninit")
            self.assertEqual(pvgroups[3][0], "masarExampleMbboUninit")
            self.assertEqual(pvgroups[4][0], "masarExample0002")
            self.assertEqual(pvgroups[5][0], "masarExample0003")
            self.assertEqual(pvgroups[6][0], "masarExample0004")
            self.assertEqual(pvgroups[7][0], "masarExampleFloatArray")
            pvgroups = retrieveGroupPvs(conn, 3)
            self.assertEqual(pvgroups[0][0], "masarExample0000")
            self.assertEqual(pvgroups[1][0], "masarExample0001")
            self.assertEqual(pvgroups[2][0], "masarExample0002")
            self.assertEqual(pvgroups[3][0], "masarExample0004")
            self.assertEqual(pvgroups[4][0], "masarExampleCharArray")
            self.assertEqual(pvgroups[5][0], "masarExampleShortArray")
            self.assertEqual(pvgroups[6][0], "masarExampleLongArray")
            self.assertEqual(pvgroups[7][0], "masarExampleStringArray")
            self.assertEqual(pvgroups[8][0], "masarExampleFloatArray")
            self.assertEqual(pvgroups[9][0], "masarExampleDoubleArray")
            self.assertEqual(pvgroups[10][0], "masarExampleMbboUninitTest")
            servicename = "masar"
            masarconf = "testconf"
            saveService(conn, servicename, desc='test desc')
            saveServiceConfig(conn, servicename, masarconf, system='SR', status='active',
                              configversion=20140420, configdesc='test desc')

            res = saveServicePvGroup(conn, masarconf, [pvgname1, pvgname2])
            conn.commit()
            conn.close()
        except:
            raise
        save_params = {'configname': 'testconf',
                       'servicename': 'masar'}
        res1 = self.mc.saveSnapshot(save_params)
        self.assertNotEqual(res1, None)
        self.assertNotEqual(res1, False)
        event_id = res1[0]
        retrieve_params = {'eventid': str(event_id)}
        result = self.mc.retrieveSnapshot(retrieve_params)
        self.assertNotEqual(result, None)
        self.assertNotEqual(result, False)

        expected_results = (('masarExample0000',  # ChannelName 0
                            'masarExample0001',  # ChannelName 1
                            'masarExampleBoUninit',  # ChannelName 2
                            'masarExampleMbboUninit',  # ChannelName 3
                            'masarExample0002',  # ChannelName 4
                            'masarExample0003',  # ChannelName 5
                            'masarExample0004',  # ChannelName 6
                            'masarExampleCharArray',  # ChannelName 7
                            'masarExampleShortArray',  # ChannelName 8
                            'masarExampleLongArray',  # ChannelName 9
                            'masarExampleStringArray',  # ChannelName 10
                            'masarExampleFloatArray',  # ChannelName 11
                            'masarExampleDoubleArray',  # ChannelName 12
                            'masarExampleMbboUninitTest'),  # ChannelName 13
                            (10,  # 0000 Value
                            'string value',  # 0001 Value
                            '0',  # BoUninit Value (appropriately returned as string,
                            1,  # MbboUninit Value
                            'zero',  # 0002 Value
                            'one',  # 0003 Value
                            1.9,  # 0004 Value
                            (),  # CharArray Value
                            (),  # ShortArray Value
                            (),  # LongArray Value
                            (),  # StringArray Value
                            (),  # FloatArrayValue
                            (),  # DoubleArray Value
                            1),  # MbboUninitTest Value
                            (5, 0, 0, 5, 0, 0, 6, 4, 1, 5, 0, 2, 6, 5),  # DBR type
                            (1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1),  # isConnected
                            (631152000, 631152000, 631152000, 631152000, 631152000, 631152000, 631152000, 631152000, 631152000, 631152000,
                            631152000, 631152000, 631152000, 631152000),  # SecondsPastEpoch
                            (0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0),  # NanoSeconds
                            (0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0),  # UserTag
                            (0, 0, 3, 0, 3, 0, 0, 3, 3, 3, 3, 3, 3, 0),  # Severity
                            (3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3),  # Status
                            ('UDF_ALARM', 'UDF_ALARM', 'UDF_ALARM', 'UDF_ALARM', 'UDF_ALARM', 'UDF_ALARM', 'UDF_ALARM', 'UDF_ALARM',
                             'UDF_ALARM', 'UDF_ALARM', 'UDF_ALARM', 'UDF_ALARM', 'UDF_ALARM', 'UDF_ALARM'))  # Message
        self.assertSequenceEqual(result, expected_results)
    def testSaveSQLiteServiceConfigs(self):
        # DB SETUP
        __sqlitedb__ = os.environ["MASAR_SQLITE_DB"]
        try:
            conn = sqlite3.connect(__sqlitedb__)
            cur = conn.cursor()
            __sql__ = None
            if __sql__ is None:
                from pymasarsqlite.db.masarsqlite import SQL
            else:
                sqlfile = open(__sql__)
                SQL = sqlfile.read()
            if SQL is None:
                print ('SQLite script is empty. Cannot create SQLite db.')
                raise IOError('SQLite script is empty. Cannot create SQLite db.')
            else:
                cur.executescript(SQL)
                cur.execute("PRAGMA main.page_size= 4096;")
                cur.execute("PRAGMA main.default_cache_size= 10000;")
                cur.execute("PRAGMA main.locking_mode=EXCLUSIVE;")
                cur.execute("PRAGMA main.synchronous=NORMAL;")
                cur.execute("PRAGMA main.journal_mode=WAL;")
                cur.execute("PRAGMA main.temp_store = MEMORY;")

            cur.execute('select name from sqlite_master where type=\'table\'')
            masarconf = 'SR_All_20140421'
            servicename = 'masar'

            pvgname = 'masarpvgroup'
            pvgdesc = 'this is my new pv group for masar service with same group name'
            pvs = ["masarExample0000",
                   "masarExample0001",
                   "masarExampleBoUninit",
                   "masarExampleMbboUninit",
                   "masarExample0002",
                   "masarExample0003",
                   "masarExample0004",
                   "masarExampleCharArray",
                   "masarExampleShortArray",
                   "masarExampleLongArray",
                   "masarExampleStringArray",
                   "masarExampleFloatArray",
                   "masarExampleDoubleArray",
                   "masarExampleMbboUninitTest"]
            res = savePvGroup(conn, pvgname, func=pvgdesc)
            res = saveGroupPvs(conn, pvgname, pvs)
            pvgroups = retrievePvGroups(conn)
            saveService(conn, servicename, desc='test desc')
            conn.commit()
            conn.close()
            savePvGroups(self.parsed_json['pvgroups'])
            saveSQLiteServiceConfig(self.parsed_json)
            conn = sqlite3.connect(__sqlitedb__)
            pvgroups = retrievePvGroups(conn)
            self.assertEqual('BR_MG_Set_20130419', pvgroups[1][1])
            self.assertEqual('Booster magnet power supply set points', pvgroups[1][2])
            self.assertEqual(3, len(pvgroups[1][3].split(':')))  # Confirms correct date format
            self.assertEqual(3, len(pvgroups[1][3].split('-')))  # 2016-07-28 18:18:36
            self.assertEqual(None, pvgroups[1][4])
            configresult = retrieveServiceConfigs(conn)
            self.assertEqual('BR_MG_SCR_20130419', configresult[1][1])
            self.assertEqual('BR ramping PS daily SCR setpoint', configresult[1][2])
            self.assertEqual(3, len(configresult[1][3].split(':')))  # Confirms correct date format
            self.assertEqual(3, len(configresult[1][3].split('-')))  # 2016-07-28 18:18:36
            self.assertEqual(None, configresult[1][4])
            self.assertEqual('active', configresult[1][5])
        except sqlite3.Error, e:
            print ("Error %s:" % e.args[0])
            raise
Example #10
0
    def testConfiguration(self):
        channel = 'masarService'
        self.mc = masarClient.client(channelname=channel)
        # DB SETUP
        __sqlitedb__ = os.environ["MASAR_SQLITE_DB"]
        try:
            conn = sqlite3.connect(__sqlitedb__)
            cur = conn.cursor()
            __sql__ = None
            if __sql__ is None:
                from pymasarsqlite.db.masarsqlite import SQL
            else:
                sqlfile = open(__sql__)
                SQL = sqlfile.read()
            if SQL is None:
                print('SQLite script is empty. Cannot create SQLite db.')
                sys.exit()
            else:
                cur.executescript(SQL)
                cur.execute("PRAGMA main.page_size= 4096;")
                cur.execute("PRAGMA main.default_cache_size= 10000;")
                cur.execute("PRAGMA main.locking_mode=EXCLUSIVE;")
                cur.execute("PRAGMA main.synchronous=NORMAL;")
                cur.execute("PRAGMA main.journal_mode=WAL;")
                cur.execute("PRAGMA main.temp_store = MEMORY;")

            cur.execute('select name from sqlite_master where type=\'table\'')
            masarconf = 'SR_All_20140421'
            servicename = 'masar'

            pvgname = 'masarpvgroup'
            pvgdesc = 'this is my new pv group for masar service with same group name'
            pvs = ["masarExampleDoubleArray"]
            res = savePvGroup(conn, pvgname, func=pvgdesc)
            self.assertEqual([1], res)
            res2 = saveGroupPvs(conn, pvgname, pvs)
            with self.assertRaises(Exception) as context:
                saveGroupPvs(conn, "badname", pvs)
            self.assertEqual(
                context.exception.message,
                'pv group name (badname) is not unique, or not exist.')
            self.assertEqual([1], res2)
            pvgroups = retrievePvGroups(conn)
            self.assertEqual(5, len(pvgroups[0]))
            self.assertEqual(1, pvgroups[0][0])
            self.assertEqual(pvgname, pvgroups[0][1])
            self.assertEqual(pvgdesc, pvgroups[0][2])
            self.assertNotEqual(None, pvgroups[0][3])
            # The following 2 tests are to confirm the date string is in the correct format
            self.assertEqual(3, len(pvgroups[0][3].split('-')))
            self.assertEqual(3, len(pvgroups[0][3].split(':')))
            self.assertEqual(None, pvgroups[0][4])
            test_desc = 'test desc'
            test_system = 'SR'
            test_status = 'active'
            test_version = 20140420
            saveService(conn, servicename, desc=test_desc)

            with self.assertRaises(Exception) as context:
                saveServiceConfig(conn,
                                  "bad servicename",
                                  masarconf,
                                  system=test_system,
                                  status=test_status,
                                  configversion=test_version,
                                  configdesc=test_desc)
            self.assertEqual(
                "service with given name (bad servicename) does not exist.",
                context.exception.message)
            with self.assertRaises(Exception) as context:
                saveServiceConfig(conn,
                                  servicename,
                                  masarconf,
                                  system=test_system,
                                  status="bad status",
                                  configversion=test_version,
                                  configdesc=test_desc)
            self.assertEqual(
                "Service status has to be either active, or inactive",
                context.exception.message)
            saveServiceConfig(conn,
                              servicename,
                              masarconf,
                              system=test_system,
                              status=test_status,
                              configversion=test_version,
                              configdesc=test_desc)
            with self.assertRaises(Exception) as context:
                saveServiceConfig(conn,
                                  servicename,
                                  masarconf,
                                  system=test_system,
                                  status=test_status,
                                  configversion=test_version,
                                  configdesc=test_desc)
            self.assertEqual('service config exists already.',
                             context.exception.message)

            with self.assertRaises(
                    IndexError
            ):  # TODO: Should this be a more specific error message?
                saveServicePvGroup(conn, "bad config", [pvgname])
            with self.assertRaises(Exception) as context:
                res3 = saveServicePvGroup(
                    conn, masarconf,
                    ["bad pvgname"])  # this test prints a message to console
            self.assertEqual(
                "given pv group name (bad pvgname) does not exist.",
                context.exception.message)
            res3 = saveServicePvGroup(conn, masarconf, [pvgname])
            self.assertEqual([1], res3)
            with self.assertRaises(Exception) as context:
                pvlist = retrieveServiceConfigPVs(
                    conn, masarconf, servicename="bad servicename")
            pvlist = retrieveServiceConfigPVs(conn,
                                              masarconf,
                                              servicename=servicename)
            self.assertEqual(
                context.exception.message,
                'Given service (bad servicename) does not exist.')
            self.assertEqual(pvs, pvlist)
            self.expected_column_names = ('config_idx', 'config_name',
                                          'config_desc', 'config_create_date',
                                          'config_version', 'status')
            results = retrieveServiceConfigs(conn, "bad servicename",
                                             masarconf)
            self.assertSequenceEqual(self.expected_column_names, results[0])
            self.assertEqual(1, len(results))  # IE: no data returned
            self.assertEqual(len(self.expected_column_names), len(results[0]))
            results = retrieveServiceConfigs(conn, servicename, "bad conf")
            self.assertSequenceEqual(self.expected_column_names, results[0])
            self.assertEqual(1, len(results))  # IE: no data returned
            self.assertEqual(len(self.expected_column_names), len(results[0]))
            results = retrieveServiceConfigs(conn, servicename, masarconf)
            # Label tests
            self.assertSequenceEqual(self.expected_column_names, results[0])
            self.assertEqual(2, len(results))
            self.assertEqual(len(self.expected_column_names), len(results[0]))
            # Data tests
            self.assertEqual(masarconf, results[1][1])
            self.assertEqual(test_desc, results[1][2])
            self.assertNotEqual(None, results[1][3])
            self.assertEqual(1, results[1][0])
            self.assertEqual(len(self.expected_column_names), len(results[1]))
            # The following 2 tests are to confirm the date string is in the correct format
            self.assertEqual(3, len(results[1][3].split('-')))
            self.assertEqual(3, len(results[1][3].split(':')))
            self.assertEqual(test_version, results[1][4])
            self.assertEqual(test_status, results[1][5])
            conn.commit()
            conn.close()
        except sqlite3.Error, e:
            print("Error %s:" % e.args[0])
            raise
Example #11
0
    def testMultiGroup(self):
        # DB SETUP
        __sqlitedb__ = os.environ["MASAR_SQLITE_DB"]
        try:
            conn = sqlite3.connect(__sqlitedb__)
            pvgname1 = 'masarpvgroup1'
            pvgdesc1 = 'this is my new pv group for masar service with same group name'
            pvs1 = [
                "masarExample0000", "masarExample0001", "masarExampleBoUninit",
                "masarExampleMbboUninit", "masarExample0002",
                "masarExample0003", "masarExampleFloatArray",
                "masarExample0004"
            ]
            res1 = savePvGroup(conn, pvgname1, func=pvgdesc1)
            res1 = saveGroupPvs(conn, pvgname1, pvs1)
            pvgname2 = 'masarpvgroup2'
            pvgdesc2 = 'this is my new pv group for masar service with same group name'
            pvs2 = [
                "masarExample0000", "masarExample0001", "masarExample0002",
                "masarExample0004", "masarExampleCharArray",
                "masarExampleShortArray", "masarExampleLongArray",
                "masarExampleStringArray", "masarExampleFloatArray",
                "masarExampleDoubleArray", "masarExampleMbboUninitTest"
            ]
            res2 = savePvGroup(conn, pvgname2, func=pvgdesc2)
            res2 = saveGroupPvs(conn, pvgname2, pvs2)
            pvgroups = retrievePvGroups(conn)
            self.assertEqual(pvgroups[0][1], "masarpvgroup")
            self.assertEqual(pvgroups[1][1], "masarpvgroup1")
            self.assertEqual(pvgroups[2][1], "masarpvgroup2")
            pvgroups = retrieveGroupPvs(conn, 2)
            self.assertEqual(pvgroups[0][0], "masarExample0000")
            self.assertEqual(pvgroups[1][0], "masarExample0001")
            self.assertEqual(pvgroups[2][0], "masarExampleBoUninit")
            self.assertEqual(pvgroups[3][0], "masarExampleMbboUninit")
            self.assertEqual(pvgroups[4][0], "masarExample0002")
            self.assertEqual(pvgroups[5][0], "masarExample0003")
            self.assertEqual(pvgroups[6][0], "masarExample0004")
            self.assertEqual(pvgroups[7][0], "masarExampleFloatArray")
            pvgroups = retrieveGroupPvs(conn, 3)
            self.assertEqual(pvgroups[0][0], "masarExample0000")
            self.assertEqual(pvgroups[1][0], "masarExample0001")
            self.assertEqual(pvgroups[2][0], "masarExample0002")
            self.assertEqual(pvgroups[3][0], "masarExample0004")
            self.assertEqual(pvgroups[4][0], "masarExampleCharArray")
            self.assertEqual(pvgroups[5][0], "masarExampleShortArray")
            self.assertEqual(pvgroups[6][0], "masarExampleLongArray")
            self.assertEqual(pvgroups[7][0], "masarExampleStringArray")
            self.assertEqual(pvgroups[8][0], "masarExampleFloatArray")
            self.assertEqual(pvgroups[9][0], "masarExampleDoubleArray")
            self.assertEqual(pvgroups[10][0], "masarExampleMbboUninitTest")
            servicename = "masar"
            masarconf = "testconf"
            saveService(conn, servicename, desc='test desc')
            saveServiceConfig(conn,
                              servicename,
                              masarconf,
                              system='SR',
                              status='active',
                              configversion=20140420,
                              configdesc='test desc')

            res = saveServicePvGroup(conn, masarconf, [pvgname1, pvgname2])
            conn.commit()
            conn.close()
        except:
            raise
        save_params = {'configname': 'testconf', 'servicename': 'masar'}
        res1 = self.mc.saveSnapshot(save_params)
        self.assertNotEqual(res1, None)
        self.assertNotEqual(res1, False)
        event_id = res1[0]
        retrieve_params = {'eventid': str(event_id)}
        result = self.mc.retrieveSnapshot(retrieve_params)
        self.assertNotEqual(result, None)
        self.assertNotEqual(result, False)

        expected_results = (
            (
                'masarExample0000',  # ChannelName 0
                'masarExample0001',  # ChannelName 1
                'masarExampleBoUninit',  # ChannelName 2
                'masarExampleMbboUninit',  # ChannelName 3
                'masarExample0002',  # ChannelName 4
                'masarExample0003',  # ChannelName 5
                'masarExample0004',  # ChannelName 6
                'masarExampleCharArray',  # ChannelName 7
                'masarExampleShortArray',  # ChannelName 8
                'masarExampleLongArray',  # ChannelName 9
                'masarExampleStringArray',  # ChannelName 10
                'masarExampleFloatArray',  # ChannelName 11
                'masarExampleDoubleArray',  # ChannelName 12
                'masarExampleMbboUninitTest'),  # ChannelName 13
            (
                10,  # 0000 Value
                'string value',  # 0001 Value
                '0',  # BoUninit Value (appropriately returned as string,
                1,  # MbboUninit Value
                'zero',  # 0002 Value
                'one',  # 0003 Value
                1.9,  # 0004 Value
                (),  # CharArray Value
                (),  # ShortArray Value
                (),  # LongArray Value
                (),  # StringArray Value
                (),  # FloatArrayValue
                (),  # DoubleArray Value
                1),  # MbboUninitTest Value
            (5, 0, 0, 5, 0, 0, 6, 4, 1, 5, 0, 2, 6, 5),  # DBR type
            (1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1),  # isConnected
            (631152000, 631152000, 631152000, 631152000, 631152000, 631152000,
             631152000, 631152000, 631152000, 631152000, 631152000, 631152000,
             631152000, 631152000),  # SecondsPastEpoch
            (0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0),  # NanoSeconds
            (0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0),  # UserTag
            (0, 0, 3, 0, 3, 0, 0, 3, 3, 3, 3, 3, 3, 0),  # Severity
            (3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3),  # Status
            ('UDF_ALARM', 'UDF_ALARM', 'UDF_ALARM', 'UDF_ALARM', 'UDF_ALARM',
             'UDF_ALARM', 'UDF_ALARM', 'UDF_ALARM', 'UDF_ALARM', 'UDF_ALARM',
             'UDF_ALARM', 'UDF_ALARM', 'UDF_ALARM', 'UDF_ALARM'))  # Message
        self.assertSequenceEqual(result, expected_results)