44 Commits

Author SHA1 Message Date
Andreas Jaeger
96b56519bf Update hacking for Python3
The repo is Python using both Python 2 and 3 now, so update hacking to
version 2.0 which supports Python 2 and 3. Note that latest hacking
release 3.0 only supports version 3.

Fix problems found.

Remove hacking and friends from lower-constraints, they are not needed
for installation.

Change-Id: I9bd913ee1b32ba1566c420973723296766d1812f
2020-04-03 21:21:07 +02:00
Matthew Oliver
817ca078e1 py3: port cli recon tests
Also a drive by HASH_PATH_PREFIX/SUFFIX bytesting fix which was
breaking ring and relinker tests.

Change-Id: I1db8f102361770cfed2b12f689789d1e8c21c3e4
2018-04-13 06:39:43 +00:00
Tim Burke
36c42974d6 py3: Port more CLI tools
Bring under test

 - test/unit/cli/test_dispersion_report.py
 - test/unit/cli/test_info.py and
 - test/unit/cli/test_relinker.py

I've verified that swift-*-info (at least) behave reasonably under
py3, even swift-object-info when there's non-utf8 metadata on the
data/meta file.

Change-Id: Ifed4b8059337c395e56f5e9f8d939c34fe4ff8dd
2018-02-28 21:10:01 +00:00
Peter Lisák
206f674014 Added swift version to recon cli
Show swift version and check if the same on hosts by using
`swift-recon --swift-version`.

Ex:
$ swift-recon --swift-versions

Versions matched (2.7.1.dev144), 0 error[s] while checking hosts.

or if differs

Versions not matched (2.7.1.dev144, 2.7.1.dev145),
0 error[s] while checking hosts.

Change-Id: I3c2e569f0c44168333251bb58bab4b5582e15a45
2017-12-05 13:14:20 -08:00
Jenkins
33b07c5fc5 Merge "Add a jitter for check of time synchronization." 2017-08-18 23:55:47 +00:00
Christian Schwede
2410b616bb Fix swiftdir option and usage of storage policy aliases
If swift-recon/swift-get-nodes/swift-object-info is used with the
swiftdir option they will read rings from the given directory; however
they are still using /etc/swift/swift.conf to find the policies on the
current node.

This makes it impossible to maintain a local swift.conf copy (if you
don't have write access to /etc/swift) or check multiple clusters from
the same node.

Until now swift-recon was also not usable with storage policy aliases,
this patch fixes this as well.

Closes-Bug: 1577582
Closes-Bug: 1604707
Closes-Bug: 1617951
Co-Authored-By: Alistair Coles <alistairncoles@gmail.com>
Co-Authored-By: Thiago da Silva <thiago@redhat.com>
Change-Id: I13188d42ec19e32e4420739eacd1e5b454af2ae3
2017-07-12 16:23:04 -04:00
lijunbo
6788bf4aad Fixed get ring name from recon cli
This patch uses a more specific string to match
the ring name in recon cli.

Almost all the places in the project where need to get the
suffix (like ring.gz, ts, data and .etc) will include the '.'
in front, if a file named 'object.sring.gz' in the swift_dir
will be added in the ring_names, which is not what we want.

Co-Authored-By: Kota Tsuyuzaki <tsuyuzaki.kota@lab.ntt.co.jp>
Closes-Bug: #1680704
Change-Id: Ida659fa71585f9b0cf36da75b58b28e6a25533df
2017-04-13 07:01:03 +00:00
Alistair Coles
609b5182c4 Refactor recon to use single md5_hash_for_file function
There were several implementations of hashing the content
of a file in cli/recon.py and common/middleware/recon.py.
This patch relocates one implementation (_hash_for_ringfile,
introduced in the Related Change) to common/utils.py and
refactors recon cli and middleware to use that function.

Also improves use of mocking in the unit tests to eliminate passing
custom file opener functions to the ReconMiddleware get_ring_md5
and get_swift_conf_md5 methods.

Related-Change: I9623752c3cd2361f57864f3e938e1baf5e9292d7

Change-Id: Iaad88e49aadeb28f614aafa1e9596fe07ce9793a
2016-12-02 18:22:59 +00:00
Ondřej Nový
e3e457da66 Respect server type for --md5 check in swift-recon
MD5 sum compare of server ring ignores server_type parameter
now. This could be confusing and this should only test
specified server_type, same as --replication, --validate-servers,
etc.

Change-Id: I9095309c24f42aec1330757c88e7b242b2a6a865
2016-10-31 07:26:22 +00:00
Jenkins
7c8b549ab9 Merge "Py3: Fixes eventlet ImportError: No module named urllib2" 2016-09-30 05:39:48 +00:00
Lokesh S
eea574a78a Py3: Fixes eventlet ImportError: No module named urllib2
Python3:
from eventlet.green.urllib import request
Python2:
from eventlet.green import urllib2

Change-Id: Ib38865e0b6a8f076b8a54de4fae221d49f315c91
2016-09-07 09:04:30 +00:00
Gábor Antal
488f88e30a Use more specific asserts in test/unit/cli tests
I changed asserts with more specific assert methods.
e.g.: from assertTrue(sth == None) to assertIsNone(*) or
assertTrue(isinstance(inst, type)) to assertIsInstace(inst, type)
or assertTrue(not sth) to assertFalse(sth).

The code gets more readable, and a better description will be shown on fail.

Change-Id: I39305808ad2349dc11a42261b41dbb347ac0618a
2016-08-03 12:19:40 +00:00
Peter Lisák
a3f28e29a2 Add a jitter for check of time synchronization.
If a request time of check is smaller than a time diff (between local and remote
server) and that time diff is tolerable small then it still prints:
!! http://server:port/recon/time current time is 2016-07-05 06:24:02, but
remote is 2016-07-05 06:24:02, differs by 0.00 sec

So you can use a jitter option to consider it as time synchronized:
swift-recon -T --jitter 0.01

Change-Id: I4891397e7cc0817819201b361f79f8fe7fdcfc89
2016-07-28 09:44:10 +02:00
Jenkins
d8fcdb5778 Merge "Added unit test cases for cli/recon.py" 2016-07-08 23:30:42 +00:00
Christian Schwede
65a9a6d21b Add simple multiple server type test
Ensures that swift-recon actually gathers data from multiple
server types if more than one is given on the command line.

Change-Id: I4017b82fb044265ec117df01e14968752df02201
2016-06-12 21:17:15 +00:00
Sivasathurappan Radhakrishnan
66c77e049d Added unit test cases for cli/recon.py
Added unit test cases to cover code paths of umount_check
and async_check function.

Change-Id: I236d24b1b22ce244b3fb9546ff31223426edb8ed
2016-06-03 17:02:36 +00:00
Christopher Bartz
81a4355c2d Adds storage policy option to recon
With this patch, recon gets policy-aware in regard to the hosts to retrieve.
If no policy is passed and the server_type is object,
all hosts of all policies are retrieved.
Previously, recon did only retrieve the hosts of the storage-policy 0.

Change-Id: If5735cd6721eac504aed8aaf3884cb91b6a0fcac
Closes-Bug: 1541491
2016-02-09 13:39:52 +01:00
Ondřej Nový
edc823e803 Show UTC time in swift-recon.
It's not consistent now for example local time in replication part and
UTC time at begging of line. Use _ptime in swift-recon for all time
printing and this function returns UTC now.
Change-Id: I732d9851db157130a08e825e8093b7e244b63e9c
2016-01-14 12:49:09 +01:00
Samuel Merritt
e31ecb24b6 Get rid of contextlib.nested() for py3
contextlib.nested() is missing completely in Python 3.

Since 2.7, we can use multiple context managers in a 'with' statement,
like so:

    with thing1() as t1, thing2() as t2:
        do_stuff()

Now, if we had some code that needed to nest an arbitrary number of
context managers, there's stuff we could do with contextlib.ExitStack
and such... but we don't. We only use contextlib.nested() in tests to
set up bunches of mocks without crazy-deep indentation, and all that
stuff fits perfectly into multiple-context-manager 'with' statements.

Change-Id: Id472958b007948f05dbd4c7fb8cf3ffab58e2681
2015-10-23 11:44:54 -07:00
Lisak, Peter
a486490029 swift-recon fails with socket.timeout exception
If some server is overloaded or timeout set too low, swift-recon fails with
raised socket.timeout exception.

This error should be processed the same way as HTTPError/URLError.

Change-Id: Ide8843977ab224fa866097d0f0b765d6899c66b8
2015-10-12 14:42:01 +02:00
Victor Stinner
c0af385173 py3: Replace urllib imports with six.moves.urllib
The urllib, urllib2 and urlparse modules of Python 2 were reorganized
into a new urllib namespace on Python 3. Replace urllib, urllib2 and
urlparse imports with six.moves.urllib to make the modified code
compatible with Python 2 and Python 3.

The initial patch was generated by the urllib operation of the sixer
tool on: bin/* swift/ test/.

Change-Id: I61a8c7fb7972eabc7da8dad3b3d34bceee5c5d93
2015-10-08 15:24:13 +02:00
janonymous
36bc4cd9ed Python 3 using builtins instead of __builtin__, rename raw_input() to input() from six.moves
Using these modules from six

Replacements:
*input() from six.moves could be used instead of raw_input()
*__builtin__ with six.moves.builtins

Change-Id: I8749dd33496ed8718bd2c6620c9dc5240c2ce683
2015-09-04 23:07:36 +05:30
Hisashi Osanai
79ba4a8598 Enable Object Replicator's failure count in recon
This patch makes the count of object replication failure in recon.
And "failure_nodes" is added to Account Replicator and
Container Replicator.

Recon shows the count of object repliction failure as follows:
$ curl http://<ip>:<port>/recon/replication/object
{
    "replication_last": 1416334368.60865,
    "replication_stats": {
        "attempted": 13346,
        "failure": 870,
	"failure_nodes": {
            "192.168.0.1": {"sdb1": 3},
            "192.168.0.2": {"sdb1": 851,
                            "sdc1": 1,
                            "sdd1": 8},
            "192.168.0.3": {"sdb1": 3,
                            "sdc1": 4}
	},
        "hashmatch": 0,
        "remove": 0,
        "rsync": 0,
        "start": 1416354240.9761429,
        "success": 1908
    },
    "replication_time": 2316.5563162644703,
    "object_replication_last": 1416334368.60865,
    "object_replication_time": 2316.5563162644703
}

Note that 'object_replication_last' and 'object_replication_time' are
considered to be transitional and will be removed in the subsequent
releases. Use 'replication_last' and 'replication_time' instead.

Additionaly this patch adds the count in swift-recon and it will be
showed as follows:
$ swift-recon object -r
========================================================================
=======
--> Starting reconnaissance on 4 hosts
========================================================================
=======
[2014-11-27 16:14:09] Checking on replication
[replication_failure] low: 0, high: 0, avg: 0.0, total: 0, Failed: 0.0%,
no_result: 0, reported: 4
[replication_success] low: 3, high: 3, avg: 3.0, total: 12,
Failed: 0.0%, no_result: 0, reported: 4
[replication_time] low: 0, high: 0, avg: 0.0, total: 0, Failed: 0.0%,
no_result: 0, reported: 4
[replication_attempted] low: 1, high: 1, avg: 1.0, total: 4,
Failed: 0.0%, no_result: 0, reported: 4
Oldest completion was 2014-11-27 16:09:45 (4 minutes ago) by
192.168.0.4:6002.
Most recent completion was 2014-11-27 16:14:19 (-10 seconds ago) by
192.168.0.1:6002.
========================================================================
=======

In case there is a cluster which has servers, a server runs with this
patch and the other servers run without this patch. If swift-recon
executes on the server which runs with this patch, there are unnecessary
information on the output such as [failure], [success] and [attempted].
Because other servers which run without this patch are not able to
send a response with information that this patch needs.
Therefore once you apply this patch, you also apply this patch to other
servers before you execute swift-recon.

DocImpact
Change-Id: Iecd33655ae2568482833131f422679996c374d78
Co-Authored-By: Kenichiro Matsuda <matsuda_kenichi@jp.fujitsu.com>
Co-Authored-By: Brian Cline <bcline@softlayer.com>
Implements: blueprint enable-object-replication-failure-in-recon
2015-08-18 11:40:02 +09:00
Jenkins
617c6b0107 Merge "Time synchronization check in recon." 2015-08-18 01:21:22 +00:00
janonymous
f449e91472 pep8 fix: assertEquals -> assertEqual
assertEquals is deprecated in py3, fixing in:
dir: test/unit/cli/*

Change-Id: I9a2fc1f717beafd5fa8408942046e310e8de0318
2015-08-05 22:32:02 +05:30
Victor Stinner
a0db56dcde Fix pep8 E265 warning of hacking 0.10
Fix the warning E265 "block comment should start with '# '" added in pep
1.5.

Change-Id: Ib57282e958be9c7cddffc7bca34fbbf1d4c460fd
2015-07-30 09:33:18 +02:00
Ondrej Novy
dd2f1be3b1 Time synchronization check in recon.
This change add call time to recon middleware and param --time to
recon CLI. This is usefull for checking if time in cluster is
synchronized.

Change-Id: I62373e681f64d0bd71f4aeb287953dd3b2ea5662
2015-07-23 11:35:02 +02:00
Victor Stinner
6e70f3fa32 Get StringIO and cStringIO from six.moves
* replace "from cStringIO import StringIO"
  with "from six.moves import cStringIO as StringIO"
* replace "from StringIO import StringIO"
  with "from six import StringIO"
* replace "import cStringIO" and "cStringIO.StringIO()"
  with "from six import moves" and "moves.cStringIO()"
* replace "import StringIO" and "StringIO.StringIO()"
  with "import six" and "six.StringIO()"

This patch was generated by the stringio operation of the sixer tool:
https://pypi.python.org/pypi/sixer

Change-Id: Iacba77fec3045f96773d1090c0bd48613729a561
2015-07-15 16:56:33 +02:00
Christian Schwede
b4c1d73ad5 Make swift-recon compatible for servers without storage policies
Swift recon introduced a new key for storage policies, and the CLI expected this
key in the server response. However, if one updates the CLI but not yet the
server an exception will be raised, because there is no default value and no
check if the key is included in the response.

This change checks if the policies key is included in the response and updates
one test to ensure backward compability.

Closes-Bug: 1453599

Change-Id: I7c7a90f9933bec2ab45595df9dc600a6cba65666
2015-06-01 07:00:39 +00:00
Christian Schwede
663ccd4e7a More tests for swift recon
Change-Id: I8d568c0f6fbe1c01d97491740aebf299deb63732
2015-04-15 06:36:06 +00:00
Christian Schwede
e16df14a73 Add test for swift_recon.disk_usage
Change-Id: I4cab7aa6df3f0e1933e52ee5dbbb829f30604f10
2015-04-14 16:00:37 -07:00
Lorcan
0a46793662 Add swift-recon feature to track swift-drive-audit error count
This is a follow-on from a previous commit which added recon info
for swift-drive-audit (https://review.openstack.org/#/c/122468/).

Here, the "--drievaudit" option is added to swift-recon tool. This
feature gives the statistics for the system-wide drive errors flagged
by swift-drive-audit. An example of the output is as follows:
(verbose mode)

swift-recon --driveaudit -v
===============================================================================
--> Starting reconnaissance on 5 hosts
===============================================================================
[2015-03-11 17:13:39] Checking drive-audit errors
-> http://1.2.3.4:6000/recon/driveaudit: {'drive_audit_errors': 14}
-> http://1.2.3.5:6000/recon/driveaudit: {'drive_audit_errors': 0}
-> http://1.2.3.6:6000/recon/driveaudit: {'drive_audit_errors': 37}
-> http://1.2.3.7:6000/recon/driveaudit: {'drive_audit_errors': 101}
-> http://1.2.3.8:6000/recon/driveaudit: {'drive_audit_errors': 0}
[drive_audit_errors] low: 0, high: 101, avg: 30.4, total: 152, Failed: 0.0%, no_result: 0, reported: 5
===============================================================================

Change-Id: Ia16c52a9d613eeb3de1a5a428d88dd1233631912
2015-03-23 11:38:32 +00:00
Mahati Chamarthy
a248a5c09e Ring checker in swift-recon
This patch validates the server end points on the ring. And also generates
a report on issues found.

Change-Id: I913799a35d5c9178164021cfb7fcb448141b058b
2015-02-26 01:26:02 +05:30
Daisuke Morita
f8fa1a9234 Show each policy's information on quarantined files in recon
After the release of Swift ver. 2.0.0, some recon responses do not
show each policy's information yet. To make things worse, some recon
results only count on policy-0's score, therefore the total is not
shown in the recon results.

This patch makes the count of quarantined files policy-aware for recon
requests. Suppose a number of quarantined objects for policy-0 is 2
and a number for policy-1 is 3, recon sums up every policy's amount
and shows information for each policy as follows.

$ curl http://<host>:<port>/recon/quarantined
{"accounts": 0, "containers": 0, "objects": 5, "policies": {"0":
{"objects": 2}, "1": {"objects": 3}}}

Moreover, this patch adds stats for each policy in CLI output.

Change-Id: I07217c635f6fc4ea809ddbc3d859c4e81c4fde37
Related-Bug: 1375327
Related-Bug: 1375332
2015-01-20 18:42:20 +09:00
Jenkins
513eeb80d7 Merge "updated hacking rules" 2014-10-03 01:47:40 +00:00
Keshava Bharadwaj
0f93fff46a Fixes unit tests to clean up temporary directories
This patch fixes the unit tests to remove the temporary directories
created during run of unit tests. Some of unit tests did not tear down
correctly, whatever it had set it up for running. This would over period
of time bloat up the tmp directory. As on date, there were around 49 tmp
directories left uncleared per round of unit tests. This patch fixes it.

Change-Id: If591375ca9cc87d52c7c9c6dc16c9fb4b49e99fc
2014-09-26 22:39:48 +05:30
John Dickinson
e567722c4e updated hacking rules
1) Added comment for H231, which we were already enforcing. H231
is for Python 3.x compatible except statements.

2) Added check for H201, which we were enforcing in reviews
but waiting on hacking checks to be updated. H201 is for bare
except statements, and the update in upstream hacking is to
support the "  # noqa" flag on it.

The H201 check catches some existing bare excepts that are fixed.

Change-Id: I68638aa9ea925ef62f9035a426548c2c804911a8
2014-09-25 11:04:31 -07:00
Christian Schwede
fc5cee5f05 Allow filtering by region in swift-recon
The option "-r" is already used, thus only "--region" is used to specify
filter by region.

Change-Id: If769f2f3191c202933b03b48fe0f22b7c94a4dd6
Closes-Bug: 1369583
2014-09-15 17:31:16 +00:00
Christian Schwede
e21703ff7b Add test for swift-recon --auditor
Related-Bug: 1329785
Change-Id: I47cecd8a4cd55ca75c2a51153be7bb61c27d0ea0
2014-06-25 14:07:52 +00:00
Jenkins
570e50fe22 Merge "Change assertCalledWith to assert_called_with" 2014-06-24 05:04:06 +00:00
Paul Luse
8326dc9f2a Add Storage Policy Support to Recon Middleware
Recon middleware returns object ring file MD5 sums; this patch
updates it to include other object files that may be present
because of Storage Policies.  Also adds unit test coverage for
the MD5 reporting function which previously had none.

The recon script will now check all rings the server responds with
match the on-disk md5's regardless of server-type; including any
storage policy object rings.

Note the small change to the ring save method, needed to
stimulate the right code paths in 2.6 and 2.7 versions of
gzip to enable testing of ring MD5 sums.

DocImpact
Implements: blueprint storage-policies
Change-Id: I01efd2999d6d9c57ee8693ac3a6236ace17c5566
2014-06-18 21:09:54 -07:00
Paul Luse
d32169c9c8 Change assertCalledWith to assert_called_with
In test_ptime() 2 uses of the former failed to assert with bogus
values used in the assert.  Using assert_called_with() instead
correctly performs the assertion.

Change-Id: Idbd918f8e8d3ec5a4110725b949710fb54b4ba9a
2014-06-10 08:08:13 -07:00
Samuel Merritt
31dac18625 Check swift.conf MD5 with recon
I've seen several folks recently have problems with their Swift
clusters because they had different hash prefixes on different
nodes. Let's help them out by having recon check that.

Note that MD5-equality is stronger than what we need (which is
ConfigParser-equality for a particular set of keys), but this way we
don't expose the secret hash prefix and suffix across the internal
network, just the MD5 checksum of the file containing them.

Change-Id: I3af984ee45947345891b3c596a88e3464f178cc7
2014-04-10 14:08:27 -07:00
Christian Schwede
cd4b4da8b6 Add some tests for bin/swift-recon
Fix also minor bug in zone filtering when zone set to 0.

Moved bin/swift-recon to swift/cli/recon.py, which makes
it possible to import it without using some scary hacks.
bin/swift-recon is now created by setup.py install.

Closes-Bug: #1261692
Change-Id: Id0729991c8ece73604467480dbf93fec7d8eb196
2014-01-31 15:34:37 +00:00