示例#1
0
文件: manager.py 项目: flyapen/UgFlu
        def checkNotRunning(comp, parentState):
            name = comp.getName()

            comps = dict([(x.get('name'), x)
                          for x in parentState.get('components')])
            runningComps = dict([(x.get('name'), x)
                                  for x in parentState.get('components')
                                  if x.get('mood') != moods.sleeping.value])
            if name not in comps:
                # We don't have it at all; allow it
                return True
            elif name not in runningComps:
                # We have it, but it's not running. Allow it after deleting
                # the old one.
                oldComp = comps[name]
                self.deleteComponent(oldComp)
                return True

            # if we get here, the component is already running; warn if
            # the running configuration is different. Return False in
            # all cases.
            parent = comps[name].get('parent').get('name')
            newConf = c.getConfigDict()
            oldConf = comps[name].get('config')

            if newConf == oldConf:
                self.debug('%s already has component %s running with '
                           'same configuration', parent, name)
                self.clearMessage('loadComponent-%s' % oldConf['avatarId'])
                return False

            self.info('%s already has component %s, but configuration '
                      'not the same -- notifying admin', parent, name)

            diff = config.dictDiff(oldConf, newConf)
            diffMsg = config.dictDiffMessageString(diff, 'existing', 'new')

            self.addMessage(messages.WARNING,
                            'loadComponent-%s' % oldConf['avatarId'],
                            N_('Could not load component %r into %r: '
                               'a component is already running with '
                               'this name, but has a different '
                               'configuration.'), name, parent,
                            debug=diffMsg)
            return False
示例#2
0
        def verifyExistingComponentState(conf, state):
            # condition (1)
            state.setJobState(self.jobState)
            self.componentState = state

            self.upgradeConfig(state, conf)
            if state.get('config') != conf:
                diff = config.dictDiff(state.get('config'), conf)
                diffMsg = config.dictDiffMessageString(diff, 'internal conf',
                                                       'running conf')
                self.addMessage(messages.WARNING,
                                'stale-config',
                                N_("Component logged in with stale "
                                   "configuration. To fix this, stop "
                                   "this component and then restart "
                                   "the manager."),
                                debug=("Updating internal conf from "
                                       "running conf:\n" + diffMsg))
                self.warning('updating internal component state for %r', state)
                self.debug('changes to conf: %s',
                           config.dictDiffMessageString(diff))
                state.set('config', conf)
示例#3
0
        def verifyExistingComponentState(conf, state):
            # condition (1)
            state.setJobState(self.jobState)
            self.componentState = state

            self.upgradeConfig(state, conf)
            if state.get('config') != conf:
                diff = config.dictDiff(state.get('config'), conf)
                diffMsg = config.dictDiffMessageString(diff,
                                                   'internal conf',
                                                   'running conf')
                self.addMessage(messages.WARNING, 'stale-config',
                                N_("Component logged in with stale "
                                   "configuration. To fix this, stop "
                                   "this component and then restart "
                                   "the manager."),
                                debug=("Updating internal conf from "
                                       "running conf:\n" + diffMsg))
                self.warning('updating internal component state for %r',
                             state)
                self.debug('changes to conf: %s',
                           config.dictDiffMessageString(diff))
                state.set('config', conf)
示例#4
0
 def test(d1, d2, s):
     msg = config.dictDiffMessageString(config.dictDiff(d1, d2))
     self.assertEquals(msg, s)
示例#5
0
 def assertOND(self, d1, d2, old, new, diff):
     o, n, d = config.dictDiff(d1, d2)
     self.assertEquals(old, o)
     self.assertEquals(new, n)
     self.assertEquals(diff, d)
示例#6
0
 def test(d1, d2, s):
     msg = config.dictDiffMessageString(config.dictDiff(d1, d2))
     self.assertEquals(msg, s)
示例#7
0
 def assertOND(self, d1, d2, old, new, diff):
     o, n, d = config.dictDiff(d1, d2)
     self.assertEquals(old, o)
     self.assertEquals(new, n)
     self.assertEquals(diff, d)