Commit fe08658f authored by Gabriel Monnerat's avatar Gabriel Monnerat

[SlapOS Core] Improve configure-local command and add test for this command

parent de11308a
include CHANGES.txt
include slapos/proxy/schema.sql
include slapos/slapos-client.cfg.example
include slapos/slapos-proxy.cfg.example
include slapos/slapos.cfg.example
recursive-include slapos *.in *.txt *.xsd
from setuptools import setup, find_packages
from shutil import copyfile
import glob
import os
from slapos.version import version
name = 'slapos.core'
long_description = open("README.txt").read() + "\n" + \
open("CHANGES.txt").read() + "\n"
......@@ -11,6 +11,12 @@ long_description = open("README.txt").read() + "\n" + \
for f in sorted(glob.glob(os.path.join('slapos', 'README.*.txt'))):
long_description += '\n' + open(f).read() + '\n'
slapos_folder_path = os.path.dirname(__file__)
for template_name in ('slapos-client.cfg.example',
'slapos-proxy.cfg.example', 'slapos.cfg.example'):
copyfile(os.path.join(slapos_folder_path, template_name),
os.path.join(slapos_folder_path, 'slapos', template_name))
additional_install_requires = []
# Even if argparse is available in python2.7, some python2.7 installations
# do not have it, so checking python version is dangerous
......
# This is an example configuration file for a standalone micro slapos master
# a.k.a slapproxy
[slapos]
instance_root = /srv/slapgrid
software_root = /opt/slapgrid
computer_id = local_computer
[slapproxy]
host = 127.0.0.1
port = 5000
......@@ -8,7 +13,7 @@ database_uri = /opt/slapos/slapproxy.db
# Below is the list of software maintained by slapos.org and contributors
# It is used to simulate a proper configuration of a real slapos master.
software_product_list =
erp5 http://git.erp5.org/gitweb/slapos.git/blob_plain/refs/tags/slapos-0.143:/software/erp5/software.cfg
erp5 http://git.erp5.org/gitweb/slapos.git/blob_plain/refs/tags/slapos-0.195:/software/erp5/software.cfg
erp5_branch http://git.erp5.org/gitweb/slapos.git/blob_plain/refs/heads/erp5:/software/erp5/software.cfg
kumofs http://git.erp5.org/gitweb/slapos.git/blob_plain/refs/tags/slapos-0.141:/software/kumofs/software.cfg
kvm http://git.erp5.org/gitweb/slapos.git/blob_plain/refs/tags/slapos-0.193:/software/kvm/software.cfg
......
......@@ -5,10 +5,10 @@ import functools
import os
import sys
import cliff
from cliff import command
class Command(cliff.command.Command):
class Command(command.Command):
def get_parser(self, prog_name):
parser = argparse.ArgumentParser(
......
This diff is collapsed.
# This is an example configuration file for a standalone micro slapos master
# a.k.a slapproxy
[slapproxy]
host = %(host)s
port = %(port)s
database_uri = /opt/slapos/slapproxy.db
# Below is the list of software maintained by slapos.org and contributors
# It is used to simulate a proper configuration of a real slapos master.
software_product_list =
erp5 http://git.erp5.org/gitweb/slapos.git/blob_plain/refs/tags/slapos-0.143:/software/erp5/software.cfg
erp5_branch http://git.erp5.org/gitweb/slapos.git/blob_plain/refs/heads/erp5:/software/erp5/software.cfg
kumofs http://git.erp5.org/gitweb/slapos.git/blob_plain/refs/tags/slapos-0.141:/software/kumofs/software.cfg
kvm http://git.erp5.org/gitweb/slapos.git/blob_plain/refs/tags/slapos-0.193:/software/kvm/software.cfg
maarch http://git.erp5.org/gitweb/slapos.git/blob_plain/refs/tags/slapos-0.159:/software/maarch/software.cfg
mariadb http://git.erp5.org/gitweb/slapos.git/blob_plain/refs/tags/slapos-0.152:/software/mariadb/software.cfg
memcached http://git.erp5.org/gitweb/slapos.git/blob_plain/refs/tags/slapos-0.82:/software/memcached/software.cfg
slaposwebrunner http://git.erp5.org/gitweb/slapos.git/blob_plain/refs/tags/slapos-0.160:/software/slaprunner/software.cfg
wordpress http://git.erp5.org/gitweb/slapos.git/blob_plain/refs/tags/slapos-0.163:/software/wordpress/software.cfg
zabbixagent http://git.erp5.org/gitweb/slapos.git/blob_plain/refs/tags/slapos-0.162:/software/zabbix-agent/software.cfg
[slapos]
# Replace computer_id by the unique identifier of your computer on your SlapOS,
# Master, usually starting by COMP-
computer_id = %(computer_id)s
master_url = %(master_url)s
software_root = /opt/slapgrid
instance_root = /srv/slapgrid
[slapformat]
# Replace by your network interface providing IPv6 if you don't use re6st
interface_name = %(interface_name)s
# Change "create_tap" into "true" if you need to host KVM services
create_tap = false
partition_amount = %(partition_amount)s
computer_xml = /opt/slapos/slapos.xml
log_file = /opt/slapos/log/slapos-node-format.log
partition_base_name = slappart
user_base_name = slappart
# You can choose any other local network which does not conflict with your
# current machine configuration
ipv4_local_network = %(ipv4_local_network)
# Change to true if you want slapos to use local-only IPv6
use_unique_local_address = True
[networkcache]
# Define options for binary cache, used to download already compiled software.
download-binary-cache-url = http://www.shacache.org/shacache
download-cache-url = https://www.shacache.org/shacache
download-binary-dir-url = http://www.shacache.org/shadir
# Configuration to Upload Configuration for Binary cache
#upload-binary-dir-url = https://www.shacache.org/shadir
#upload-binary-cache-url = https://www.shacache.org/shacache
#signature_private_key_file = /etc/opt/slapos/shacache/signature.key
#signature_certificate_file = /etc/opt/slapos/shacache/signature.cert
#upload-cache-url = https://www.shacache.org/shacache
#shacache-cert-file = /etc/opt/slapos/shacache/shacache.cert
#shacache-key-file = /etc/opt/slapos/shacache/shacache.key
#upload-binary-dir-url = https://www.shacache.org/shadir
#upload-binary-cache-url = https://www.shacache.org/shacache
#upload-dir-url = https://www.shacache.org/shadir
#shadir-cert-file = /etc/opt/slapos/shacache/shacache.cert
#shadir-key-file = /etc/opt/slapos/shacache/shacache.key
# List of signatures of uploaders we trust:
# Romain Courteaud
# Sebastien Robin
# Kazuhiko Shiozaki
# Cedric de Saint Martin
# Yingjie Xu
# Gabriel Monnerat
# Lukasz Nowak
# Marco Mariani
# Test Agent Signature
signature-certificate-list =
-----BEGIN CERTIFICATE-----
MIIB4DCCAUkCADANBgkqhkiG9w0BAQsFADA5MQswCQYDVQQGEwJGUjEZMBcGA1UE
CBMQRGVmYXVsdCBQcm92aW5jZTEPMA0GA1UEChMGTmV4ZWRpMB4XDTExMDkxNTA5
MDAwMloXDTEyMDkxNTA5MDAwMlowOTELMAkGA1UEBhMCRlIxGTAXBgNVBAgTEERl
ZmF1bHQgUHJvdmluY2UxDzANBgNVBAoTBk5leGVkaTCBnzANBgkqhkiG9w0BAQEF
AAOBjQAwgYkCgYEApYZv6OstoqNzxG1KI6iE5U4Ts2Xx9lgLeUGAMyfJL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f+4CiMJNlXPwh
7N+X2kvRpHdXAHkBOxX3j34AeCZrSpu/yDQ=
-----END CERTIFICATE-----
-----BEGIN CERTIFICATE-----
MIIB9jCCAV+gAwIBAgIJAKRvzcy7OH0UMA0GCSqGSIb3DQEBBQUAMBMxETAPBgNV
BAMMCENPTVAtNzcyMCAXDTEyMDgxMDE1NDI1MVoYDzIxMTIwNzE3MTU0MjUxWjAT
MREwDwYDVQQDDAhDT01QLTc3MjCBnzANBgkqhkiG9w0BAQEFAAOBjQAwgYkCgYEA
o7aipd6MbnuGDeR1UJUjuMLQUariAyQ2l2ZDS6TfOwjHiPw/mhzkielgk73kqN7A
sUREx41eTcYCXzTq3WP3xCLE4LxLg1eIhd4nwNHj8H18xR9aP0AGjo4UFl5BOMa1
mwoyBt3VtfGtUmb8whpeJgHhqrPPxLoON+i6fIbXDaUCAwEAAaNQME4wHQYDVR0O
BBYEFEfjy3OopT2lOksKmKBNHTJE2hFlMB8GA1UdIwQYMBaAFEfjy3OopT2lOksK
mKBNHTJE2hFlMAwGA1UdEwQFMAMBAf8wDQYJKoZIhvcNAQEFBQADgYEAaNRx6YN2
M/p3R8/xS6zvH1EqJ3FFD7XeAQ52WuQnKSREzuw0dsw12ClxjcHiQEFioyTiTtjs
5pW18Ry5Ie7iFK4cQMerZwWPxBodEbAteYlRsI6kePV7Gf735Y1RpuN8qZ2sYL6e
x2IMeSwJ82BpdEI5niXxB+iT0HxhmR+XaMI=
-----END CERTIFICATE-----
# List of URL(s) which shouldn't be downloaded from binary cache.
# Any URL beginning by a blacklisted URL will be blacklisted as well.
download-from-binary-cache-url-blacklist =
http://git.erp5.org/gitweb/slapos.git/blob_plain/HEAD
http://git.erp5.org/gitweb/slapos.git/blob_plain/refs/heads
/
# List of URL(s) which shouldn't be uploaded into binary cache.
# Any URL beginning by a blacklisted URL will be blacklisted as well.
upload-to-binary-cache-url-blacklist =
http://git.erp5.org/gitweb/slapos.git/blob_plain/HEAD
http://git.erp5.org/gitweb/slapos.git/blob_plain/refs/heads
/
......@@ -65,6 +65,7 @@ COMPUTER_PARTITION_STOPPED_STATE = 'stopped'
SLAPGRID_SUCCESS = 0
SLAPGRID_FAIL = 1
SLAPGRID_PROMISE_FAIL = 2
PROMISE_TIMEOUT = 3
# XXX hardcoded watchdog_path
WATCHDOG_PATH = '/opt/slapos/bin/slapos-watchdog'
......@@ -214,7 +215,7 @@ def create_slapgrid_object(options, logger):
upload_dir_url=op.get('upload-dir-url'),
master_ca_file=op.get('master_ca_file'),
certificate_repository_path=op.get('certificate_repository_path'),
promise_timeout=op['promise_timeout'],
promise_timeout=op.get('promise_timeout', PROMISE_TIMEOUT),
shacache_cert_file=op.get('shacache-cert-file'),
shacache_key_file=op.get('shacache-key-file'),
shadir_cert_file=op.get('shadir-cert-file'),
......
......@@ -69,8 +69,6 @@ class ProxyConfig(object):
def setConfig(self):
if not self.database_uri:
raise ValueError('database-uri is required.')
self.software_product_list = _generateSoftwareProductListFromString(
getattr(self, 'software_product_list', ''))
def do_proxy(conf):
......@@ -80,5 +78,7 @@ def do_proxy(conf):
app.logger.setLevel(logging.INFO)
app.config['computer_id'] = conf.computer_id
app.config['DATABASE_URI'] = conf.database_uri
app.config['software_product_list'] = conf.software_product_list
app.config['software_product_list'] = \
_generateSoftwareProductListFromString(
getattr(conf, 'software_product_list', ""))
app.run(host=conf.host, port=int(conf.port))
##############################################################################
#
# Copyright (c) 2014 Vifib SARL and Contributors. All Rights Reserved.
#
# WARNING: This program as such is intended to be used by professional
# programmers who take the whole responsibility of assessing all potential
# consequences resulting from its eventual inadequacies and bugs
# End users who are looking for a ready-to-use solution with commercial
# guarantees and support are strongly adviced to contract a Free Software
# Service Company
#
# This program is Free Software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 3
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#
##############################################################################
import os
import unittest
import shutil
import tempfile
import slapos.slap
import slapos.cli.configure_local
from slapos.cli.configure_local import ConfigureLocalCommand, _createConfigurationDirectory
from slapos.cli.entry import SlapOSApp
from argparse import Namespace
from ConfigParser import ConfigParser
# Disable any command to launch slapformat and supervisor
slapos.cli.configure_local._runFormat = lambda x: "Do nothing"
slapos.cli.configure_local.launchSupervisord = lambda socket, \
configuration_file, logger: "Do nothing"
class TestConfigureLocal(unittest.TestCase):
def setUp(self):
self.slap = slapos.slap.slap()
self.app = SlapOSApp()
self.temp_dir = tempfile.mkdtemp()
os.environ["HOME"] = self.temp_dir
self.instance_root = tempfile.mkdtemp()
self.software_root = tempfile.mkdtemp()
if os.path.exists(self.temp_dir):
shutil.rmtree(self.temp_dir)
def tearDown(self):
for temp_path in (self.temp_dir, \
self.instance_root, self.software_root):
if os.path.exists(temp_path):
shutil.rmtree(temp_path)
def test_configure_local_environment_with_default_value(self):
config = ConfigureLocalCommand(self.app, Namespace())
config.__dict__.update({i.dest: i.default \
for i in config.get_parser(None)._option_string_actions.values()})
config.slapos_configuration_directory = self.temp_dir
config.slapos_buildout_directory = self.temp_dir
config.slapos_instance_root = self.instance_root
slapos.cli.configure_local.do_configure(
config, config.fetch_config, self.app.log)
expected_software_root = "/opt/slapgrid"
self.assertTrue(
os.path.exists("%s/.slapos/slapos-client.cfg" % self.temp_dir))
with open(self.temp_dir + '/slapos-proxy.cfg') as fout:
proxy_config = ConfigParser()
proxy_config.readfp(fout)
self.assertEquals(proxy_config.get('slapos', 'instance_root'),
self.instance_root)
self.assertEquals(proxy_config.get('slapos', 'software_root'),
expected_software_root)
with open(self.temp_dir + '/slapos.cfg') as fout:
proxy_config = ConfigParser()
proxy_config.readfp(fout)
self.assertEquals(proxy_config.get('slapos', 'instance_root'),
self.instance_root)
self.assertEquals(proxy_config.get('slapos', 'software_root'),
expected_software_root)
def test_configure_local_environment(self):
config = ConfigureLocalCommand(self.app, Namespace())
config.__dict__.update({i.dest: i.default \
for i in config.get_parser(None)._option_string_actions.values()})
config.slapos_configuration_directory = self.temp_dir
config.slapos_buildout_directory = self.temp_dir
config.slapos_instance_root = self.instance_root
config.slapos_software_root = self.software_root
slapos.cli.configure_local.do_configure(
config, config.fetch_config, self.app.log)
log_folder = os.path.join(config.slapos_buildout_directory, 'log')
self.assertTrue(os.path.exists(log_folder), "%s not exists" % log_folder)
self.assertTrue(
os.path.exists("%s/.slapos/slapos-client.cfg" % self.temp_dir))
with open(self.temp_dir + '/slapos-proxy.cfg') as fout:
proxy_config = ConfigParser()
proxy_config.readfp(fout)
self.assertEquals(proxy_config.get('slapos', 'instance_root'),
self.instance_root)
self.assertEquals(proxy_config.get('slapos', 'software_root'),
self.software_root)
with open(self.temp_dir + '/slapos.cfg') as fout:
proxy_config = ConfigParser()
proxy_config.readfp(fout)
self.assertEquals(proxy_config.get('slapos', 'instance_root'),
self.instance_root)
self.assertEquals(proxy_config.get('slapos', 'software_root'),
self.software_root)
log_file = proxy_config.get('slapformat', 'log_file')
self.assertTrue(log_file.startswith(log_folder),
"%s don't starts with %s" % (log_file, log_folder))
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