Commit b14bce48 authored by Kostas Vogias's avatar Kostas Vogias Committed by Stavros Sachtouris

Add VOLUME_TYPE and IGNORE_SSL in config template

parent 186582eb
......@@ -16,9 +16,20 @@
# Copy this file as config.py and fill in the appropriate values
AUTH_URL = 'https://accounts.example.com/identity/v2.0'
ADMIN_TOKEN = 'your_token'
IGNORE_SSL = False
CA_CERTS = '/etc/ssl/certs/ca-certificates.crt'
KEYSTONE_URL = 'https://okeanos-astavoms.example.com'
HOST = 'this-host.example.com or IP'
PORT = '8080'
PASTE_INI = '/home/user/snf-occi/ci/soi.ini'
# Possible values (1,2)
# Volume type=1, drbd
# Volume type=2, archipelago
VOLUME_TYPE = 2
DISABLE_STORAGE_LINK_CREATION = False
DISABLE_STORAGE_LINK_DELETION = False
......@@ -12,6 +12,7 @@
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
from soi.config import VOLUME_TYPE
def _openstackify_volumes_display_names(response):
......@@ -62,7 +63,7 @@ def snf_create_volume(cls, req, name, size):
size = str(int(float(size)))
req.environ['kwargs'] = {'size': size, 'display_name': name,
'volume_type': '2',
'volume_type': str(VOLUME_TYPE),
'project': project_id}
response = req.get_response(cls.app)
r = cls.get_from_response(response, "volume", {})
......
......@@ -12,11 +12,12 @@
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
from soi import config
import webob.exc
def _openstackify_volumes_info(volumes):
"""Adjust server_id, device_index, volume_id to OpensStack"""
for volume in volumes:
volume['displayName'] = volume['display_name']
for attachment in volume['attachments']:
......@@ -33,6 +34,7 @@ def snf_get_all_volume_links(cls, req):
response = req.get_response(cls.app)
r = cls.get_from_response(response, "volumes", [])
_openstackify_volumes_info(r)
return r
......@@ -49,6 +51,12 @@ def snf_get_server_volume_links(cls, req, server_id):
def snf_create_server_volume_link(cls, req, server_id, volume_id,
dev=None):
"""Synnefo: Attach a volume to a server"""
if config.DISABLE_STORAGE_LINK_CREATION:
msg = 'attaching a volume to a server'
raise webob.exc.HTTPNotImplemented(
explanation="Method for {0} is not supported".format(msg))
project_id = req.environ.get('HTTP_X_PROJECT_ID', None)
req.environ['service_type'] = 'compute'
......@@ -64,6 +72,11 @@ def snf_create_server_volume_link(cls, req, server_id, volume_id,
def snf_delete_server_volumes_link(cls, req, server_id, volume_id):
"""Synnefo: Delete a volume attachment"""
if config.DISABLE_STORAGE_LINK_DELETION:
msg = 'deleting a server`s volume link'
raise webob.exc.HTTPNotImplemented(
explanation="Method for {0} is not supported".format(msg))
req.environ['service_type'] = 'compute'
req.environ['method_name'] = 'volume_attachment_delete'
req.environ['kwargs'] = {'server_id': server_id,
......
......@@ -31,12 +31,16 @@ from kamaki.clients.astakos import AstakosClient
from kamaki.clients.cyclades import (
CycladesComputeClient, CycladesNetworkClient, CycladesBlockStorageClient)
from kamaki.clients.utils import https
from soi.config import AUTH_URL, CA_CERTS
from soi.config import AUTH_URL, CA_CERTS, IGNORE_SSL
import webob.exc
# endpoints are offered auth-free, so no need for an admin token
ADMIN_TOKEN = ''
https.patch_with_certs(CA_CERTS)
if IGNORE_SSL:
https.patch_ignore_ssl()
auth = AstakosClient(AUTH_URL, ADMIN_TOKEN)
endpoints = {'identity': AUTH_URL}
......
......@@ -13,8 +13,10 @@
# You should have received a copy of the GNU General Public License
from soi.tests import fakes
from soi import storage_link
from soi import storage_link, config
from mock import patch
import webob.exc
from nose.tools import assert_raises
def test_openstackify_volumes_info():
......@@ -99,9 +101,10 @@ def test_snf_get_server_volume_links(gr, gfr):
@patch('soi.tests.fakes.FakeReq.get_response', return_value='my response')
def test_snf_create_server_volume_link(gr, gfr):
"""Test snf_create_server_volume_link method"""
setattr(config, "DISABLE_STORAGE_LINK_CREATION", False)
cls, req = fakes.DummyClass(), fakes.FakeReq()
server_id = '1234'
volume_id = '1234'
volume_id = '666'
dev = ""
project_id = 'a project id'
req.environ['HTTP_X_PROJECT_ID'] = project_id
......@@ -120,9 +123,25 @@ def test_snf_create_server_volume_link(gr, gfr):
gfr.assert_called_once_with('my response', 'volumeAttachment', {})
def test_snf_create_server_volume_link_disabled():
"""Test snf_create_server_volume_link method disabled"""
setattr(config, "DISABLE_STORAGE_LINK_CREATION", True)
cls, req = fakes.DummyClass(), fakes.FakeReq()
server_id = '1234'
volume_id = '666'
dev = ""
project_id = 'a project id'
req.environ['HTTP_X_PROJECT_ID'] = project_id
assert_raises(webob.exc.HTTPNotImplemented,
storage_link.snf_create_server_volume_link, cls, req,
server_id, volume_id, dev)
@patch('soi.tests.fakes.FakeReq.get_response', return_value='my response')
def test_snf_delete_server_volumes_link(gr):
"""Test snf_delete_server_volumes_link method"""
setattr(config, "DISABLE_STORAGE_LINK_DELETION", False)
cls, req = fakes.DummyClass(), fakes.FakeReq()
server_id = '1234'
volume_id = '666'
......@@ -135,3 +154,14 @@ def test_snf_delete_server_volumes_link(gr):
'attachment_id': volume_id}
)
gr.assert_called_once_with(cls.app)
def test_snf_delete_server_volumes_link_disabled():
"""Test snf_delete_server_volumes_link method"""
setattr(config, "DISABLE_STORAGE_LINK_DELETION", True)
cls, req = fakes.DummyClass(), fakes.FakeReq()
server_id = '1234'
volume_id = '666'
assert_raises(webob.exc.HTTPNotImplemented,
storage_link.snf_delete_server_volumes_link, cls, req,
server_id, volume_id)
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