Ejemplo n.º 1
0
def simple_test():
    cf = ChannelFinderClient(**cfinput)
    #cf.set(property=Property('test-prop1', 'lyyang', 'v1'))
    #cf.set(property=Property('test-prop2', 'cf-asd', 'v2'))
    #cf.set(property=Property('test-prop3', 'lyyang'))
    #cf.set(property=Property('test-prop4', 'lyyang'))
    #cf.delete(propertyName='test-prop1')
    #cf.delete(propertyName='test-prop3')

    pvname1 = 'SR:C00-BI:G00{DCCT:00}CUR-RB'
    pvname2 = 'SR:C00-Glb:G00{CHROM:00}RB-X'
    pvname3 = 'SR:C00-Glb:G00{CHROM:00}RB-Y'
    cf.update(property=Property('test-prop2', 'cf-asd', 'v1'),
              channelNames=[pvname1, pvname2, pvname3])
    #chs = cf.find(property=[('test-prop2', '*')])
    #if chs is not None:
    #    for ch in chs:
    #        print ch.Name
    #        for p in ch.Properties:
    #            print "  ", p.Name,"=",p.Value, p.Owner, ", "
    #        print "/"

    cf.delete(property=Property('test-prop2', 'cf-asd', 'v1'),
              channelNames=[pvname2, pvname3])
    chs = cf.find(property=[('test-prop2', '*')])
    if chs is not None:
        for ch in chs:
            print ch.Name,
            for p in ch.Properties:
                print p.Name, "=", p.Value, ", ",
            print " /"
Ejemplo n.º 2
0
def simple_test():
    cf = ChannelFinderClient(**cfinput)
    #cf.set(property=Property('test-prop1', 'lyyang', 'v1'))
    #cf.set(property=Property('test-prop2', 'cf-asd', 'v2'))
    #cf.set(property=Property('test-prop3', 'lyyang'))
    #cf.set(property=Property('test-prop4', 'lyyang'))
    #cf.delete(propertyName='test-prop1')
    #cf.delete(propertyName='test-prop3')

    pvname1='SR:C00-BI:G00{DCCT:00}CUR-RB'
    pvname2='SR:C00-Glb:G00{CHROM:00}RB-X'
    pvname3='SR:C00-Glb:G00{CHROM:00}RB-Y'
    cf.update(property=Property('test-prop2', 'cf-asd', 'v1'),
              channelNames=[pvname1, pvname2, pvname3])
    #chs = cf.find(property=[('test-prop2', '*')])
    #if chs is not None:
    #    for ch in chs:
    #        print ch.Name
    #        for p in ch.Properties: 
    #            print "  ", p.Name,"=",p.Value, p.Owner, ", "
    #        print "/"

    cf.delete(property=Property('test-prop2', 'cf-asd', 'v1'), 
              channelNames=[pvname2, pvname3])
    chs = cf.find(property=[('test-prop2', '*')])
    if chs is not None:
        for ch in chs:
            print ch.Name,
            for p in ch.Properties: 
                print p.Name,"=",p.Value,", ", 
            print " /"
Ejemplo n.º 3
0
 def testAddUpdateChannelsWithProperties(self):
     '''
     This is to check that existing properties of channels are not affected.
     '''
     unaffectedProperty = Property('unaffectedProperty', self.owner, 'unchanged')
     # create default client
     client = ChannelFinderClient(BaseURL=self.baseURL, username=self.username, password=self.password)
     client.set(property=unaffectedProperty)
     
     # add new pv's
     t1 = str(time())
     hostName1 = 'update-test-hostname' + t1
     iocName1 = 'update-test-iocName' + t1
     # New Channels added
     client = ChannelFinderClient(BaseURL=self.baseURL, username=self.username, password=self.password);
     client.set(channel=Channel('cf-update-pv1', 'cf-update', properties=[unaffectedProperty]))
     updateChannelFinder(['cf-update-pv1', 'cf-update-pv2'], \
                         hostName1, \
                         iocName1, \
                         owner=self.owner, \
                         time=t1, \
                         service=self.baseURL , \
                         username=self.username, \
                         password=self.password)
     channels = client.find(property=[('hostName', hostName1), ('iocName', iocName1), ('time', t1)])
     self.assertTrue(len(channels) == 2, 'failed to create the channels with appropriate properties')
     channels = client.find(name='cf-update-pv1')
     self.assertTrue(len(channels) == 1)
     self.assertTrue(len(channels[0].Properties) == 5)
     # Cleanup
     client.delete(channelName='cf-update-pv1')
     client.delete(channelName='cf-update-pv2')
     client.delete(propertyName=unaffectedProperty.Name)
Ejemplo n.º 4
0
    def testAddUpdateChannels(self):
        # Check the method finds the error conditions and raises exceptions
        self.assertRaises(Exception, updateChannelFinder, [[], None, None])
        self.assertRaises(Exception, updateChannelFinder,
                          [[], None, 'iocname'])
        self.assertRaises(Exception, updateChannelFinder,
                          [[], 'hostName', None])
        # create default client
        client = ChannelFinderClient()

        # add new pv's
        t1 = str(time())
        hostName1 = 'update-test-hostname' + t1
        iocName1 = 'update-test-iocName' + t1
        channels = client.find(property=[('hostName',
                                          hostName1), ('iocName', iocName1)])
        self.assertTrue(channels == None or len(channels) == 0,
                        'channels already present')
        # New Channels added
        updateChannelFinder(['cf-update-pv1', 'cf-update-pv2'], \
                            hostName1, \
                            iocName1, \
                            owner=self.owner, \
                            time=t1, \
                            service=self.baseURL , \
                            username=self.username, \
                            password=self.password)
        channels = client.find(property=[('hostName',
                                          hostName1), ('iocName',
                                                       iocName1), ('time',
                                                                   t1)])
        self.assertTrue(
            len(channels) == 2,
            'failed to create the channels with appropriate properties')
        t2 = str(time())
        hostName2 = 'update-test-hostname' + t2
        iocName2 = 'update-test-iocName' + t2
        # Existing channels are updated
        updateChannelFinder(['cf-update-pv1', 'cf-update-pv2'], \
                            hostName2, \
                            iocName2, \
                            owner=self.owner, \
                            time=t2, \
                            service=self.baseURL , \
                            username=self.username, \
                            password=self.password)
        # no channels should have the old proerty values
        self.assertTrue(not client.find(property=[('hostName', hostName1), ('iocName', iocName1), ('time', t1)]), \
                        'failed to update the channels with appropriate properties, old values found')
        # channels should be updated to the new values
        self.assertTrue(len(client.find(property=[('hostName', hostName2), ('iocName', iocName2), ('time', t2)])) == 2, \
                        'failed to update the channels with appropriate properties')
        # Cleanup
        client = ChannelFinderClient(BaseURL=self.baseURL,
                                     username=self.username,
                                     password=self.password)
        client.delete(channelName='cf-update-pv1')
        client.delete(channelName='cf-update-pv2')
        pass
Ejemplo n.º 5
0
 def test_run(self):
     '''
     Tests main program full sweep.
     '''
     CFPropertyManager.run("cf-property-manager-test-dbl",
                           "cf-property-manager-test-cfg")
     os.remove("cf-property-manager-test-cfg")
     os.remove("cf-property-manager-test-dbl")
     client = ChannelFinderClient()
     client.delete(channelName="UT:RF-Cu:1{LD}Time:ShtDwn-I")
Ejemplo n.º 6
0
 def testAddUpdateChannels(self):
     # Check the method finds the error conditions and raises exceptions
     self.assertRaises(Exception, updateChannelFinder, [[], None, None])
     self.assertRaises(Exception, updateChannelFinder, [[], None, 'iocname'])
     self.assertRaises(Exception, updateChannelFinder, [[], 'hostName', None])
     # create default client
     client = ChannelFinderClient()
     
     # add new pv's
     t1 = str(time())
     hostName1 = 'update-test-hostname' + t1
     iocName1 = 'update-test-iocName' + t1
     channels = client.find(property=[('hostName', hostName1), ('iocName', iocName1)])
     self.assertTrue(channels == None or len(channels) == 0, 'channels already present')
     # New Channels added
     updateChannelFinder(['cf-update-pv1', 'cf-update-pv2'], \
                         hostName1, \
                         iocName1, \
                         owner=self.owner, \
                         time=t1, \
                         service=self.baseURL , \
                         username=self.username, \
                         password=self.password)
     channels = client.find(property=[('hostName', hostName1), ('iocName', iocName1), ('time', t1)])
     self.assertTrue(len(channels) == 2, 'failed to create the channels with appropriate properties')
     t2 = str(time())
     hostName2 = 'update-test-hostname' + t2
     iocName2 = 'update-test-iocName' + t2
     # Existing channels are updated
     updateChannelFinder(['cf-update-pv1', 'cf-update-pv2'], \
                         hostName2, \
                         iocName2, \
                         owner=self.owner, \
                         time=t2, \
                         service=self.baseURL , \
                         username=self.username, \
                         password=self.password)
     # no channels should have the old proerty values 
     self.assertTrue(client.find(property=[('hostName', hostName1), ('iocName', iocName1), ('time', t1)]) == None, \
                     'failed to update the channels with appropriate properties, old values found')
     # channels should be updated to the new values
     self.assertTrue(len(client.find(property=[('hostName', hostName2), ('iocName', iocName2), ('time', t2)])) == 2, \
                     'failed to update the channels with appropriate properties')
     # Cleanup
     client = ChannelFinderClient(BaseURL=self.baseURL, username=self.username, password=self.password)
     client.delete(channelName='cf-update-pv1')
     client.delete(channelName='cf-update-pv2')
     pass
Ejemplo n.º 7
0
 def testPVUpdate(self):
     '''
     Test condition 
     IOC turned on with ch1, ch2
     IOC turned on with ch1 only
     IOC turned on with ch1, ch2
     '''
     try:
         updateChannelFinder(['ch1', 'ch2'], \
                             'testHost', \
                             'testIOC', \
                             owner=self.owner, \
                             time=time(), \
                             service=self.baseURL, \
                             username=self.username, password=self.password)
         client = ChannelFinderClient(BaseURL=self.baseURL, username=self.username, password=self.password)
         chs = client.find(property=[('hostName', 'testHost'), ('iocName', 'testIOC'), ('pvStatus', 'Active')])
         self.assertEqual(len(chs), 2, 'Expected 2 positive matches but found ' + str(len(chs)))
         updateChannelFinder(['ch1'], \
                             'testHost', \
                             'testIOC', \
                             owner=self.owner, \
                             time=time(), \
                             service=self.baseURL, \
                             username=self.username, password=self.password)
         chs = client.find(property=[('hostName', 'testHost'), ('iocName', 'testIOC'), ('pvStatus', 'Active')])
         self.assertEqual(len(chs), 1, 'Expected 1 positive matches but found ' + str(len(chs)))
         self.assertTrue(chs[0].Name == 'ch1', 'channel with name ch1 not found')
         chs = client.find(property=[('hostName', 'testHost'), ('iocName', 'testIOC'), ('pvStatus', 'InActive')])
         self.assertEqual(len(chs), 1, 'Expected 1 positive matches but found ' + str(len(chs)))
         self.assertTrue(chs[0].Name == 'ch2', 'channel with name ch2 not found')            
         updateChannelFinder(['ch1', 'ch2'], \
                             'testHost', \
                             'testIOC', \
                             owner=self.owner, \
                             time=time(), \
                             service=self.baseURL, \
                             username=self.username, password=self.password)
         chs = client.find(property=[('hostName', 'testHost'), ('iocName', 'testIOC'), ('pvStatus', 'Active')])
         self.assertEqual(len(chs), 2, 'Expected 2 positive matches but found ' + str(len(chs)))
     finally:
         client.delete(channelName='ch1')
         client.delete(channelName='ch2')
Ejemplo n.º 8
0
def main():
    if len(sys.argv) < 2:
        parser.print_help()
        return 1

    args = parser.parse_args(sys.argv[2:])

    if args.channelsfile is None:
        parser.print_help()
        return 1

    if args.channelsfile is None:
        parser.print_help()
        return 1

    try:
        if args.url is None:
            cfc = ChannelFinderClient()
            args.url = "https://127.0.0.1:8181/ChannelFinder"
        else:
            if args.username is None:
                args.username = r_input("Enter username: "******"Enter password: "******"Cannot connect to channelfinder service.")
        return 1

    ds = DataSource(source=args.channelsfile)
    pv_data = ds.get_data()
    if args.op == 'del':
        try:
            [cfc.delete(channelName=pv['name']) for pv in pv_data]
        except:
            print(
                "Channels deleting ERROR, probably channel(s) does not exist.")
    else:  # args.op == 'add'
        if args.username is None:
            write_cfs(pv_data, args.url, force=True)
        else:
            write_cfs(pv_data,
                      args.url,
                      username=args.username,
                      password=args.password)
    return 0
Ejemplo n.º 9
0
 def testPVMove(self):
     '''
     ch1, ch2 on host1, ioc1
     ch1 on host1, ioc1; ch2 on host1, ioc2 (case1)
     ch1, ch2 on host1, ioc1 (reset)
     ch1 on host1, ioc1; ch2 on host2, ioc2 (case2)
     ch1, ch2 on host1, ioc1 (reset)
     '''
     try:
         updateChannelFinder(['ch1', 'ch2'], \
                             'host1', \
                             'ioc1', \
                             owner=self.owner, \
                             time=time(),\
                             service=self.baseURL, \
                             username=self.username, password=self.password)
         client = ChannelFinderClient(BaseURL=self.baseURL, username=self.username, password=self.password)
         chs = client.find(property=[('hostName', 'host1'), ('iocName', 'ioc1')])
         self.assertEqual(len(chs), 2, 'Expected 2 positive matches but found ' + str(len(chs)))
         '''CASE1'''
         updateChannelFinder(['ch1'], \
                             'host1', \
                             'ioc1', \
                             time=time(), \
                             owner=self.owner, service=self.baseURL, \
                             username=self.username, password=self.password)
         updateChannelFinder(['ch2'], \
                             'host1', \
                             'ioc2', \
                             time=time(), \
                             owner=self.owner, service=self.baseURL, \
                             username=self.username, password=self.password)
         chs = client.find(property=[('hostName', 'host1')])
         self.assertEqual(len(chs), 2, 'Expected 1 positive matches but found ' + str(len(chs)))
         self.assertEqual(client.find(property=[('hostName', 'host1'), ('iocName', 'ioc1')])[0].Name, 'ch1', \
                          'Failed to find the expected channel _ch1_ with prop host1, ioc1')
         self.assertEqual(client.find(property=[('hostName', 'host1'), ('iocName', 'ioc2')])[0].Name, 'ch2', \
                          'Failed to find the expected channel _ch2_ with prop host1, ioc2')
         '''RESET'''
         updateChannelFinder(['ch1', 'ch2'], \
                             'host1', \
                             'ioc1', \
                             time=time(), \
                             owner=self.owner, service=self.baseURL, \
                             username=self.username, password=self.password)
         self.assertEqual(len(client.find(property=[('hostName', 'host1'), ('iocName', 'ioc1')])), 2, \
                          'Failed to reset the channels')            
         '''CASE2'''
         updateChannelFinder(['ch1'], \
                             'host1', \
                             'ioc1', \
                             owner=self.owner, \
                             time=time(), \
                             service=self.baseURL, username=self.username, \
                             password=self.password)
         updateChannelFinder(['ch2'], \
                             'host2', \
                             'ioc2', \
                             owner=self.owner, service=self.baseURL, \
                             time=time(), \
                             username=self.username, password=self.password)
         self.assertEqual(client.find(property=[('hostName', 'host1'), ('iocName', 'ioc1')])[0].Name, 'ch1', \
                          'Failed to find the expected channel _ch1_ with prop host1, ioc1')
         self.assertEqual(client.find(property=[('hostName', 'host2'), ('iocName', 'ioc2')])[0].Name, 'ch2', \
                          'Failed to find the expected channel _ch2_ with prop host1, ioc2')
         '''RESET'''
         updateChannelFinder(['ch1', 'ch2'], \
                             'host1', \
                             'ioc1', \
                             owner=self.owner, \
                             time=time(), \
                             service=self.baseURL, \
                             username=self.username, password=self.password)
         self.assertEqual(len(client.find(property=[('hostName', 'host1'), ('iocName', 'ioc1')])), 2, \
                          'Failed to reset the channels')
     finally:
         client.delete(channelName='ch1')
         client.delete(channelName='ch2')
Ejemplo n.º 10
0
 def testPreservingOfAttributes(self):
     '''
     This test is to ensure that existing properties and tags are left untouched.
     Case1:
     first time the cf-update comes across these channels and adds hostName and iocName
     Case2:
     the hostName is changed
     Case3:
     the iocName is changed
     Case4:
     both hostName and iocName are changed
     Case5:
     the channel is removed
     in all cases the existing unaffected* property and tag should remain with the channel               
     '''
     unaffectedProperty = Property('unaffectedProperty', self.owner, 'unchanged')
     unaffectedTag = Tag('unaffectedTag', self.owner)
     # create default client
     client = ChannelFinderClient(BaseURL=self.baseURL, username=self.username, password=self.password)
     client.set(property=unaffectedProperty)
     client.set(tag=unaffectedTag)
     
     client.set(channel=Channel('cf-update-pv1', 'cf-update', properties=[unaffectedProperty], tags=[unaffectedTag]))     
     client.set(channel=Channel('cf-update-pv2', 'cf-update', properties=[unaffectedProperty], tags=[unaffectedTag]))
     
     # Case1:
     hostName = 'initialHost'
     iocName = 'initialIoc'
     updateChannelFinder(['cf-update-pv1', 'cf-update-pv2'], \
                         hostName, \
                         iocName, \
                         owner=self.owner, \
                         time=time(), \
                         service=self.baseURL , \
                         username=self.username, \
                         password=self.password)
     channels = client.find(name='cf-update-pv*')
     for channel in channels:
         self.assertTrue(unaffectedProperty in channel.Properties and unaffectedTag in channel.Tags)
         self.assertTrue(channel.getProperties()['hostName'] == hostName and \
                         channel.getProperties()['iocName'] == iocName and \
                         channel.getProperties()['pvStatus'] == 'Active', \
                         'Failed to update channels with the correct hostName and/or iocName')
     # Case2:
     hostName = 'newHost'
     updateChannelFinder(['cf-update-pv1', 'cf-update-pv2'], \
                         hostName, \
                         iocName, \
                         owner=self.owner, \
                         time=time(), \
                         service=self.baseURL , \
                         username=self.username, \
                         password=self.password)
     channels = client.find(name='cf-update-pv*')
     for channel in channels:
         self.assertTrue(unaffectedProperty in channel.Properties and unaffectedTag in channel.Tags)
         self.assertTrue(channel.getProperties()['hostName'] == hostName and \
                         channel.getProperties()['iocName'] == iocName and \
                         channel.getProperties()['pvStatus'] == 'Active', \
                         'Failed to update channels with the correct hostName and/or iocName')
     self.assertTrue(client.find(property=[('hostName', 'initialHost')]) == None, 'Failed to cleanup old property')
     # Case 3:
     iocName = 'newIoc'
     updateChannelFinder(['cf-update-pv1', 'cf-update-pv2'], \
                         hostName, \
                         iocName, \
                         owner=self.owner, \
                         time=time(), \
                         service=self.baseURL , \
                         username=self.username, \
                         password=self.password)
     channels = client.find(name='cf-update-pv*')
     for channel in channels:
         self.assertTrue(unaffectedProperty in channel.Properties and unaffectedTag in channel.Tags)
         self.assertTrue(channel.getProperties()['hostName'] == hostName and \
                         channel.getProperties()['iocName'] == iocName and \
                         channel.getProperties()['pvStatus'] == 'Active', 'Failed to update channels with the correct hostName and/or iocName')
     self.assertTrue(client.find(property=[('hostName', 'initialHost')]) == None, 'Failed to cleanup old property')
     self.assertTrue(client.find(property=[('iocName', 'initialIoc')]) == None, 'Failed to cleanup old property')
     # Case 4:
     updateChannelFinder([], \
                         hostName, \
                         iocName, \
                         owner=self.owner, \
                         time=time(), \
                         service=self.baseURL , \
                         username=self.username, \
                         password=self.password)
     channels = client.find(name='cf-update-pv*')
     for channel in channels:
         self.assertTrue(unaffectedProperty in channel.Properties and unaffectedTag in channel.Tags)
         self.assertTrue(channel.getProperties()['hostName'] == hostName and \
                         channel.getProperties()['iocName'] == iocName and \
                         channel.getProperties()['pvStatus'] == 'InActive', \
                         'Failed to update channels with the correct hostName and/or iocName')
     self.assertTrue(client.find(property=[('hostName', 'initialHost')]) == None, 'Failed to cleanup old property')
     self.assertTrue(client.find(property=[('iocName', 'initialIoc')]) == None, 'Failed to cleanup old property')
     
     # Cleanup
     client.delete(channelName='cf-update-pv1')
     client.delete(channelName='cf-update-pv2')
     client.delete(propertyName=unaffectedProperty.Name)
     client.delete(tagName=unaffectedTag.Name)
Ejemplo n.º 11
0
    def testPreservingOfAttributes(self):
        '''
        This test is to ensure that existing properties and tags are left untouched.
        Case1:
        first time the cf-update comes across these channels and adds hostName and iocName
        Case2:
        the hostName is changed
        Case3:
        the iocName is changed
        Case4:
        both hostName and iocName are changed
        Case5:
        the channel is removed
        in all cases the existing unaffected* property and tag should remain with the channel               
        '''
        unaffectedProperty = {
            u'name': u'unaffectedProperty',
            u'owner': self.owner,
            u'value': u'unchanged'
        }
        unaffectedTag = {u'name': u'unaffectedTag', u'owner': self.owner}
        # create default client
        client = ChannelFinderClient(BaseURL=self.baseURL,
                                     username=self.username,
                                     password=self.password)
        client.set(property=unaffectedProperty)
        client.set(tag=unaffectedTag)

        client.set(
            channel={
                u'name': u'cf-update-pv1',
                u'owner': u'cf-update',
                u'properties': [unaffectedProperty],
                u'tags': [unaffectedTag]
            })
        client.set(
            channel={
                u'name': u'cf-update-pv2',
                u'owner': u'cf-update',
                u'properties': [unaffectedProperty],
                u'tags': [unaffectedTag]
            })

        # Case1:
        hostName = 'initialHost'
        iocName = 'initialIoc'
        updateChannelFinder(['cf-update-pv1', 'cf-update-pv2'], \
                            hostName, \
                            iocName, \
                            owner=self.owner, \
                            time=time(), \
                            service=self.baseURL , \
                            username=self.username, \
                            password=self.password)
        channels = client.find(name='cf-update-pv*')
        for channel in channels:
            self.assertTrue(unaffectedProperty in channel['properties']
                            and unaffectedTag in channel['tags'])
            self.assertTrue(
                self.__check4properties(
                    {
                        u'name': u'hostName',
                        u'value': hostName
                    }, channel['properties']) and self.__check4properties(
                        {
                            u'name': u'iocName',
                            u'value': iocName
                        }, channel['properties']) and self.__check4properties(
                            {
                                u'name': u'pvStatus',
                                u'value': u'Active'
                            }, channel['properties']),
                'Failed to update channels with the correct hostName and/or iocName'
            )
        # Case2:
        hostName = 'newHost'
        updateChannelFinder(['cf-update-pv1', 'cf-update-pv2'], \
                            hostName, \
                            iocName, \
                            owner=self.owner, \
                            time=time(), \
                            service=self.baseURL , \
                            username=self.username, \
                            password=self.password)
        channels = client.find(name='cf-update-pv*')
        for channel in channels:
            self.assertTrue(unaffectedProperty in channel['properties']
                            and unaffectedTag in channel['tags'])
            self.assertTrue(
                self.__check4properties(
                    {
                        u'name': u'hostName',
                        u'value': hostName
                    }, channel['properties']) and self.__check4properties(
                        {
                            u'name': u'iocName',
                            u'value': iocName
                        }, channel['properties']) and self.__check4properties(
                            {
                                u'name': u'pvStatus',
                                u'value': u'Active'
                            }, channel['properties']),
                'Failed to update channels with the correct hostName and/or iocName'
            )
        self.assertTrue(
            not client.find(property=[('hostName', 'initialHost')]),
            'Failed to cleanup old property')
        # Case 3:
        iocName = 'newIoc'
        updateChannelFinder(['cf-update-pv1', 'cf-update-pv2'], \
                            hostName, \
                            iocName, \
                            owner=self.owner, \
                            time=time(), \
                            service=self.baseURL , \
                            username=self.username, \
                            password=self.password)
        channels = client.find(name='cf-update-pv*')
        for channel in channels:
            self.assertTrue(unaffectedProperty in channel['properties']
                            and unaffectedTag in channel['tags'])
            self.assertTrue(
                self.__check4properties(
                    {
                        u'name': u'hostName',
                        u'value': hostName
                    }, channel['properties']) and self.__check4properties(
                        {
                            u'name': u'iocName',
                            u'value': iocName
                        }, channel['properties']) and self.__check4properties(
                            {
                                u'name': u'pvStatus',
                                u'value': u'Active'
                            }, channel['properties']),
                'Failed to update channels with the correct hostName and/or iocName'
            )
        self.assertTrue(
            not client.find(property=[('hostName', 'initialHost')]),
            'Failed to cleanup old property')
        self.assertTrue(not client.find(property=[('iocName', 'initialIoc')]),
                        'Failed to cleanup old property')
        # Case 4:
        updateChannelFinder([], \
                            hostName, \
                            iocName, \
                            owner=self.owner, \
                            time=time(), \
                            service=self.baseURL , \
                            username=self.username, \
                            password=self.password)
        channels = client.find(name='cf-update-pv*')
        for channel in channels:
            self.assertTrue(unaffectedProperty in channel['properties']
                            and unaffectedTag in channel['tags'])
            self.assertTrue(
                self.__check4properties(
                    {
                        u'name': u'hostName',
                        u'value': hostName
                    }, channel['properties']) and self.__check4properties(
                        {
                            u'name': u'iocName',
                            u'value': iocName
                        }, channel['properties']) and self.__check4properties(
                            {
                                u'name': u'pvStatus',
                                u'value': u'Inactive'
                            }, channel['properties']),
                'Failed to update channels with the correct hostName and/or iocName'
            )
        self.assertTrue(
            not client.find(property=[('hostName', 'initialHost')]),
            'Failed to cleanup old property')
        self.assertTrue(not client.find(property=[('iocName', 'initialIoc')]),
                        'Failed to cleanup old property')

        # Cleanup
        '''
        TODO this cleanup code should not be contingent to the successful completion of all checks...
        This could pollute CF 
        '''
        client.delete(channelName='cf-update-pv1')
        client.delete(channelName='cf-update-pv2')
        client.delete(propertyName=unaffectedProperty[u'name'])
        client.delete(tagName=unaffectedTag[u'name'])
Ejemplo n.º 12
0
 def testPreservingOfAttributes(self):
     '''
     This test is to ensure that existing properties and tags are left untouched.
     Case1:
     first time the cf-update comes across these channels and adds hostName and iocName
     Case2:
     the hostName is changed
     Case3:
     the iocName is changed
     Case4:
     both hostName and iocName are changed
     Case5:
     the channel is removed
     in all cases the existing unaffected* property and tag should remain with the channel               
     '''
     unaffectedProperty = {u'name':u'unaffectedProperty', u'owner':self.owner, u'value':u'unchanged'}
     unaffectedTag = {u'name':u'unaffectedTag', u'owner':self.owner}
     # create default client
     client = ChannelFinderClient(BaseURL=self.baseURL, username=self.username, password=self.password)
     client.set(property=unaffectedProperty)
     client.set(tag=unaffectedTag)
     
     client.set(channel={u'name':u'cf-update-pv1', u'owner':u'cf-update', u'properties':[unaffectedProperty], u'tags':[unaffectedTag]})
     client.set(channel={u'name':u'cf-update-pv2', u'owner':u'cf-update', u'properties':[unaffectedProperty], u'tags':[unaffectedTag]})
     
     # Case1:
     hostName = 'initialHost'
     iocName = 'initialIoc'
     updateChannelFinder(['cf-update-pv1', 'cf-update-pv2'], \
                         hostName, \
                         iocName, \
                         owner=self.owner, \
                         time=time(), \
                         service=self.baseURL , \
                         username=self.username, \
                         password=self.password)
     channels = client.find(name='cf-update-pv*')
     for channel in channels:
         self.assertTrue(unaffectedProperty in channel['properties'] and unaffectedTag in channel['tags'])
         self.assertTrue(self.__check4properties({u'name':u'hostName', u'value':hostName}, channel['properties']) and 
                         self.__check4properties({u'name':u'iocName', u'value':iocName}, channel['properties']) and 
                         self.__check4properties({u'name':u'pvStatus', u'value':u'Active'}, channel['properties']),
                         'Failed to update channels with the correct hostName and/or iocName')
     # Case2:
     hostName = 'newHost'
     updateChannelFinder(['cf-update-pv1', 'cf-update-pv2'], \
                         hostName, \
                         iocName, \
                         owner=self.owner, \
                         time=time(), \
                         service=self.baseURL , \
                         username=self.username, \
                         password=self.password)
     channels = client.find(name='cf-update-pv*')
     for channel in channels:
         self.assertTrue(unaffectedProperty in channel['properties'] and unaffectedTag in channel['tags'])
         self.assertTrue(self.__check4properties({u'name':u'hostName', u'value':hostName}, channel['properties']) and 
                         self.__check4properties({u'name':u'iocName', u'value':iocName}, channel['properties']) and 
                         self.__check4properties({u'name':u'pvStatus', u'value':u'Active'}, channel['properties']),
                         'Failed to update channels with the correct hostName and/or iocName')
     self.assertTrue(not client.find(property=[('hostName', 'initialHost')]), 'Failed to cleanup old property')
     # Case 3:
     iocName = 'newIoc'
     updateChannelFinder(['cf-update-pv1', 'cf-update-pv2'], \
                         hostName, \
                         iocName, \
                         owner=self.owner, \
                         time=time(), \
                         service=self.baseURL , \
                         username=self.username, \
                         password=self.password)
     channels = client.find(name='cf-update-pv*')
     for channel in channels:
         self.assertTrue(unaffectedProperty in channel['properties'] and unaffectedTag in channel['tags'])
         self.assertTrue(self.__check4properties({u'name':u'hostName', u'value':hostName}, channel['properties']) and 
                         self.__check4properties({u'name':u'iocName', u'value':iocName}, channel['properties']) and 
                         self.__check4properties({u'name':u'pvStatus', u'value':u'Active'}, channel['properties']),
                         'Failed to update channels with the correct hostName and/or iocName')
     self.assertTrue(not client.find(property=[('hostName', 'initialHost')]), 'Failed to cleanup old property')
     self.assertTrue(not client.find(property=[('iocName', 'initialIoc')]), 'Failed to cleanup old property')
     # Case 4:
     updateChannelFinder([], \
                         hostName, \
                         iocName, \
                         owner=self.owner, \
                         time=time(), \
                         service=self.baseURL , \
                         username=self.username, \
                         password=self.password)
     channels = client.find(name='cf-update-pv*')
     for channel in channels:
         self.assertTrue(unaffectedProperty in channel['properties'] and unaffectedTag in channel['tags'])
         self.assertTrue(self.__check4properties({u'name':u'hostName', u'value':hostName}, channel['properties']) and 
                         self.__check4properties({u'name':u'iocName', u'value':iocName}, channel['properties']) and 
                         self.__check4properties({u'name':u'pvStatus', u'value':u'Inactive'}, channel['properties']),
                         'Failed to update channels with the correct hostName and/or iocName')
     self.assertTrue(not client.find(property=[('hostName', 'initialHost')]), 'Failed to cleanup old property')
     self.assertTrue(not client.find(property=[('iocName', 'initialIoc')]), 'Failed to cleanup old property')
     
     # Cleanup
     '''
     TODO this cleanup code should not be contingent to the successful completion of all checks...
     This could pollute CF 
     '''
     client.delete(channelName='cf-update-pv1')
     client.delete(channelName='cf-update-pv2')
     client.delete(propertyName=unaffectedProperty[u'name'])
     client.delete(tagName=unaffectedTag[u'name'])