Beispiel #1
0
def __clientRPC(function, params):
    alarm = Alarm()
    timeStamp = TimeStamp()

    ntnv = NTNameValue(function, params)

    # now do issue + wait
    channelRPC = ChannelRPC("masarService")
    channelRPC.issueConnect()
    if not channelRPC.waitConnect(1.0):
        print "error when waiting connection.", channelRPC.getMessage()
        exit(1)
    channelRPC.issueRequest(ntnv.getNTNameValue(), False)
    result = channelRPC.waitResponse()
    if result is None:
        print channelRPC.getMessage()
        exit(1)
#    print "problem to get nttable using getNTTable()"
    if function in ["retrieveSnapshot", "getLiveMachine", "saveSnapshot"]:
        result = NTMultiChannel(result)
    elif function in [
            "retrieveServiceEvents", "retrieveServiceConfigs",
            "retrieveServiceConfigProps"
    ]:
        result = NTTable(result)
        label = result.getLabels()
        print "label", label
        print result.getPVStructure()
    elif function == "updateSnapshotEvent":
        result = NTScalar(result)


#    print "Problem above"
#     print result

    result.getAlarm(alarm)
    # print alarm

    result.getTimeStamp(timeStamp)
    # print timeStamp

    # numberValues = result.getNumberValues()
    # print "numberValues", numberValues

    #
    #    i = 0
    #    while i < numberValues :
    #        value = nttable.getValue(i)
    #        print "value",label[i],value
    #        i += 1
    return result
Beispiel #2
0
class TestNTNameValue(unittest.TestCase):
    '''
    Sets up default NTNameValue object to be used in each test
    '''
    def setUp(self):
        function = 'saveSnapshot'
        params = {'configname': 'sr_test', 'servicename': 'masar'}
        self.test_ntnv = NTNameValue(function, params)

    '''
    This test just confirms that a PVStructure is returned and is not equal to none
    '''

    def testGetPVStructure(self):
        self.assertNotEqual(self.test_ntnv.getPVStructure(), None)

    '''
    Tests getter for service and config name, also tests default value assignment
    '''

    def testGetName(self):
        test_ntnv_servicename = self.test_ntnv.getName()[0]
        test_ntnv_configname = self.test_ntnv.getName()[1]
        self.assertEqual(
            test_ntnv_servicename, "servicename",
            "servicename returned incorrect default value:  " +
            str(test_ntnv_servicename))
        self.assertEqual(
            test_ntnv_configname, "configname",
            "configname returned incorrect default value:  " +
            str(test_ntnv_configname))

    '''
    Tests getter for values, also tests default value assignment
    '''

    def testGetValue(self):
        test_ntnv_value_one = self.test_ntnv.getValue()[0]
        test_ntnv_value_two = self.test_ntnv.getValue()[1]
        self.assertEqual(
            test_ntnv_value_one, "masar",
            "ntnv value one returned incorrect default value:  " +
            str(test_ntnv_value_one))
        self.assertEqual(
            test_ntnv_value_two, "sr_test",
            "ntnv value two returned incorrect default value:  " +
            str(test_ntnv_value_two))

    '''
    def ntnv_asserts(self, function, params):

        alarm = Alarm()
        time_stamp = TimeStamp()
        ntnv = NTNameValue(function, params)
        self.channelRPC.issueRequest(ntnv.getNTNameValue(), False)
        response = self.channelRPC.waitResponse()
        self.assertNotEqual(response, None, "ChannelRPC connection failure.")
        result = NTMultiChannel(response)
        result.getAlarm(alarm)
        result.getTimeStamp(time_stamp)
        self.assertEqual(3, len(str(time_stamp).split(":")))  # Timestamp string format test

        self.assertIn(alarm.getStatus(), alarm.getStatusChoices())
        self.assertIn(alarm.getSeverity(), alarm.getSeverityChoices())
Beispiel #4
0
    def ntnv_asserts(self, function, params):

        alarm = Alarm()
        time_stamp = TimeStamp()
        ntnv = NTNameValue(function, params)
        self.channelRPC.issueRequest(ntnv.getNTNameValue(), False)
        response = self.channelRPC.waitResponse()
        self.assertNotEqual(response, None, "ChannelRPC connection failure.")
        result = NTMultiChannel(response)
        result.getAlarm(alarm)
        result.getTimeStamp(time_stamp)
        self.assertEqual(3, len(
            str(time_stamp).split(":")))  # Timestamp string format test

        self.assertIn(alarm.getStatus(), alarm.getStatusChoices())
        self.assertIn(alarm.getSeverity(), alarm.getSeverityChoices())
def __clientRPC(function, params):
    alarm = Alarm()
    timeStamp = TimeStamp()

    ntnv = NTNameValue(function, params)

    # now do issue + wait
    channelRPC = ChannelRPC("masarService")
    channelRPC.issueConnect()
    if not channelRPC.waitConnect(1.0):
        print "error when waiting connection.", channelRPC.getMessage()
        exit(1)
    channelRPC.issueRequest(ntnv.getNTNameValue(), False)
    result = channelRPC.waitResponse()
    if result is None:
        print channelRPC.getMessage()
        exit(1)
#    print "problem to get nttable using getNTTable()"
    if function in ["retrieveSnapshot", "getLiveMachine", "saveSnapshot"]:
        result = NTMultiChannel(result)
    elif function in ["retrieveServiceEvents", "retrieveServiceConfigs", "retrieveServiceConfigProps"]:
        result = NTTable(result)
        label = result.getLabels()
        print "label", label
        print result.getPVStructure()
    elif function == "updateSnapshotEvent":
        result = NTScalar(result)
#    print "Problem above"
#     print result

    result.getAlarm(alarm)
    # print alarm

    result.getTimeStamp(timeStamp)
    # print timeStamp

    # numberValues = result.getNumberValues()
    # print "numberValues", numberValues

#
#    i = 0
#    while i < numberValues :
#        value = nttable.getValue(i)
#        print "value",label[i],value
#        i += 1
    return result
Beispiel #6
0
def __clientRPC(function, params):
    alarm = Alarm()
    timeStamp = TimeStamp()

    ntnv = NTNameValue(function,params)
    
    # now do issue + wait
    channelRPC = ChannelRPC("masarService","record[process=true]field()")
    channelRPC.issueConnect()
    if not channelRPC.waitConnect(1.0) :
        print channelRPC.getMessage()
        exit(1)
    channelRPC.issueRequest(ntnv.getNTNameValue(),False)
    result = channelRPC.waitRequest()
    if(result==None) :
        print channelRPC.getMessage()
        exit(1)
    nttable = NTTable(result)
    print nttable
    
    nttable.getAlarm(alarm.getAlarmPy())
#    print alarm;
    
    nttable.getTimeStamp(timeStamp.getTimeStampPy())
#    print timeStamp;
    
#    numberValues = nttable.getNumberValues()
#    print "numberValues",numberValues
#    
#    label = nttable.getLabel()
#    print "label",label
#    
#    i = 0
#    while i < numberValues :
#        value = nttable.getValue(i)
#        print "value",label[i],value
#        i += 1
    return nttable
class TestNTNameValue(unittest.TestCase):

    '''
    Sets up default NTNameValue object to be used in each test
    '''
    def setUp(self):
        function = 'saveSnapshot'
        params = {'configname': 'sr_test',
                  'servicename': 'masar'}
        self.test_ntnv = NTNameValue(function, params)

    '''
    This test just confirms that a PVStructure is returned and is not equal to none
    '''
    def testGetPVStructure(self):
        self.assertNotEqual(self.test_ntnv.getPVStructure(), None)


    '''
    Tests getter for service and config name, also tests default value assignment
    '''
    def testGetName(self):
        test_ntnv_servicename = self.test_ntnv.getName()[0]
        test_ntnv_configname = self.test_ntnv.getName()[1]
        self.assertEqual(test_ntnv_servicename, "servicename", "servicename returned incorrect default value:  " + str(test_ntnv_servicename))
        self.assertEqual(test_ntnv_configname, "configname", "configname returned incorrect default value:  " + str(test_ntnv_configname))

    '''
    Tests getter for values, also tests default value assignment
    '''
    def testGetValue(self):
        test_ntnv_value_one = self.test_ntnv.getValue()[0]
        test_ntnv_value_two = self.test_ntnv.getValue()[1]
        self.assertEqual(test_ntnv_value_one, "masar", "ntnv value one returned incorrect default value:  " + str(test_ntnv_value_one))
        self.assertEqual(test_ntnv_value_two, "sr_test", "ntnv value two returned incorrect default value:  " + str(test_ntnv_value_two))

    '''
Beispiel #8
0
 def setUp(self):
     function = 'saveSnapshot'
     params = {'configname': 'sr_test', 'servicename': 'masar'}
     self.test_ntnv = NTNameValue(function, params)
Beispiel #9
0
# testnameValue.py
#

import time

from masarclient.ntnameValue import NTNameValue as NTNameValue
from masarclient.alarm import Alarm as Alarm
from masarclient.timeStamp import TimeStamp as TimeStamp

timeStamp = TimeStamp()
alarm = Alarm()

function = 'saveSnapshot'
params = {'configname': 'sr_test',
          'servicename': 'masar'}

ntnv = NTNameValue(function,params)
print ntnv

newntnv = ntnv.getNTNameValue()
print newntnv
print ntnv.getName()
print ntnv.getValue()

print ntnv.getTimeStamp(timeStamp)
print ntnv.getAlarm(alarm)
 def setUp(self):
     function = 'saveSnapshot'
     params = {'configname': 'sr_test',
               'servicename': 'masar'}
     self.test_ntnv = NTNameValue(function, params)