Fixed wrong use of pymongo update

Change-Id: Id92d5d5acfedfc6236aab47844444aef06672c06
This commit is contained in:
aviau 2015-06-02 17:52:03 -04:00
parent 906542757c
commit f084ed90a3
15 changed files with 44 additions and 24 deletions

View File

@ -22,7 +22,7 @@ class Host(types.Base):
host_name = wsme.wsattr(wtypes.text, mandatory=True)
"""The name of the host"""
address = wsme.wsattr(wtypes.text, mandatory=True)
address = wsme.wsattr(wtypes.text, mandatory=False)
"""The address of the host. Normally, this is an IP address."""
max_check_attempts = wsme.wsattr(int, mandatory=False, default=3)

View File

@ -37,7 +37,8 @@ class BusinessImpactModulationHandler(handler.Handler):
self.request.mongo_connection.shinken.businessimpactmodulations.update(
{"business_impact_modulation_name": name},
modulation_dict
{"$set": modulation_dict},
upsert=True
)
def delete(self, name):

View File

@ -34,7 +34,8 @@ class CheckModulationHandler(handler.Handler):
self.request.mongo_connection.shinken.checkmodulations.update(
{"checkmodulation_name": checkmodulation_name},
checkmodulation_dict
{"$set": checkmodulation_dict},
upsert=True
)
def delete(self, checkmodulation_name):

View File

@ -34,7 +34,8 @@ class CommandHandler(handler.Handler):
self.request.mongo_connection.shinken.commands.update(
{"command_name": command_name},
command_dict
{"$set": command_dict},
upsert=True
)
def delete(self, command_name):

View File

@ -35,7 +35,8 @@ class ContactHandler(handler.Handler):
self.request.mongo_connection.shinken.contacts.update(
{"contact_name": contact_name},
contact_dict
{"$set": contact_dict},
upsert=True
)
def delete(self, contact_name):

View File

@ -35,7 +35,8 @@ class ContactGroupHandler(handler.Handler):
self.request.mongo_connection.shinken.contactgroups.update(
{"contactgroup_name": group_name},
group_dict
{"$set": group_dict},
upsert=True
)
def delete(self, group_name):

View File

@ -35,7 +35,8 @@ class HostHandler(handler.Handler):
self.request.mongo_connection.shinken.hosts.update(
{"host_name": host_name},
host_dict
{"$set": host_dict},
upsert=True
)
def delete(self, host_name):

View File

@ -35,7 +35,8 @@ class HostGroupHandler(handler.Handler):
self.request.mongo_connection.shinken.hostgroups.update(
{"hostgroup_name": group_name},
group_dict
{"$set": group_dict},
upsert=True
)
def delete(self, group_name):

View File

@ -35,7 +35,8 @@ class MacroModulationHandler(handler.Handler):
self.request.mongo_connection.shinken.macromodulations.update(
{"macromodulation_name": modulation_name},
modulation_dict
{"$set": modulation_dict},
upsert=True
)
def delete(self, modulation_name):

View File

@ -33,7 +33,8 @@ class NotificationWayHandler(handler.Handler):
self.request.mongo_connection.shinken.notificationways.update(
{"notificationway_name": notificationway_name},
notificationway_dict
{"$set": notificationway_dict},
upsert=True
)
def delete(self, notificationway_name):

View File

@ -35,7 +35,8 @@ class RealmHandler(handler.Handler):
self.request.mongo_connection.shinken.realms.update(
{"realm_name": realm_name},
realm_dict
{"$set": realm_dict},
upsert=True
)
def delete(self, realm_name):

View File

@ -35,7 +35,8 @@ class ServiceHandler(handler.Handler):
self.request.mongo_connection.shinken.hosts.update(
{"host_name": id},
host_dict
{"$set": host_dict},
upsert=True
)
def delete(self, host_name, service_description):

View File

@ -35,7 +35,8 @@ class ServiceGroupHandler(handler.Handler):
self.request.mongo_connection.shinken.servicegroups.update(
{"servicegroup_name": group_name},
group_dict
{"$set": group_dict},
upsert=True
)
def delete(self, group_name):

View File

@ -35,7 +35,8 @@ class TimePeriodHandler(handler.Handler):
self.request.mongo_connection.shinken.timeperiods.update(
{"timeperiod_name": timeperiod_name},
timeperiod_dict
{"$set": timeperiod_dict},
upsert=True
)
def delete(self, timeperiod_name):

View File

@ -45,7 +45,8 @@ class TestHostController(functionalTest.FunctionalTest):
"host_name": "bogus-router333", "address": "192.168.1.254",
"max_check_attempts": 5, "check_period": "24x7",
"contacts": "admin,carl", "contact_groups": "router-admins",
"notification_interval": 30, "notification_period": "24x7"
"notification_interval": 30, "notification_period": "24x7",
'use': 'test'
},
]
self.mongoconnection.shinken.hosts.insert(
@ -133,14 +134,8 @@ class TestHostController(functionalTest.FunctionalTest):
def test_update_host(self):
put_host = {
u"host_name": u"bogus-router333",
u"address": u"newputaddress",
u"max_check_attempts": 222225,
u"check_period": u"newtimeperiod",
u"contacts": u"aaa,bbb",
u"contact_groups": u"newgroup",
u"notification_interval": 333,
u"notification_period": u"newnotificationperiod"
u'host_name': u'bogus-router333',
u'contacts': u'newcontacts',
}
response = self.put_json(
"/v2/config/hosts/bogus-router333", params=put_host
@ -152,7 +147,19 @@ class TestHostController(functionalTest.FunctionalTest):
)
)
self.assertEqual(put_host, mongo_host.as_dict())
expected = {
'address': u'192.168.1.254',
'check_period': u'24x7',
'notification_interval': 30,
'contacts': u'newcontacts',
'notification_period': u'24x7',
'contact_groups': u'',
'host_name': u'bogus-router333',
'max_check_attempts': 3,
'use': u'test'
}
self.assertEqual(expected, mongo_host.as_dict())
self.assertEqual(response.status_int, 204)
def test_delete_host(self):