Commit 3a5a89a9 authored by Thomas Gambier's avatar Thomas Gambier 🚴🏼

slapos/recipe: add python3 support to zero_knowledge

See merge request !872
parents a9289763 57d0ce54
...@@ -25,7 +25,7 @@ ...@@ -25,7 +25,7 @@
# #
############################################################################## ##############################################################################
import ConfigParser from six.moves import configparser
import os import os
import zc.buildout import zc.buildout
...@@ -53,7 +53,7 @@ class WriteRecipe(GenericBaseRecipe): ...@@ -53,7 +53,7 @@ class WriteRecipe(GenericBaseRecipe):
def install(self): def install(self):
# Set up the parser, and write config file if needed # Set up the parser, and write config file if needed
self.parser = ConfigParser.ConfigParser() self.parser = configparser.ConfigParser()
try: try:
self.parser.read(self.path) self.parser.read(self.path)
#clean_options(options) #clean_options(options)
...@@ -63,7 +63,7 @@ class WriteRecipe(GenericBaseRecipe): ...@@ -63,7 +63,7 @@ class WriteRecipe(GenericBaseRecipe):
with open(self.path, 'w') as file: with open(self.path, 'w') as file:
self.parser.write(file) self.parser.write(file)
# If the file or section do not exist # If the file or section do not exist
except (ConfigParser.NoSectionError, IOError) as e: except (configparser.NoSectionError, IOError) as e:
self.full_install() self.full_install()
def full_install(self): def full_install(self):
...@@ -94,7 +94,7 @@ class ReadRecipe(GenericBaseRecipe): ...@@ -94,7 +94,7 @@ class ReadRecipe(GenericBaseRecipe):
self.path = options['file-path'].strip() self.path = options['file-path'].strip()
# Set up the parser, and write config file if needed # Set up the parser, and write config file if needed
self.parser = ConfigParser.ConfigParser() self.parser = configparser.ConfigParser()
if os.path.exists(self.path): if os.path.exists(self.path):
self.parser.read(self.path) self.parser.read(self.path)
for section in self.parser.sections(): for section in self.parser.sections():
......
import os
import shutil
import tempfile
import unittest
import zc.buildout.testing
from slapos.recipe import zero_knowledge
class ZeroKnowledgeTest(unittest.TestCase):
def setUp(self):
self.tmp_dir = tempfile.mkdtemp()
self.addCleanup(shutil.rmtree, self.tmp_dir)
self.buildout = zc.buildout.testing.Buildout()
self.buildout['buildout']['directory'] = self.tmp_dir
def test_write_read(self):
buildout = self.buildout
buildout['zero-knowledge-write'] = {
'filename': 'zero-knowledge.cfg',
'recipe': 'slapos.cookbook:zero-knowledge.read',
'secret': '?',
}
buildout['zero-knowledge-read'] = {
'filename': 'zero-knowledge.cfg',
'recipe': 'slapos.cookbook:zero-knowledge.read',
}
write_recipe = zero_knowledge.WriteRecipe(
buildout,
'zero-knowledge-write',
buildout['zero-knowledge-write'],
)
write_recipe.install()
self.assertTrue(os.path.exists(os.path.join(self.tmp_dir, 'zero-knowledge.cfg',)))
zero_knowledge.ReadRecipe(
buildout,
'zero-knowledge-read',
buildout['zero-knowledge-read'],
)
self.assertEqual(buildout['zero-knowledge-read']['secret'], '?')
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment