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>
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>
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>
Replace uses of the deprecated img.Open(...) pattern with the new open
image functions where applicable.
Signed-off-by: John Mulligan <jmulligan@redhat.com>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>