Exemplo n.º 1
0
 def setUp(self):
     """Set up self._trie with 111 tokens, one of them a blessed version."""
     self._trie = pytrie.StringTrie()
     self._store = EphemeralStore()
     blessed_version = BlessedVersion(MasterHandler._BLESSED_VERSION,
                                      MasterHandler._MASTER_OWNER)
     for i in range(0, 10):
         some_token = Token(blessed_version.advance_version(),
                            '/some_dir/some_token_%d' % i,
                            priority=i,
                            data='some_data_%d' % i)
         self._trie[some_token.name] = some_token
         self._store.commit_tokens(updates=[some_token])
         for j in range(0, 10):
             some_other_token = Token(
                 blessed_version.advance_version(),
                 '/some_dir/some_token_%d/some_other_token_%d' % (i, j),
                 priority=j,
                 data='some_data_%d_%d' % (i, j))
             self._trie[some_other_token.name] = some_other_token
             self._store.commit_tokens(updates=[some_other_token])
     blessed_version.advance_version()
     self._trie[MasterHandler._BLESSED_VERSION] = blessed_version
     self._store.commit_tokens(updates=[blessed_version])
     self._check_version_uniqueness()
Exemplo n.º 2
0
 def test_advance_version(self):
     blessed_version = BlessedVersion('some_name', 'some_owner')
     self.assertEqual('some_name', blessed_version.name)
     self.assertEqual('some_owner', blessed_version.owner)
     versions = []
     for _ in range(1, 1000):
         versions.append(blessed_version.advance_version())
     sorted_versions = list(versions)
     sorted_versions.sort()
     self.assertEqual(sorted_versions, versions)
Exemplo n.º 3
0
 def test_advance_version(self):
     blessed_version = BlessedVersion('some_name', 'some_owner')
     self.assertEqual('some_name', blessed_version.name)
     self.assertEqual('some_owner', blessed_version.owner)
     versions = []
     for _ in range(1, 1000):
         versions.append(blessed_version.advance_version())
     sorted_versions = list(versions)
     sorted_versions.sort()
     self.assertEqual(sorted_versions, versions)
Exemplo n.º 4
0
def _try_generate_blessed_version(store):
    blessed_version = BlessedVersion(MasterHandler._BLESSED_VERSION,
                                     MasterHandler._MASTER_OWNER)
    active_tokens = store.read_active_tokens()
    for token in active_tokens:
        if token.name == blessed_version.name:
            return
    store.commit_tokens([blessed_version])
Exemplo n.º 5
0
 def setUp(self):
     """Set up self._trie with 111 tokens, one of them a blessed version."""
     self._trie = pytrie.StringTrie()
     self._store = EphemeralStore()
     blessed_version = BlessedVersion(MasterHandler._BLESSED_VERSION,
                                      MasterHandler._MASTER_OWNER)
     for i in range(0, 10):
         some_token = Token(blessed_version.advance_version(),
                            '/some_dir/some_token_%d' % i,
                            priority=i,
                            data='some_data_%d' % i)
         self._trie[some_token.name] = some_token
         self._store.commit_tokens(updates=[some_token])
         for j in range(0, 10):
             some_other_token = Token(
                 blessed_version.advance_version(),
                 '/some_dir/some_token_%d/some_other_token_%d' % (i, j),
                 priority=j,
                 data='some_data_%d_%d' % (i, j))
             self._trie[some_other_token.name] = some_other_token
             self._store.commit_tokens(updates=[some_other_token])
     blessed_version.advance_version()
     self._trie[MasterHandler._BLESSED_VERSION] = blessed_version
     self._store.commit_tokens(updates=[blessed_version])
     self._check_version_uniqueness()
Exemplo n.º 6
0
 def _load_tokens(self):
     try:
         tokens = self._store.read_active_tokens()
         for token in tokens:
             self._trie[token.name] = token
         blessed_version = self._trie.get(MasterHandler._BLESSED_VERSION)
         if blessed_version:
             # Note that blessed_version is an instance of Token class.  We
             # need a BlessedVersion object.
             self._trie[MasterHandler._BLESSED_VERSION] = (
                 BlessedVersion.from_token(blessed_version))
         else:
             assert not self._trie
             self._trie[MasterHandler._BLESSED_VERSION] = BlessedVersion(
                 MasterHandler._BLESSED_VERSION,
                 MasterHandler._MASTER_OWNER)
             self._store.commit_tokens(
                 updates=[self._trie[MasterHandler._BLESSED_VERSION]])
     except:
         LOG.exception('')
         # A failure here may indicate that the token tree was populated
         # partially.  It's dangerous to continue in this state so just
         # exit.
         sys.exit(1)
Exemplo n.º 7
0
 def _load_tokens(self):
     try:
         tokens = self._store.read_active_tokens()
         for token in tokens:
             self._trie[token.name] = token
         blessed_version = self._trie.get(MasterHandler._BLESSED_VERSION)
         if blessed_version:
             # Note that blessed_version is an instance of Token class.  We
             # need a BlessedVersion object.
             self._trie[MasterHandler._BLESSED_VERSION] = (
                 BlessedVersion.from_token(blessed_version))
         else:
             assert not self._trie
             self._trie[MasterHandler._BLESSED_VERSION] = BlessedVersion(
                 MasterHandler._BLESSED_VERSION,
                 MasterHandler._MASTER_OWNER)
             self._store.commit_tokens(
                 updates=[self._trie[MasterHandler._BLESSED_VERSION]])
     except:
         LOG.exception('')
         # A failure here may indicate that the token tree was populated
         # partially.  It's dangerous to continue in this state so just
         # exit.
         sys.exit(1)