~ubuntu-branches/ubuntu/raring/cinder/raring-updates

« back to all changes in this revision

Viewing changes to cinder/tests/api/openstack/volume/contrib/test_hosts.py

Tags: upstream-2013.1~g2
ImportĀ upstreamĀ versionĀ 2013.1~g2

Show diffs side-by-side

added added

removed removed

Lines of Context:
15
15
#    License for the specific language governing permissions and limitations
16
16
#    under the License.
17
17
 
 
18
import datetime
 
19
 
18
20
from lxml import etree
19
21
import webob.exc
20
22
 
21
23
from cinder.api.openstack.volume.contrib import hosts as os_hosts
22
24
from cinder import context
23
 
import datetime
24
25
from cinder import db
25
26
from cinder import flags
26
27
from cinder.openstack.common import log as logging
34
35
curr_time = timeutils.utcnow()
35
36
 
36
37
SERVICE_LIST = [
37
 
        {'created_at': created_time, 'updated_at': curr_time,
38
 
         'host': 'test.host.1', 'topic': 'cinder-volume', 'disabled': 0,
39
 
         'availability_zone': 'cinder'},
40
 
        {'created_at': created_time, 'updated_at': curr_time,
41
 
         'host': 'test.host.1', 'topic': 'cinder-volume', 'disabled': 0,
42
 
         'availability_zone': 'cinder'},
43
 
        {'created_at': created_time, 'updated_at': curr_time,
44
 
         'host': 'test.host.1', 'topic': 'cinder-volume', 'disabled': 0,
45
 
         'availability_zone': 'cinder'},
46
 
        {'created_at': created_time, 'updated_at': curr_time,
47
 
         'host': 'test.host.1', 'topic': 'cinder-volume', 'disabled': 0,
48
 
         'availability_zone': 'cinder'}]
 
38
    {'created_at': created_time, 'updated_at': curr_time,
 
39
     'host': 'test.host.1', 'topic': 'cinder-volume', 'disabled': 0,
 
40
     'availability_zone': 'cinder'},
 
41
    {'created_at': created_time, 'updated_at': curr_time,
 
42
     'host': 'test.host.1', 'topic': 'cinder-volume', 'disabled': 0,
 
43
     'availability_zone': 'cinder'},
 
44
    {'created_at': created_time, 'updated_at': curr_time,
 
45
     'host': 'test.host.1', 'topic': 'cinder-volume', 'disabled': 0,
 
46
     'availability_zone': 'cinder'},
 
47
    {'created_at': created_time, 'updated_at': curr_time,
 
48
     'host': 'test.host.1', 'topic': 'cinder-volume', 'disabled': 0,
 
49
     'availability_zone': 'cinder'}]
49
50
 
50
51
LIST_RESPONSE = [{'service-status': 'available', 'service': 'cinder-volume',
51
52
                  'zone': 'cinder', 'service-state': 'enabled',
97
98
 
98
99
        cinder_hosts = os_hosts._list_hosts(self.req, 'cinder-volume')
99
100
        expected = [host for host in LIST_RESPONSE
100
 
                if host['service'] == 'cinder-volume']
 
101
                    if host['service'] == 'cinder-volume']
101
102
        self.assertEqual(cinder_hosts, expected)
102
103
 
103
104
    def test_list_hosts_with_zone(self):
107
108
 
108
109
    def test_bad_status_value(self):
109
110
        self.assertRaises(webob.exc.HTTPBadRequest, self.controller.update,
110
 
                self.req, 'test.host.1', body={'status': 'bad'})
111
 
        self.assertRaises(webob.exc.HTTPBadRequest, self.controller.update,
112
 
                self.req, 'test.host.1', body={'status': 'disablabc'})
 
111
                          self.req, 'test.host.1', body={'status': 'bad'})
 
112
        self.assertRaises(webob.exc.HTTPBadRequest,
 
113
                          self.controller.update,
 
114
                          self.req,
 
115
                          'test.host.1',
 
116
                          body={'status': 'disablabc'})
113
117
 
114
118
    def test_bad_update_key(self):
115
119
        bad_body = {'crazy': 'bad'}
116
120
        self.assertRaises(webob.exc.HTTPBadRequest, self.controller.update,
117
 
                self.req, 'test.host.1', body=bad_body)
 
121
                          self.req, 'test.host.1', body=bad_body)
118
122
 
119
123
    def test_bad_update_key_and_correct_udpate_key(self):
120
124
        bad_body = {'status': 'disable', 'crazy': 'bad'}
121
125
        self.assertRaises(webob.exc.HTTPBadRequest, self.controller.update,
122
 
                self.req, 'test.host.1', body=bad_body)
 
126
                          self.req, 'test.host.1', body=bad_body)
123
127
 
124
128
    def test_good_udpate_keys(self):
125
129
        body = {'status': 'disable'}
127
131
                          self.req, 'test.host.1', body=body)
128
132
 
129
133
    def test_bad_host(self):
130
 
        self.assertRaises(webob.exc.HTTPNotFound, self.controller.update,
131
 
                self.req, 'bogus_host_name', body={'disabled': 0})
 
134
        self.assertRaises(webob.exc.HTTPNotFound,
 
135
                          self.controller.update,
 
136
                          self.req,
 
137
                          'bogus_host_name',
 
138
                          body={'disabled': 0})
132
139
 
133
140
    def test_show_forbidden(self):
134
141
        self.req.environ['cinder.context'].is_admin = False