diff options
| author | Vishvananda Ishaya <vishvananda@yahoo.com> | 2010-06-24 04:11:56 +0100 |
|---|---|---|
| committer | andy <github@anarkystic.com> | 2010-06-24 04:11:56 +0100 |
| commit | d658b59128c8b9a6671cc3cb157249d5a9d2c9eb (patch) | |
| tree | c08998fe152bce2f27d1aaf0d1a1b171ff5daa5f | |
| parent | ab7c9651539dd88f7e545641bdc5a16f69d5dfb0 (diff) | |
| download | nova-d658b59128c8b9a6671cc3cb157249d5a9d2c9eb.tar.gz nova-d658b59128c8b9a6671cc3cb157249d5a9d2c9eb.tar.xz nova-d658b59128c8b9a6671cc3cb157249d5a9d2c9eb.zip | |
add project ids to volumes
| -rw-r--r-- | nova/endpoint/cloud.py | 3 | ||||
| -rw-r--r-- | nova/tests/storage_unittest.py | 34 | ||||
| -rw-r--r-- | nova/volume/storage.py | 19 |
3 files changed, 26 insertions, 30 deletions
diff --git a/nova/endpoint/cloud.py b/nova/endpoint/cloud.py index 2f30d2992..93efa1361 100644 --- a/nova/endpoint/cloud.py +++ b/nova/endpoint/cloud.py @@ -279,7 +279,8 @@ class CloudController(object): # TODO(vish): refactor this to create the volume object here and tell storage to create it res = rpc.call(FLAGS.storage_topic, {"method": "create_volume", "args" : {"size": size, - "user_id": context.user.id}}) + "user_id": context.user.id, + "project_id": context.project.id}}) def _format_result(result): volume = self._get_volume(context, result['result']) return {'volumeSet': [self.format_volume(context, volume)]} diff --git a/nova/tests/storage_unittest.py b/nova/tests/storage_unittest.py index 4f2a60b25..d2daccf6f 100644 --- a/nova/tests/storage_unittest.py +++ b/nova/tests/storage_unittest.py @@ -1,12 +1,12 @@ # vim: tabstop=4 shiftwidth=4 softtabstop=4 # Copyright [2010] [Anso Labs, LLC] -# +# # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at -# +# # http://www.apache.org/licenses/LICENSE-2.0 -# +# # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -14,15 +14,6 @@ # limitations under the License. import logging -import StringIO -import time -import unittest -from xml.etree import ElementTree - -from nova import vendor -import mox -from tornado import ioloop -from twisted.internet import defer from nova import exception from nova import flags @@ -50,7 +41,8 @@ class StorageTestCase(test.TrialTestCase): def test_run_create_volume(self): vol_size = '0' user_id = 'fake' - volume_id = self.mystorage.create_volume(vol_size, user_id) + project_id = 'fake' + volume_id = self.mystorage.create_volume(vol_size, user_id, project_id) # TODO(termie): get_volume returns differently than create_volume self.assertEqual(volume_id, storage.get_volume(volume_id)['volume_id']) @@ -59,22 +51,24 @@ class StorageTestCase(test.TrialTestCase): self.assertRaises(exception.Error, storage.get_volume, volume_id) - + def test_too_big_volume(self): vol_size = '1001' user_id = 'fake' + project_id = 'fake' self.assertRaises(TypeError, self.mystorage.create_volume, - vol_size, user_id) + vol_size, user_id, project_id) def test_run_attach_detach_volume(self): # Create one volume and one node to test with instance_id = "storage-test" vol_size = "5" user_id = "fake" + project_id = 'fake' mountpoint = "/dev/sdf" - volume_id = self.mystorage.create_volume(vol_size, user_id) - + volume_id = self.mystorage.create_volume(vol_size, user_id, project_id) + volume_obj = storage.get_volume(volume_id) volume_obj.start_attach(instance_id, mountpoint) rv = yield self.mynode.attach_volume(volume_id, @@ -84,7 +78,7 @@ class StorageTestCase(test.TrialTestCase): self.assertEqual(volume_obj['attachStatus'], "attached") self.assertEqual(volume_obj['instance_id'], instance_id) self.assertEqual(volume_obj['mountpoint'], mountpoint) - + self.assertRaises(exception.Error, self.mystorage.delete_volume, volume_id) @@ -92,12 +86,12 @@ class StorageTestCase(test.TrialTestCase): rv = yield self.mystorage.detach_volume(volume_id) volume_obj = storage.get_volume(volume_id) self.assertEqual(volume_obj['status'], "available") - + rv = self.mystorage.delete_volume(volume_id) self.assertRaises(exception.Error, storage.get_volume, volume_id) - + def test_multi_node(self): # TODO(termie): Figure out how to test with two nodes, # each of them having a different FLAG for storage_node diff --git a/nova/volume/storage.py b/nova/volume/storage.py index 5ebd8b941..7da5afe20 100644 --- a/nova/volume/storage.py +++ b/nova/volume/storage.py @@ -71,7 +71,7 @@ def get_volume(volume_id): class BlockStore(object): """ There is one BlockStore running on each volume node. - However, each BlockStore can report on the state of + However, each BlockStore can report on the state of *all* volumes in the cluster. """ def __init__(self): @@ -86,14 +86,14 @@ class BlockStore(object): pass @validate.rangetest(size=(0, 100)) - def create_volume(self, size, user_id): + def create_volume(self, size, user_id, project_id): """ Creates an exported volume (fake or real), restarts exports to make it available. Volume at this point has size, owner, and zone. """ logging.debug("Creating volume of size: %s" % (size)) - vol = self.volume_class.create(size, user_id) + vol = self.volume_class.create(size, user_id, project_id) datastore.Redis.instance().sadd('volumes', vol['volume_id']) datastore.Redis.instance().sadd('volumes:%s' % (FLAGS.storage_name), vol['volume_id']) self._restart_exports() @@ -155,7 +155,7 @@ class Volume(datastore.RedisModel): super(Volume, self).__init__(object_id=volume_id) @classmethod - def create(cls, size, user_id): + def create(cls, size, user_id, project_id): volume_id = utils.generate_uid('vol') vol = cls(volume_id=volume_id) #TODO(vish): do we really need to store the volume id as .object_id .volume_id and ['volume_id']? @@ -163,6 +163,7 @@ class Volume(datastore.RedisModel): vol['node_name'] = FLAGS.storage_name vol['size'] = size vol['user_id'] = user_id + vol['project_id'] = project_id vol['availability_zone'] = FLAGS.storage_availability_zone vol["instance_id"] = 'none' vol["mountpoint"] = 'none' @@ -185,26 +186,26 @@ class Volume(datastore.RedisModel): self['instance_id'] = instance_id self['mountpoint'] = mountpoint self['status'] = "in-use" - self['attachStatus'] = "attaching" + self['attachStatus'] = "attaching" self['attachTime'] = time.strftime('%Y-%m-%dT%H:%M:%SZ', time.gmtime()) self['deleteOnTermination'] = 'False' self.save() - + def finish_attach(self): """ """ - self['attachStatus'] = "attached" + self['attachStatus'] = "attached" self.save() def start_detach(self): """ """ - self['attachStatus'] = "detaching" + self['attachStatus'] = "detaching" self.save() def finish_detach(self): self['instance_id'] = None self['mountpoint'] = None self['status'] = "available" - self['attachStatus'] = "detached" + self['attachStatus'] = "detached" self.save() def destroy(self): |
