From 3e04606f87c8cb3207ffeb717a6f5407b77b4d12 Mon Sep 17 00:00:00 2001 From: Peter Portante Date: Tue, 6 May 2014 10:54:05 -0400 Subject: [PATCH] Add a env var to use in-memory obj server in func Add an environment variable to enable the use of the in-memory object server during in-process functional test runs. It might be worth-while to just run under both object servers in-tree, but this at least enables it, without having to figure out how to make two test runs in two different environments. DocImpact Change-Id: Id76b008e1f273c639ae61550affddc32c5d7c419 Signed-off-by: Thiago da Silva --- doc/source/development_guidelines.rst | 22 +++++++++++++++++++++- doc/source/development_saio.rst | 2 ++ swift/obj/mem_diskfile.py | 2 +- test/functional/__init__.py | 8 ++++++-- 4 files changed, 30 insertions(+), 4 deletions(-) diff --git a/doc/source/development_guidelines.rst b/doc/source/development_guidelines.rst index 0a62e2c595..76b5126be7 100644 --- a/doc/source/development_guidelines.rst +++ b/doc/source/development_guidelines.rst @@ -51,6 +51,25 @@ To execute the unit tests: - `tox -e pep8,py26` +The functional tests may be executed against a :doc:`development_saio` or +other running Swift cluster using the command: + +- `tox -e func` + +The endpoint and authorization credentials to be used by functional tests +should be configured in the ``test.conf`` file as described in the section +:ref:`setup_scripts`. + +If the ``test.conf`` file is not found then the functional test framework will +instantiate a set of Swift servers in the same process that executes the +functional tests. This 'in-process test' mode may also be enabled (or disabled) +by setting the environment variable ``SWIFT_TEST_IN_PROCESS`` to a true (or +false) value prior to executing `tox -e func`. + +When using the 'in-process test' mode, the optional in-memory +object server may be selected by setting the environment variable +``SWIFT_TEST_IN_MEMORY_OBJ`` to a true value. + ------------ Coding Style ------------ @@ -78,7 +97,7 @@ The documentation in docstrings should follow the PEP 257 conventions More specifically: - 1. Triple qutes should be used for all docstrings. + 1. Triple quotes should be used for all docstrings. 2. If the docstring is simple and fits on one line, then just use one line. 3. For docstrings that take multiple lines, there should be a newline @@ -117,3 +136,4 @@ another year added, and date ranges are not needed.:: # implied. # See the License for the specific language governing permissions and # limitations under the License. + diff --git a/doc/source/development_saio.rst b/doc/source/development_saio.rst index 9e635c0331..e33e60db2a 100644 --- a/doc/source/development_saio.rst +++ b/doc/source/development_saio.rst @@ -398,6 +398,8 @@ commands are as follows: .. literalinclude:: /../saio/swift/object-server/4.conf +.. _setup_scripts: + ------------------------------------ Setting up scripts for running Swift ------------------------------------ diff --git a/swift/obj/mem_diskfile.py b/swift/obj/mem_diskfile.py index d02cdbe43e..efb8c6c8c0 100644 --- a/swift/obj/mem_diskfile.py +++ b/swift/obj/mem_diskfile.py @@ -395,5 +395,5 @@ class DiskFile(object): :param timestamp: timestamp to compare with each file """ fp, md = self._filesystem.get_object(self._name) - if md['X-Timestamp'] < Timestamp(timestamp): + if md and md['X-Timestamp'] < Timestamp(timestamp): self._filesystem.del_object(self._name) diff --git a/test/functional/__init__.py b/test/functional/__init__.py index 4994e17a3b..65f521bd24 100644 --- a/test/functional/__init__.py +++ b/test/functional/__init__.py @@ -48,7 +48,7 @@ from swift.common.utils import config_true_value from swift.proxy import server as proxy_server from swift.account import server as account_server from swift.container import server as container_server -from swift.obj import server as object_server +from swift.obj import server as object_server, mem_server as mem_object_server import swift.proxy.controllers.obj # In order to get the proper blocking behavior of sockets without using @@ -133,6 +133,7 @@ max_file_size = %d def in_process_setup(the_object_server=object_server): print >>sys.stderr, 'IN-PROCESS SERVERS IN USE FOR FUNCTIONAL TESTS' + print >>sys.stderr, 'Using object_server: %s' % the_object_server.__name__ monkey_patch_mimetools() @@ -408,7 +409,10 @@ def setup_package(): config.update(get_config('func_test')) if in_process: - in_process_setup() + in_mem_obj_env = os.environ.get('SWIFT_TEST_IN_MEMORY_OBJ') + in_mem_obj = utils.config_true_value(in_mem_obj_env) + in_process_setup(the_object_server=( + mem_object_server if in_mem_obj else object_server)) global web_front_end web_front_end = config.get('web_front_end', 'integral')