Skip to content

Commit

Permalink
Add server type in OPTIONS response
Browse files Browse the repository at this point in the history
Change-Id: I731872eaf2c878476525aa05fd60b9121be43e29
  • Loading branch information
MahatiC committed Jan 29, 2015
1 parent 13f529c commit c8f02a8
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 1 deletion.
2 changes: 2 additions & 0 deletions swift/account/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@
class AccountController(BaseStorageServer):
"""WSGI controller for the account server."""

server_type = 'account-server'

def __init__(self, conf, logger=None):
super(AccountController, self).__init__(conf)
self.logger = logger or get_logger(conf, log_route='account-server')
Expand Down
9 changes: 8 additions & 1 deletion swift/common/base_storage_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
# limitations under the License.

import inspect
from swift import __version__ as swift_version
from swift.common.utils import public, timing_stats, config_true_value
from swift.common.swob import Response

Expand All @@ -30,6 +31,11 @@ def __init__(self, conf, **kwargs):
replication_server = config_true_value(replication_server)
self.replication_server = replication_server

@property
def server_type(self):
raise NotImplementedError(
'Storage nodes have not implemented the Server type.')

@property
def allowed_methods(self):
if self._allowed_methods is None:
Expand Down Expand Up @@ -64,7 +70,8 @@ def OPTIONS(self, req):
:returns: swob.Response object
"""
# Prepare the default response
headers = {'Allow': ', '.join(self.allowed_methods)}
headers = {'Allow': ', '.join(self.allowed_methods),
'Server': '%s/%s' % (self.server_type, swift_version)}
resp = Response(status=200, request=req, headers=headers)

return resp
1 change: 1 addition & 0 deletions swift/container/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ class ContainerController(BaseStorageServer):
# Ensure these are all lowercase
save_headers = ['x-container-read', 'x-container-write',
'x-container-sync-key', 'x-container-sync-to']
server_type = 'container-server'

def __init__(self, conf, logger=None):
super(ContainerController, self).__init__(conf)
Expand Down
2 changes: 2 additions & 0 deletions swift/obj/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ def __len__(self):
class ObjectController(BaseStorageServer):
"""Implements the WSGI application for the Swift Object Server."""

server_type = 'object-server'

def __init__(self, conf, logger=None):
"""
Creates a new WSGI application for the Swift Object Server. An
Expand Down
3 changes: 3 additions & 0 deletions test/unit/account/test_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import simplejson
import xml.dom.minidom

from swift import __version__ as swift_version
from swift.common.swob import Request
from swift.common import constraints
from swift.account.server import AccountController
Expand Down Expand Up @@ -66,6 +67,8 @@ def test_OPTIONS(self):
self.assertTrue(
verb in resp.headers['Allow'].split(', '))
self.assertEquals(len(resp.headers['Allow'].split(', ')), 7)
self.assertEquals(resp.headers['Server'],
(server_handler.server_type + '/' + swift_version))

def test_DELETE_not_found(self):
req = Request.blank('/sda1/p/a', environ={'REQUEST_METHOD': 'DELETE',
Expand Down
3 changes: 3 additions & 0 deletions test/unit/container/test_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
from eventlet import spawn, Timeout, listen
import simplejson

from swift import __version__ as swift_version
from swift.common.swob import Request, HeaderKeyDict
import swift.container
from swift.container import server as container_server
Expand Down Expand Up @@ -312,6 +313,8 @@ def test_OPTIONS(self):
self.assertTrue(
verb in resp.headers['Allow'].split(', '))
self.assertEquals(len(resp.headers['Allow'].split(', ')), 7)
self.assertEquals(resp.headers['Server'],
(self.controller.server_type + '/' + swift_version))

def test_PUT(self):
req = Request.blank(
Expand Down
3 changes: 3 additions & 0 deletions test/unit/obj/test_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@

from nose import SkipTest

from swift import __version__ as swift_version
from test.unit import FakeLogger, debug_logger, mocked_http_conn
from test.unit import connect_tcp, readuntil2crlfs, patch_policies
from swift.obj import server as object_server
Expand Down Expand Up @@ -1136,6 +1137,8 @@ def test_OPTIONS(self):
self.assertTrue(
verb in resp.headers['Allow'].split(', '))
self.assertEquals(len(resp.headers['Allow'].split(', ')), 8)
self.assertEquals(resp.headers['Server'],
(server_handler.server_type + '/' + swift_version))

def test_GET(self):
# Test swift.obj.server.ObjectController.GET
Expand Down

0 comments on commit c8f02a8

Please sign in to comment.