34
35
curr_time = timeutils.utcnow()
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'}]
50
51
LIST_RESPONSE = [{'service-status': 'available', 'service': 'cinder-volume',
51
52
'zone': 'cinder', 'service-state': 'enabled',
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)
103
104
def test_list_hosts_with_zone(self):
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,
116
body={'status': 'disablabc'})
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)
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)
124
128
def test_good_udpate_keys(self):
125
129
body = {'status': 'disable'}
127
131
self.req, 'test.host.1', body=body)
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,
138
body={'disabled': 0})
133
140
def test_show_forbidden(self):
134
141
self.req.environ['cinder.context'].is_admin = False