uricp 0.0.15 → 0.0.16

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (41) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +3 -0
  3. data/Gemfile.lock +1 -8
  4. data/Jenkinsfile +27 -0
  5. data/Rakefile +19 -36
  6. data/bionic/Dockerfile +2 -2
  7. data/centos7/Dockerfile +2 -2
  8. data/features/step_definitions/orbit_steps.rb +11 -4
  9. data/lib/segment_upload.rb +20 -22
  10. data/lib/uricp.rb +3 -3
  11. data/lib/uricp/curl_primitives.rb +31 -33
  12. data/lib/uricp/orbit_auth.rb +23 -27
  13. data/lib/uricp/segmenter.rb +12 -16
  14. data/lib/uricp/strategy/cache_common.rb +11 -11
  15. data/lib/uricp/strategy/cached_get.rb +14 -20
  16. data/lib/uricp/strategy/cleaner.rb +2 -8
  17. data/lib/uricp/strategy/common.rb +25 -18
  18. data/lib/uricp/strategy/local_convert.rb +9 -16
  19. data/lib/uricp/strategy/local_link.rb +10 -8
  20. data/lib/uricp/strategy/piped_cache.rb +7 -13
  21. data/lib/uricp/strategy/piped_cache_convert.rb +14 -18
  22. data/lib/uricp/strategy/piped_compress.rb +3 -8
  23. data/lib/uricp/strategy/piped_decompress.rb +7 -11
  24. data/lib/uricp/strategy/piped_local_compress.rb +0 -4
  25. data/lib/uricp/strategy/piped_local_decompress.rb +10 -16
  26. data/lib/uricp/strategy/piped_local_get.rb +0 -5
  27. data/lib/uricp/strategy/piped_local_put.rb +3 -9
  28. data/lib/uricp/strategy/piped_rbd_get.rb +44 -0
  29. data/lib/uricp/strategy/piped_remote_get.rb +20 -20
  30. data/lib/uricp/strategy/rbd_remote_put.rb +36 -0
  31. data/lib/uricp/strategy/rbd_sweeper.rb +22 -0
  32. data/lib/uricp/strategy/remote_put.rb +11 -17
  33. data/lib/uricp/strategy/segmented_remote_put.rb +16 -28
  34. data/lib/uricp/strategy/sweeper.rb +2 -8
  35. data/lib/uricp/uri_strategy.rb +14 -13
  36. data/lib/uricp/version.rb +2 -2
  37. data/trusty/Dockerfile +2 -2
  38. data/uricp.gemspec +0 -1
  39. data/xenial/Dockerfile +2 -2
  40. metadata +7 -20
  41. data/spec/something_spec.rb +0 -5
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 34a83d1c4afd7b3c2b43eeec01b42e06ff8ea55edf8450110ca70363be693d64
4
- data.tar.gz: 64d75d6bc450453f5e2204ab085759a912c265116934be3d7595861f1b5dafb8
3
+ metadata.gz: d7db104674249fa9443799b004c877667e22b142d26a7c7a2220ef668865dfbc
4
+ data.tar.gz: d333e085bb1b666e09883fbd9b9006334d6c15acd17ac781629697bcc0766e5a
5
5
  SHA512:
6
- metadata.gz: f92262c06bf7b035a453fb51358d429e8617487c76df209520abf3d0d322644787e4cbec5d83fdd77fa8a749de41d29e30e1b00248963efd2a26bdfcaf8edc56
7
- data.tar.gz: 1f6533f5334330c3653da3e952715428478f55f1b956d9fdb9b9b9290d7ff0c45391fce3363c132f8dcb85deeb47930ef4dda36cdc1baea9f52a12ae98c4d2f2
6
+ metadata.gz: 7e16104719cca1e2def15b5d9b2d7cbdbcb84b68f7d69a566b8eddd64e699654ea72f066102bb8949e2eb583ffd54aad9549b5094746747382930cf18a1de5a8
7
+ data.tar.gz: b0f839f96f8975ce95121085fdba25ecb1451fc38dbc975de250a6277ffe584a5548f6033138cb46ae8f200a0e6c063e45b2eb25b26ea4e6cefad0d592b91294
@@ -0,0 +1,3 @@
1
+ AllCops:
2
+ TargetRubyVersion: 2.4
3
+
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- uricp (0.0.15)
4
+ uricp (0.0.16)
5
5
  filesize (= 0.0.2)
6
6
  methadone (~> 2.0.0)
7
7
  open4 (~> 1.3.0)
@@ -38,14 +38,8 @@ GEM
38
38
  rake (10.4.2)
39
39
  rdoc (4.2.2)
40
40
  json (~> 1.4)
41
- rspec (2.99.0)
42
- rspec-core (~> 2.99.0)
43
- rspec-expectations (~> 2.99.0)
44
- rspec-mocks (~> 2.99.0)
45
- rspec-core (2.99.2)
46
41
  rspec-expectations (2.99.2)
47
42
  diff-lcs (>= 1.1.3, < 2.0)
48
- rspec-mocks (2.99.4)
49
43
  sendfile (1.2.2)
50
44
 
51
45
  PLATFORMS
@@ -58,7 +52,6 @@ DEPENDENCIES
58
52
  inifile (~> 1.1)
59
53
  rake (~> 10.4.0)
60
54
  rdoc (~> 4.2.0)
61
- rspec (~> 2.99)
62
55
  uricp!
63
56
 
64
57
  BUNDLED WITH
@@ -29,6 +29,11 @@ pipeline {
29
29
  always {
30
30
  sh 'bundle exec rake features:clean'
31
31
  }
32
+ failure {
33
+ mail to: 'sysadmin@brightbox.co.uk',
34
+ subject: "Uricp Tests Failed: ${currentBuild.fullDisplayName}",
35
+ body: "${env.BUILD_URL}"
36
+ }
32
37
  }
33
38
  }
34
39
  stage("Trusty, Ruby 1.9.3") {
@@ -46,6 +51,11 @@ pipeline {
46
51
  always {
47
52
  sh 'bundle exec rake features:clean'
48
53
  }
54
+ failure {
55
+ mail to: 'sysadmin@brightbox.co.uk',
56
+ subject: "Uricp Tests Failed: ${currentBuild.fullDisplayName}",
57
+ body: "${env.BUILD_URL}"
58
+ }
49
59
  }
50
60
  }
51
61
  stage("Xenial, Ruby 2.3.1") {
@@ -63,6 +73,11 @@ pipeline {
63
73
  always {
64
74
  sh 'bundle exec rake features:clean'
65
75
  }
76
+ failure {
77
+ mail to: 'sysadmin@brightbox.co.uk',
78
+ subject: "Uricp Tests Failed: ${currentBuild.fullDisplayName}",
79
+ body: "${env.BUILD_URL}"
80
+ }
66
81
  }
67
82
  }
68
83
  stage("Bionic, Ruby 2.5.1") {
@@ -80,7 +95,19 @@ pipeline {
80
95
  always {
81
96
  sh 'bundle exec rake features:clean'
82
97
  }
98
+ failure {
99
+ mail to: 'sysadmin@brightbox.co.uk',
100
+ subject: "Uricp Tests Failed: ${currentBuild.fullDisplayName}",
101
+ body: "${env.BUILD_URL}"
102
+ }
83
103
  }
84
104
  }
85
105
  }
106
+ post {
107
+ failure {
108
+ mail to: 'sysadmin@brightbox.co.uk',
109
+ subject: "Uricp Tests Failed: ${currentBuild.fullDisplayName}",
110
+ body: "${env.BUILD_URL}"
111
+ }
112
+ }
86
113
  }
data/Rakefile CHANGED
@@ -2,19 +2,19 @@ def dump_load_path
2
2
  puts $LOAD_PATH.join("\n")
3
3
  found = nil
4
4
  $LOAD_PATH.each do |path|
5
- if File.exists?(File.join(path,"rspec"))
6
- puts "Found rspec in #{path}"
7
- if File.exists?(File.join(path,"rspec","core"))
8
- puts "Found core"
9
- if File.exists?(File.join(path,"rspec","core","rake_task"))
10
- puts "Found rake_task"
11
- found = path
12
- else
13
- puts "!! no rake_task"
14
- end
5
+ next unless File.exist?(File.join(path, 'rspec'))
6
+
7
+ puts "Found rspec in #{path}"
8
+ if File.exist?(File.join(path, 'rspec', 'core'))
9
+ puts 'Found core'
10
+ if File.exist?(File.join(path, 'rspec', 'core', 'rake_task'))
11
+ puts 'Found rake_task'
12
+ found = path
15
13
  else
16
- puts "!!! no core"
14
+ puts '!! no rake_task'
17
15
  end
16
+ else
17
+ puts '!!! no core'
18
18
  end
19
19
  end
20
20
  if found.nil?
@@ -26,13 +26,6 @@ end
26
26
  require 'bundler'
27
27
  require 'rake/clean'
28
28
 
29
- begin
30
- require 'rspec/core/rake_task'
31
- rescue LoadError
32
- dump_load_path
33
- raise
34
- end
35
-
36
29
  require 'cucumber'
37
30
  require 'cucumber/rake/task'
38
31
  gem 'rdoc' # we need the installed RDoc gem, not the system one
@@ -42,13 +35,7 @@ include Rake::DSL
42
35
 
43
36
  Bundler::GemHelper.install_tasks
44
37
 
45
-
46
- RSpec::Core::RakeTask.new do |t|
47
- # Put spec opts in a file named .rspec in root
48
- end
49
-
50
-
51
- CUKE_RESULTS = 'results.html'
38
+ CUKE_RESULTS = 'results.html'.freeze
52
39
  CLEAN << CUKE_RESULTS
53
40
  namespace(:features) do
54
41
  Cucumber::Rake::Task.new(:new_qemu) do |t|
@@ -64,11 +51,9 @@ namespace(:features) do
64
51
 
65
52
  task(:clean) do
66
53
  if ENV['ORBIT_USER'] && ENV['ORBIT_KEY']
67
- %w{temp_dlo test_upload}.each do |test_file|
68
- sh "swift --quiet --insecure -A #{ENV['ORBIT_URL'] || "https://orbit.gb1.brightbox.com/v1"} -U #{ENV['ORBIT_USER']} -K #{ENV['ORBIT_KEY']} delete #{test_file}" do |ok, res|
69
- if !ok
70
- puts "Delete failed: #{res.exitstatus}"
71
- end
54
+ %w[temp_dlo test_upload].each do |test_file|
55
+ sh "swift --quiet --insecure -A #{ENV['ORBIT_URL'] || 'https://orbit.gb1.brightbox.com/v1'} -U #{ENV['ORBIT_USER']} -K #{ENV['ORBIT_KEY']} delete #{test_file}" do |ok, res|
56
+ puts "Delete failed: #{res.exitstatus}" unless ok
72
57
  end
73
58
  end
74
59
  end
@@ -76,11 +61,9 @@ namespace(:features) do
76
61
  end
77
62
 
78
63
  Rake::RDocTask.new do |rd|
79
-
80
- rd.main = "README.rdoc"
81
-
82
- rd.rdoc_files.include("README.rdoc","lib/**/*.rb","bin/**/*")
83
- end
64
+ rd.main = 'README.rdoc'
84
65
 
85
- task :default => [:spec,"features:new_qemu"]
66
+ rd.rdoc_files.include('README.rdoc', 'lib/**/*.rb', 'bin/**/*')
67
+ end
86
68
 
69
+ task default: [:spec, 'features:new_qemu']
@@ -13,8 +13,8 @@ RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y -qq \
13
13
  curl \
14
14
  ruby \
15
15
  ruby-dev \
16
- python-swiftclient
16
+ python-swiftclient \
17
+ ruby-bundler
17
18
 
18
19
  RUN echo "gem: --no-ri --no-rdoc" >> "$HOME/.gemrc"
19
- RUN gem install bundler
20
20
 
@@ -8,7 +8,8 @@ RUN yum update -y && yum -y install \
8
8
  git \
9
9
  qemu-img \
10
10
  ruby-devel \
11
- rubygems
11
+ rubygems \
12
+ rubygem-bundler
12
13
 
13
14
  RUN yum -y install python-setuptools && \
14
15
  easy_install pip && \
@@ -16,5 +17,4 @@ RUN yum -y install python-setuptools && \
16
17
  pip install python-swiftclient
17
18
 
18
19
  RUN echo "gem: --no-ri --no-rdoc" >> "$HOME/.gemrc"
19
- RUN gem install bundler
20
20
 
@@ -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)
@@ -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
@@ -7,26 +7,26 @@ require 'uricp/strategy/local_link'
7
7
  require 'uricp/strategy/piped_cache'
8
8
  require 'uricp/strategy/piped_cache_convert'
9
9
  require 'uricp/strategy/piped_local_get'
10
+ require 'uricp/strategy/piped_rbd_get'
10
11
  require 'uricp/strategy/piped_local_put'
11
12
  require 'uricp/strategy/piped_remote_get'
12
13
  require 'uricp/strategy/piped_compress'
13
14
  require 'uricp/strategy/piped_decompress'
14
15
  require 'uricp/strategy/piped_local_decompress'
15
16
  require 'uricp/strategy/piped_local_compress'
17
+ require 'uricp/strategy/rbd_remote_put'
16
18
  require 'uricp/strategy/segmented_remote_put'
17
19
  require 'uricp/strategy/remote_put'
18
20
  require 'uricp/strategy/cached_get'
21
+ require 'uricp/strategy/rbd_sweeper'
19
22
  require 'uricp/strategy/sweeper'
20
23
  require 'uricp/strategy/cleaner'
21
24
  require 'uricp/uri_strategy'
22
25
  require 'uricp/orbit_auth'
23
26
 
24
27
  module Uricp
25
-
26
28
  UnsupportedURLtype = Class.new(ArgumentError)
27
29
  MissingCache = Class.new(ArgumentError)
28
30
  UnsupportedConversion = Class.new(ArgumentError)
29
31
  ConversionRequired = Class.new(ArgumentError)
30
-
31
32
  end
32
-
@@ -1,45 +1,43 @@
1
1
  module Uricp::CurlPrimitives
2
+ attr_reader :options
2
3
 
3
- attr_reader :options
4
+ def from
5
+ options['from_uri']
6
+ end
4
7
 
5
- def from
6
- options['from_uri']
7
- end
8
+ def from=(target)
9
+ options['from_uri'] = target
10
+ end
8
11
 
9
- def from=(target)
10
- options['from_uri'] = target
11
- end
12
+ def to
13
+ options['to_uri']
14
+ end
12
15
 
13
- def to
14
- options['to_uri']
15
- end
16
+ def to=(target)
17
+ options['to_uri'] = target
18
+ end
16
19
 
17
- def to=(target)
18
- options['to_uri'] = target
19
- end
20
-
21
- def curl_command
22
- "curl --fail --silent"
23
- end
20
+ def curl_command
21
+ 'curl --fail --silent'
22
+ end
24
23
 
25
- def authentication
26
- "-H X-Auth-Token:#{options['authenticator'].call}" if http_authentication?
27
- end
24
+ def authentication
25
+ "-H X-Auth-Token:#{options['authenticator'].call}" if http_authentication?
26
+ end
28
27
 
29
- def http_authentication?
30
- options['authenticator']
31
- end
28
+ def http_authentication?
29
+ options['authenticator']
30
+ end
32
31
 
33
- def curl_upload_from(source, destination = to)
34
- "#{curl_command} #{authentication} -T #{source} #{destination.to_s};"
35
- end
32
+ def curl_upload_from(source, destination = to)
33
+ "#{curl_command} #{authentication} -T #{source} #{destination};"
34
+ end
36
35
 
37
- def curl_download_to_pipe
38
- "#{curl_command} #{authentication} #{from.to_s} |"
39
- end
36
+ def curl_download_to_pipe
37
+ "#{curl_command} #{authentication} #{from} |"
38
+ end
40
39
 
41
- def curl_manifest(object_manifest, destination = to)
42
- "#{curl_command} #{authentication} -X PUT -H 'X-Object-Manifest: #{object_manifest}' #{destination.to_s} --data-binary ''"
43
- end
44
-
40
+ def curl_manifest(object_manifest, destination = to)
41
+ "#{curl_command} #{authentication} -X PUT -H 'X-Object-Manifest: #{object_manifest}' #{destination} --data-binary ''"
42
+ end
45
43
  end
@@ -1,8 +1,6 @@
1
1
  require 'open-uri'
2
2
  module Uricp
3
-
4
3
  class OrbitAuth
5
-
6
4
  AuthenticationFailure = Class.new(ArgumentError)
7
5
 
8
6
  def initialize(auth_uri, auth_id, auth_key)
@@ -14,9 +12,9 @@ module Uricp
14
12
  def storage_url
15
13
  @storage_url ||
16
14
  begin
17
- authenticate
18
- @storage_url
19
- end
15
+ authenticate
16
+ @storage_url
17
+ end
20
18
  end
21
19
 
22
20
  def token
@@ -26,27 +24,27 @@ module Uricp
26
24
 
27
25
  def self.validate_options(options)
28
26
  if options['auth-token'] && (options['auth-key'] || options['auth-user'])
29
- raise ::OptionParser::NeedlessArgument,
30
- "use either key based or token based authentication"
27
+ raise ::OptionParser::NeedlessArgument,
28
+ 'use either key based or token based authentication'
31
29
  end
32
30
  if options['auth-key'].nil? ^ options['auth-user'].nil?
33
- raise ::OptionParser::MissingArgument,
34
- "'auth-user' requires 'auth-key'"
31
+ raise ::OptionParser::MissingArgument,
32
+ "'auth-user' requires 'auth-key'"
35
33
  end
36
34
  if (options['auth-token'] || options['auth-user']) && options['auth_uri'].nil?
37
- raise ::OptionParser::NeedlessArgument,
38
- "authentication is for http uris only"
35
+ raise ::OptionParser::NeedlessArgument,
36
+ 'authentication is for http uris only'
39
37
  end
40
38
  end
41
39
 
42
40
  def self.add_auth_token(options)
43
41
  if options['auth-user']
44
- orbit_credentials = self.new(options['auth_uri'],
45
- options['auth-user'], options['auth-key'])
46
- options['authenticator'] = orbit_credentials.method(:token)
42
+ orbit_credentials = new(options['auth_uri'],
43
+ options['auth-user'], options['auth-key'])
44
+ options['authenticator'] = orbit_credentials.method(:token)
47
45
  elsif options['auth-token']
48
46
  orbit_token = options['auth-token']
49
- options['authenticator'] = lambda { orbit_token }
47
+ options['authenticator'] = -> { orbit_token }
50
48
  end
51
49
  options.delete('auth-key')
52
50
  options.delete('auth-user')
@@ -54,29 +52,27 @@ module Uricp
54
52
  end
55
53
 
56
54
  def self.add_auth_to_optionparser(app)
57
- app.on("--auth-token AUTH_TOKEN",
58
- "Use AUTH_TOKEN for non-local requests")
59
- app.on("--auth-user AUTH_USER",
60
- "Use AUTH_USER for authentication")
61
- app.on("--auth-key AUTH_KEY",
62
- "Use AUTH_KEY for authentication")
55
+ app.on('--auth-token AUTH_TOKEN',
56
+ 'Use AUTH_TOKEN for non-local requests')
57
+ app.on('--auth-user AUTH_USER',
58
+ 'Use AUTH_USER for authentication')
59
+ app.on('--auth-key AUTH_KEY',
60
+ 'Use AUTH_KEY for authentication')
63
61
  end
64
62
 
65
- private
63
+ private
66
64
 
67
65
  def authenticate
68
66
  @auth_uri.open(
69
67
  'X-Auth-User' => @auth_id,
70
- 'X-Auth-Key' => @auth_key,
71
- 'Range' => 'bytes=0-0'
68
+ 'X-Auth-Key' => @auth_key,
69
+ 'Range' => 'bytes=0-0'
72
70
  ) do |uri|
73
71
  @storage_url = uri.meta['x-storage-url']
74
- @token = uri.meta['x-auth-token']
72
+ @token = uri.meta['x-auth-token']
75
73
  end
76
74
  rescue OpenURI::HTTPError => e
77
75
  raise AuthenticationFailure, "Cannot authenticate against #{@auth_uri}"
78
76
  end
79
-
80
77
  end
81
-
82
78
  end