Added delete endpoint to service
Change-Id: I7eea2c1dc54daf6a954158cc99b5b429fc972227
This commit is contained in:
parent
052ac2fde3
commit
cd8453ad2f
@ -16,8 +16,8 @@ import pecan
|
||||
from pecan import rest
|
||||
import wsmeext.pecan as wsme_pecan
|
||||
|
||||
from surveil.api.datamodel import command
|
||||
from surveil.api.handlers import command_handler
|
||||
from surveil.api.datamodel.config import command
|
||||
from surveil.api.handlers.config import command_handler
|
||||
|
||||
|
||||
class CommandController(rest.RestController):
|
||||
|
@ -18,10 +18,10 @@ import requests
|
||||
import wsmeext.pecan as wsme_pecan
|
||||
|
||||
from surveil.api.datamodel import checkresult
|
||||
from surveil.api.datamodel import host
|
||||
from surveil.api.datamodel import service
|
||||
from surveil.api.handlers import host_handler
|
||||
from surveil.api.handlers import service_handler
|
||||
from surveil.api.datamodel.config import host
|
||||
from surveil.api.datamodel.config import service
|
||||
from surveil.api.handlers.config import host_handler
|
||||
from surveil.api.handlers.config import service_handler
|
||||
|
||||
|
||||
class ServiceCheckResultsSubController(rest.RestController):
|
||||
@ -62,6 +62,15 @@ class HostServiceSubController(rest.RestController):
|
||||
)
|
||||
return s
|
||||
|
||||
@wsme_pecan.wsexpose(None, status_code=204)
|
||||
def delete(self):
|
||||
"""Delete a specific service."""
|
||||
handler = service_handler.ServiceHandler(pecan.request)
|
||||
handler.delete(
|
||||
pecan.request.context['host_name'],
|
||||
pecan.request.context['service_description']
|
||||
)
|
||||
|
||||
|
||||
class HostServicesSubController(rest.RestController):
|
||||
|
||||
|
@ -16,8 +16,8 @@ import pecan
|
||||
from pecan import rest
|
||||
import wsmeext.pecan as wsme_pecan
|
||||
|
||||
from surveil.api.datamodel import service
|
||||
from surveil.api.handlers import service_handler
|
||||
from surveil.api.datamodel.config import service
|
||||
from surveil.api.handlers.config import service_handler
|
||||
|
||||
|
||||
class ServicesController(rest.RestController):
|
||||
|
0
surveil/api/datamodel/config/__init__.py
Normal file
0
surveil/api/datamodel/config/__init__.py
Normal file
0
surveil/api/handlers/config/__init__.py
Normal file
0
surveil/api/handlers/config/__init__.py
Normal file
@ -12,7 +12,7 @@
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
from surveil.api.datamodel import command
|
||||
from surveil.api.datamodel.config import command
|
||||
from surveil.api.handlers import handler
|
||||
|
||||
|
@ -12,7 +12,7 @@
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
from surveil.api.datamodel import host
|
||||
from surveil.api.datamodel.config import host
|
||||
from surveil.api.handlers import handler
|
||||
|
||||
|
@ -12,7 +12,7 @@
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
from surveil.api.datamodel import service
|
||||
from surveil.api.datamodel.config import service
|
||||
from surveil.api.handlers import handler
|
||||
|
||||
|
||||
@ -38,10 +38,11 @@ class ServiceHandler(handler.Handler):
|
||||
host_dict
|
||||
)
|
||||
|
||||
def delete(self, id):
|
||||
"""Delete existing host."""
|
||||
self.request.mongo_connection.shinken.hosts.remove(
|
||||
{"host_name": id}
|
||||
def delete(self, host_name, service_description):
|
||||
"""Delete existing service."""
|
||||
self.request.mongo_connection.shinken.services.remove(
|
||||
{"host_name": host_name,
|
||||
"service_description": service_description}
|
||||
)
|
||||
|
||||
def create(self, data):
|
@ -15,7 +15,7 @@
|
||||
import copy
|
||||
import json
|
||||
|
||||
from surveil.api.datamodel import command
|
||||
from surveil.api.datamodel.config import command
|
||||
from surveil.tests.api import functionalTest
|
||||
|
||||
|
||||
|
@ -17,7 +17,8 @@ import json
|
||||
|
||||
import httpretty
|
||||
|
||||
from surveil.api.datamodel import host
|
||||
from surveil.api.datamodel.config import host
|
||||
from surveil.api.datamodel.config import service
|
||||
from surveil.tests.api import functionalTest
|
||||
|
||||
|
||||
@ -174,6 +175,20 @@ class TestHostController(functionalTest.FunctionalTest):
|
||||
json.loads(response.body.decode())
|
||||
)
|
||||
|
||||
def test_delete_specific_service(self):
|
||||
mongo_services = [service.Service(**h) for h
|
||||
in self.mongoconnection.shinken.services.find()]
|
||||
self.assertEqual(1, len(mongo_services))
|
||||
|
||||
self.app.delete(
|
||||
'/v2/config/hosts/bogus-router/services/service-example'
|
||||
)
|
||||
|
||||
mongo_services = [service.Service(**h) for h
|
||||
in self.mongoconnection.shinken.services.find()]
|
||||
|
||||
self.assertEqual(0, len(mongo_services))
|
||||
|
||||
@httpretty.activate
|
||||
def test_submit_service_result(self):
|
||||
httpretty.register_uri(httpretty.POST,
|
||||
|
@ -15,7 +15,7 @@
|
||||
import copy
|
||||
import json
|
||||
|
||||
from surveil.api.datamodel import service
|
||||
from surveil.api.datamodel.config import service
|
||||
from surveil.tests.api import functionalTest
|
||||
|
||||
|
||||
@ -102,7 +102,7 @@ class TestServiceController(functionalTest.FunctionalTest):
|
||||
)
|
||||
self.assertEqual(response.status_int, 200)
|
||||
|
||||
def test_add_host(self):
|
||||
def test_add_service(self):
|
||||
new_service = {
|
||||
"host_name": "SOMEHOSTNAME",
|
||||
"service_description": "check-new-thing",
|
||||
|
Loading…
x
Reference in New Issue
Block a user