Exemplo n.º 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
Exemplo n.º 2
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
Exemplo n.º 3
0
    def nttable_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 = NTTable(response)
        label = result.getLabels()
        self.assertNotEqual(label, None)
        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())
Exemplo n.º 4
0
    def nttable_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 = NTTable(response)
        label = result.getLabels()
        self.assertNotEqual(label, None)
        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())
Exemplo n.º 5
0
 def setUp(self):
     self.parameters = {'column_one': 'string',
                        'column_two': 'double'}
     self.test_nttable = NTTable(self.parameters)
Exemplo n.º 6
0
class TestNTTable(unittest.TestCase):

    '''
    Sets up new NTTable for each test with same initial parameters
    '''
    def setUp(self):
        self.parameters = {'column_one': 'string',
                           'column_two': 'double'}
        self.test_nttable = NTTable(self.parameters)

    '''
    Tests getter for TimeStamp

    PLANNING: Not sure what to be testing for here, for now I'll just make sure a TimeStamp is returned
    that has the correct default value and leave the testing of TimeStamp itself to test_timeStamp.py
    '''
    def testGetTimeStamp(self):
        test_timestamp = TimeStamp()
        self.test_nttable.getTimeStamp(test_timestamp)
        test_stamp = TimeStamp()
        self.assertGreaterEqual(test_timestamp._diffInt(test_stamp), 0, "Unexpected time stamp value, "
                                                                        "given time stamp is earlier than default time")
        test_stamp.getCurrent()
        self.assertLess(test_timestamp._diffInt(test_stamp), 0, "Unexpected time stamp value, "
                                                                  "given time stamp is in the future")
    '''
    Tests getter for Alarm

    PLANNING: Not sure what to be testing for here, for now I'll just make sure the correct alarm is returned
    '''
    def testGetAlarm(self):
        test_alarm = Alarm()
        test_message = "test message"
        test_alarm.setMessage(test_message)
        self.test_nttable.getAlarm(test_alarm)
        self.assertEqual(test_alarm.getMessage(), test_message, "Alarm.message returned an unexpected value: " + str(test_alarm.getMessage()) + " expected " + str(test_message))
        self.assertEqual(test_alarm.getSeverity(), "NONE", "Alarm.severity returned an unexpected value: " + str(test_alarm.getSeverity()) + " expected NONE ")
        self.assertEqual(test_alarm.getStatus(), "NONE", "Alarm.status returned an unexpected value: " + str(test_alarm.getStatus()) + " expected NONE ")

    '''
    Tests getter for Labels
    '''
    def testGetLabels(self):
        labels = self.test_nttable.getLabels()
        test_nttable_keys = self.parameters.keys()
        for i in range(len(labels)):
            self.assertEqual(test_nttable_keys[i], labels[i], "Labels do not match given keys:  " + str(test_nttable_keys[i]) + " != " + str(labels[i]))

    '''
    This was a bad test, it assumed that the second value in each argument was meant to
    be the data, when in fact it was a type declaration. No data is entered and no data is returned.

    The test has been modified to check for the expected output given no data being input.
    There should be a new test to add data and make sure it is returned correctly.
    '''
    def testGetColumn(self):
        labels = self.test_nttable.getLabels()
        test_nttable_keys = self.parameters.keys()
        for i in range(len(labels)):
            test_column = self.test_nttable.getColumn(labels[i])
            self.assertEqual((), test_column)
    if __name__ == '__main__':
        unittest.main()
Exemplo n.º 7
0
# testtable.py
#

import time

from masarclient.nttable import NTTable as NTTable
from masarclient.alarm import Alarm as Alarm
from masarclient.timeStamp import TimeStamp as TimeStamp

timeStamp = TimeStamp()
alarm = Alarm()

params = {'column1': 'string', 'column2': 'double'}

nttable = NTTable(params)
print nttable

newnttable = nttable.getNTTable()
print newnttable
print "getTimeStamp"
nttable.getTimeStamp(timeStamp)
print timeStamp
print "getAlarm"
nttable.getAlarm(alarm)
print alarm
labels = nttable.getLabels()
print labels
n = len(labels)
for label in labels:
    column = nttable.getColumn(label)
    print column
Exemplo n.º 8
0
# testtable.py
#

import time

from masarclient.nttable import NTTable as NTTable
from masarclient.alarm import Alarm as Alarm
from masarclient.timeStamp import TimeStamp as TimeStamp

timeStamp = TimeStamp()
alarm = Alarm()

params = {"column1": "string", "column2": "double"}

nttable = NTTable(params)
print nttable

newnttable = nttable.getNTTable()
print newnttable
print "getTimeStamp"
nttable.getTimeStamp(timeStamp)
print timeStamp
print "getAlarm"
nttable.getAlarm(alarm)
print alarm
labels = nttable.getLabels()
print labels
n = len(labels)
for label in labels:
    column = nttable.getColumn(label)
    print column