def saveMongoService(json): conn, collection = utils.conn(host=masarconfig.get('mongodb', 'host'), port=masarconfig.get('mongodb', 'port'), db=masarconfig.get('mongodb', 'database')) for conf in json['configs']: params = { "desc": conf['config_desc'], "system": conf['system'], "status": "active" } try: saveconfig(conn, collection, conf['config_name'], **params) except: # TODO: This should be more specific print("configuration name (%s) exists already." % (conf['config_name'])) pvgroups = {} # {"pvgname":["pv1","pv2"]} for pvgroup in json['pvgroups']: pvlist = [] pv_file = pvgroup['pvlist'] if os.path.exists(pv_file): with open(pv_file) as file: for line in file: pvlist.append(line.strip()) pvgroups[pvgroup['name']] = pvlist for conf in json['pvg2config']: pvs = [] for pvgroup in conf['pvgroups']: pvs = pvs + pvgroups[pvgroup] updateconfig(conn, collection, conf['config_name'], pvlist={"names": pvs})
def mongoSetUp(): # DB SETUP conn, collection = utils.conn(host=masarconfig.get('mongodb', 'host'), port=masarconfig.get('mongodb', 'port'), db=masarconfig.get('mongodb', 'database')) conn.drop_database(masarconfig.get('mongodb', 'database')) name = "SR_All_20140421" params = { "desc": "SR daily SCR setpoint without IS kick and septum: SR and RF", "system": "SR", "status": "active", "version": 20140421, } newid = saveconfig(conn, collection, name, **params) # res0 = retrieveconfig(self.conn, collection, name) pvs = [ "masarExample0000", "masarExample0001", # "masarExampleBoUninit", "masarExampleMbboUninit", "masarExample0002", "masarExample0003", "masarExample0004", "masarExampleCharArray", "masarExampleShortArray", "masarExampleLongArray", "masarExampleStringArray", "masarExampleFloatArray", "masarExampleDoubleArray", "masarExampleMbboUninitTest" ] # TODO: Save will fail if list contains only 1 PV updateconfig(conn, collection, name, pvlist={"names": pvs})
def saveMongoService(json): conn, collection = utils.conn(host=masarconfig.get('mongodb', 'host'), port=masarconfig.get('mongodb', 'port'), db=masarconfig.get('mongodb', 'database')) for conf in json['configs']: params = {"desc": conf['config_desc'], "system": conf['system'], "status": "active"} try: saveconfig(conn, collection, conf['config_name'], **params) except: # TODO: This should be more specific print ("configuration name (%s) exists already." % (conf['config_name'])) pvgroups = {} # {"pvgname":["pv1","pv2"]} for pvgroup in json['pvgroups']: pvlist = [] pv_file = pvgroup['pvlist'] if os.path.exists(pv_file): with open(pv_file) as file: for line in file: pvlist.append(line.strip()) pvgroups[pvgroup['name']] = pvlist for conf in json['pvg2config']: pvs = [] for pvgroup in conf['pvgroups']: pvs = pvs + pvgroups[pvgroup] updateconfig(conn, collection, conf['config_name'], pvlist={"names": pvs})
def MONGODB_TEST_SETUP(self): self.conn, collection = utils.conn(host=masarconfig.get('mongodb', 'host'), port=masarconfig.get('mongodb', 'port'), db=masarconfig.get('mongodb', 'database')) self.conn.drop_database(masarconfig.get('mongodb', 'database')) name = "SR_All_20140421" params = {"desc": "SR daily SCR setpoint without IS kick and septum: SR and RF", "system": "SR", "status": "active", "version": 20140421, } newid = saveconfig(self.conn, collection, name, **params) # res0 = retrieveconfig(self.conn, collection, name) pvs = ["masarExample0000", "masarExample0001", # "masarExampleBoUninit", "masarExampleMbboUninit", "masarExample0002", "masarExample0003", "masarExample0004", "masarExampleCharArray", "masarExampleShortArray", "masarExampleLongArray", "masarExampleStringArray", "masarExampleFloatArray", "masarExampleDoubleArray", "masarExampleMbboUninitTest"] # TODO: Save will fail if list contains only 1 PV updateconfig(self.conn, collection, name, pvlist={"names": pvs}) # res3 = retrieveconfig(self.conn, collection, name, withpvs=True) return self.conn
def testConfiguration(self): channel = 'masarService' self.mc = masarClient.client(channelname=channel) # DB SETUP self.conn, collection = utils.conn( host=masarconfig.get('mongodb', 'host'), port=masarconfig.get('mongodb', 'port'), db=masarconfig.get('mongodb', 'database')) self.conn.drop_database(masarconfig.get('mongodb', 'database')) name = "SR_All_20140421" test_status = 'active' test_version = 20140421 test_system = 'SR' test_desc = "SR daily SCR setpoint without IS kick and septum: SR and RF" params = { "desc": test_desc, "system": test_system, "status": test_status, "version": test_version, } newid = saveconfig(self.conn, collection, name, **params) self.assertNotEqual(None, newid) res0 = retrieveconfig(self.conn, collection, name) self.assertEqual(test_status, res0[0]['status']) self.assertEqual(1, res0[0]['configidx']) self.assertEqual(name, res0[0]['name']) self.assertEqual(test_system, res0[0]['system']) self.assertNotEqual(None, res0[0]['created_on']) # The following 2 tests are to confirm the date string is in the correct format self.assertEqual(3, len(res0[0]['created_on'].split('-'))) self.assertEqual(3, len(res0[0]['created_on'].split(':'))) self.assertEqual(test_version, res0[0]['version']) self.assertEqual(test_desc, res0[0]['desc']) pvs = ["masarExampleDoubleArray"] pvlist = {"names": pvs} res = updateconfig(self.conn, collection, name, pvlist=pvlist) self.assertEqual(True, res) res3 = retrieveconfig(self.conn, collection, name, withpvs=True) self.assertEqual(test_status, res3[0]['status']) self.assertEqual(1, res3[0]['configidx']) self.assertEqual(name, res3[0]['name']) self.assertEqual(test_system, res3[0]['system']) self.assertNotEqual(None, res3[0]['created_on']) # The following 2 tests are to confirm the date string is in the correct format self.assertEqual(3, len(res3[0]['created_on'].split('-'))) self.assertEqual(3, len(res3[0]['created_on'].split(':'))) self.assertEqual(test_version, res3[0]['version']) self.assertEqual(test_desc, res3[0]['desc']) self.assertEqual(pvlist, res3[0]['pvlist']) self.assertNotEqual(None, res3[0]['updated_on']) # The following 2 tests are to confirm the date string is in the correct format self.assertEqual(3, len(res3[0]['updated_on'].split('-'))) self.assertEqual(3, len(res3[0]['updated_on'].split(':'))) # drop DB self.conn.drop_database(masarconfig.get('mongodb', 'database')) utils.close(self.conn)
def testConfiguration(self): channel = 'masarService' self.mc = masarClient.client(channelname=channel) # DB SETUP self.conn, collection = utils.conn(host=masarconfig.get('mongodb', 'host'), port=masarconfig.get('mongodb', 'port'), db=masarconfig.get('mongodb', 'database')) self.conn.drop_database(masarconfig.get('mongodb', 'database')) name = "SR_All_20140421" test_status = 'active' test_version = 20140421 test_system = 'SR' test_desc = "SR daily SCR setpoint without IS kick and septum: SR and RF" params = {"desc": test_desc, "system": test_system, "status": test_status, "version": test_version, } newid = saveconfig(self.conn, collection, name, **params) self.assertNotEqual(None, newid) res0 = retrieveconfig(self.conn, collection, name) self.assertEqual(test_status, res0[0]['status']) self.assertEqual(1, res0[0]['configidx']) self.assertEqual(name, res0[0]['name']) self.assertEqual(test_system, res0[0]['system']) self.assertNotEqual(None, res0[0]['created_on']) # The following 2 tests are to confirm the date string is in the correct format self.assertEqual(3, len(res0[0]['created_on'].split('-'))) self.assertEqual(3, len(res0[0]['created_on'].split(':'))) self.assertEqual(test_version, res0[0]['version']) self.assertEqual(test_desc, res0[0]['desc']) pvs = ["masarExampleDoubleArray"] pvlist = {"names": pvs} res = updateconfig(self.conn, collection, name, pvlist=pvlist) self.assertEqual(True, res) res3 = retrieveconfig(self.conn, collection, name, withpvs=True) self.assertEqual(test_status, res3[0]['status']) self.assertEqual(1, res3[0]['configidx']) self.assertEqual(name, res3[0]['name']) self.assertEqual(test_system, res3[0]['system']) self.assertNotEqual(None, res3[0]['created_on']) # The following 2 tests are to confirm the date string is in the correct format self.assertEqual(3, len(res3[0]['created_on'].split('-'))) self.assertEqual(3, len(res3[0]['created_on'].split(':'))) self.assertEqual(test_version, res3[0]['version']) self.assertEqual(test_desc, res3[0]['desc']) self.assertEqual(pvlist, res3[0]['pvlist']) self.assertNotEqual(None,res3[0]['updated_on']) # The following 2 tests are to confirm the date string is in the correct format self.assertEqual(3, len(res3[0]['updated_on'].split('-'))) self.assertEqual(3, len(res3[0]['updated_on'].split(':'))) # drop DB self.conn.drop_database(masarconfig.get('mongodb', 'database')) utils.close(self.conn)
def testSaveMasarMongoDB(self): app = QtGui.QApplication(sys.argv) ui = dbmanagerUI() ui.dbsource = 1 # Called normally with menu selection ui.defaultmongodb() ui.test_in_progress_flag = 1 ui.savemasarmongodb() masarconf = 'newcfgname' conn, collection = utils.conn(host=masarconfig.get('mongodb', 'host'), port=masarconfig.get('mongodb', 'port'), db=masarconfig.get('mongodb', 'database')) res3 = retrieveconfig(conn, collection, masarconf, withpvs=True) self.assertEqual('newcfgname', res3[0]['name']) self.assertEqual('newmsystem', res3[0]['system']) self.assertEqual('newcfgdesc', res3[0]['desc'])
def testUpdateMasarConfigStatus(self): app = QtGui.QApplication(sys.argv) ui = dbmanagerUI() ui.dbsource = 1 # Called normally with menu selection ui.defaultmongodb() masarconf = 'SR_All_20140421' conn, collection = utils.conn(host=masarconfig.get('mongodb', 'host'), port=masarconfig.get('mongodb', 'port'), db=masarconfig.get('mongodb', 'database')) ui.updatemasarconfigstatus("inactive", 1) res3 = retrieveconfig(conn, collection, masarconf, withpvs=True) self.assertEqual("inactive", res3[0]['status']) ui.updatemasarconfigstatus("active",1) res3 = retrieveconfig(conn, collection, masarconf, withpvs=True) self.assertEqual("active", res3[0]['status'])
def testSaveMasarMongoDB(self): app = QtGui.QApplication(sys.argv) ui = dbmanagerUI() ui.dbsource = 1 # Called normally with menu selection ui.defaultmongodb() ui.test_in_progress_flag = 1 ui.savemasarmongodb() masarconf = 'newcfgname' conn, collection = utils.conn(host=masarconfig.get('mongodb', 'host'), port=masarconfig.get('mongodb', 'port'), db=masarconfig.get( 'mongodb', 'database')) res3 = retrieveconfig(conn, collection, masarconf, withpvs=True) self.assertEqual('newcfgname', res3[0]['name']) self.assertEqual('newmsystem', res3[0]['system']) self.assertEqual('newcfgdesc', res3[0]['desc'])
def testUpdateMasarConfigStatus(self): app = QtGui.QApplication(sys.argv) ui = dbmanagerUI() ui.dbsource = 1 # Called normally with menu selection ui.defaultmongodb() masarconf = 'SR_All_20140421' conn, collection = utils.conn(host=masarconfig.get('mongodb', 'host'), port=masarconfig.get('mongodb', 'port'), db=masarconfig.get( 'mongodb', 'database')) ui.updatemasarconfigstatus("inactive", 1) res3 = retrieveconfig(conn, collection, masarconf, withpvs=True) self.assertEqual("inactive", res3[0]['status']) ui.updatemasarconfigstatus("active", 1) res3 = retrieveconfig(conn, collection, masarconf, withpvs=True) self.assertEqual("active", res3[0]['status'])
def testSaveMongoServiceConfigs(self): conn, collection = utils.conn(host=masarconfig.get('mongodb', 'host'), port=masarconfig.get('mongodb', 'port'), db=masarconfig.get('mongodb', 'database')) conn.drop_database(masarconfig.get('mongodb', 'database')) saveMongoService(self.parsed_json) res3 = retrieveconfig(conn, collection, 'BR_MG_SCR_20130419', withpvs=True) self.assertEqual(res3[0]['status'], 'active') self.assertEqual('BR_MG_SCR_20130419', res3[0]['name']) self.assertEqual(res3[0]['pvlist']['names'], [u'masarExample0000', u'masarExample0001', u'masarExampleBoUninit', u'masarExampleMbboUninit', u'masarExample0002', u'masarExample0003', u'masarExample0004', u'masarExampleCharArray', u'masarExampleShortArray', u'masarExampleLongArray', u'masarExampleStringArray', u'masarExampleFloatArray', u'masarExampleDoubleArray', u'masarExampleMbboUninitTest']) self.assertEqual('BR', res3[0]['system']) self.assertEqual(3, len(res3[0]['created_on'].split('-'))) # Date format test self.assertEqual(3, len(res3[0]['created_on'].split(':'))) # 2016-07-28 18:18:36 self.assertEqual(None, res3[0]['version']) self.assertEqual(3, len(res3[0]['updated_on'].split('-'))) # Date format test self.assertEqual(3, len(res3[0]['updated_on'].split(':'))) # 2016-07-28 18:18:36 self.assertNotEqual(None, res3[0]['_id']) self.assertEqual('BR ramping PS daily SCR setpoint', res3[0]['desc'])
def tearDown(self): self.conn.drop_database(masarconfig.get('mongodb', 'database')) utils.close(self.conn)
def tearDown(self): #print "database: ", self.conn.database_names() #print "collections: ", self.conn[self.collection] #print "collections: ", self.conn[self.collection].collection_names() self.conn.drop_database(masarconfig.get('mongodb', 'database')) utils.close(self.conn)
def setUp(self): self.conn, self.collection = utils.conn( host=masarconfig.get('mongodb', 'host'), port=masarconfig.get('mongodb', 'port'), db=masarconfig.get('mongodb', 'database'))
def setUp(self): self.conn, self.collection = utils.conn(host=masarconfig.get('mongodb','host'), port=masarconfig.get('mongodb','port'), db=masarconfig.get('mongodb','database'))