uricp 0.0.15 → 0.0.20

Sign up to get free protection for your applications and to get access to all the features.
Files changed (57) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +3 -0
  3. data/Gemfile.lock +16 -21
  4. data/Jenkinsfile +90 -33
  5. data/Rakefile +24 -36
  6. data/almalinux8/Dockerfile +26 -0
  7. data/bin/uricp +25 -11
  8. data/bionic/Dockerfile +4 -3
  9. data/centos7/Dockerfile +17 -12
  10. data/cucumber.yml +1 -0
  11. data/features/check_uri_path.feature +14 -0
  12. data/features/rbd_access.feature +226 -0
  13. data/features/step_definitions/orbit_steps.rb +11 -4
  14. data/features/step_definitions/rbd_steps.rb +8 -0
  15. data/features/step_definitions/uricp_steps.rb +8 -4
  16. data/focal/Dockerfile +28 -0
  17. data/lib/segment_upload.rb +20 -22
  18. data/lib/uricp/curl_primitives.rb +31 -33
  19. data/lib/uricp/orbit_auth.rb +23 -27
  20. data/lib/uricp/segmenter.rb +12 -16
  21. data/lib/uricp/strategy/cache_common.rb +30 -12
  22. data/lib/uricp/strategy/cached_get.rb +19 -22
  23. data/lib/uricp/strategy/cleaner.rb +2 -8
  24. data/lib/uricp/strategy/common.rb +76 -18
  25. data/lib/uricp/strategy/local_convert.rb +10 -17
  26. data/lib/uricp/strategy/local_link.rb +10 -8
  27. data/lib/uricp/strategy/piped_cache.rb +11 -16
  28. data/lib/uricp/strategy/piped_cache_convert.rb +14 -18
  29. data/lib/uricp/strategy/piped_compress.rb +3 -8
  30. data/lib/uricp/strategy/piped_decompress.rb +7 -11
  31. data/lib/uricp/strategy/piped_local_compress.rb +0 -4
  32. data/lib/uricp/strategy/piped_local_decompress.rb +10 -16
  33. data/lib/uricp/strategy/piped_local_get.rb +0 -5
  34. data/lib/uricp/strategy/piped_local_put.rb +3 -9
  35. data/lib/uricp/strategy/piped_rbd_get.rb +30 -0
  36. data/lib/uricp/strategy/piped_remote_get.rb +20 -20
  37. data/lib/uricp/strategy/rbd_cache_base_snap.rb +27 -0
  38. data/lib/uricp/strategy/rbd_cache_check.rb +42 -0
  39. data/lib/uricp/strategy/rbd_cache_clone.rb +40 -0
  40. data/lib/uricp/strategy/rbd_cache_upload.rb +40 -0
  41. data/lib/uricp/strategy/rbd_cached_get.rb +36 -0
  42. data/lib/uricp/strategy/rbd_cached_put.rb +33 -0
  43. data/lib/uricp/strategy/rbd_flattener.rb +23 -0
  44. data/lib/uricp/strategy/rbd_put.rb +38 -0
  45. data/lib/uricp/strategy/rbd_snap.rb +56 -0
  46. data/lib/uricp/strategy/rbd_sweeper.rb +23 -0
  47. data/lib/uricp/strategy/remote_put.rb +11 -17
  48. data/lib/uricp/strategy/segmented_remote_put.rb +16 -28
  49. data/lib/uricp/strategy/sweeper.rb +2 -8
  50. data/lib/uricp/uri_strategy.rb +22 -13
  51. data/lib/uricp/version.rb +4 -2
  52. data/lib/uricp.rb +27 -19
  53. data/uricp.gemspec +3 -3
  54. data/xenial/Dockerfile +4 -3
  55. metadata +41 -25
  56. data/spec/something_spec.rb +0 -5
  57. data/trusty/Dockerfile +0 -20
data/bionic/Dockerfile CHANGED
@@ -1,6 +1,8 @@
1
1
  FROM ubuntu:bionic
2
2
  MAINTAINER support@brightbox.co.uk
3
3
 
4
+ RUN echo "gem: --no-ri --no-rdoc" >> "$HOME/.gemrc"
5
+
4
6
  RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y -qq software-properties-common
5
7
 
6
8
  #RUN apt-add-repository ppa:brightbox/ruby-ng
@@ -13,8 +15,7 @@ RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y -qq \
13
15
  curl \
14
16
  ruby \
15
17
  ruby-dev \
16
- python-swiftclient
18
+ python-swiftclient \
19
+ ruby-bundler
17
20
 
18
- RUN echo "gem: --no-ri --no-rdoc" >> "$HOME/.gemrc"
19
- RUN gem install bundler
20
21
 
data/centos7/Dockerfile CHANGED
@@ -1,20 +1,25 @@
1
1
  FROM centos:7
2
2
  MAINTAINER support@brightbox.co.uk
3
3
 
4
- RUN yum update -y && yum -y install \
5
- epel-release \
4
+ RUN echo "gem: --no-ri --no-rdoc" >> "$HOME/.gemrc"
5
+ RUN yum update -y
6
+ RUN yum -y install \
7
+ centos-release-openstack-train \
8
+ epel-release
9
+ RUN yum -y install \
6
10
  gcc \
7
11
  make \
8
12
  git \
9
13
  qemu-img \
14
+ lz4 \
10
15
  ruby-devel \
11
- rubygems
12
-
13
- RUN yum -y install python-setuptools && \
14
- easy_install pip && \
15
- pip install --upgrade setuptools && \
16
- pip install python-swiftclient
17
-
18
- RUN echo "gem: --no-ri --no-rdoc" >> "$HOME/.gemrc"
19
- RUN gem install bundler
20
-
16
+ rubygems \
17
+ rubygem-bundler \
18
+ ceph-common \
19
+ python-swiftclient
20
+ RUN mkdir -p /etc/ceph
21
+ ARG RBD_USR=libvirt
22
+ ARG RBD_PSW
23
+ ARG CEPH_MON
24
+ RUN echo -e "[client.$RBD_USR]\nkey = $RBD_PSW\n" > /etc/ceph/ceph.client.$RBD_USR.keyring
25
+ RUN echo -e "[global]\nmon_host = $CEPH_MON\n" > /etc/ceph/ceph.conf
data/cucumber.yml CHANGED
@@ -1,3 +1,4 @@
1
1
  default: --profile new-qemu-image
2
2
  new-qemu-image: --tags ~@old-qemu-image
3
3
  old-qemu-image: --tags ~@new-qemu-image
4
+ rbd: --tags @rbd
@@ -0,0 +1,14 @@
1
+ Feature: Check URI paths
2
+ In order to ensure reliable uricp usage
3
+ As a command line user
4
+ I want to reject badly formed URIs
5
+
6
+ Scenario: source URI is incorrectly formatted
7
+ When I run `uricp --dry-run file:fred rbd:///servers/fred`
8
+ Then the exit status should not be 0
9
+ And the stderr should contain "invalid argument: 'from_uri' has missing path"
10
+
11
+ Scenario: target URI is incorrectly formatted
12
+ When I run `uricp --dry-run file:///fred rbd:servers/fred`
13
+ Then the exit status should not be 0
14
+ And the stderr should contain "invalid argument: 'to_uri' has missing path"
@@ -0,0 +1,226 @@
1
+ @rbd
2
+ Feature: Manipulate file images in ceph
3
+ in order to manipulate file images in ceph
4
+ as a command line user
5
+ I want to retrieve the uri via an optional cache and copy correctly to target in the right format
6
+
7
+ background:
8
+ given an empty directory named "/tmp/uricp"
9
+ and the default aruba timeout is 15 seconds
10
+
11
+ Scenario: HTTP URI qcow2 to rbd - no cache
12
+ When I successfully run `uricp --dry-run http://orbit.brightbox.com/v1/acc-tqs4c/downloads/freedos.qcow2 rbd:///servers/srv-testy`
13
+ And the output should contain:
14
+ """
15
+ rbd import --no-progress --id libvirt - 'servers/srv-testy'
16
+ """
17
+
18
+ Scenario: HTTP URI qcow2 to raw via unpopulated rbd cache
19
+ Given a correctly initialised cache at "/tmp/uricp"
20
+ When I successfully run `uricp --dry-run --target-format=raw --cache=/tmp/uricp http://orbit.brightbox.com/v1/acc-tqs4c/downloads/freedos.qcow2 rbd:///servers/srv-testy`
21
+ And the output should contain:
22
+ """
23
+ rbd import --no-progress --id libvirt - 'servers/freedos.qcow2'
24
+ """
25
+ And the output should contain:
26
+ """
27
+ rbd snap create --id libvirt 'servers/freedos.qcow2@base'
28
+ """
29
+ And the output should contain:
30
+ """
31
+ rbd snap protect --id libvirt 'servers/freedos.qcow2@base'
32
+ """
33
+ And the output should contain:
34
+ """
35
+ rbd clone --no-progress --id libvirt 'servers/freedos.qcow2@base' 'servers/srv-testy'
36
+ """
37
+
38
+ Scenario: HTTP URI from file cache via unpopulated rbd cache
39
+ Given a correctly initialised cache at "/tmp/uricp"
40
+ And a 102400 byte file named "/tmp/uricp/cache/freedos.qcow2"
41
+ When I successfully run `uricp --dry-run --target-format=raw --cache=/tmp/uricp http://orbit.brightbox.com/v1/acc-tqs4c/downloads/freedos.qcow2 rbd:///servers/srv-testy`
42
+ And the output should contain:
43
+ """
44
+ rbd import --no-progress --id libvirt '/tmp/uricp/cache/freedos.qcow2' 'servers/freedos.qcow2'
45
+ """
46
+ And the output should contain:
47
+ """
48
+ rbd snap create --id libvirt 'servers/freedos.qcow2@base'
49
+ """
50
+ And the output should contain:
51
+ """
52
+ rbd snap protect --id libvirt 'servers/freedos.qcow2@base'
53
+ """
54
+ And the output should contain:
55
+ """
56
+ rbd clone --no-progress --id libvirt 'servers/freedos.qcow2@base' 'servers/srv-testy'
57
+ """
58
+
59
+ Scenario: HTTP URI to rbd via populated caches
60
+ Given a correctly initialised cache at "/tmp/uricp"
61
+ When I successfully run `uricp --dry-run --dry-cache --target-format=raw --cache=/tmp/uricp http://orbit.brightbox.com/v1/acc-tqs4c/downloads/freedos.qcow2 rbd:///servers/srv-testy`
62
+ And the output should not contain:
63
+ """
64
+ snap create
65
+ """
66
+ And the output should contain:
67
+ """
68
+ rbd clone --no-progress --id libvirt 'servers/freedos.qcow2@base' 'servers/srv-testy'
69
+ """
70
+
71
+ Scenario: rbd to rbd - no cache
72
+ Given a correctly initialised cache at "/tmp/uricp"
73
+ When I successfully run `uricp --dry-run rbd:///servers/img-testy rbd:///servers/srv-testy`
74
+ And the output should contain:
75
+ """
76
+ rbd snap create --id libvirt 'servers/img-testy@uricp_snap'
77
+ """
78
+ And the output should contain:
79
+ """
80
+ rbd snap protect --id libvirt 'servers/img-testy@uricp_snap'
81
+ """
82
+ And the output should contain:
83
+ """
84
+ rbd snap unprotect --id libvirt 'servers/img-testy@uricp_snap'
85
+ """
86
+ And the output should contain:
87
+ """
88
+ rbd snap rm --id libvirt 'servers/img-testy@uricp_snap';
89
+ """
90
+ And the output should contain:
91
+ """
92
+ rbd clone --no-progress --id libvirt 'servers/img-testy@uricp_snap' 'servers/srv-testy'
93
+ """
94
+
95
+ Scenario: rbd to rbd - unpopulated cache
96
+ Given a correctly initialised cache at "/tmp/uricp"
97
+ When I successfully run `uricp --dry-run --cache=/tmp/uricp rbd:///servers/srv-testy rbd:///servers/img-testy`
98
+ And the output should contain:
99
+ """
100
+ rbd snap create --id libvirt 'servers/srv-testy@uricp_snap'
101
+ """
102
+ And the output should contain:
103
+ """
104
+ rbd snap protect --id libvirt 'servers/srv-testy@uricp_snap'
105
+ """
106
+ And the output should contain:
107
+ """
108
+ rbd snap unprotect --id libvirt 'servers/srv-testy@uricp_snap'
109
+ """
110
+ And the output should contain:
111
+ """
112
+ rbd snap rm --id libvirt 'servers/srv-testy@uricp_snap';
113
+ """
114
+ And the output should not contain:
115
+ """
116
+ rbd export --no-progress --id libvirt 'servers/srv-testy@uricp_snap' -
117
+ """
118
+ And the output should contain:
119
+ """
120
+ rbd clone --no-progress --id libvirt 'servers/srv-testy@uricp_snap' 'servers/img-testy'
121
+ """
122
+ And the output should not contain:
123
+ """
124
+ rbd export --no-progress --id libvirt 'servers/img-testy@base' -
125
+ """
126
+ And the output should contain:
127
+ """
128
+ rbd snap create --id libvirt 'servers/img-testy@base'
129
+ """
130
+ And the output should contain:
131
+ """
132
+ rbd snap protect --id libvirt 'servers/img-testy@base'
133
+ """
134
+ And the output should contain:
135
+ """
136
+ rbd flatten --id libvirt --no-progress 'servers/img-testy'
137
+ """
138
+
139
+ Scenario: rbd to rbd - populated cache
140
+ Given a correctly initialised cache at "/tmp/uricp"
141
+ When I successfully run `uricp --dry-run --dry-cache --cache=/tmp/uricp rbd:///servers/img-testy rbd:///servers/srv-testy`
142
+ And the output should not contain:
143
+ """
144
+ snap create
145
+ """
146
+ And the output should contain:
147
+ """
148
+ rbd clone --no-progress --id libvirt 'servers/img-testy@base' 'servers/srv-testy'
149
+ """
150
+
151
+ Scenario: RBD export.
152
+ Given a correctly initialised cache at "/tmp/uricp"
153
+ When I successfully run `uricp --dry-run --compress rbd:///servers/srv-testy file:///tmp/img-testy`
154
+ And the output should contain:
155
+ """
156
+ rbd snap create --id libvirt 'servers/srv-testy@uricp_snap'
157
+ """
158
+ And the output should contain:
159
+ """
160
+ rbd snap protect --id libvirt 'servers/srv-testy@uricp_snap'
161
+ """
162
+ And the output should contain:
163
+ """
164
+ rbd snap unprotect --id libvirt 'servers/srv-testy@uricp_snap'
165
+ """
166
+ And the output should contain:
167
+ """
168
+ rbd snap rm --id libvirt 'servers/srv-testy@uricp_snap';
169
+ """
170
+ And the output should contain:
171
+ """
172
+ rbd export --no-progress --id libvirt 'servers/srv-testy@uricp_snap' -
173
+ """
174
+
175
+ Scenario: RBD export with cacheing - populated cache
176
+ Given a correctly initialised cache at "/tmp/uricp"
177
+ When I run `uricp --dry-run --dry-cache --compress --cache=/tmp/uricp rbd:///servers/srv-testy file:///tmp/img-testy`
178
+ Then the exit status should be 70
179
+ And the output should contain:
180
+ """
181
+ Unsupported transfer
182
+ """
183
+
184
+ Scenario: RBD export with cacheing - empty cache
185
+ Given a correctly initialised cache at "/tmp/uricp"
186
+ When I successfully run `uricp --dry-run --compress --cache=/tmp/uricp rbd:///servers/srv-testy file:///tmp/img-testy`
187
+ And the output should contain:
188
+ """
189
+ rbd snap create --id libvirt 'servers/srv-testy@uricp_snap'
190
+ """
191
+ And the output should contain:
192
+ """
193
+ rbd snap protect --id libvirt 'servers/srv-testy@uricp_snap'
194
+ """
195
+ And the output should contain:
196
+ """
197
+ rbd snap unprotect --id libvirt 'servers/srv-testy@uricp_snap'
198
+ """
199
+ And the output should contain:
200
+ """
201
+ rbd snap rm --id libvirt 'servers/srv-testy@uricp_snap';
202
+ """
203
+ And the output should not contain:
204
+ """
205
+ rbd export --no-progress --id libvirt 'servers/srv-testy@uricp_snap' -
206
+ """
207
+ And the output should contain:
208
+ """
209
+ rbd clone --no-progress --id libvirt 'servers/srv-testy@uricp_snap' 'servers/img-testy'
210
+ """
211
+ And the output should contain:
212
+ """
213
+ rbd export --no-progress --id libvirt 'servers/img-testy@base' -
214
+ """
215
+ And the output should contain:
216
+ """
217
+ rbd snap create --id libvirt 'servers/img-testy@base'
218
+ """
219
+ And the output should contain:
220
+ """
221
+ rbd snap protect --id libvirt 'servers/img-testy@base'
222
+ """
223
+ And the output should contain:
224
+ """
225
+ rbd flatten --id libvirt --no-progress 'servers/img-testy'
226
+ """
@@ -18,12 +18,19 @@ def fetch_orbit_token
18
18
  @current_url_target = ENV['ORBIT_URL'] || 'https://orbit.brightbox.com/v1'
19
19
  cmd = "curl -I #{@current_url_target} -H 'X-Auth-User: #{@clientid}' -H 'X-Auth-Key: #{@key}'"
20
20
  run_simple(unescape(cmd))
21
- stdout_from(cmd).each_line do |line|
21
+ output = stdout_from(cmd)
22
+ output.each_line do |line|
22
23
  key, value = line.strip.split(/\s*:\s*/,2)
23
- @current_auth_token = value if key == 'X-Auth-Token'
24
- @current_storage_url = value if key == 'X-Storage-Url'
24
+ case key.to_s.downcase
25
+ when 'x-auth-token'
26
+ @current_auth_token = value
27
+ when 'x-storage-url'
28
+ @current_storage_url = value
29
+ end
30
+ end
31
+ unless @current_auth_token && @current_storage_url
32
+ raise(RuntimeError, "Credentials not accepted. Can't obtain auth token for tests.\n#{output}")
25
33
  end
26
- raise(RuntimeError, "Credentials not accepted. Can't obtain auth token for tests.") unless @current_auth_token && @current_storage_url
27
34
  end
28
35
 
29
36
  def create_download_file(filetype, name, container)
@@ -0,0 +1,8 @@
1
+ Then(/^a ceph entry named "(.*?)" should exist$/) do |arg1|
2
+ pending # express the regexp above with the code you wish you had
3
+ end
4
+
5
+ Then(/^a ceph snapshot named "(.*?)" should exist$/) do |arg1|
6
+ pending # express the regexp above with the code you wish you had
7
+ end
8
+
@@ -1,8 +1,10 @@
1
1
  Then(/^the file named "(.*?)" should have a file format of "(.*?)"$/) do |filename, format|
2
2
  case format
3
3
  when 'lz4'
4
- assert_exact_output([0x184D2204].pack('V'),
5
- File.open(filename, 'rb') {|f| f.read(4) }.to_s)
4
+ assert_exact_output(
5
+ [0x184D2204].pack('V'),
6
+ File.open(filename, 'rb') { |f| f.read(4) } || String.new
7
+ )
6
8
  when 'qcow2v3', 'qcow3'
7
9
  steps %{
8
10
  When I successfully run `qemu-img info #{filename}`
@@ -10,8 +12,10 @@ Then(/^the file named "(.*?)" should have a file format of "(.*?)"$/) do |filena
10
12
  And the output from "qemu-img info #{filename}" should contain "compat: 1.1"
11
13
  }
12
14
  else
13
- assert_no_partial_output([0x184D2204].pack('V'),
14
- File.open(filename, 'rb') {|f| f.read(4) }.to_s)
15
+ assert_no_partial_output(
16
+ [0x184D2204].pack('V'),
17
+ File.open(filename, 'rb') { |f| f.read(4) } || String.new
18
+ )
15
19
  steps(%{
16
20
  When I successfully run `qemu-img info #{filename}`
17
21
  Then the output from "qemu-img info #{filename}" should contain "file format: #{format}"
data/focal/Dockerfile ADDED
@@ -0,0 +1,28 @@
1
+ FROM ubuntu:focal
2
+ MAINTAINER support@brightbox.co.uk
3
+
4
+ RUN echo "gem: --no-ri --no-rdoc" >> "$HOME/.gemrc"
5
+
6
+ RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y -qq software-properties-common
7
+
8
+ #RUN apt-add-repository ppa:brightbox/ruby-ng
9
+
10
+ RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y -qq \
11
+ build-essential \
12
+ git \
13
+ qemu-utils \
14
+ liblz4-tool \
15
+ curl \
16
+ ruby \
17
+ ruby-dev \
18
+ python3-swiftclient \
19
+ ruby-bundler \
20
+ ceph-common
21
+
22
+ RUN gem install bundler -v '~> 1.7'
23
+ RUN mkdir -p /etc/ceph
24
+ ARG RBD_USR=libvirt
25
+ ARG RBD_PSW
26
+ ARG CEPH_MON
27
+ RUN /bin/echo -e "[client.$RBD_USR]\nkey = $RBD_PSW\n" > /etc/ceph/ceph.client.$RBD_USR.keyring
28
+ RUN /bin/echo -e "[global]\nmon_host = $CEPH_MON\n" > /etc/ceph/ceph.conf
@@ -1,36 +1,34 @@
1
- require "uricp/version"
2
- require "uricp/curl_primitives"
3
- require "uricp/orbit_auth"
4
- require "uricp/segmenter"
1
+ require 'uricp/version'
2
+ require 'uricp/curl_primitives'
3
+ require 'uricp/orbit_auth'
4
+ require 'uricp/segmenter'
5
5
 
6
6
  module Uricp
7
-
8
7
  UnsupportedURLtype = Class.new(ArgumentError)
9
-
10
8
  end
11
9
 
12
- #Monkey patch a copy_stream facility in using 'sendfile'
10
+ # Monkey patch a copy_stream facility in using 'sendfile'
13
11
  unless IO.respond_to? :copy_stream
14
12
  require 'sendfile'
15
13
 
16
- def IO.copy_stream(src, dst, copy_length=nil, offset=nil)
17
- unless src.stat.pipe?
18
- current_pos = src.pos
19
- count = dst.sendfile(src, offset || current_pos, copy_length)
20
- src.seek(count, IO::SEEK_CUR)
21
- return count
22
- else
14
+ def IO.copy_stream(src, dst, copy_length = nil, offset = nil)
15
+ if src.stat.pipe?
23
16
  amount = copy_length.to_i
24
17
  buf_size = [amount, 2**16].min
25
- buffer=""
26
- while amount > 0 do
27
- src.read(buf_size, buffer)
28
- amount_read = buffer.length
29
- dst.write(buffer)
30
- amount -= amount_read
31
- break if src.eof?
18
+ buffer = ''
19
+ while amount > 0
20
+ src.read(buf_size, buffer)
21
+ amount_read = buffer.length
22
+ dst.write(buffer)
23
+ amount -= amount_read
24
+ break if src.eof?
32
25
  end
33
- return copy_length.to_i - amount
26
+ copy_length.to_i - amount
27
+ else
28
+ current_pos = src.pos
29
+ count = dst.sendfile(src, offset || current_pos, copy_length)
30
+ src.seek(count, IO::SEEK_CUR)
31
+ count
34
32
  end
35
33
  rescue EOFError
36
34
  0