~ubuntu-cloud-archive/ubuntu/precise/nova/trunk

« back to all changes in this revision

Viewing changes to nova/tests/api/openstack/compute/contrib/test_flavor_rxtx.py

  • Committer: Package Import Robot
  • Author(s): Chuck Short, Chuck Short, Soren Hansen
  • Date: 2012-09-07 17:49:53 UTC
  • mfrom: (1.1.61)
  • Revision ID: package-import@ubuntu.com-20120907174953-oapuvix1jxm830he
Tags: 2012.2~rc1~20120907.15996-0ubuntu1
[ Chuck Short ]
* New upstream release.
* debian/nova-common.postinst: Drop nova_sudoers permission changing
  since we do it in the debian/rules. (LP: #995285)

[ Soren Hansen ]
* Update debian/watch to account for symbolically named tarballs and
  use newer URL.
* Fix Launchpad URLs in debian/watch.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright 2012 Nebula, Inc.
 
2
#
 
3
#    Licensed under the Apache License, Version 2.0 (the "License"); you may
 
4
#    not use this file except in compliance with the License. You may obtain
 
5
#    a copy of the License at
 
6
#
 
7
#         http://www.apache.org/licenses/LICENSE-2.0
 
8
#
 
9
#    Unless required by applicable law or agreed to in writing, software
 
10
#    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 
11
#    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 
12
#    License for the specific language governing permissions and limitations
 
13
#    under the License.
 
14
 
 
15
from lxml import etree
 
16
import webob
 
17
 
 
18
from nova.compute import instance_types
 
19
from nova import flags
 
20
from nova.openstack.common import jsonutils
 
21
from nova import test
 
22
from nova.tests.api.openstack import fakes
 
23
 
 
24
 
 
25
FLAGS = flags.FLAGS
 
26
 
 
27
 
 
28
FAKE_FLAVORS = {
 
29
    'flavor 1': {
 
30
        "flavorid": '1',
 
31
        "name": 'flavor 1',
 
32
        "memory_mb": '256',
 
33
        "root_gb": '10',
 
34
        "rxtx_factor": '1.0',
 
35
    },
 
36
    'flavor 2': {
 
37
        "flavorid": '2',
 
38
        "name": 'flavor 2',
 
39
        "memory_mb": '512',
 
40
        "root_gb": '10',
 
41
        "rxtx_factor": None,
 
42
    },
 
43
}
 
44
 
 
45
 
 
46
def fake_instance_type_get_by_flavor_id(flavorid):
 
47
    return FAKE_FLAVORS['flavor %s' % flavorid]
 
48
 
 
49
 
 
50
def fake_instance_type_get_all(*args, **kwargs):
 
51
    return FAKE_FLAVORS
 
52
 
 
53
 
 
54
class FlavorRxtxTest(test.TestCase):
 
55
    content_type = 'application/json'
 
56
    prefix = ''
 
57
 
 
58
    def setUp(self):
 
59
        super(FlavorRxtxTest, self).setUp()
 
60
        ext = ('nova.api.openstack.compute.contrib'
 
61
              '.flavor_rxtx.Flavor_rxtx')
 
62
        self.flags(osapi_compute_extension=[ext])
 
63
        fakes.stub_out_nw_api(self.stubs)
 
64
        self.stubs.Set(instance_types, "get_all_types",
 
65
                       fake_instance_type_get_all)
 
66
        self.stubs.Set(instance_types,
 
67
                       "get_instance_type_by_flavor_id",
 
68
                       fake_instance_type_get_by_flavor_id)
 
69
 
 
70
    def _make_request(self, url):
 
71
        req = webob.Request.blank(url)
 
72
        req.headers['Accept'] = self.content_type
 
73
        res = req.get_response(fakes.wsgi_app())
 
74
        return res
 
75
 
 
76
    def _get_flavor(self, body):
 
77
        return jsonutils.loads(body).get('flavor')
 
78
 
 
79
    def _get_flavors(self, body):
 
80
        return jsonutils.loads(body).get('flavors')
 
81
 
 
82
    def assertFlavorRxtx(self, flavor, rxtx):
 
83
        self.assertEqual(str(flavor.get('%srxtx_factor' % self.prefix)), rxtx)
 
84
 
 
85
    def test_show(self):
 
86
        url = '/v2/fake/flavors/1'
 
87
        res = self._make_request(url)
 
88
 
 
89
        self.assertEqual(res.status_int, 200)
 
90
        self.assertFlavorRxtx(self._get_flavor(res.body), '1.0')
 
91
 
 
92
    def test_detail(self):
 
93
        url = '/v2/fake/flavors/detail'
 
94
        res = self._make_request(url)
 
95
 
 
96
        self.assertEqual(res.status_int, 200)
 
97
        flavors = self._get_flavors(res.body)
 
98
        self.assertFlavorRxtx(flavors[0], '1.0')
 
99
        self.assertFlavorRxtx(flavors[1], '')
 
100
 
 
101
 
 
102
class FlavorRxtxXmlTest(FlavorRxtxTest):
 
103
    content_type = 'application/xml'
 
104
 
 
105
    def _get_flavor(self, body):
 
106
        return etree.XML(body)
 
107
 
 
108
    def _get_flavors(self, body):
 
109
        return etree.XML(body).getchildren()