~0x44/nova/bug838466

« back to all changes in this revision

Viewing changes to nova/tests/storage_unittest.py

  • Committer: Jesse Andrews
  • Date: 2010-05-28 06:05:26 UTC
  • Revision ID: git-v1:bf6e6e718cdc7488e2da87b21e258ccc065fe499
initial commit

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# vim: tabstop=4 shiftwidth=4 softtabstop=4
 
2
# Copyright [2010] [Anso Labs, LLC]
 
3
 
4
#    Licensed under the Apache License, Version 2.0 (the "License");
 
5
#    you may not use this file except in compliance with the License.
 
6
#    You may obtain a copy of the License at
 
7
 
8
#        http://www.apache.org/licenses/LICENSE-2.0
 
9
 
10
#    Unless required by applicable law or agreed to in writing, software
 
11
#    distributed under the License is distributed on an "AS IS" BASIS,
 
12
#    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 
13
#    See the License for the specific language governing permissions and
 
14
#    limitations under the License.
 
15
 
 
16
import logging
 
17
import StringIO
 
18
import time
 
19
import unittest
 
20
from xml.etree import ElementTree
 
21
 
 
22
from nova import vendor
 
23
import mox
 
24
from tornado import ioloop
 
25
from twisted.internet import defer
 
26
 
 
27
from nova import exception
 
28
from nova import flags
 
29
from nova import test
 
30
from nova.compute import node
 
31
from nova.volume import storage
 
32
 
 
33
 
 
34
FLAGS = flags.FLAGS
 
35
 
 
36
 
 
37
class StorageTestCase(test.TrialTestCase):
 
38
    def setUp(self):
 
39
        logging.getLogger().setLevel(logging.DEBUG)
 
40
        super(StorageTestCase, self).setUp()
 
41
        self.mynode = node.Node()
 
42
        self.mystorage = None
 
43
        self.flags(fake_libvirt=True,
 
44
                   fake_storage=True,
 
45
                   redis_db=8)
 
46
        if FLAGS.fake_storage:
 
47
            self.mystorage = storage.FakeBlockStore()
 
48
        else:
 
49
            self.mystorage = storage.BlockStore()
 
50
 
 
51
    @test.skip_if_fake
 
52
    def test_run_create_volume(self):
 
53
        vol_size = '0'
 
54
        user_id = 'fake'
 
55
        volume_id = self.mystorage.create_volume(vol_size, user_id)
 
56
        # rv = self.mystorage.describe_volumes()
 
57
 
 
58
        # Volumes have to be sorted by timestamp in order to work here...
 
59
        # TODO(termie): get_volume returns differently than create_volume
 
60
        self.assertEqual(volume_id,
 
61
                         self.mystorage.get_volume(volume_id)['volume_id'])
 
62
 
 
63
        rv = self.mystorage.delete_volume(volume_id)
 
64
        self.assertRaises(exception.Error,
 
65
                          self.mystorage.get_volume,
 
66
                          volume_id)
 
67
 
 
68
    @test.skip_if_fake
 
69
    def test_run_attach_detach_volume(self):
 
70
        # Create one volume and one node to test with
 
71
        instance_id = "storage-test"
 
72
        # TODO(joshua) - Redo this test, can't make fake instances this way any more
 
73
        # rv = self.mynode.run_instance(instance_id)
 
74
        vol_size = "5"
 
75
        user_id = "fake"
 
76
        volume_id = self.mystorage.create_volume(vol_size, user_id)
 
77
        rv = self.mystorage.attach_volume(volume_id,
 
78
                                          instance_id,
 
79
                                          "/dev/sdf")
 
80
        volume_obj = self.mystorage.get_volume(volume_id)
 
81
        self.assertEqual(volume_obj['status'], "attached")
 
82
        # TODO(???): assert that it's attached to the right instance
 
83
 
 
84
        rv = self.mystorage.detach_volume(volume_id)
 
85
        volume_obj = self.mystorage.get_volume(volume_id)
 
86
        self.assertEqual(volume_obj['status'], "available")