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 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
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
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')
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')
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)
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'])
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'])