Commit Graph

354 Commits

Author SHA1 Message Date
John Mulligan 4691e0cb4c rbd: update TestReadAt to use new approach for create & open
Update the TestReadAt function to use the new CreateImage and OpenImage
functions.

Signed-off-by: John Mulligan <jmulligan@redhat.com>
2020-01-31 14:32:38 -05:00
John Mulligan 1842bd74e6 rbd: in TestRemoveImage ensure options are destroyed
The resources of the rbd image options must be cleaned up or we leak.

Signed-off-by: John Mulligan <jmulligan@redhat.com>
2020-01-31 14:32:38 -05:00
John Mulligan fc29c7f30a rbd: replace repeated "magic" literal values with vars
Throughout rbd_test.go the values of 1<<22 and 22 are repeated when
created rbd images. For the common cases, replace these with variables.

Signed-off-by: John Mulligan <jmulligan@redhat.com>
2020-01-31 14:32:38 -05:00
John Mulligan 2a74b02c2b rbd: create a standalone RemoveImage function
Currently, the code only provides a .Remove function on the Image type.
But this is unnecessary as the underlying api only requires an io
context and name. Make a function that matches the underlying api
better.

Signed-off-by: John Mulligan <jmulligan@redhat.com>
2020-01-31 14:32:38 -05:00
John Mulligan 635ca3cdb2 rbd: rename Create4 to CreateImage
In the future, CreateImage should be the canonical way one creates an
rbd image. Like the underlying ceph apis CreateImage does not return an
Image, only an error code. Open image handles should be acquired through
the OpenImage functions.

Because Create4 was fairly recently added to library there should not be
consumers in the wild. Thus we don't retain the current version for
backwards compatibility.

Signed-off-by: John Mulligan <jmulligan@redhat.com>
2020-01-31 14:32:38 -05:00
John Mulligan 13028061e7 rbd: update tests to use new open image functions
Replace uses of the deprecated img.Open(...) pattern with the new open
image functions where applicable.

Signed-off-by: John Mulligan <jmulligan@redhat.com>
2020-01-31 14:32:38 -05:00
John Mulligan 0239a8469d rbd: update test case for "old" deprecated open
Rename test case to mark the "old" deprecated open func as such.
This also adds a missing bit of coverage to the test.

Signed-off-by: John Mulligan <jmulligan@redhat.com>
2020-01-31 14:32:38 -05:00
John Mulligan 674d0e4041 rbd: reimplement Image Open function in terms of simpler functions
Signed-off-by: John Mulligan <jmulligan@redhat.com>
2020-01-31 14:32:38 -05:00
John Mulligan 20a458a614 rbd: add new more idomatic functions for opening rbd images
Create new OpenImage & OpenImageReadOnly functions to replace the use of
Open() on image types. This function more closely matches the underlying
of the librbd function calls.

The third argument to the functions is a snapshot name but we also
create a new constant to clearly indicate that an image should be opened
w/o a snapshot. Internally, this also ensures that a null string is
passed to the C api.

Signed-off-by: John Mulligan <jmulligan@redhat.com>
2020-01-31 14:32:38 -05:00
John Mulligan 09813739ed testing: use Go 1.12 from go upstream in ci container
When building the container image for running tests take the older of
the two current releases from Go upstream. We use the older version
in order to make sure we are testing with something supported but maybe
not everyone is on 1.13 yet.
This also enables the use of go modules to ensure we get the proper
versions of dependencies.

Signed-off-by: John Mulligan <jmulligan@redhat.com>
2020-01-30 07:46:18 +01:00
Niels de Vos 5adb04909d rados: standardize error naming
RadosError-prefixes are not recommended, instead just Err as prefix is
used.

Also, errors are constants, not variables.

For existing users, backwards compatible constants are available. These
will need to be removed in a future go-ceph release.

Signed-off-by: Niels de Vos <ndevos@redhat.com>
2020-01-29 16:51:49 +01:00
Niels de Vos c6b65af9ec rados: add Create() function to create new objects
Signed-off-by: Niels de Vos <ndevos@redhat.com>
2020-01-29 16:51:49 +01:00
John Mulligan 15a55c9000 cephfs: add a doc.go file documenting the package
The minimal doc.go file matches the style currently used for rados and
rbd.

Signed-off-by: John Mulligan <jmulligan@redhat.com>
2020-01-28 16:10:39 +01:00
John Mulligan d0cf66be62 errutil: add a package level doc comment
Currently, errutil is a single file package (not counting tests) so we
add a doc comment for the package to the existing file.

Signed-off-by: John Mulligan <jmulligan@redhat.com>
2020-01-28 16:10:39 +01:00
John Mulligan c433abf787 cephfs: allow creating mount with an id
The ceph api function supports passing a string to identify the
client doing the mount. Expose that aspect of the api with a
new function CreateMountWithId.

Signed-off-by: John Mulligan <jmulligan@redhat.com>
2020-01-28 08:52:51 +01:00
John Mulligan dfabc3db54 go-ceph: fix typo in doc.go
It's 'rbd' not 'rdb'.

Signed-off-by: John Mulligan <jmulligan@redhat.com>
2020-01-28 08:38:59 +01:00
John Mulligan 296c551613 cephfs: test creating a cephfs mount from a rados Conn
Verify the cephfs CreateFromRados function.

Signed-off-by: John Mulligan <jmulligan@redhat.com>
2020-01-27 18:30:10 +01:00
John Mulligan 9929f63b13 cephfs: wrap ceph_create_from_rados function
Support creating a cephfs 'mount' from an existing rados connection
using the ceph_create_from_rados function.

Signed-off-by: John Mulligan <jmulligan@redhat.com>
2020-01-27 18:30:10 +01:00
John Mulligan 46ed646e03 rados: support fetching the cluster from the Conn
The cephfs function ceph_create_from_rados requires the cluster_t
value, which is current private to the Conn type. Alias the cluster_t
type and allow other pkgs to get it if needed.

Signed-off-by: John Mulligan <jmulligan@redhat.com>
2020-01-27 18:30:10 +01:00
John Mulligan 7ccc2a2d9b go-ceph: publish library as a go module
Establish a go.mod (and go.sum) file such that this library can be
handled as a Go module. This has the added benefit of now being
useful outside of gopath.
I do not believe we need to release to provide/use module support but
we should possibly start considering creating v0 tags soonish.

See also: https://blog.golang.org/publishing-go-modules

Signed-off-by: John Mulligan <jmulligan@redhat.com>
2020-01-27 17:53:38 +01:00
John Mulligan 5cf2b02a6c rados: clean up var lines in rados.go and add doc comments
Signed-off-by: John Mulligan <jmulligan@redhat.com>
2020-01-23 08:09:36 -05:00
John Mulligan 1585362d3a rados: fix incorrect doc comment on SetOmap func
Signed-off-by: John Mulligan <jmulligan@redhat.com>
2020-01-23 08:09:36 -05:00
John Mulligan 90cd306e99 rados: fix incorrect doc comment for ListXattrs function
Signed-off-by: John Mulligan <jmulligan@redhat.com>
2020-01-23 08:09:36 -05:00
John Mulligan bcec1ab9c1 rados: fix incorrect doc comment on SetXattr
Signed-off-by: John Mulligan <jmulligan@redhat.com>
2020-01-23 08:09:36 -05:00
John Mulligan f16013ebce rados: fix incorrect doc comment on ListLockers function
Signed-off-by: John Mulligan <jmulligan@redhat.com>
2020-01-23 08:09:36 -05:00
John Mulligan b1740e9680 rados: fix incorrect doc comments on Unlock & BreakLock
Signed-off-by: John Mulligan <jmulligan@redhat.com>
2020-01-23 08:09:36 -05:00
John Mulligan f6a143f24f rados: add 'implements' subsection to GetPoolStats doc comment
Signed-off-by: John Mulligan <jmulligan@redhat.com>
2020-01-23 08:09:36 -05:00
John Mulligan 8cdeebc38f rados: fix incorrect doc comment for GetPoolStats
Signed-off-by: John Mulligan <jmulligan@redhat.com>
2020-01-23 08:09:36 -05:00
John Mulligan f6d77333b7 rados: fix and update doc comments for PGCommand funcs
Signed-off-by: John Mulligan <jmulligan@redhat.com>
2020-01-23 08:09:36 -05:00
John Mulligan 0dfa7bcfac rados: add missing doc comment for OpenIOContext function
Signed-off-by: John Mulligan <jmulligan@redhat.com>
2020-01-23 08:09:36 -05:00
John Mulligan 65f2417c4c rados: add doc comment for not connected error
Signed-off-by: John Mulligan <jmulligan@redhat.com>
2020-01-23 08:09:36 -05:00
John Mulligan bc9b7c58ed rados: add doc comments for RadosError type
Signed-off-by: John Mulligan <jmulligan@redhat.com>
2020-01-23 08:09:36 -05:00
Niels de Vos 030eaaa548 rbd/tests: check for io.EOF while testing Read()
Signed-off-by: Niels de Vos <ndevos@redhat.com>
2020-01-23 08:05:34 +01:00
Niels de Vos 522182cbc3 rbd: Read() should return io.EOF on short reads
The case of a short read is not detected correctly. This causes Read()
to not return io.EOF where it is expected.

By comparing 'len(data)' instead of unassigned 'n' (set to 0), the
number of bytes that have been read can be compared to the number of
bytes that were requested.

Signed-off-by: Niels de Vos <ndevos@redhat.com>
2020-01-23 08:05:34 +01:00
John Mulligan de60dcb33b rados: add a test case for the >4086 buffer code path in ListPools
The code path where the pools result buffer was increased in size
then re-fetched was not being tested. Test it.

Signed-off-by: John Mulligan <jmulligan@redhat.com>
2020-01-23 07:45:35 +01:00
John Mulligan 15dfd6fc09 rados: reduce boilerplate in TestGetPoolByName using testify
Testfiy's assert and require libs have helpful functions for
checking values. Use them to reduce a bunch of boilerplate code in the
TestGetPoolByName function.

Signed-off-by: John Mulligan <jmulligan@redhat.com>
2020-01-23 07:45:35 +01:00
John Mulligan b5a0045d70 rados: add test coverage for failure to get config option
Signed-off-by: John Mulligan <jmulligan@redhat.com>
2020-01-23 07:45:35 +01:00
John Mulligan b8f04da105 rados: add test coverage for failure to open io context
Signed-off-by: John Mulligan <jmulligan@redhat.com>
2020-01-23 07:45:35 +01:00
John Mulligan dd1e25e5a4 rados: test error condition in PingMonitor
Signed-off-by: John Mulligan <jmulligan@redhat.com>
2020-01-23 07:45:35 +01:00
Niels de Vos f170634d82 rbd/tests: add special "read 0 bytes" case
Signed-off-by: Niels de Vos <ndevos@redhat.com>
2020-01-22 16:48:18 +01:00
Niels de Vos a0fcd9202c rbd/tests: add WriteAt() and ReadAt() tests
Signed-off-by: Niels de Vos <ndevos@redhat.com>
2020-01-22 16:48:18 +01:00
Niels de Vos 508f808017 rbd: WriteAt() should return io.EOF on short reads
The case of a short read is not detected correctly. This causes ReadAt()
to not return io.EOF where it is expected.

By comparing 'len(data)' instead of unassigned 'n' (set to 0), the
number of bytes that have been read can be compared to the number of
bytes that were requested.

Signed-off-by: Niels de Vos <ndevos@redhat.com>
2020-01-22 16:48:18 +01:00
John Mulligan 224217212d rados: drop extra else + return indent blocks
Clean up if-return-else-return pattern ocurrances in rados package's
ioctx file.

Signed-off-by: John Mulligan <jmulligan@redhat.com>
2020-01-22 10:35:02 +01:00
John Mulligan 18dcd69eb6 rados: drop extra else + return indent blocks
Clean up if-return-else-return pattern ocurrances in rados package's
conn.go file.

Signed-off-by: John Mulligan <jmulligan@redhat.com>
2020-01-22 10:35:02 +01:00
John Mulligan bb375f68ac rados: convert less-than-zero error checks to getRadosError
A number of the error handling checks do not seem to need to check
for specific non-zero error returns so we should be able to
convert to getRadosError rather than a lot of boiler-plate.

Signed-off-by: John Mulligan <jmulligan@redhat.com>
2020-01-22 10:35:02 +01:00
John Mulligan d7bcba78dd rados: use getRadosError where obviously applicable
A number of the functions in rados do not use the simple error
conversion function where is obviously applies. Convert them to use it.

Signed-off-by: John Mulligan <jmulligan@redhat.com>
2020-01-22 10:35:02 +01:00
John Mulligan df46476e21 rados: make get rados error a private function
There is no good reason why the internal error handling support should
be exposed outside the rados package. Make the function lower-cased and
thus private.

Signed-off-by: John Mulligan <jmulligan@redhat.com>
2020-01-22 10:35:02 +01:00
Niels de Vos c412600bfd rbd/options: move tests to "rbd" package
Signed-off-by: Niels de Vos <ndevos@redhat.com>
2020-01-22 10:15:28 +01:00
Niels de Vos a74d34ec0d rbd/options: increase test coverage
Signed-off-by: Niels de Vos <ndevos@redhat.com>
2020-01-22 10:15:28 +01:00
Niels de Vos f0bfebcac5 rbd/tests: force librbd errors by passing a closed image
In order to get a higher test coverage for rbd/rbd.go, there is a need
to trigger errors for the librbd functions. This makes it possible to
test the error path. The new TestClosedImage() function tricks
RbdImage.validate() into accepting an image that is closed, but still
references the closed image.

librbd is expected to return an error when the image is closed. However,
passing a closed image does not result in stable behavior. Sometimes
librbd causes a panic, at other times there will be a hang and the test
will time-out.

The TestClosedImage() function is disabled, it will skip all testing but
remains available so that it could be enabled in the future.

Signed-off-by: Niels de Vos <ndevos@redhat.com>
2020-01-22 09:31:58 +01:00