~blamar/+junk/openstack-api-arrrg

« back to all changes in this revision

Viewing changes to nova/tests/node_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 import utils
 
31
from nova.compute import model
 
32
from nova.compute import node
 
33
 
 
34
FLAGS = flags.FLAGS
 
35
 
 
36
 
 
37
class InstanceXmlTestCase(test.TrialTestCase):
 
38
    # @defer.inlineCallbacks
 
39
    def test_serialization(self):
 
40
        # TODO: Reimplement this, it doesn't make sense in redis-land
 
41
        return
 
42
        
 
43
        # instance_id = 'foo'
 
44
        # first_node = node.Node()
 
45
        # inst = yield first_node.run_instance(instance_id)
 
46
        # 
 
47
        # # force the state so that we can verify that it changes
 
48
        # inst._s['state'] = node.Instance.NOSTATE
 
49
        # xml = inst.toXml()
 
50
        # self.assert_(ElementTree.parse(StringIO.StringIO(xml)))
 
51
        # 
 
52
        # second_node = node.Node()
 
53
        # new_inst = node.Instance.fromXml(second_node._conn, pool=second_node._pool, xml=xml)
 
54
        # self.assertEqual(new_inst.state, node.Instance.RUNNING)
 
55
        # rv = yield first_node.terminate_instance(instance_id)
 
56
        
 
57
 
 
58
class NodeConnectionTestCase(test.TrialTestCase):
 
59
    def setUp(self):
 
60
        logging.getLogger().setLevel(logging.DEBUG)
 
61
        super(NodeConnectionTestCase, self).setUp()
 
62
        self.flags(fake_libvirt=True,
 
63
                   fake_storage=True,
 
64
                   fake_users=True,
 
65
                    redis_db=8)
 
66
        self.node = node.Node()
 
67
    
 
68
    def create_instance(self):
 
69
        instdir = model.InstanceDirectory()
 
70
        inst = instdir.new()
 
71
        # TODO(ja): add ami, ari, aki, user_data
 
72
        inst['reservation_id'] = 'r-fakeres'
 
73
        inst['launch_time'] = '10'
 
74
        inst['owner_id'] = 'fake'
 
75
        inst['node_name'] = FLAGS.node_name
 
76
        inst['mac_address'] = utils.generate_mac()
 
77
        inst['ami_launch_index'] = 0
 
78
        inst.save()
 
79
        return inst['instance_id']
 
80
    
 
81
    @defer.inlineCallbacks
 
82
    def test_run_describe_terminate(self):
 
83
        instance_id = self.create_instance()
 
84
 
 
85
        rv = yield self.node.run_instance(instance_id)
 
86
 
 
87
        rv = yield self.node.describe_instances()
 
88
        self.assertEqual(rv[instance_id].name, instance_id)
 
89
 
 
90
        rv = yield self.node.terminate_instance(instance_id)
 
91
 
 
92
        rv = yield self.node.describe_instances()
 
93
        self.assertEqual(rv, {})
 
94
 
 
95
    @defer.inlineCallbacks
 
96
    def test_reboot(self):
 
97
        instance_id = self.create_instance()
 
98
        rv = yield self.node.run_instance(instance_id)
 
99
        
 
100
        rv = yield self.node.describe_instances()
 
101
        logging.debug("describe_instances returns %s" % (rv))
 
102
        self.assertEqual(rv[instance_id].name, instance_id)
 
103
        
 
104
        yield self.node.reboot_instance(instance_id)
 
105
 
 
106
        rv = yield self.node.describe_instances()
 
107
        self.assertEqual(rv[instance_id].name, instance_id)
 
108
        rv = yield self.node.terminate_instance(instance_id)
 
109
 
 
110
    @defer.inlineCallbacks
 
111
    def test_console_output(self):
 
112
        instance_id = self.create_instance()
 
113
        rv = yield self.node.run_instance(instance_id)
 
114
        
 
115
        console = yield self.node.get_console_output(instance_id)
 
116
        self.assert_(console)
 
117
        rv = yield self.node.terminate_instance(instance_id)
 
118
 
 
119
    @defer.inlineCallbacks
 
120
    def test_run_instance_existing(self):
 
121
        instance_id = self.create_instance()
 
122
        rv = yield self.node.run_instance(instance_id)
 
123
 
 
124
        rv = yield self.node.describe_instances()
 
125
        self.assertEqual(rv[instance_id].name, instance_id)
 
126
        
 
127
        self.assertRaises(exception.Error, self.node.run_instance, instance_id)
 
128
        rv = yield self.node.terminate_instance(instance_id)