tests: pre-commit regression tests

Framework for writing test cases to be submitted with patches.

This framework and the test cases get exercised by Jenkins in
the pre-commit regression test. Jenkins is configured to give
a +1 verified vote only if the regression test passes without
failures (which includes test cases added/changed by the patch
being tested)

Every patch should include a test case (either extensions/changes
to existing test cases or add new ones, as appropriate). The test
case should be part of the same commit so that both code and
test case get reviewed together.

Test cases added are cumulative. Every new patch gets
tested against its own test case and every test case previously
added.

A lot of new commits in the near future will be pure test cases
(with no code change) which will get added in "catch up" mode.

The tool used for implementing test cases is 'prove', and the
framework itself is modeled similar to the POSIX compliance
filesystem test suite.

Under the top level directory, a new directory named 'tests/'
is added. This contains top level classifier directories and
framework files/scripts.

Functionality tests should be created under a classifier directory
below 'tests/'. For e.g:

  tests/basic/mount.t
  tests/performance/write-behind.t

Bugs which get fixed should include a test case script named
by the bug id, so that we are guaranteed any new change will
not bring the issue back. For e.g:

  tests/bugs/bug-123456.t

Triggering of regression tests in Jenkins is manual at this point
as we do not want the entire test suite to run against every
revision of a patch while it is still in the review/resubmit cycle.

Signed-off-by: Anand Avati <avati@redhat.com>

Change-Id: I8078244619135ccaba38e068925f8ca85141055a
BUG: 764966
Signed-off-by: Anand Avati <avati@redhat.com>
Reviewed-on: http://review.gluster.org/4101
Tested-by: Gluster Build System <jenkins@build.gluster.com>
nfs: do lookup on getattr after brick-status change

By doing a lookup, we get a chance to do all of the self-heal checks that
would occur if we were using native protocol, and return proper status if
the self-heal fails.  Best of all, we don't need to misrepresent times.

Change-Id: I76477d1e5fce4d83e4029e02fcdd71e81e23110d
BUG: 830134
Signed-off-by: Jeff Darcy <jdarcy@redhat.com>
Reviewed-on: http://review.gluster.org/4058
Tested-by: Gluster Build System <jenkins@build.gluster.com>
Reviewed-by: Vijay Bellur <vbellur@redhat.com>
In some cases AI_ADDRCONFIG confuses NetBSD 6.0

BUG: 764655
Change-Id: I29198c94c6788f9e01f57e11798f3d3d7cd9c8de
Signed-off-by: Emmanuel Dreyfus <manu@netbsd.org>
Reviewed-on: http://review.gluster.org/4105
Reviewed-by: Anand Avati <avati@redhat.com>
Tested-by: Anand Avati <avati@redhat.com>
NetBSD negative timeout missing support workaround

Newer and simplier version: since the default of negative_timeout is 0,
we can just avoid sending a fuse_entry in that case, and this is enough
to work around the problem.

BUG: 764655
Change-Id: Ibfc6230e3cb9871ccade7fb756e61ebc47cb6487
Signed-off-by: Emmanuel Dreyfus <manu@netbsd.org>
Reviewed-on: http://review.gluster.org/4115
Reviewed-by: Anand Avati <avati@redhat.com>
Tested-by: Anand Avati <avati@redhat.com>
glusterd: do not log rdma not found messages in error mode

Change-Id: Ie35b05ed2ee004bd6479ccdd3459cbcd9cf8c208
BUG: 867313
Signed-off-by: Raghavendra Bhat <raghavendra@redhat.com>
Reviewed-on: http://review.gluster.org/4094
Reviewed-by: Amar Tumballi <amarts@redhat.com>
Reviewed-by: Vijay Bellur <vbellur@redhat.com>
Tested-by: Gluster Build System <jenkins@build.gluster.com>
glusterd: fix for remove-brick on just created/stopped volumes

in a fix to avoid race between stopping the brick and deleting
it in remove-brick (15396f490d23c665d51a64a049679cb40472ab05)
we moved delete of the brick inside stop volume, which was
totally inside the 'if (volinfo->status == STARTED)' section.
thus it made remove-brick of stopped/created volume as a failure.

Signed-off-by: Amar Tumballi <amarts@redhat.com>
BUG: 867252
Change-Id: Ie251e59a0b7ddb6965d8d48fb2a3bdb3bd11653d
Reviewed-on: http://review.gluster.org/4127
Reviewed-by: Jeff Darcy <jdarcy@redhat.com>
Tested-by: Gluster Build System <jenkins@build.gluster.com>
Tested-by: Jeff Darcy <jdarcy@redhat.com>
Add OCF compliant resource agents for glusterd and volumes

These resource agents plug glusterd into Open Cluster Framework
(OCF) compliant cluster resource managers, like Pacemaker.

The glusterd RA is fairly trivial; it simply manages the glusterd daemon
like any upstart or systemd job would, except that Pacemaker can
do it in a cluster-aware fashion.

The volume RA is a bit more involved; It starts a volume and monitors
individual brick's daemons in a cluster aware fashion, recovering bricks
when their processes fail.

Note that this does NOT imply people would deploy GlusterFS servers
in pairs, or anything of that nature. Pacemaker has the ability to
deploy cluster resources as clones, meaning glusterd and volumes would be
configured as follows in a Pacemaker cluster:

primitive p_glusterd ocf:glusterfs:glusterd \
	op monitor interval="30"
primitive p_volume_demo ocf:glusterfs:volume \
	params volname="demo" \
	op monitor interval="10"
clone cl_glusterd p_glusterd \
	meta interleave="true"
clone cl_volume_demo p_volume_demo \
	meta interleave="true" ordered="true"
colocation c_volume_on_glusterd inf: cl_volume_demo cl_glusterd
order o_glusterd_before_volume 0: cl_glusterd cl_volume_demo

The cluster status then looks as follows (in a 4-node cluster; note
the configuration above could be applied, unchanged, to a cluster
of any number of nodes):

============
Last updated: Fri Mar 30 10:54:50 2012
Last change: Thu Mar 29 17:20:17 2012 via crmd on gluster02.h
Stack: openais
Current DC: gluster03.h	- partition with quorum
Version: 1.1.6-3.el6-a02c0f19a00c1eb2527ad38f146ebc0834814558
4 Nodes configured, 4 expected votes
8 Resources configured.
============

Online: [ gluster02.h gluster03.h gluster04.h gluster01.h ]

 Clone Set: cl_glusterd [p_glusterd]
     Started: [ gluster02.h gluster03.h gluster04.h gluster01.h ]
 Clone Set: cl_volume_demo [p_volume_demo]
     Started: [ gluster01.h gluster02.h gluster03.h gluster04.h ]

This is also a way of providing automatic glusterd and brick recovery
in systems where neither upstart nor systemd are available.

Change-Id: Ied46657bdfd2dd72dc97cf41b0eb7adcecacd18f
BUG: 869559
Signed-off-by: Florian Haas <florian@hastexo.com>
Reviewed-on: http://review.gluster.org/3043
Tested-by: Gluster Build System <jenkins@build.gluster.com>
Reviewed-by: Anand Avati <avati@redhat.com>
glusterd: Remove brick from brick list on all nodes.

Change-Id: I7150691886550b80cf5de11464a36c3254c5d21b
BUG: 866916
Signed-off-by: Krishnan Parthasarathi <kparthas@redhat.com>
Reviewed-on: http://review.gluster.org/4128
Tested-by: Gluster Build System <jenkins@build.gluster.com>
Reviewed-by: Anand Avati <avati@redhat.com>
core: add STACK_WIND_TAIL for more efficient default_xxx.

Change-Id: Ic38e2183d1320bb17c014aca33779471c8db5d5f
BUG: 867132
Signed-off-by: Jeff Darcy <jdarcy@redhat.com>
Reviewed-on: http://review.gluster.org/4092
Tested-by: Gluster Build System <jenkins@build.gluster.com>
Reviewed-by: Anand Avati <avati@redhat.com>
object-storage: Bump size of metadata stored per xattr key

For Gluster, since we require XFS, and XFS has a max metadata value size of 64
KB, use the increased stored size to reduce the number of system calls, and
how often we exit and enter the Python interpreter (via calls to pyxattr
module).

Today, with the hardcoded 254 byte limit per xattr key/value pair, adding a
couple hundred bytes of user specified metadata can translate to up to three
xattr key/value pairs (remember that the internal python metadata dictionary
is pickled first and then stored in chunks in the keys).

Change-Id: I6648106e8fac31f973ce207a6fecbcdab11fa271
BUG: 865493
Signed-off-by: Peter Portante <peter.portante@redhat.com>
Reviewed-on: http://review.gluster.org/4108
Reviewed-by: Mohammed Junaid <junaid@redhat.com>
Tested-by: Anand Avati <avati@redhat.com>
object-storage: reduce the number of getxattr system calls by one

Initial step towards addressing BZ 865619.

Prior to the patch, reading metadata for a given object or container involves
at minimum three getxattr system calls for objects that use only one xattr
key/value pair:

    1. (via pyxattr)  getxattr() to see if key exists and get its value
       length (so it can allocate memory for second call below)
    2. (from pyxattr) getxattr() to get actual value data
    3. (via pyxattr)  getxattr() to see if following key exists

For objects and containers that only have to use one xattr key/value pair,
this patch reduces the number system calls by one. This can be significant
given that almost every Swift API operation requires reads of the object or
containers metadata.

This patch is mostly a change to plugins.utils.read_metadata() to try to
unpickle the accumulated metadata as each key/value pair is read, rather than
trying to accumulate all the key/value pairs and unpickle at the end. Once we
get enough data to form the pickle, we no longer keep trying to get more keys,
even if those keys exist.

The extra keys can exist when the size of the stored metadata shrinks below a
key threshold. See https://bugzilla.redhat.com/show_bug.cgi?id=865619 for more
details.

See also https://bugzilla.redhat.com/show_bug.cgi?id=865858.

This patch also adds a unit test infrastructure, and uses it to test with full
coverage, the read_metadata, write_metadata and clean_metadata functions. As a
result, we found that an infinite loop would occur in clean_metadata() when an
unexpected IOError would occur trying to remove a key (this patch contains a
fix).

Change-Id: Ia1838c5e73af453b65360c1c525824231aa7c5d4
BUG: 865619
Signed-off-by: Peter Portante <peter.portante@redhat.com>
Reviewed-on: http://review.gluster.org/4109
Reviewed-by: Kaleb KEITHLEY <kkeithle@redhat.com>
Reviewed-by: Jeff Darcy <jdarcy@redhat.com>
Tested-by: Anand Avati <avati@redhat.com>
Move _add_timestamp() closer to where it is used

Simple refactoring to move _add_timestamp() closer to where it is used ahead
of further refactoring changes.

Change-Id: I175c5672202f2d961c72d4e2f4a441b47de1ba28
Signed-off-by: Peter Portante <peter.portante@redhat.com>
Reviewed-on: http://review.gluster.org/4110
Reviewed-by: Kaleb KEITHLEY <kkeithle@redhat.com>
Reviewed-by: Mohammed Junaid <junaid@redhat.com>
Tested-by: Anand Avati <avati@redhat.com>
Further reduce extended attribute reads/writes

More refactoring towards reducing the number of extended attribute
reads/writes to the file system. See BZ 868120:
    http://bugzilla.redhat.com/show_bug.cgi?id=868120

Basically the redundant routines restore_object, restore_account and
restore_container have been collapsed to one routine, restore_metadata, which
will only write out metadata if the new metadata is different from what was
originally read.

Along with these changes come a set of unit tests for all the functions
related to the routines that are in this module in the call tree where
restore_metadata is invoked.

Change-Id: I957ee2f8646cbe6df4d4420d3bdfb1f6ac62bdd2
BUG: 868120
Signed-off-by: Peter Portante <peter.portante@redhat.com>
Reviewed-on: http://review.gluster.org/4111
Reviewed-by: Kaleb KEITHLEY <kkeithle@redhat.com>
Reviewed-by: Jeff Darcy <jdarcy@redhat.com>
Tested-by: Anand Avati <avati@redhat.com>
Reduce the number of stat/fstat system calls made

This address BZ 868086, https://bugzilla.redhat.com/show_bug.cgi?id=868086

This refactoring consolidates the code a bit, and uses os.stat calls to get
all the information in one call when gathering the metadata for an object. The
five stat system calls (invoked via all the os.path.*() calls) have been
reduced to one.

We also added a unit test for the one new behavior where get_object_metadata()
will now throw an OSError exception if it has a problem stat'ing a file that
exists.

Change-Id: Iad5410c77938af68a47be757a3170abd201adeb0
BUG: 868086
Signed-off-by: Peter Portante <peter.portante@redhat.com>
Reviewed-on: http://review.gluster.org/4112
Reviewed-by: Kaleb KEITHLEY <kkeithle@redhat.com>
Reviewed-by: Mohammed Junaid <junaid@redhat.com>
Tested-by: Anand Avati <avati@redhat.com>
protocols: Suppress getxattr log when errno is ENOENT

Change-Id: I3f4fe3f382aec5fd142cc409b80bd73aebd8b39b
BUG: 861015
Signed-off-by: Pranith Kumar K <pkarampu@redhat.com>
Reviewed-on: http://review.gluster.org/4097
Reviewed-by: Jeff Darcy <jdarcy@redhat.com>
Tested-by: Gluster Build System <jenkins@build.gluster.com>
Minor refactorings to mark an internal routine

Just a couple of changes to mark a routine as internal to this module (leading
underscore, helps understand what is part of the utils API and what is not),
and use of the positional argument for memcache for consistency and reduction
in line count (doing this ahead of another refactoring to keep changes
concise).

Change-Id: I71581ad6ac4c383b1de787b767be568fc0a87eef
Signed-off-by: Peter Portante <peter.portante@redhat.com>
Reviewed-on: http://review.gluster.org/4138
Reviewed-by: Kaleb KEITHLEY <kkeithle@redhat.com>
Reviewed-by: Mohammed Junaid <junaid@redhat.com>
Tested-by: Gluster Build System <jenkins@build.gluster.com>
glusterd: op-version handshake implementation

Brings in a new rpc program MGMT_HANDSHAKE, which implements the op-version
handshake. This is required for bringing in the op-version feature as described
in http://www.gluster.org/community/documentation/index.php/Features/Opversion

Change-Id: I4333fd2714dbbd3a2a3fca5862cbb3c56615529e
BUG: 814534
Signed-off-by: Kaushal M <kaushal@redhat.com>
Reviewed-on: http://review.gluster.org/3688
Reviewed-by: Vijay Bellur <vbellur@redhat.com>
Tested-by: Gluster Build System <jenkins@build.gluster.com>