Commit Graph

282 Commits

Author SHA1 Message Date
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
Niels de Vos 6a17d59988 rbd: split Create() off into Create2() ad Create3() following librbd.h
The C library offers rbd_create2() and rbd_create3() and does not try to
cover all options with rbd_create(). For users that are familiar with
the C API, the Create2() and Create3() functions have been added.

The existing Create() API still handles the complete set of
rbd_create*() functions, so backwards compatibility is covered.

Signed-off-by: Niels de Vos <ndevos@redhat.com>
2019-12-11 09:09:54 -05:00
zhangyue de3bd20fe3 bugfix: use GetError instead of RDBError to return
Signed-off-by: zhangyue <zy675793960@yeah.net>
2019-12-11 08:44:00 -05:00
John Mulligan fa319f99bb rbd: use uuid library, rather than shelling out, in rbd test
Previously, the tests were shelling out to run 'uuidgen' which
is not particularly efficient and a bit ugly. Switch this test
to use the same uuid library already in use by the rados test code.

Signed-off-by: John Mulligan <jmulligan@redhat.com>
2019-12-06 11:23:03 -05:00
Sven Anderson 472f6dd5bb Tests: avoid segmentation faults in tests
This change replaces a couple of functions from the "assert" package
with the corresponding functions from the "require", where the
following code relies on a non-nil object.

Signed-off-by: Sven Anderson <sven@redhat.com>
2019-12-06 11:12:34 -05:00
John Mulligan 20d12ba7bc test: disable test results caching with -count flag
According to the 'go test' help, "The idiomatic way to disable test
caching explicitly is to use -count=1." This removes GOCACHE=off in
favor of using -count=1 as GOCACHE=off breaks other tooling including
the use of go modules.

Signed-off-by: John Mulligan <jmulligan@redhat.com>
2019-12-05 14:04:15 -05:00
John Mulligan 5b6bad390a test: make entrypoint script behavior configurable
Adds cli parsing to the entrypoint script allowing for:
1. Custom path to micro-osd script
   This allows easier testing of the script itself or quick
   and dirty customization for special one-off tests
2. Selecting tests to run (or "ALL" or "NONE")
   This allows the user to run only a subset of the tests as needed.
3. Option to pause indefinitely after tests complete
   This keeps the containerized environment alive after tests
   have run for debugging or just for creating a quick and dirty
   ceph environment for playing around.

Signed-off-by: John Mulligan <jmulligan@redhat.com>
2019-12-05 14:04:15 -05:00
John Mulligan ac1d6a6554 dockerfile: use exec form for entrypoint script
Using the exec form will allow us to pass arguments to the
container/entrypoint in the future.

Signed-off-by: John Mulligan <jmulligan@redhat.com>
2019-12-05 14:04:15 -05:00
Sven Anderson 1bc4d888b8 Makefile: Fix CONTAINER_OPTS for Fedora
Fedora based distributions don't use AppArmor but SELinux instead.
This change detects the distribution and sets the --security-opts
accordingly.

Signed-off-by: Sven Anderson <sven@redhat.com>
2019-12-05 13:32:55 -05:00