Add recheck and fix tests
Change-Id: I74fc2cfb646325aaafe2cb8e52acbfc0a0e0d9e4
This commit is contained in:
parent
0aeab5a876
commit
75537551f4
surveil
@ -16,11 +16,13 @@ from pecan import rest
|
||||
|
||||
from surveil.api.controllers.v2.actions import acknowledge
|
||||
from surveil.api.controllers.v2.actions import downtime
|
||||
from surveil.api.controllers.v2.actions import recheck
|
||||
|
||||
|
||||
class ActionsController(rest.RestController):
|
||||
acknowledge = acknowledge.AcknowledgeController()
|
||||
downtime = downtime.DowntimeController()
|
||||
recheck = recheck.RecheckController()
|
||||
# externalcommands = ExternalCommandsController()
|
||||
# engine = EngineController()
|
||||
pass
|
||||
|
41
surveil/api/controllers/v2/actions/recheck.py
Normal file
41
surveil/api/controllers/v2/actions/recheck.py
Normal file
@ -0,0 +1,41 @@
|
||||
# Copyright 2015 - Savoir-Faire Linux inc.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
# not use this file except in compliance with the License. You may obtain
|
||||
# a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
import pecan
|
||||
from pecan import rest
|
||||
import requests
|
||||
import wsmeext.pecan as wsme_pecan
|
||||
|
||||
from surveil.api.datamodel.actions import recheck
|
||||
from surveil.api.datamodel import info
|
||||
from surveil.common import util
|
||||
|
||||
|
||||
class RecheckController(rest.RestController):
|
||||
|
||||
@util.policy_enforce(['authenticated'])
|
||||
@wsme_pecan.wsexpose(info.Info,
|
||||
body=recheck.Recheck,
|
||||
status_code=200)
|
||||
def post(self, rc):
|
||||
"""Schedule a forced check."""
|
||||
|
||||
data = rc.as_dict()
|
||||
|
||||
requests.post(
|
||||
pecan.request.ws_arbiter_url + "/recheck",
|
||||
data=data
|
||||
)
|
||||
|
||||
return info.Info(message='Recheck received.')
|
37
surveil/api/datamodel/actions/recheck.py
Normal file
37
surveil/api/datamodel/actions/recheck.py
Normal file
@ -0,0 +1,37 @@
|
||||
# Copyright 2015 - Savoir-Faire Linux inc.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
# not use this file except in compliance with the License. You may obtain
|
||||
# a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
import wsme
|
||||
import wsme.types as wtypes
|
||||
|
||||
from surveil.api.datamodel import types
|
||||
|
||||
|
||||
class Recheck(types.Base):
|
||||
host_name = wsme.wsattr(wtypes.text, mandatory=True)
|
||||
"""The name of the host"""
|
||||
|
||||
service_description = wsme.wsattr(wtypes.text, mandatory=False)
|
||||
"""The service description"""
|
||||
|
||||
time_stamp = wsme.wsattr(int, mandatory=False)
|
||||
"""Time stamp for the recheck"""
|
||||
|
||||
@classmethod
|
||||
def sample(cls):
|
||||
return cls(
|
||||
host_name="localhost",
|
||||
service_description="ws-arbiter",
|
||||
time_stamp=1430150469,
|
||||
)
|
0
surveil/tests/api/controllers/v2/actions/__init__.py
Normal file
0
surveil/tests/api/controllers/v2/actions/__init__.py
Normal file
@ -32,8 +32,9 @@ class TestAcknowledgeController(functionalTest.FunctionalTest):
|
||||
|
||||
self.assertEqual(response.status_int, 200)
|
||||
|
||||
self.assertEqual(httpretty.last_request().body,
|
||||
'action=add&host_name=localhost')
|
||||
self.assert_count_equal_backport(httpretty.last_request().body.decode()
|
||||
.split('&'),
|
||||
['host_name=localhost', 'action=add'])
|
||||
self.assertEqual(httpretty.last_request().path,
|
||||
'/acknowledge')
|
||||
|
||||
@ -50,7 +51,9 @@ class TestAcknowledgeController(functionalTest.FunctionalTest):
|
||||
|
||||
self.assertEqual(response.status_int, 200)
|
||||
|
||||
self.assertEqual(httpretty.last_request().body,
|
||||
'duration=86400&action=delete&host_name=localhost')
|
||||
self.assert_count_equal_backport(httpretty.last_request().body.decode()
|
||||
.split('&'),
|
||||
['host_name=localhost',
|
||||
'action=delete'])
|
||||
self.assertEqual(httpretty.last_request().path,
|
||||
'/downtime')
|
||||
|
@ -33,8 +33,10 @@ class TestDowntimeController(functionalTest.FunctionalTest):
|
||||
|
||||
self.assertEqual(response.status_int, 200)
|
||||
|
||||
self.assertEqual(httpretty.last_request().body,
|
||||
'duration=86400&action=add&host_name=localhost')
|
||||
self.assert_count_equal_backport(httpretty.last_request().body.decode()
|
||||
.split('&'),
|
||||
['host_name=localhost', 'action=add',
|
||||
'duration=86400'])
|
||||
self.assertEqual(httpretty.last_request().path,
|
||||
'/downtime')
|
||||
|
||||
@ -52,7 +54,9 @@ class TestDowntimeController(functionalTest.FunctionalTest):
|
||||
|
||||
self.assertEqual(response.status_int, 200)
|
||||
|
||||
self.assertEqual(httpretty.last_request().body,
|
||||
'duration=86400&action=delete&host_name=localhost')
|
||||
self.assert_count_equal_backport(httpretty.last_request().body.decode()
|
||||
.split('&'),
|
||||
['host_name=localhost',
|
||||
'action=delete', 'duration=86400'])
|
||||
self.assertEqual(httpretty.last_request().path,
|
||||
'/downtime')
|
||||
|
39
surveil/tests/api/controllers/v2/actions/test_recheck.py
Normal file
39
surveil/tests/api/controllers/v2/actions/test_recheck.py
Normal file
@ -0,0 +1,39 @@
|
||||
# Copyright 2015 - Savoir-Faire Linux inc.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
# not use this file except in compliance with the License. You may obtain
|
||||
# a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
import httpretty
|
||||
|
||||
from surveil.tests.api import functionalTest
|
||||
|
||||
|
||||
class TestRecheckController(functionalTest.FunctionalTest):
|
||||
|
||||
@httpretty.activate
|
||||
def test_recheck_post(self):
|
||||
httpretty.register_uri(httpretty.POST,
|
||||
self.ws_arbiter_url + "/recheck")
|
||||
|
||||
recheck = {
|
||||
"host_name": "localhost",
|
||||
}
|
||||
|
||||
response = self.post_json("/v2/actions/recheck/", params=recheck)
|
||||
|
||||
self.assertEqual(response.status_int, 200)
|
||||
|
||||
self.assert_count_equal_backport(httpretty.last_request().body.decode()
|
||||
.split('&'),
|
||||
['host_name=localhost'])
|
||||
self.assertEqual(httpretty.last_request().path,
|
||||
'/recheck')
|
@ -98,7 +98,8 @@ class FunctionalTest(base.BaseTestCase):
|
||||
return func
|
||||
|
||||
for action in ('get', 'post', 'put', 'delete',
|
||||
'post', 'post_json', 'put_json'):
|
||||
'post', 'post_json', 'put_json',
|
||||
'delete_json'):
|
||||
setattr(self, action, make_action(action))
|
||||
|
||||
def tearDown(self):
|
||||
|
Loading…
x
Reference in New Issue
Block a user