Commit f2b44b36 authored by Łukasz Nowak's avatar Łukasz Nowak

Implement SSL authentication to shadir and shacache.

Squashed commit of the following:

commit 154041e95f9e6427c274d9c46edbba14ab66b4d6
Author: Łukasz Nowak <luke@nexedi.com>
Date:   Wed Aug 31 19:05:40 2011 +0200

    Cleanup the code (pyflaked)

commit 4cf44c7f2baf02a056d21b88a4a1a21b534aea75
Author: Łukasz Nowak <luke@nexedi.com>
Date:   Wed Aug 31 17:17:40 2011 +0200

    Cover passing SSL auth keys to buildout.

commit b8207942ba678f6dd3a34c45c56b100d94a44d87
Author: Łukasz Nowak <luke@nexedi.com>
Date:   Wed Aug 31 17:14:46 2011 +0200

    Fix typo.

commit 551a3e3c017d83ca1ba4b7a50c66d1a0b847cf8e
Author: Łukasz Nowak <luke@nexedi.com>
Date:   Wed Aug 31 17:08:39 2011 +0200

    Allow to specify and pass SSL auth key and certs.
parent e23e4587
......@@ -29,7 +29,6 @@ import os
import shutil
import subprocess
import pkg_resources
import shutil
import stat
import tempfile
from supervisor import xmlrpc
......@@ -47,7 +46,8 @@ class Software(object):
"""This class is responsible of installing a software release"""
def __init__(self, url, software_root, console, buildout,
signature_private_key_file=None, upload_cache_url=None,
upload_dir_url=None):
upload_dir_url=None, shacache_cert_file=None, shacache_key_file=None,
shadir_cert_file=None, shadir_key_file=None):
"""Initialisation of class parameters
"""
self.url = url
......@@ -60,6 +60,10 @@ class Software(object):
self.signature_private_key_file = signature_private_key_file
self.upload_cache_url = upload_cache_url
self.upload_dir_url = upload_dir_url
self.shacache_cert_file = shacache_cert_file
self.shacache_key_file = shacache_key_file
self.shadir_cert_file = shadir_cert_file
self.shadir_key_file = shadir_key_file
def install(self):
""" Fetches buildout configuration from the server, run buildout with
......@@ -90,7 +94,12 @@ class Software(object):
for buildout_option, value in (
('%ssignature-private-key-file=%s', self.signature_private_key_file),
('%supload-cache-url=%s', self.upload_cache_url),
('%supload-dir-url=%s', self.upload_dir_url)):
('%supload-dir-url=%s', self.upload_dir_url),
('%sshacache-cert-file=%s', self.shacache_cert_file),
('%sshacache-key-file=%s', self.shacache_key_file),
('%sshadir-cert-file=%s', self.shadir_cert_file),
('%sshadir-key-file=%s', self.shadir_key_file),
):
if value:
buildout_parameter_list.append( \
buildout_option % ('networkcache:', value))
......
......@@ -180,6 +180,10 @@ def parseArgumentTupleAndReturnSlapgridObject(*argument_tuple):
if signature_private_key_file:
mandatory_file_list.append(signature_private_key_file)
for k in ['shacache-cert-file', 'shacache-key-file', 'shadir-cert-file',
'shadir-key-file']:
mandatory_file_list.append(option_dict.get(k, None))
for f in mandatory_file_list:
if f is not None:
if not os.path.exists(f):
......@@ -217,7 +221,12 @@ def parseArgumentTupleAndReturnSlapgridObject(*argument_tuple):
upload_dir_url=option_dict.get('upload-dir-url', None),
console=option_dict['console'],
buildout=option_dict.get('buildout'),
promise_timeout=option_dict['promise_timeout']),
promise_timeout=option_dict['promise_timeout'],
shacache_cert_file=option_dict.get('shacache-cert-file', None),
shacache_key_file=option_dict.get('shacache-key-file', None),
shadir_cert_file=option_dict.get('shadir-cert-file', None),
shadir_key_file=option_dict.get('shadir-key-file', None),
),
option_dict])
......@@ -290,7 +299,11 @@ class Slapgrid(object):
master_ca_file=None,
certificate_repository_path=None,
console=False,
promise_timeout=3):
promise_timeout=3,
shacache_cert_file=None,
shacache_key_file=None,
shadir_cert_file=None,
shadir_key_file=None):
"""Makes easy initialisation of class parameters"""
# Parses arguments
self.software_root = os.path.abspath(software_root)
......@@ -307,6 +320,10 @@ class Slapgrid(object):
self.signature_private_key_file = signature_private_key_file
self.upload_cache_url = upload_cache_url
self.upload_dir_url = upload_dir_url
self.shacache_cert_file = shacache_cert_file
self.shacache_key_file = shacache_key_file
self.shadir_cert_file = shadir_cert_file
self.shadir_key_file = shadir_key_file
# Configures logger
self.logger = logging.getLogger('Slapgrid')
# Creates objects from slap module
......@@ -382,7 +399,11 @@ class Slapgrid(object):
console=self.console, buildout=self.buildout,
signature_private_key_file=self.signature_private_key_file,
upload_cache_url=self.upload_cache_url,
upload_dir_url=self.upload_dir_url).install()
upload_dir_url=self.upload_dir_url,
shacache_cert_file=self.shacache_cert_file,
shacache_key_file=self.shacache_key_file,
shadir_cert_file=self.shadir_cert_file,
shadir_key_file=self.shadir_key_file).install()
except (SystemExit, KeyboardInterrupt):
exception = traceback.format_exc()
software_release.error(exception)
......
......@@ -315,7 +315,7 @@ chmod 755 etc/run/wrapper
if os.path.getsize(wrapper_log) > 0:
break
time.sleep(0.2)
last_size = os.path.getsize(wrapper_log)
os.path.getsize(wrapper_log)
self.assertTrue('Working' in open(wrapper_log, 'r').read())
self.assertSortedListEqual(os.listdir(self.software_root),
[software_hash])
......
......@@ -3,8 +3,6 @@ from slapos.grid import utils
from slapos.tests.slapgrid import BasicMixin
import os
import unittest
import tempfile
import sys
class FakeCallAndRead:
......@@ -31,6 +29,10 @@ class TestSoftwareSlapObject(BasicMixin, unittest.TestCase):
self.signature_private_key_file = '/signature/private/key_file'
self.upload_cache_url = 'http://example.com/uploadcache'
self.upload_dir_url = 'http://example.com/uploaddir'
self.shacache_cert_file = '/path/to/shacache/cert/file'
self.shacache_key_file = '/path/to/shacache/key/file'
self.shadir_cert_file = '/path/to/shadir/cert/file'
self.shadir_key_file = '/path/to/shadir/key/file'
def tearDown(self):
BasicMixin.tearDown(self)
......@@ -48,7 +50,11 @@ class TestSoftwareSlapObject(BasicMixin, unittest.TestCase):
buildout=self.buildout,
signature_private_key_file='/signature/private/key_file',
upload_cache_url='http://example.com/uploadcache',
upload_dir_url='http://example.com/uploaddir')
upload_dir_url='http://example.com/uploaddir',
shacache_cert_file=self.shacache_cert_file,
shacache_key_file=self.shacache_key_file,
shadir_cert_file=self.shadir_cert_file,
shadir_key_file=self.shadir_key_file)
software.install()
......@@ -61,6 +67,14 @@ class TestSoftwareSlapObject(BasicMixin, unittest.TestCase):
in command_list)
self.assertTrue('networkcache:upload-dir-url=%s' % self.upload_dir_url
in command_list)
self.assertTrue('networkcache:shacache-cert-file=%s' % self.shacache_cert_file
in command_list)
self.assertTrue('networkcache:shacache-key-file=%s' % self.shacache_key_file
in command_list)
self.assertTrue('networkcache:shadir-cert-file=%s' % self.shadir_cert_file
in command_list)
self.assertTrue('networkcache:shadir-key-file=%s' % self.shadir_key_file
in command_list)
def test_software_install_without_networkcache(self):
"""
......
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