Fix python34 support

Thanks @ntfournier !

Change-Id: I5b8075d0cb04cbde594dcb9be7c999dd6e90be70
This commit is contained in:
Vincent Fournier 2015-05-12 11:16:10 -04:00 committed by aviau
parent a6582fa5ce
commit 8362f81a8d
22 changed files with 70 additions and 51 deletions

View File

@ -15,6 +15,7 @@
import pecan
from pecan import rest
import wsme.types as wtypes
import wsmeext.pecan as wsme_pecan
from surveil.api.handlers.bansho import config_handler
@ -24,7 +25,7 @@ from surveil.common import util
class ConfigController(rest.RestController):
@util.policy_enforce(['authenticated'])
@wsme_pecan.wsexpose(unicode)
@wsme_pecan.wsexpose(wtypes.text)
def get(self):
"""Retrieve user config, empty dict if no config exists."""
user_name = pecan.request.headers.get('X-User-Id')
@ -33,7 +34,7 @@ class ConfigController(rest.RestController):
return config
@util.policy_enforce(['authenticated'])
@wsme_pecan.wsexpose(body=unicode)
@wsme_pecan.wsexpose(body=wtypes.text,)
def post(self, config):
"""Save user config.

View File

@ -15,6 +15,7 @@
import pecan
from pecan import rest
import wsme.types as wtypes
import wsmeext.pecan as wsme_pecan
from surveil.api.datamodel.config import businessimpactmodulation as mod
@ -33,7 +34,7 @@ class BusinessImpactModulationsController(rest.RestController):
return modulations
@util.policy_enforce(['authenticated'])
@wsme_pecan.wsexpose(mod.BusinessImpactModulation, unicode)
@wsme_pecan.wsexpose(mod.BusinessImpactModulation, wtypes.text)
def get_one(self, modulation_name):
"""Returns a specific business impact modulation."""
handler = bh.BusinessImpactModulationHandler(pecan.request)
@ -52,7 +53,7 @@ class BusinessImpactModulationsController(rest.RestController):
@util.policy_enforce(['authenticated'])
@wsme_pecan.wsexpose(mod.BusinessImpactModulation,
unicode,
wtypes.text,
status_code=204)
def delete(self, modulation_name):
"""Returns a specific business impact modulation."""
@ -61,7 +62,7 @@ class BusinessImpactModulationsController(rest.RestController):
@util.policy_enforce(['authenticated'])
@wsme_pecan.wsexpose(mod.BusinessImpactModulation,
unicode,
wtypes.text,
body=mod.BusinessImpactModulation,
status_code=204)
def put(self, modulaion_name, modulation):

View File

@ -15,6 +15,7 @@
import pecan
from pecan import rest
import wsme.types as wtypes
import wsmeext.pecan as wsme_pecan
from surveil.api.datamodel.config import checkmodulation
@ -33,7 +34,7 @@ class CheckModulationsController(rest.RestController):
return checkmodulations
@util.policy_enforce(['authenticated'])
@wsme_pecan.wsexpose(checkmodulation.CheckModulation, unicode)
@wsme_pecan.wsexpose(checkmodulation.CheckModulation, wtypes.text)
def get_one(self, checkmodulation_name):
"""Returns a specific check modulation."""
handler = checkmodulation_handler.CheckModulationHandler(pecan.request)
@ -52,7 +53,7 @@ class CheckModulationsController(rest.RestController):
@util.policy_enforce(['authenticated'])
@wsme_pecan.wsexpose(checkmodulation.CheckModulation,
unicode, status_code=204)
wtypes.text, status_code=204)
def delete(self, checkmodulation_name):
"""Returns a specific check modulation."""
handler = checkmodulation_handler.CheckModulationHandler(pecan.request)
@ -60,7 +61,7 @@ class CheckModulationsController(rest.RestController):
@util.policy_enforce(['authenticated'])
@wsme_pecan.wsexpose(checkmodulation.CheckModulation,
unicode,
wtypes.text,
body=checkmodulation.CheckModulation,
status_code=204)
def put(self, checkmodulation_name, checkmodulation):

View File

@ -15,6 +15,7 @@
import pecan
from pecan import rest
import wsme.types as wtypes
import wsmeext.pecan as wsme_pecan
from surveil.api.datamodel.config import contactgroup
@ -33,7 +34,7 @@ class ContactGroupsController(rest.RestController):
return contact_groups
@util.policy_enforce(['authenticated'])
@wsme_pecan.wsexpose(contactgroup.ContactGroup, unicode)
@wsme_pecan.wsexpose(contactgroup.ContactGroup, wtypes.text)
def get_one(self, group_name):
"""Returns a contact group."""
handler = contactgroup_handler.ContactGroupHandler(pecan.request)
@ -51,7 +52,8 @@ class ContactGroupsController(rest.RestController):
handler.create(data)
@util.policy_enforce(['authenticated'])
@wsme_pecan.wsexpose(contactgroup.ContactGroup, unicode, status_code=204)
@wsme_pecan.wsexpose(contactgroup.ContactGroup, wtypes.text,
status_code=204)
def delete(self, group_name):
"""Delete a specific contact group."""
handler = contactgroup_handler.ContactGroupHandler(pecan.request)
@ -59,7 +61,7 @@ class ContactGroupsController(rest.RestController):
@util.policy_enforce(['authenticated'])
@wsme_pecan.wsexpose(contactgroup.ContactGroup,
unicode,
wtypes.text,
body=contactgroup.ContactGroup,
status_code=204)
def put(self, group_name, contactgroup):

View File

@ -15,6 +15,7 @@
import pecan
from pecan import rest
import wsme.types as wtypes
import wsmeext.pecan as wsme_pecan
from surveil.api.datamodel.config import contact
@ -33,7 +34,7 @@ class ContactsController(rest.RestController):
return hosts
@util.policy_enforce(['authenticated'])
@wsme_pecan.wsexpose(contact.Contact, unicode)
@wsme_pecan.wsexpose(contact.Contact, wtypes.text)
def get_one(self, contact_name):
"""Returns a specific contact."""
handler = contact_handler.ContactHandler(pecan.request)
@ -51,7 +52,7 @@ class ContactsController(rest.RestController):
handler.create(data)
@util.policy_enforce(['authenticated'])
@wsme_pecan.wsexpose(contact.Contact, unicode, status_code=204)
@wsme_pecan.wsexpose(contact.Contact, wtypes.text, status_code=204)
def delete(self, contact_name):
"""Returns a specific contact."""
handler = contact_handler.ContactHandler(pecan.request)
@ -59,7 +60,7 @@ class ContactsController(rest.RestController):
@util.policy_enforce(['authenticated'])
@wsme_pecan.wsexpose(contact.Contact,
unicode,
wtypes.text,
body=contact.Contact,
status_code=204)
def put(self, contact_name, contact):

View File

@ -15,6 +15,7 @@
import pecan
from pecan import rest
import wsme.types as wtypes
import wsmeext.pecan as wsme_pecan
from surveil.api.datamodel.config import hostgroup
@ -33,7 +34,7 @@ class HostGroupsController(rest.RestController):
return host_groups
@util.policy_enforce(['authenticated'])
@wsme_pecan.wsexpose(hostgroup.HostGroup, unicode)
@wsme_pecan.wsexpose(hostgroup.HostGroup, wtypes.text)
def get_one(self, group_name):
"""Returns a host group."""
handler = hostgroup_handler.HostGroupHandler(pecan.request)
@ -51,7 +52,7 @@ class HostGroupsController(rest.RestController):
handler.create(data)
@util.policy_enforce(['authenticated'])
@wsme_pecan.wsexpose(hostgroup.HostGroup, unicode, status_code=204)
@wsme_pecan.wsexpose(hostgroup.HostGroup, wtypes.text, status_code=204)
def delete(self, group_name):
"""Returns a specific host group."""
handler = hostgroup_handler.HostGroupHandler(pecan.request)
@ -59,7 +60,7 @@ class HostGroupsController(rest.RestController):
@util.policy_enforce(['authenticated'])
@wsme_pecan.wsexpose(hostgroup.HostGroup,
unicode,
wtypes.text,
body=hostgroup.HostGroup,
status_code=204)
def put(self, group_name, hostgroup):

View File

@ -15,6 +15,7 @@
import pecan
from pecan import rest
import wsme.types as wtypes
import wsmeext.pecan as wsme_pecan
from surveil.api.datamodel.config import macromodulation
@ -33,7 +34,7 @@ class MacroModulationController(rest.RestController):
return modulations
@util.policy_enforce(['authenticated'])
@wsme_pecan.wsexpose(macromodulation.MacroModulation, unicode)
@wsme_pecan.wsexpose(macromodulation.MacroModulation, wtypes.text)
def get_one(self, timeperiod_name):
"""Returns a specific macro modulation."""
handler = macromodulation_handler.MacroModulationHandler(pecan.request)
@ -52,7 +53,7 @@ class MacroModulationController(rest.RestController):
@util.policy_enforce(['authenticated'])
@wsme_pecan.wsexpose(macromodulation.MacroModulation,
unicode,
wtypes.text,
status_code=204)
def delete(self, modulation_name):
"""Returns a specific macro modulation."""
@ -61,7 +62,7 @@ class MacroModulationController(rest.RestController):
@util.policy_enforce(['authenticated'])
@wsme_pecan.wsexpose(macromodulation.MacroModulation,
unicode,
wtypes.text,
body=macromodulation.MacroModulation,
status_code=204)
def put(self, modulation_name, modulation):

View File

@ -15,6 +15,7 @@
import pecan
from pecan import rest
import wsme.types as wtypes
import wsmeext.pecan as wsme_pecan
from surveil.api.datamodel.config import notificationway
@ -33,7 +34,7 @@ class NotificationWaysController(rest.RestController):
return notificationsway
@util.policy_enforce(['authenticated'])
@wsme_pecan.wsexpose(notificationway.NotificationWay, unicode)
@wsme_pecan.wsexpose(notificationway.NotificationWay, wtypes.text)
def get_one(self, notificationway_name):
"""Returns a specific notification way."""
handler = notificationway_handler.NotificationWayHandler(pecan.request)
@ -53,7 +54,7 @@ class NotificationWaysController(rest.RestController):
@util.policy_enforce(['authenticated'])
@wsme_pecan.wsexpose(
notificationway.NotificationWay,
unicode,
wtypes.text,
status_code=204
)
def delete(self, notificationway_name):
@ -63,7 +64,7 @@ class NotificationWaysController(rest.RestController):
@util.policy_enforce(['authenticated'])
@wsme_pecan.wsexpose(notificationway.NotificationWay,
unicode,
wtypes.text,
body=notificationway.NotificationWay,
status_code=204)
def put(self, notificationway_name, notificationway):

View File

@ -15,6 +15,7 @@
import pecan
from pecan import rest
import wsme.types as wtypes
import wsmeext.pecan as wsme_pecan
from surveil.api.datamodel.config import realm
@ -33,7 +34,7 @@ class RealmsController(rest.RestController):
return realms
@util.policy_enforce(['authenticated'])
@wsme_pecan.wsexpose(realm.Realm, unicode)
@wsme_pecan.wsexpose(realm.Realm, wtypes.text)
def get_one(self, realm_name):
"""Returns a specific realm."""
handler = realm_handler.RealmHandler(pecan.request)
@ -51,7 +52,7 @@ class RealmsController(rest.RestController):
handler.create(data)
@util.policy_enforce(['authenticated'])
@wsme_pecan.wsexpose(realm.Realm, unicode, status_code=204)
@wsme_pecan.wsexpose(realm.Realm, wtypes.text, status_code=204)
def delete(self, realm_name):
"""Deletes a specific realm."""
handler = realm_handler.RealmHandler(pecan.request)
@ -59,7 +60,7 @@ class RealmsController(rest.RestController):
@util.policy_enforce(['authenticated'])
@wsme_pecan.wsexpose(realm.Realm,
unicode,
wtypes.text,
body=realm.Realm,
status_code=204)
def put(self, realm_name, realm):

View File

@ -15,6 +15,7 @@
import pecan
from pecan import rest
import wsme.types as wtypes
import wsmeext.pecan as wsme_pecan
from surveil.api.datamodel.config import servicegroup
@ -33,7 +34,7 @@ class ServiceGroupsController(rest.RestController):
return service_groups
@util.policy_enforce(['authenticated'])
@wsme_pecan.wsexpose(servicegroup.ServiceGroup, unicode)
@wsme_pecan.wsexpose(servicegroup.ServiceGroup, wtypes.text)
def get_one(self, group_name):
"""Returns a service group."""
handler = servicegroup_handler.ServiceGroupHandler(pecan.request)
@ -51,7 +52,8 @@ class ServiceGroupsController(rest.RestController):
handler.create(data)
@util.policy_enforce(['authenticated'])
@wsme_pecan.wsexpose(servicegroup.ServiceGroup, unicode, status_code=204)
@wsme_pecan.wsexpose(servicegroup.ServiceGroup, wtypes.text,
status_code=204)
def delete(self, group_name):
"""Returns a specific service group."""
handler = servicegroup_handler.ServiceGroupHandler(pecan.request)
@ -59,7 +61,7 @@ class ServiceGroupsController(rest.RestController):
@util.policy_enforce(['authenticated'])
@wsme_pecan.wsexpose(servicegroup.ServiceGroup,
unicode,
wtypes.text,
body=servicegroup.ServiceGroup,
status_code=204)
def put(self, group_name, servicegroup):

View File

@ -15,6 +15,7 @@
import pecan
from pecan import rest
import wsme.types as wtypes
import wsmeext.pecan as wsme_pecan
from surveil.api.datamodel.config import timeperiod
@ -33,7 +34,7 @@ class TimePeriodsController(rest.RestController):
return time_periods
@util.policy_enforce(['authenticated'])
@wsme_pecan.wsexpose(timeperiod.TimePeriod, unicode)
@wsme_pecan.wsexpose(timeperiod.TimePeriod, wtypes.text)
def get_one(self, timeperiod_name):
"""Returns a specific time period."""
handler = timeperiod_handler.TimePeriodHandler(pecan.request)
@ -51,7 +52,7 @@ class TimePeriodsController(rest.RestController):
handler.create(data)
@util.policy_enforce(['authenticated'])
@wsme_pecan.wsexpose(timeperiod.TimePeriod, unicode, status_code=204)
@wsme_pecan.wsexpose(timeperiod.TimePeriod, wtypes.text, status_code=204)
def delete(self, timeperiod_name):
"""Returns a specific time period."""
handler = timeperiod_handler.TimePeriodHandler(pecan.request)
@ -59,7 +60,7 @@ class TimePeriodsController(rest.RestController):
@util.policy_enforce(['authenticated'])
@wsme_pecan.wsexpose(timeperiod.TimePeriod,
unicode,
wtypes.text,
body=timeperiod.TimePeriod,
status_code=204)
def put(self, timeperiod_name, timeperiod):

View File

@ -50,8 +50,8 @@ def _build_where_clause(filters):
clause = []
first = True
for filter_name, filter_data in filters.items():
for field, values in filter_data.items():
for filter_name, filter_data in sorted(filters.items()):
for field, values in sorted(filter_data.items()):
for value in values:
if first:
clause.append('WHERE')

View File

@ -42,7 +42,7 @@ class TestBusinessImpactModulationController(functionalTest.FunctionalTest):
def test_get_all_modulations(self):
response = self.get('/v2/config/businessimpactmodulations')
self.assertItemsEqual(
self.assert_count_equal_backport(
json.loads(response.body.decode()),
[
{'business_impact': 1,

View File

@ -42,7 +42,7 @@ class TestCheckModulationsController(functionalTest.FunctionalTest):
def test_get_all_checkmodulations(self):
response = self.get('/v2/config/checkmodulations')
self.assertItemsEqual(
self.assert_count_equal_backport(
json.loads(response.body.decode()),
[
{'checkmodulation_name': 'ping_day',

View File

@ -44,7 +44,7 @@ class TestMacroModulationController(functionalTest.FunctionalTest):
def test_get_all_macromodulations(self):
response = self.get('/v2/config/macromodulations')
self.assertItemsEqual(
self.assert_count_equal_backport(
[
{
'macromodulation_name': 'HighDuringNight',

View File

@ -51,7 +51,7 @@ class TestNotificationWayController(functionalTest.FunctionalTest):
def test_get_all_notificationways(self):
response = self.get('/v2/config/notificationways')
self.assertItemsEqual(
self.assert_count_equal_backport(
json.loads(response.body.decode()),
[
{

View File

@ -42,7 +42,7 @@ class TestTimePeriodsController(functionalTest.FunctionalTest):
def test_get_all_timeperiods(self):
response = self.get('/v2/config/timeperiods')
self.assertItemsEqual(
self.assert_count_equal_backport(
json.loads(response.body.decode()),
[
{'timeperiod_name': 'misc-single-days',

View File

@ -127,7 +127,8 @@ class TestStatusHosts(functionalTest.FunctionalTest):
"acknowledged": True,
"host_name": "ws-arbiter"}]
self.assertItemsEqual(json.loads(response.body), expected)
self.assert_count_equal_backport(json.loads(response.body.decode()),
expected)
def test_query_hosts(self):
query = {
@ -144,7 +145,8 @@ class TestStatusHosts(functionalTest.FunctionalTest):
expected = [{"host_name": "ws-arbiter", "last_check": 1429405764}]
self.assertItemsEqual(json.loads(response.body), expected)
self.assert_count_equal_backport(json.loads(response.body.decode()),
expected)
def test_get_specific_host(self):
@ -161,7 +163,8 @@ class TestStatusHosts(functionalTest.FunctionalTest):
"host_name": "localhost",
"address": "localhost"}
self.assertItemsEqual(json.loads(response.body), expected)
self.assert_count_equal_backport(json.loads(response.body.decode()),
expected)
def test_get_specific_host_service(self):
response = self.get(
@ -175,4 +178,5 @@ class TestStatusHosts(functionalTest.FunctionalTest):
'state': 'OK',
'host_name': 'ws-arbiter',
'service_description': 'check-ws-arbiter'}
self.assertItemsEqual(json.loads(response.body), expected)
self.assert_count_equal_backport(json.loads(response.body.decode()),
expected)

View File

@ -74,7 +74,8 @@ class TestStatusServices(functionalTest.FunctionalTest):
},
]
self.assertItemsEqual(json.loads(response.body), expected)
self.assertEqual(json.loads(response.body.decode()),
expected)
def test_query_services(self):
query = {
@ -97,4 +98,5 @@ class TestStatusServices(functionalTest.FunctionalTest):
'service_description': 'Apache'}
]
self.assertEqual(json.loads(response.body), expected)
self.assertEqual(json.loads(response.body.decode()),
expected)

View File

@ -47,4 +47,4 @@ class FieldsFilterTest(base.BaseTestCase):
expected = [{"last_check": 1429400984, "host_name": "test_keystone"}]
self.assertItemsEqual(result, expected)
self.assert_count_equal_backport(result, expected)

View File

@ -35,7 +35,7 @@ class LiveQueryFilterTest(base.BaseTestCase):
expected = "WHERE state=0 AND description='test_keystone'"
self.assertItemsEqual(result, expected)
self.assert_count_equal_backport(result, expected)
def test_build_where_clause_no_filters(self):
filters = {}
@ -46,7 +46,7 @@ class LiveQueryFilterTest(base.BaseTestCase):
expected = ""
self.assertItemsEqual(result, expected)
self.assert_count_equal_backport(result, expected)
def test_build_influx_query(self):
query = live_query.LiveQuery(
@ -64,7 +64,7 @@ class LiveQueryFilterTest(base.BaseTestCase):
expected = "SELECT * FROM ALERT GROUP BY *, host_name LIMIT 10"
self.assertItemsEqual(result, expected)
self.assert_count_equal_backport(result, expected)
def test_build_influx_query_orderby(self):
query = live_query.LiveQuery(
@ -86,4 +86,4 @@ class LiveQueryFilterTest(base.BaseTestCase):
"GROUP BY *, host_name "
"ORDER BY time DESC LIMIT 10")
self.assertItemsEqual(result, expected)
self.assert_count_equal_backport(result, expected)

View File

@ -1,6 +1,6 @@
[tox]
minverson = 1.6
envlist = py33, py27, pep8, docs
envlist = py34, py27, pep8, docs
skipsdist = True
[testenv]