コード例 #1
0
    def purge_consul_metadata(self):
        """
        This method is responsible for purging all instances' metadata from
        Consul if they exist.
        """
        if not settings.CONSUL_ENABLED:
            return

        self.logger.info('Purging consul metadata with prefix: %s.', self.consul_prefix)
        agent = ConsulAgent(prefix=self.consul_prefix)
        agent.purge()
コード例 #2
0
    def test_purge_no_prefix(self):
        """
        Purging with no prefix will remove all of the keys from Consul's Key-Value store
        """
        agent = ConsulAgent()
        self.client.kv.put('key', 'value')
        self.client.kv.put('another_key', 'another value')
        self.client.kv.put('dummy_key', '1')

        _, values = self.client.kv.get('', recurse=True)
        self.assertEqual(len(values), 3)

        agent.purge()
        _, values = self.client.kv.get('', recurse=True)
        self.assertIsNone(values)
コード例 #3
0
    def test_purge_with_prefix(self):
        """
        Purging with prefix should only remove the prefixed keys with the given prefix.
        All other values must not be touched.
        """
        prefix = 'nice-prefix'
        agent = ConsulAgent(prefix=prefix)
        self.client.kv.put(prefix + 'key', 'value')
        self.client.kv.put(prefix + 'another_key', 'another value')
        self.client.kv.put('dummy_key', '1')

        _, values = self.client.kv.get('', recurse=True)
        self.assertEqual(len(values), 3)

        agent.purge()
        _, values = self.client.kv.get('', recurse=True)
        self.assertEqual(len(values), 1)