Commit Graph

290 Commits

Author SHA1 Message Date
John Mulligan 62c53cd682 contrib: create a hacky script for comparing api coverage
This fairly hacky script can be used to check how much of the
various apis are covered by the go-ceph library.
It doesn't care about a lot of subtlety at the moment but does
give a fair idea of what types of functions are implemented vs.
those that are not.
Requires the tool 'castxml'.

Signed-off-by: John Mulligan <jmulligan@redhat.com>
2020-01-21 08:00:38 +01:00
John Mulligan 280b9b01d4 entrypoint: handle the sub-packages separately
Run the tests for each sub-package as a separate invocation.
Make the package selectable.
This has a few small advantages:
* When iterating on a single package the other packages do not run
* Better coverage summary line printed after each test
* Slightly better output with verbose test output

Signed-off-by: John Mulligan <jmulligan@redhat.com>
2020-01-20 17:41:15 +01:00
John Mulligan b177121473 cephfs: replace tests mount setup boilerplate with func
In the cephfs tests the setup of the mount/connection was largely being
done as a copy-n-paste. This change adds a common setup function for
most of the test cases that need an active connection.
Similar to other recent changes this also adds a timeout such that
if the test fails to get a connection it will fail quickly rather
than block forever.

Signed-off-by: John Mulligan <jmulligan@redhat.com>
2020-01-20 16:52:45 +01:00
John Mulligan d51628ca59 rados: update test setup code to avoid blocking forever
When working on the previous rbd change it was determined that the
connection setup code would block forever if the ceph config was missing
or bad when running the tests. Adjust the connection setup in the rados
pkg such that the tests will not block forever.

Signed-off-by: John Mulligan <jmulligan@redhat.com>
2020-01-20 16:52:45 +01:00
John Mulligan 3ec0541977 rbd: replace tests conn setup boilerplate with func
In the rbd tests the setup of the rados connection was essentially copy
and paste with very little proper error checking.
This change adds a common setup function that checks all error
conditions as well as prevents the tests from blocking forever if
something is wrong with the ability of the tests to connect.

Signed-off-by: John Mulligan <jmulligan@redhat.com>
2020-01-20 16:52:45 +01:00
John Mulligan 6c949c1954 testing: enable exported vars check as warning
(Re-)enable the revive check for exported vars/functions/etc at the
warning level. We have a lot of pre-existing failures here so we do not
want to fail on these, but we would like a list so we can work on
eliminating them.

Signed-off-by: John Mulligan <jmulligan@redhat.com>
2019-12-17 08:30:02 +01:00
John Mulligan e8c0d8f3e3 testing: set revive to treat new check failures as errors
Previously, revive was configured to only warn on detected issues.  We
have eliminated all those issues and so can set revive to error out and
thus the 'make check' rule will fail if new issues are introduced.

Signed-off-by: John Mulligan <jmulligan@redhat.com>
2019-12-17 08:30:02 +01:00
Anthony ARNAUD 777e79c046 rbd: add metadata functions on image to get, set, remove metadata
Signed-off-by: Anthony ARNAUD <github@anthony-arnaud.fr>
2019-12-16 18:10:18 +01:00
Niels de Vos 2b2fcc121d rbd: fix broken Image.Copy() and add an exhaustive test for it
The arguments passed to Copy() would normally be pointers, just like it
is done with other similar functions. This never worked correctly, as
the arguments were not validated correctly (not recognized) and the
error "Must specify either destination pool or destination image" always
got returned.

Modifying Image.Copy() into something usable would result in a complete
rewrite. Instead of a single Image.Copy() function that tries to cover
rbd_copy() and rbd_copy2(), provide Image.Copy() and Image.Copy2() so
that the API matches the librbd.so interface.

Signed-off-by: Niels de Vos <ndevos@redhat.com>
2019-12-16 11:27:18 -05:00
John Mulligan 4589af9dfd cephfs: fix linting errors found in cephfs_test.go
Now that cephfs_test.go is part of the cephfs package, the linter is
checking it and finding errors. Fix them.

Signed-off-by: John Mulligan <jmulligan@redhat.com>
2019-12-16 16:59:25 +01:00
John Mulligan d4b6798928 rados: add test function for error type and functions
Signed-off-by: John Mulligan <jmulligan@redhat.com>
2019-12-16 16:59:25 +01:00
John Mulligan 105ccc6ee1 entrypoint: enable coverage for errutil package
Signed-off-by: John Mulligan <jmulligan@redhat.com>
2019-12-16 16:59:25 +01:00
John Mulligan 73753d5482 cephfs: test error type and error handling functions
Signed-off-by: John Mulligan <jmulligan@redhat.com>
2019-12-16 16:59:25 +01:00
John Mulligan 9f46b4621b cephfs: include cephfs_test.go in cephfs package
This will allow us to test private functions from the cephfs package
int our test file.

Signed-off-by: John Mulligan <jmulligan@redhat.com>
2019-12-16 16:59:25 +01:00
John Mulligan 811f851c99 rbd: convert to common errno handling
Use the errno handling function originally created for rbd and
then made common in rbd package.

Signed-off-by: John Mulligan <jmulligan@redhat.com>
2019-12-16 16:59:25 +01:00
John Mulligan bd99f64517 rados: convert to common errno handling
Use the errno handling function originally created for rbd and
then made common in rados package.

Signed-off-by: John Mulligan <jmulligan@redhat.com>
2019-12-16 16:59:25 +01:00
John Mulligan b6ad17881a cephfs: convert cephfs error type to exported type
Convert cephfs packages previously unexposed type to a public one and
replace a bunch of the existing boilerplate error handling with a
convenience function similar to those found ind rbd and rados.

Signed-off-by: John Mulligan <jmulligan@redhat.com>
2019-12-16 16:59:25 +01:00
John Mulligan 72ea0669c2 cephfs: use common error extraction function
Signed-off-by: John Mulligan <jmulligan@redhat.com>
2019-12-16 16:59:25 +01:00
John Mulligan 887dec1c50 errutil: common error handling functions
Signed-off-by: John Mulligan <jmulligan@redhat.com>
2019-12-16 16:59:25 +01:00
Niels de Vos f15486e0a2 test/rbd: check for expected errors with Image.Clone()
Signed-off-by: Niels de Vos <ndevos@redhat.com>
2019-12-16 10:12:51 -05:00
Niels de Vos f611d4a986 test/rbd: check for expected errors with Image.Open()
Signed-off-by: Niels de Vos <ndevos@redhat.com>
2019-12-16 10:12:51 -05:00
Niels de Vos 22c15e5a37 rbd: fix problems with Image.Discard()
The return value of rbd_discard() is the number of bytes that have been
discarded, or in case of an error, a negative errno value.

It seems Image.Discard() never can have worked as intended, unless the
error was disregarded. Just like Image.Write(), Image.Discard() should
return a tuple of the number of bytes discarded and an error.

Fixes: ceph/go-ceph#123
Signed-off-by: Niels de Vos <ndevos@redhat.com>
2019-12-16 10:12:51 -05:00
Niels de Vos 9381485fac test/rbd: Add tests for Image.Seek()
Signed-off-by: Niels de Vos <ndevos@redhat.com>
2019-12-16 10:12:51 -05:00
Niels de Vos 2faaf93287 test/rbd: add test for opening an Image read-only
Signed-off-by: Niels de Vos <ndevos@redhat.com>
2019-12-16 10:12:51 -05:00
Niels de Vos 30fdf64bdc test/rbd: add test for Image.Resize()
Signed-off-by: Niels de Vos <ndevos@redhat.com>
2019-12-16 10:12:51 -05:00
Niels de Vos a5cc9ff302 test/rbd: add tests for getting image properties
Signed-off-by: Niels de Vos <ndevos@redhat.com>
2019-12-16 10:12:51 -05:00
Niels de Vos dbfc54d61e rbd: RbdFeature* constants should be uint64
rbd_get_features() returns a uint64_t with the features that are set in
the image. That means combining (with logical OR) features should result
in a uint64 too. Marking all features explicitly uint64 makes it easier
and cleaner to set/test features.

Signed-off-by: Niels de Vos <ndevos@redhat.com>
2019-12-16 10:12:51 -05:00
Niels de Vos 0b8f4eb7e5 test/rbd: add test for Image.Rename()
Signed-off-by: Niels de Vos <ndevos@redhat.com>
2019-12-16 10:12:51 -05:00
Niels de Vos 65d1e9c763 rbd: include rbd_test.go in rbd package
Keeping the _test.go code in the same package allows for the testing
of private functions. AFAWK it is more conventional as well.

See-also: ceph/go-ceph#135
Signed-off-by: Niels de Vos <ndevos@redhat.com>
2019-12-16 10:12:51 -05:00
John Mulligan 7c1e4f2ca9 rbd: convert test to use errors with conventional names
We recently created errors in the rbd that match the golang convention
but left aliases for external code. Switch the test code to use the
newer more standard form instead of the "aliases."

Signed-off-by: John Mulligan <jmulligan@redhat.com>
2019-12-16 11:32:21 +01:00
John Mulligan 36fc3510d8 rbd: use conventional naming style for errors
A recent PR added new error values that were similar to the existing
naming convention but were not the normal go convention. Change all the
errors to match typical convention but leave the older names as aliases
such that older code will continue to work (for now).

Signed-off-by: John Mulligan <jmulligan@redhat.com>
2019-12-16 11:32:21 +01:00
John Mulligan a2d1c64180 rbd: separate standard lib imports from pkg imports
By convention many projects are separating the golang stdlib imports
from other imports. Do that as well for rbd.go.

Signed-off-by: John Mulligan <jmulligan@redhat.com>
2019-12-16 10:03:58 +01:00
John Mulligan 8a2d18be87 rados: include rados_test.go in rados package
Keeping the _test.go code in the same package allows for the testing
of private functions. AFAIK it is more conventional as well.

Signed-off-by: John Mulligan <jmulligan@redhat.com>
2019-12-16 09:49:47 +01:00
Yue Zhu 750fe1830e rados: add support for sending PG commands 2019-12-13 16:30:00 +01:00
John Mulligan ce5d3ef04d cephfs: remove use of logging in package
After discussion we decided to entirely drop logging from the library.
Future users should rely instead of the error types and values the
function calls return.

Signed-off-by: John Mulligan <jmulligan@redhat.com>
2019-12-13 15:17:27 +01:00
John Mulligan e07f6a6050 rados: replace Println calls with a proper error
Replace the odd calls to Println with a comparable error value.

Signed-off-by: John Mulligan <jmulligan@redhat.com>
2019-12-13 15:17:27 +01:00
John Mulligan fdc33a8e69 github: configure a pull request template
Template provides brief reminders on what the project expects on
all prs.

Signed-off-by: John Mulligan <jmulligan@redhat.com>
2019-12-12 16:17:31 -05:00
Niels de Vos a713db983a rbd: return more useful error messages
Translate the return value (errno) from the C rbd_*() functions into the
standardized strerror() error message.

Signed-off-by: Niels de Vos <ndevos@redhat.com>
2019-12-12 13:56:53 -05:00
John Mulligan dcfe969b09 rbd: use correct style for package doc comment
Signed-off-by: John Mulligan <jmulligan@redhat.com>
2019-12-12 11:34:51 -05:00
John Mulligan 5d0b9b17a0 rados: use correct style for package doc comment
Signed-off-by: John Mulligan <jmulligan@redhat.com>
2019-12-12 11:34:51 -05:00
John Mulligan b3deb28b94 makefile: use revive for style checking
Switch use of style checker from golint to revive for both the makefile
and travis configuration.

Signed-off-by: John Mulligan <jmulligan@redhat.com>
2019-12-12 11:22:11 -05:00
John Mulligan 75fdc694be testing: add a project-wide toml config file for revive
Revive is a tool similar to golint but can be configured. Add an initial
configuration for revive.
This configuration reduces the initial issue list to something more
manageable and that can be worked on incrementally rather than trying to
boil to ocean to make the checker happy.

Signed-off-by: John Mulligan <jmulligan@redhat.com>
2019-12-12 11:22:11 -05:00
John Mulligan 5ea85a9419
Merge pull request #89 from CodeLingoBot/rewrite
Fix function comments based on best practices from Effective Go
2019-12-11 19:56:20 -05:00
Niels de Vos 2d52744470 rbd: improve error checking
Make it possible to easily validate the *Image and *Snapshot objects
before using them. This makes the use of go-ceph for RBD functions more
stable, and it is less likely that incorrect use causes Go panics.

Signed-off-by: Niels de Vos <ndevos@redhat.com>
2019-12-11 19:47:21 -05:00
John Mulligan 99de05854c ceph: remove unnecessary imports in doc.go
The package imports in doc.go were not accomplishing anything and also
were not complete (missing cephfs). This removes them.

Signed-off-by: John Mulligan <jmulligan@redhat.com>
2019-12-11 14:44:54 -05:00
John Mulligan ab02cd27c0 ceph: expand doc to go a bit
Make the doc comment in doc.go a bit more fleshed out with pointers
to the real functionality of the library.

Signed-off-by: John Mulligan <jmulligan@redhat.com>
2019-12-11 14:44:54 -05:00
John Mulligan 9460b11d88 ceph: rename package for go files in root dir
Oddly, probably a historical artifact, the .go files in the root of the
go-ceph tree were named "rados". As rados is one of our sub-packages it
seemed more correct to call the package "ceph".  This was chosen as
"go-ceph" is not a valid identifier in go and since this is already go
code prefixing with "go" seems a bit redundant.

Signed-off-by: John Mulligan <jmulligan@redhat.com>
2019-12-11 14:44:54 -05:00
Niels de Vos b86563db7e rbd: add Create4() for more advanced RBD Image creation
This allows to set additional options while creating RBD images.
Ceph-CSI will initially consume this to configure an optionally
different pool for data.

Signed-off-by: Niels de Vos <ndevos@redhat.com>
2019-12-11 13:43:58 -05:00
Niels de Vos c06593eef7 rbd: add support for RbdImageOptions
There are several RbdImageOptions that can be used to configure features
of an RBD image while creating, cloning, migrating and copying. A
follow-up patch will add Create4() where the RbdImageOptions can be
used.

Signed-off-by: Niels de Vos <ndevos@redhat.com>
2019-12-11 13:43:58 -05:00
Niels de Vos 1a06d47a0d tests: use Ceph Nautilus
Prepare for adding support for RbdImageOptions with
RBD_IMAGE_OPTION_FLATTEN that has been introduced in Ceph Mimic.
Nautilus is the most recent supported versions, so use that for testing.

Signed-off-by: Niels de Vos <ndevos@redhat.com>
2019-12-11 13:43:58 -05:00