summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYAMADA Hideki <yamada.hideki@lab.ntt.co.jp>2016-01-26 09:56:03 +0000
committerKairat Kushaev <kkushaev@mirantis.com>2016-02-11 22:25:25 +0000
commit4c4f129b042c6f6918c5e12010ba2e4d132728af (patch)
treeaab76623079b87ebe8154ba32cd674e28dab5d86
parent9683e3bedeb0c33842add19e2334104044426dfe (diff)
downloadglance_store-4c4f129b042c6f6918c5e12010ba2e4d132728af.tar.gz
Sheepdog: fix image-download failure
'port' must be a number, but a string is passed. This is caused by the commit a4ec8a272921fe55879ad0dc1b2cb850f1ea993f. Change-Id: I6c493f75d24c72c43dc2a471dd69a4be2997f3a6 Closes-Bug: #1537695 Signed-off-by: YAMADA Hideki <yamada.hideki@lab.ntt.co.jp>
-rw-r--r--glance_store/_drivers/sheepdog.py6
-rw-r--r--glance_store/tests/unit/test_sheepdog_store.py50
2 files changed, 51 insertions, 5 deletions
diff --git a/glance_store/_drivers/sheepdog.py b/glance_store/_drivers/sheepdog.py
index 8a40765..d59cd10 100644
--- a/glance_store/_drivers/sheepdog.py
+++ b/glance_store/_drivers/sheepdog.py
@@ -144,7 +144,7 @@ class StoreLocation(glance_store.location.StoreLocation):
self.port = self.specs.get('port')
def get_uri(self):
- return "sheepdog://%(addr)s:%(port)s:%(image)s" % {
+ return "sheepdog://%(addr)s:%(port)d:%(image)s" % {
'addr': self.addr,
'port': self.port,
'image': self.image}
@@ -156,7 +156,9 @@ class StoreLocation(glance_store.location.StoreLocation):
raise exceptions.BadStoreUri(message=reason)
pieces = uri[len(valid_schema):].split(':')
if len(pieces) == 3:
- self.addr, self.port, self.image = pieces
+ self.image = pieces[2]
+ self.port = int(pieces[1])
+ self.addr = pieces[0]
# This is used for backwards compatibility.
else:
self.image = pieces[0]
diff --git a/glance_store/tests/unit/test_sheepdog_store.py b/glance_store/tests/unit/test_sheepdog_store.py
index 4758349..eb139ec 100644
--- a/glance_store/tests/unit/test_sheepdog_store.py
+++ b/glance_store/tests/unit/test_sheepdog_store.py
@@ -16,6 +16,7 @@
import mock
from oslo_concurrency import processutils
from oslo_utils import units
+import oslotest
import six
from glance_store._drivers import sheepdog
@@ -25,6 +26,49 @@ from glance_store.tests import base
from glance_store.tests.unit import test_store_capabilities
+class TestStoreLocation(oslotest.base.BaseTestCase):
+ def test_process_spec(self):
+ mock_conf = mock.Mock()
+ fake_spec = {
+ 'image': '6bd59e6e-c410-11e5-ab67-0a73f1fda51b',
+ 'addr': '127.0.0.1',
+ 'port': 7000,
+ }
+ loc = sheepdog.StoreLocation(fake_spec, mock_conf)
+ self.assertEqual(fake_spec['image'], loc.image)
+ self.assertEqual(fake_spec['addr'], loc.addr)
+ self.assertEqual(fake_spec['port'], loc.port)
+
+ def test_parse_uri(self):
+ mock_conf = mock.Mock()
+ fake_uri = ('sheepdog://127.0.0.1:7000'
+ ':6bd59e6e-c410-11e5-ab67-0a73f1fda51b')
+ loc = sheepdog.StoreLocation({}, mock_conf)
+ loc.parse_uri(fake_uri)
+ self.assertEqual('6bd59e6e-c410-11e5-ab67-0a73f1fda51b', loc.image)
+ self.assertEqual('127.0.0.1', loc.addr)
+ self.assertEqual(7000, loc.port)
+
+
+class TestSheepdogImage(oslotest.base.BaseTestCase):
+ @mock.patch.object(processutils, 'execute')
+ def test_run_command(self, mock_execute):
+ image = sheepdog.SheepdogImage(
+ '127.0.0.1', 7000, '6bd59e6e-c410-11e5-ab67-0a73f1fda51b',
+ sheepdog.DEFAULT_CHUNKSIZE,
+ )
+ image._run_command('create', None)
+ expected_cmd = ('collie vdi %(command)s'
+ ' -a %(addr)s -p %(port)d %(name)s ') % {
+ 'command': 'create',
+ 'addr': '127.0.0.1',
+ 'port': 7000,
+ 'name': '6bd59e6e-c410-11e5-ab67-0a73f1fda51b',
+ }
+ actual_cmd = mock_execute.call_args[0][0]
+ self.assertEqual(expected_cmd, actual_cmd)
+
+
class TestSheepdogStore(base.StoreBaseTest,
test_store_capabilities.TestStoreCapabilitiesChecking):
@@ -43,9 +87,9 @@ class TestSheepdogStore(base.StoreBaseTest,
self.addCleanup(execute.stop)
self.store = sheepdog.Store(self.conf)
self.store.configure()
- self.store_specs = {'image': 'fake_image',
- 'addr': 'fake_addr',
- 'port': 'fake_port'}
+ self.store_specs = {'image': '6bd59e6e-c410-11e5-ab67-0a73f1fda51b',
+ 'addr': '127.0.0.1',
+ 'port': 7000}
def test_add_image(self):
called_commands = []