def testGetAllPropValues(self): ch1 = Channel('ch1', 'chOwner', properties=[ Property('location', 'propOwner', '234'), Property('prop1', 'propOwner', 'propVal') ]) ch2 = Channel('ch2', 'chOwner', properties=[ Property('location', 'propOwner', 'SR'), Property('prop2', 'propOwner', 'propVal') ]) ch3 = Channel('ch3', 'chOwner', properties=[ Property('location', 'propOwner', 'SR:234'), Property('prop2', 'propOwner', 'propVal') ]) chs = [ch1, ch2, ch3] values = ChannelUtil.getAllPropValues(chs, propertyName='location') self.assertTrue('234' in values, \ 'Failed to find property(location), value 234 for ch1') self.assertTrue('SR' in values, \ 'Failed to find property(location), value SR for ch2') self.assertTrue('SR:234' in values, \ 'Failed to find property(location), value SR:234 for ch3') pass
def testChannelUtil(self): channel1 = Channel('chName1', 'chOwner', properties=[ Property('location', 'propOwner', 'propVal'), Property('prop1', 'propOwner', 'propVal') ], tags=[Tag('myTag', 'tagOwner')]) channel2 = Channel( 'chName2', 'chOwner', properties=[ Property('location', 'propOwner', 'propVal'), Property('prop2', 'propOwner', 'propVal') ], tags=[Tag('myTag', 'tagOwner'), Tag('goldenOrbit', 'tagOwner')]) channels = [channel1, channel2] allTags = ChannelUtil.getAllTags(channels) self.assertTrue(len(allTags) == 2, \ 'expected 2 tags found ' + str(len(allTags))) allPropertyNames = ChannelUtil.getAllProperties(channels) self.assertTrue(len(allPropertyNames) == 3, \ 'expected 3 unique properties but found ' + str(len(allPropertyNames))) pass
def testValidateWithProperty(self): ch1 = Channel('ch1', 'chOwner', properties=[ Property('location', 'propOwner', '234'), Property('prop1', 'propOwner', 'propVal') ]) ch2 = Channel('ch2', 'chOwner', properties=[ Property('location', 'propOwner', 'SR'), Property('prop2', 'propOwner', 'propVal') ]) ch3 = Channel('ch3', 'chOwner', properties=[ Property('location', 'propOwner', 'SR:234'), Property('prop2', 'propOwner', 'propVal') ]) self.assertTrue( ChannelUtil.validateChannelWithProperty([ch2, ch3], Property( 'prop2', 'anyOwner', 'propVal'))) self.assertFalse(ChannelUtil.validateChannelWithProperty([ch1, ch2, ch3], Property('prop2', 'anyOwner', 'propVal')), \ 'Failed to correctly validate channels based on a PropertyValidator') pass
def testValidateWithTag(self): ch1 = Channel('chName1', 'chOwner', properties=[Property('location', 'propOwner', 'propVal'), Property('prop1', 'propOwner', 'propVal')], tags=[Tag('myTag', 'tagOwner')]) ch2 = Channel('chName2', 'chOwner', properties=[Property('location', 'propOwner', 'propVal'), Property('prop2', 'propOwner', 'propVal')], tags=[Tag('myTag', 'tagOwner'), Tag('goldenOrbit', 'tagOwner')]) self.assertTrue(ChannelUtil.validateChannelsWithTag([ch1, ch2], Tag('myTag', 'someOwner')), \ 'Failed to validate channels based on TagValidator') self.assertFalse(ChannelUtil.validateChannelsWithTag([ch1, ch2], Tag('goldenOrbit', 'someOwner')), \ 'Failed to correctly validate channels based on a TagValidator') pass
def createChannel(chName, chOwner, hostName=None, iocName=None, pvStatus='InActive', time=None): ''' Helper to create a channel object with the required properties ''' ch = Channel(chName, chOwner) ch.Properties = [] if hostName != None: ch.Properties.append(Property('hostName', chOwner, hostName)) if iocName != None: ch.Properties.append(Property('iocName', chOwner, iocName)) if pvStatus: ch.Properties.append(Property('pvStatus', chOwner, pvStatus)) if time: ch.Properties.append(Property('time', chOwner, time)) return ch
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)
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)