feat: admin endpoint to set status of a particular service
- REQUEST POST http://127.0.0.1:8888/v1.0/admin/services/status { "project_id": "98765431", "service_id": "e8b44506-71b7-4074-9bc8-1b5037ade112", "status": "deployed" } - RESPONSE 201 Implements: blueprint admin-endpoint-to-set-service-status Related-Bug: 1540482 Change-Id: I89d40601c55af6cc3c2d45352d8e24c691107bd0
This commit is contained in:
parent
be02a04ce3
commit
3647f72252
|
@ -413,6 +413,12 @@ class DefaultServicesController(base.ServicesController):
|
|||
project_id=project_id,
|
||||
project_limit=limit)
|
||||
|
||||
def set_service_provider_details(self, project_id, service_id, status):
|
||||
self.storage_controller.set_service_provider_details(
|
||||
project_id,
|
||||
service_id,
|
||||
status)
|
||||
|
||||
def get_services_limit(self, project_id):
|
||||
limit = self.storage_controller.get_service_limit(
|
||||
project_id=project_id)
|
||||
|
@ -426,7 +432,8 @@ class DefaultServicesController(base.ServicesController):
|
|||
kwargs = {
|
||||
'project_id': project_id,
|
||||
'service_obj': json.dumps(service_obj.to_dict()),
|
||||
'time_seconds': self.determine_sleep_times()
|
||||
'time_seconds': self.determine_sleep_times(),
|
||||
'context_dict': context_utils.get_current().to_dict()
|
||||
}
|
||||
|
||||
try:
|
||||
|
|
|
@ -490,6 +490,34 @@ class ServicesController(base.ServicesController):
|
|||
"project_id: {0} set to be {1}".format(project_id,
|
||||
project_limit))
|
||||
|
||||
def set_service_provider_details(self, project_id, service_id, status):
|
||||
"""set_service_provider_details
|
||||
|
||||
Set current status on service_id under project_id.
|
||||
|
||||
:param project_id
|
||||
:param service_id
|
||||
|
||||
"""
|
||||
|
||||
LOG.info("Setting service"
|
||||
"status for"
|
||||
"service_id : {0}, "
|
||||
"project_id: {1} to be {2}".format(service_id,
|
||||
project_id,
|
||||
status))
|
||||
|
||||
provider_details_dict = self.get_provider_details(
|
||||
project_id=project_id,
|
||||
service_id=service_id)
|
||||
|
||||
for provider_name in sorted(provider_details_dict.keys()):
|
||||
provider_details_dict[provider_name].status = status
|
||||
|
||||
self.update_provider_details(project_id=project_id,
|
||||
service_id=service_id,
|
||||
provider_details=provider_details_dict)
|
||||
|
||||
def get_certs_by_domain(self, domain_name, project_id=None, flavor_id=None,
|
||||
cert_type=None):
|
||||
LOG.info("Check if cert on '{0}' exists".format(domain_name))
|
||||
|
|
|
@ -157,6 +157,9 @@ class ServicesController(base.ServicesController):
|
|||
provider_service_id="73242",
|
||||
access_urls=['my_service_name.mock.com'])}
|
||||
|
||||
def set_service_provider_details(self, project_id, service_id, status):
|
||||
pass
|
||||
|
||||
def update_provider_details(self, project_id, service_name,
|
||||
provider_details):
|
||||
pass
|
||||
|
|
|
@ -26,6 +26,7 @@ from poppy.transport.validators.schemas import background_jobs
|
|||
from poppy.transport.validators.schemas import domain_migration
|
||||
from poppy.transport.validators.schemas import service_action
|
||||
from poppy.transport.validators.schemas import service_limit
|
||||
from poppy.transport.validators.schemas import service_status
|
||||
from poppy.transport.validators.schemas import ssl_certificate
|
||||
from poppy.transport.validators.stoplight import decorators
|
||||
from poppy.transport.validators.stoplight import helpers as stoplight_helpers
|
||||
|
@ -266,10 +267,51 @@ class OperatorServiceLimitController(base.Controller, hooks.HookController):
|
|||
return service_limits
|
||||
|
||||
|
||||
class ServiceStatusController(base.Controller, hooks.HookController):
|
||||
|
||||
__hooks__ = [poppy_hooks.Context(), poppy_hooks.Error()]
|
||||
|
||||
def __init__(self, driver):
|
||||
super(ServiceStatusController, self).__init__(driver)
|
||||
|
||||
@pecan.expose('json')
|
||||
@decorators.validate(
|
||||
request=rule.Rule(
|
||||
helpers.json_matches_service_schema(
|
||||
service_status.ServiceStatusSchema.get_schema(
|
||||
"service_status", "POST")),
|
||||
helpers.abort_with_message,
|
||||
stoplight_helpers.pecan_getter)
|
||||
)
|
||||
def post(self):
|
||||
|
||||
service_state_json = json.loads(pecan.request.body.decode('utf-8'))
|
||||
project_id = service_state_json['project_id']
|
||||
service_id = service_state_json['service_id']
|
||||
status = service_state_json['status']
|
||||
services_controller = self._driver.manager.services_controller
|
||||
|
||||
try:
|
||||
services_controller.set_service_provider_details(project_id,
|
||||
service_id,
|
||||
status)
|
||||
except Exception as e:
|
||||
pecan.abort(404, detail=(
|
||||
'Setting state of service {0} on tenant: {1} '
|
||||
'to {2} has failed, '
|
||||
'Reason: {3}'.format(service_id,
|
||||
project_id,
|
||||
status,
|
||||
str(e))))
|
||||
|
||||
return pecan.Response(None, 201)
|
||||
|
||||
|
||||
class AdminServiceController(base.Controller, hooks.HookController):
|
||||
def __init__(self, driver):
|
||||
super(AdminServiceController, self).__init__(driver)
|
||||
self.__class__.action = OperatorServiceActionController(driver)
|
||||
self.__class__.status = ServiceStatusController(driver)
|
||||
|
||||
|
||||
class DomainController(base.Controller, hooks.HookController):
|
||||
|
|
|
@ -0,0 +1,52 @@
|
|||
# Copyright (c) 2015 Rackspace, 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 re
|
||||
|
||||
from poppy.transport.validators import schema_base
|
||||
|
||||
|
||||
class ServiceStatusSchema(schema_base.SchemaBase):
|
||||
|
||||
"""JSON Schmema validation for /admin/services/{service_id}/status."""
|
||||
|
||||
schema = {
|
||||
'service_status': {
|
||||
'POST': {
|
||||
'type': [{
|
||||
'additionalProperties': False,
|
||||
'properties': {
|
||||
'status': {
|
||||
'enum': [u'deployed',
|
||||
u'failed'],
|
||||
'required': True
|
||||
},
|
||||
'project_id': {
|
||||
'type': 'string',
|
||||
'required': True,
|
||||
'pattern': re.compile('^([a-zA-Z0-9_\-\.]'
|
||||
'{1,256})$')
|
||||
},
|
||||
'service_id': {
|
||||
'type': 'string',
|
||||
'required': True,
|
||||
'pattern': re.compile('^[0-9a-f]{8}-([0-9a-f]'
|
||||
'{4}-){3}[0-9a-f]{12}$')
|
||||
},
|
||||
}
|
||||
}]
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,128 @@
|
|||
# coding= utf-8
|
||||
|
||||
# Copyright (c) 2015 Rackspace, 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 ddt
|
||||
|
||||
from tests.api import base
|
||||
|
||||
|
||||
@ddt.ddt
|
||||
class TestServiceStatus(base.TestBase):
|
||||
|
||||
def setUp(self):
|
||||
super(TestServiceStatus, self).setUp()
|
||||
|
||||
if self.test_config.run_operator_tests is False:
|
||||
self.skipTest(
|
||||
'Test Operator Functions is disabled in configuration')
|
||||
self.service_name = self.generate_random_string(prefix='API-Test-')
|
||||
self.flavor_id = self.test_flavor
|
||||
|
||||
domain = self.generate_random_string(
|
||||
prefix='www.api-test-domain') + '.com'
|
||||
self.domain_list = [
|
||||
{"domain": domain}
|
||||
]
|
||||
|
||||
origin = self.generate_random_string(
|
||||
prefix='api-test-origin') + u'.com'
|
||||
self.origin_list = [
|
||||
{
|
||||
u"origin": origin,
|
||||
u"port": 80,
|
||||
u"ssl": False,
|
||||
u"rules": [{
|
||||
u"name": u"default",
|
||||
u"request_url": u"/*"
|
||||
}]
|
||||
}
|
||||
]
|
||||
|
||||
self.caching_list = [
|
||||
{
|
||||
u"name": u"default",
|
||||
u"ttl": 3600,
|
||||
u"rules": [{
|
||||
u"name": "default",
|
||||
u"request_url": "/*"
|
||||
}]
|
||||
},
|
||||
{
|
||||
u"name": u"home",
|
||||
u"ttl": 1200,
|
||||
u"rules": [{
|
||||
u"name": u"index",
|
||||
u"request_url": u"/index.htm"
|
||||
}]
|
||||
}
|
||||
]
|
||||
|
||||
self.restrictions_list = [
|
||||
{
|
||||
u"name": u"website only",
|
||||
u"rules": [
|
||||
{
|
||||
u"name": domain,
|
||||
u"referrer": domain,
|
||||
u"request_url": "/*"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
|
||||
resp = self.setup_service(
|
||||
service_name=self.service_name,
|
||||
domain_list=self.domain_list,
|
||||
origin_list=self.origin_list,
|
||||
caching_list=self.caching_list,
|
||||
restrictions_list=self.restrictions_list,
|
||||
flavor_id=self.flavor_id)
|
||||
|
||||
self.assertEqual(resp.status_code, 202)
|
||||
self.assertEqual(resp.text, '')
|
||||
self.service_url = resp.headers['location']
|
||||
|
||||
self.client.wait_for_service_status(
|
||||
location=self.service_url,
|
||||
status='deployed',
|
||||
abort_on_status='failed',
|
||||
retry_interval=self.test_config.status_check_retry_interval,
|
||||
retry_timeout=self.test_config.status_check_retry_timeout)
|
||||
|
||||
@ddt.data(u'deployed', u'failed')
|
||||
def test_set_service(self, status):
|
||||
|
||||
service_id = self.service_url.rsplit('/')[-1:][0]
|
||||
project_id = self.user_project_id
|
||||
|
||||
set_service_resp = self.operator_client.set_service_status(
|
||||
project_id=project_id,
|
||||
service_id=service_id,
|
||||
status=status)
|
||||
|
||||
self.assertEqual(set_service_resp.status_code, 201)
|
||||
|
||||
service_resp = self.client.get_service(self.service_url)
|
||||
resp_body = service_resp.json()
|
||||
resp_status = resp_body['status']
|
||||
self.assertEqual(resp_status, status)
|
||||
|
||||
def tearDown(self):
|
||||
self.client.delete_service(location=self.service_url)
|
||||
if self.test_config.generate_flavors:
|
||||
self.client.delete_flavor(flavor_id=self.flavor_id)
|
||||
super(TestServiceStatus, self).tearDown()
|
|
@ -255,6 +255,25 @@ class PoppyClient(client.AutoMarshallingHTTPClient):
|
|||
url = '{0}/admin/limits/{1}'.format(self.url, project_id)
|
||||
return self.request('GET', url, requestslib_kwargs=requestslib_kwargs)
|
||||
|
||||
def set_service_status(self, project_id, service_id, status,
|
||||
requestslib_kwargs=None):
|
||||
"""Set Service State
|
||||
|
||||
:return: Response Object containing response code 201
|
||||
|
||||
POST
|
||||
/admin/services/status
|
||||
"""
|
||||
|
||||
url = '{0}/admin/services/status'.format(self.url)
|
||||
request_object = requests.ServiceStatus(
|
||||
status=status,
|
||||
project_id=project_id,
|
||||
service_id=service_id
|
||||
)
|
||||
return self.request('POST', url, request_entity=request_object,
|
||||
requestslib_kwargs=requestslib_kwargs)
|
||||
|
||||
def admin_migrate_domain(self, project_id, service_id, domain, new_cert,
|
||||
requestslib_kwargs=None):
|
||||
"""Update SAN domain
|
||||
|
|
|
@ -79,6 +79,26 @@ class ServiceAction(base.AutoMarshallingModel):
|
|||
return json.dumps(service_action_request)
|
||||
|
||||
|
||||
class ServiceStatus(base.AutoMarshallingModel):
|
||||
"""Marshalling for Action on Services status requests."""
|
||||
|
||||
def __init__(self, status, project_id, service_id):
|
||||
super(ServiceStatus, self).__init__()
|
||||
|
||||
self.status = status
|
||||
self.project_id = project_id
|
||||
self.service_id = service_id
|
||||
|
||||
def _obj_to_json(self):
|
||||
service_status_request = {
|
||||
"status": self.status,
|
||||
"project_id": self.project_id,
|
||||
"service_id": self.service_id
|
||||
}
|
||||
|
||||
return json.dumps(service_status_request)
|
||||
|
||||
|
||||
class ServiceLimit(base.AutoMarshallingModel):
|
||||
"""Marshalling for Service Limit requests."""
|
||||
|
||||
|
|
|
@ -0,0 +1,91 @@
|
|||
# Copyright (c) 2015 Rackspace, 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 json
|
||||
import uuid
|
||||
|
||||
import ddt
|
||||
from hypothesis import given
|
||||
from hypothesis import strategies
|
||||
|
||||
from tests.functional.transport.pecan import base
|
||||
|
||||
|
||||
@ddt.ddt
|
||||
class TestServicesState(base.FunctionalTest):
|
||||
|
||||
def setUp(self):
|
||||
super(TestServicesState, self).setUp()
|
||||
|
||||
self.project_id = str(uuid.uuid4())
|
||||
self.service_id = str(uuid.uuid4())
|
||||
self.req_body = {
|
||||
'project_id': self.project_id,
|
||||
'service_id': self.service_id,
|
||||
}
|
||||
|
||||
@ddt.data(u'deployed', u'failed')
|
||||
def test_services_state_valid_states(self, status):
|
||||
self.req_body['status'] = status
|
||||
response = self.app.post(
|
||||
'/v1.0/admin/services/status',
|
||||
params=json.dumps(self.req_body),
|
||||
headers={'Content-Type': 'application/json',
|
||||
'X-Project-ID': str(uuid.uuid4())})
|
||||
|
||||
self.assertEqual(response.status_code, 201)
|
||||
|
||||
@given(strategies.text())
|
||||
def test_services_state_invalid_states(self, status):
|
||||
# invalid status field
|
||||
self.req_body['status'] = status
|
||||
response = self.app.post(
|
||||
'/v1.0/admin/services/status',
|
||||
params=json.dumps(self.req_body),
|
||||
headers={'Content-Type': 'application/json',
|
||||
'X-Project-ID': str(uuid.uuid4())},
|
||||
expect_errors=True)
|
||||
|
||||
self.assertEqual(response.status_code, 400)
|
||||
|
||||
@given(strategies.text())
|
||||
def test_services_state_invalid_service_id(self, service_id):
|
||||
# invalid service_id field
|
||||
self.req_body['status'] = 'deployed'
|
||||
self.req_body['service_id'] = service_id
|
||||
response = self.app.post(
|
||||
'/v1.0/admin/services/status',
|
||||
params=json.dumps(self.req_body),
|
||||
headers={'Content-Type': 'application/json',
|
||||
'X-Project-ID': str(uuid.uuid4())},
|
||||
expect_errors=True)
|
||||
|
||||
self.assertEqual(response.status_code, 400)
|
||||
|
||||
@given(strategies.text(min_size=257))
|
||||
def test_services_state_invalid_project_id(self, project_id):
|
||||
# NOTE(TheSriram): the min size is assigned to 257, since
|
||||
# project_id regex allows upto 256 chars
|
||||
# invalid project_id field
|
||||
self.req_body['project_id'] = project_id
|
||||
self.req_body['status'] = 'deployed'
|
||||
response = self.app.post(
|
||||
'/v1.0/admin/services/status',
|
||||
params=json.dumps(self.req_body),
|
||||
headers={'Content-Type': 'application/json',
|
||||
'X-Project-ID': str(uuid.uuid4())},
|
||||
expect_errors=True)
|
||||
|
||||
self.assertEqual(response.status_code, 400)
|
Loading…
Reference in New Issue