Commit dffdfda6 authored by Cédric de Saint Martin's avatar Cédric de Saint Martin Committed by Gabriel Monnerat

[SlapOS Core] Implement support of getSoftwareReleaseListFromSoftwareProduct in proxy.

WARNING: Also remove alias support from slapos client.
parent f4416d63
......@@ -8,24 +8,3 @@ master_url = https://slap.vifib.com/
# Conclusion: node certificate != person certificate.
cert_file = certificate file location coming from your slapos master account
key_file = key file location coming from your slapos master account
# Below are softwares maintained by slapos.org and contributors
alias =
apache_frontend http://git.erp5.org/gitweb/slapos.git/blob_plain/HEAD:/software/apache-frontend/software.cfg
dokuwiki http://git.erp5.org/gitweb/slapos.git/blob_plain/refs/tags/slapos-0.158:/software/dokuwiki/software.cfg
drupal http://git.erp5.org/gitweb/slapos.git/blob_plain/refs/tags/slapos-0.151:/software/erp5/software.cfg
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
fengoffice http://git.erp5.org/gitweb/slapos.git/blob_plain/refs/tags/slapos-0.158:/software/fengoffice/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.192:/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
mysql http://git.erp5.org/gitweb/slapos.git/blob_plain/refs/tags/slapos-0.65:/software/mysql-5.1/software.cfg
opengoo http://git.erp5.org/gitweb/slapos.git/blob_plain/refs/tags/slapos-0.158:/software/opengoo/software.cfg
postgresql http://git.erp5.org/gitweb/slapos.git/blob_plain/refs/tags/slapos-0.157:/software/postgres/software.cfg
slaposwebrunner http://git.erp5.org/gitweb/slapos.git/blob_plain/refs/tags/slapos-0.160:/software/slaprunner/software.cfg
slaposwebrunner_lite http://git.erp5.org/gitweb/slapos.git/blob_plain/refs/tags/slapos-0.164:/software/slaprunner-lite/software.cfg
wordpress http://git.erp5.org/gitweb/slapos.git/blob_plain/refs/tags/slapos-0.163:/software/wordpress/software.cfg
xwiki http://git.erp5.org/gitweb/slapos.git/blob_plain/refs/tags/slapos-0.46:/software/xwiki/software.cfg
zabbixagent http://git.erp5.org/gitweb/slapos.git/blob_plain/refs/tags/slapos-0.162:/software/zabbix-agent/software.cfg
# This is an example configuration file for a standalone micro slapos master
# a.k.a slapproxy
[slapproxy]
host = 127.0.0.1
port = 5000
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
......@@ -2,7 +2,7 @@
# vim: set et sts=2:
##############################################################################
#
# Copyright (c) 2010, 2011, 2012 Vifib SARL and Contributors.
# Copyright (c) 2010, 2011, 2012, 2013 Vifib SARL and Contributors.
# All Rights Reserved.
#
# WARNING: This program as such is intended to be used by professional
......@@ -31,6 +31,24 @@
import logging
def _generateSoftwareProductListFromString(software_product_list_string):
"""
Take a string as argument (which usually comes from the software_product_list
parameter of the slapproxy configuration file), and parse it to generate
list of Software Products that slapproxy will use.
"""
try:
software_product_string_split = software_product_list_string.split('\n')
except AttributeError:
return {}
software_product_list = {}
for line in software_product_string_split:
if line:
software_reference, url = line.split(' ')
software_product_list[software_reference] = url
return software_product_list
class ProxyConfig(object):
def __init__(self, logger):
self.logger = logger
......@@ -40,7 +58,7 @@ class ProxyConfig(object):
for option, value in args.__dict__.items():
setattr(self, option, value)
# Merges the arguments and configuration
# Merge the arguments and configuration
for section in ("slapproxy", "slapos"):
configuration_dict = dict(configp.items(section))
for key in configuration_dict:
......@@ -51,6 +69,8 @@ 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):
......@@ -60,6 +80,5 @@ 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.run(host=conf.host, port=int(conf.port))
......@@ -477,3 +477,21 @@ def request_slave():
ip_list=address_list)
return xml_marshaller.xml_marshaller.dumps(software_instance)
@app.route('/getSoftwareReleaseListFromSoftwareProduct', methods=['GET'])
def getSoftwareReleaseListFromSoftwareProduct():
software_product_reference = request.args.get('software_product_reference')
software_release_url = request.args.get('software_release_url')
if software_release_url:
assert(software_product_reference is None)
raise NotImplementedError('software_release_url parameter is not supported yet.')
else:
assert(software_product_reference is not None)
if app.config['software_product_list'].has_key(software_product_reference):
software_release_url_list =\
[app.config['software_product_list'][software_product_reference]]
else:
software_release_url_list =[]
return xml_marshaller.xml_marshaller.dumps(software_release_url_list)
##############################################################################
#
# Copyright (c) 2013 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 unittest
import slapos.proxy
class TestCliProxy(unittest.TestCase):
def test_generateSoftwareProductListFromString(self):
"""
Test that generateSoftwareProductListFromString correctly parses a parameter
coming from the configuration file.
"""
software_product_list_string = """
product1 url1
product2 url2"""
software_release_url_list = {
'product1': 'url1',
'product2': 'url2',
}
self.assertEqual(
slapos.proxy._generateSoftwareProductListFromString(
software_product_list_string),
software_release_url_list
)
def test_generateSoftwareProductListFromString_emptyString(self):
self.assertEqual(
slapos.proxy._generateSoftwareProductListFromString(''),
{}
)
\ No newline at end of file
......@@ -101,6 +101,7 @@ database_uri = %(tempdir)s/lib/proxy.db
views.app.config['DATABASE_URI'] = self.proxy_db
views.app.config['HOST'] = conf.host
views.app.config['port'] = conf.port
self.app_config = views.app.config
self.app = views.app.test_client()
def add_free_partition(self, partition_amount):
......@@ -182,6 +183,65 @@ class TestInformation(BasicMixin, unittest.TestCase):
self.assertEqual(slap_partition._requested_state, 'destroyed')
self.assertEqual(slap_partition._need_modification, 0)
def test_getSoftwareReleaseListFromSoftwareProduct_software_product_reference(self):
"""
Check that calling getSoftwareReleaseListFromSoftwareProduct() in slapproxy
using a software_product_reference as parameter behaves correctly.
"""
software_product_reference = 'my_product'
software_release_url = 'my_url'
self.app_config['software_product_list'] = {
software_product_reference: software_release_url
}
response = self.app.get('/getSoftwareReleaseListFromSoftwareProduct'
'?software_product_reference=%s' %\
software_product_reference)
software_release_url_list = xml_marshaller.xml_marshaller.loads(
response.data)
self.assertEqual(
software_release_url_list,
[software_release_url]
)
def test_getSoftwareReleaseListFromSoftwareProduct_noSoftwareProduct(self):
"""
Check that calling getSoftwareReleaseListFromSoftwareProduct() in slapproxy
using a software_product_reference that doesn't exist as parameter
returns empty list.
"""
self.app_config['software_product_list'] = {'random': 'random'}
response = self.app.get('/getSoftwareReleaseListFromSoftwareProduct'
'?software_product_reference=idonotexist')
software_release_url_list = xml_marshaller.xml_marshaller.loads(
response.data)
self.assertEqual(
software_release_url_list,
[]
)
def test_getSoftwareReleaseListFromSoftwareProduct_bothParameter(self):
"""
Test that a call to getSoftwareReleaseListFromSoftwareProduct with no
parameter raises
"""
self.assertRaises(
AssertionError,
self.app.get,
'/getSoftwareReleaseListFromSoftwareProduct'
'?software_product_reference=foo'
'&software_release_url=bar'
)
def test_getSoftwareReleaseListFromSoftwareProduct_noParameter(self):
"""
Test that a call to getSoftwareReleaseListFromSoftwareProduct with both
software_product_reference and software_release_url parameters raises
"""
self.assertRaises(
AssertionError,
self.app.get, '/getSoftwareReleaseListFromSoftwareProduct'
)
class MasterMixin(BasicMixin):
"""
......
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