uricp 0.0.10 → 0.0.11

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 37bb516638075a8d54d891f2d1049e5abe1197e4
4
- data.tar.gz: 31d80850767fad7b32d5f9282031e6acdaa60b3f
3
+ metadata.gz: 054b98cbf8e67b76cc3e2b552677573fe5b5cbea
4
+ data.tar.gz: 85337e7757d5d33a03c72860770dbb10eea58bd8
5
5
  SHA512:
6
- metadata.gz: d137a74223d94356968ddaba23d2d855d0127fbea9f19fc2cee96a05c37f7900d3fe433fcccb3b6e12608d252174b9848fd882548319e794995c8828804bec2a
7
- data.tar.gz: c49e4055788800047b66611d56de7fc0270e96bb88f2fccd0e7b0da7f329e739ca7daef0b672d44df94c3f816a9158204589c4f403f0e018e771c210193a90df
6
+ metadata.gz: 3b774aecb700c7e3b290e2fd3a7140baafe012b188a0f5c9d2166539af35c6f79e6f96cfb92056c1858c0e25e465859492e94e2c5317bfa68d7d5b8c210bca9f
7
+ data.tar.gz: f4bf7e1dc1c44c0a712720d54e0f86d4ab95f332b3cdfb20c0dcd431d5d65edfbc674921bba6debdcf8290bc0491ee1476a0686456cb0177d936ba141aed9836
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- uricp (0.0.10)
4
+ uricp (0.0.11)
5
5
  filesize (= 0.0.2)
6
6
  methadone (~> 1.8.0)
7
7
  open4 (~> 1.3.0)
data/bin/uricp CHANGED
@@ -18,6 +18,9 @@ class App
18
18
  if options['segment-size']
19
19
  options['segment-size'] = Filesize.from(options['segment-size'])
20
20
  end
21
+ if options['max-cache']
22
+ options['max-cache'] = Filesize.from(options['max-cache'])
23
+ end
21
24
  validate_options
22
25
  Uricp::OrbitAuth.validate_options(options)
23
26
  set_auth_env
@@ -53,9 +56,15 @@ class App
53
56
  end
54
57
 
55
58
  def self.validate_options
56
- if options['target-format'] && !options['cache']
57
- raise ::OptionParser::MissingArgument,
58
- "'target-format' requires 'cache' option"
59
+ unless options['cache']
60
+ case
61
+ when options['target-format']
62
+ raise ::OptionParser::MissingArgument,
63
+ "'target-format' requires 'cache' option"
64
+ when options['max-cache']
65
+ raise ::OptionParser::MissingArgument,
66
+ "'max-cache' requires 'cache' option"
67
+ end
59
68
  end
60
69
  end
61
70
 
@@ -90,6 +99,8 @@ class App
90
99
  Uricp::OrbitAuth.add_auth_to_optionparser(self)
91
100
  on("--cache CACHE_ROOT",
92
101
  "Root directory of cache area")
102
+ on("--max-cache MAX_CACHE_SIZE",
103
+ "Maximum size of cached file in [GMk][i]B.")
93
104
  on("--target-format FORMAT", [:qcow2, :raw, :qcow3, :qcow2v3],
94
105
  "Image format of target", "[qcow2, raw, qcow3, qcow2v3]")
95
106
  on("--segment-size SEGMENT_SIZE",
@@ -45,6 +45,21 @@ Feature: Authenticated download of images from orbit
45
45
  And a file named "/tmp/uricp/cache/img-qcow2" should exist
46
46
  And the file named "/tmp/uricp/cache/img-qcow2" should have a file format of "qcow2v3"
47
47
 
48
+ Scenario: qcow download convert to raw, cache, within size
49
+ Given a correctly initialised cache at "/tmp/uricp"
50
+ When I retrieve "img-qcow2" with options "--target-format=raw --cache=/tmp/uricp --max-cache 10MB" from container "test" into "file:///tmp/uricp/srv-testq"
51
+ Then a file named "/tmp/uricp/srv-testq" should exist
52
+ And the file named "/tmp/uricp/srv-testq" should have a file format of "raw"
53
+ And a file named "/tmp/uricp/cache/img-qcow2" should exist
54
+ And the file named "/tmp/uricp/cache/img-qcow2" should have a file format of "qcow2v3"
55
+
56
+ Scenario: qcow download convert to raw, cache, size limited
57
+ Given a correctly initialised cache at "/tmp/uricp"
58
+ When I retrieve "img-qcow2" with options "--target-format=raw --cache=/tmp/uricp --max-cache 100kB" from container "test" into "file:///tmp/uricp/srv-testj"
59
+ Then a file named "/tmp/uricp/srv-testj" should exist
60
+ And the file named "/tmp/uricp/srv-testj" should have a file format of "raw"
61
+ And a file named "/tmp/uricp/cache/img-qcow2" should not exist
62
+
48
63
  Scenario: qcow download convert to qcow2, cache
49
64
  Given a correctly initialised cache at "/tmp/uricp"
50
65
  When I retrieve "img-qcow2" with options "--target-format=qcow2 --cache=/tmp/uricp" from container "test" into "file:///tmp/uricp/srv-test5"
@@ -88,6 +103,21 @@ Feature: Authenticated download of images from orbit
88
103
  And a file named "/tmp/uricp/cache/img-lz4cy" should exist
89
104
  And the file named "/tmp/uricp/cache/img-lz4cy" should have a file format of "lz4"
90
105
 
106
+ Scenario: lz4 download convert to raw, cache, size limited
107
+ Given a correctly initialised cache at "/tmp/uricp"
108
+ When I retrieve "img-lz4cy" with options "--target-format=raw --cache=/tmp/uricp --max-cache 2MB" from container "test" into "file:///tmp/uricp/srv-testf"
109
+ Then a file named "/tmp/uricp/srv-testf" should exist
110
+ And the file named "/tmp/uricp/srv-testf" should have a file format of "raw"
111
+ And a file named "/tmp/uricp/cache/img-lz4cy" should not exist
112
+
113
+ Scenario: lz4 download convert to raw, cache, within size
114
+ Given a correctly initialised cache at "/tmp/uricp"
115
+ When I retrieve "img-lz4cy" with options "--target-format=raw --cache=/tmp/uricp --max-cache 10MB" from container "test" into "file:///tmp/uricp/srv-test9"
116
+ Then a file named "/tmp/uricp/srv-test9" should exist
117
+ And the file named "/tmp/uricp/srv-test9" should have a file format of "raw"
118
+ And a file named "/tmp/uricp/cache/img-lz4cy" should exist
119
+ And the file named "/tmp/uricp/cache/img-lz4cy" should have a file format of "lz4"
120
+
91
121
  Scenario: lz4 download convert to raw, from cache
92
122
  Given a correctly initialised cache at "/tmp/uricp"
93
123
  And a cache of "img-lz4cy" from container "test" at "/tmp/uricp"
@@ -20,6 +20,13 @@ Feature: Download Public VM images
20
20
  And a file named "/tmp/uricp/cache/freedos.qcow2" should exist
21
21
  And the file named "/tmp/uricp/cache/freedos.qcow2" should have a file format of "qcow2"
22
22
 
23
+ Scenario: HTTP URI qcow2 via cache - size limited
24
+ Given a correctly initialised cache at "/tmp/uricp"
25
+ When I successfully run `uricp --cache=/tmp/uricp --max-cache=8MB http://orbit.brightbox.com/v1/acc-tqs4c/downloads/freedos.qcow2 file:///tmp/uricp/srv-testy`
26
+ Then a file named "/tmp/uricp/srv-testy" should exist
27
+ And the file named "/tmp/uricp/srv-testy" should have a file format of "qcow2"
28
+ And a file named "/tmp/uricp/cache/freedos.qcow2" should not exist
29
+
23
30
  Scenario: HTTP URI qcow2 to qcow2 via cache
24
31
  Given a correctly initialised cache at "/tmp/uricp"
25
32
  When I successfully run `uricp --target-format=qcow2 --cache=/tmp/uricp http://orbit.brightbox.com/v1/acc-tqs4c/downloads/freedos.qcow2 file:///tmp/uricp/srv-testy`
@@ -28,6 +35,13 @@ Feature: Download Public VM images
28
35
  And a file named "/tmp/uricp/cache/freedos.qcow2" should exist
29
36
  And the file named "/tmp/uricp/cache/freedos.qcow2" should have a file format of "qcow2"
30
37
 
38
+ Scenario: HTTP URI qcow2 to qcow2 via cache - size limited
39
+ Given a correctly initialised cache at "/tmp/uricp"
40
+ When I successfully run `uricp --target-format=qcow2 --cache=/tmp/uricp --max-cache=8Mb http://orbit.brightbox.com/v1/acc-tqs4c/downloads/freedos.qcow2 file:///tmp/uricp/srv-testy`
41
+ Then a file named "/tmp/uricp/srv-testy" should exist
42
+ And the file named "/tmp/uricp/srv-testy" should have a file format of "qcow2"
43
+ And a file named "/tmp/uricp/cache/freedos.qcow2" should not exist
44
+
31
45
  @new-qemu-image
32
46
  Scenario: HTTP URI qcow2 to qcow2v3 via cache
33
47
  Given a correctly initialised cache at "/tmp/uricp"
@@ -45,6 +59,12 @@ Feature: Download Public VM images
45
59
  And a file named "/tmp/uricp/cache/freedos.qcow2" should exist
46
60
  And the file named "/tmp/uricp/cache/freedos.qcow2" should have a file format of "qcow2"
47
61
 
62
+ Scenario: HTTP URI qcow2 to raw via cache - size limited
63
+ Given a correctly initialised cache at "/tmp/uricp"
64
+ When I successfully run `uricp --target-format=raw --cache=/tmp/uricp --max-cache=8Mb http://orbit.brightbox.com/v1/acc-tqs4c/downloads/freedos.qcow2 file:///tmp/uricp/srv-testy`
65
+ Then a file named "/tmp/uricp/srv-testy" should exist
66
+ And the file named "/tmp/uricp/srv-testy" should have a file format of "raw"
67
+ And a file named "/tmp/uricp/cache/freedos.qcow2" should not exist
48
68
 
49
69
  Scenario: HTTP URI from cache
50
70
  Given a correctly initialised cache at "/tmp/uricp"
@@ -16,6 +16,7 @@ Feature: Documented Help
16
16
  |--auth-user|
17
17
  |--auth-key|
18
18
  |--segment|
19
+ |--max-cache|
19
20
  And the option "compress" should be documented which is negatable
20
21
  And the option "dry-run" should be documented which is negatable
21
22
  And the option "force" should be documented which is negatable
@@ -72,3 +73,13 @@ Feature: Documented Help
72
73
  When I run `uricp --segment-size 100 --auth-token abcdef file:///tmp/temp https:///orbit.brightbox.com/v1/acc-xxxxx/test/test.img`
73
74
  Then the exit status should not be 0
74
75
  And the stderr should contain "Unparseable filesize"
76
+
77
+ Scenario: should not accept plain number for max-cache size
78
+ When I run `uricp --max-cache 100 --cache /tmp/uricp --auth-token abcdef file:///tmp/temp https:///orbit.brightbox.com/v1/acc-xxxxx/test/test.img`
79
+ Then the exit status should not be 0
80
+ And the stderr should contain "Unparseable filesize"
81
+
82
+ Scenario: max-cache size requires cache
83
+ When I run `uricp --max-cache 100MB --auth-token abcdef file:///tmp/temp https:///orbit.brightbox.com/v1/acc-xxxxx/test/test.img`
84
+ Then the exit status should not be 0
85
+ And the stderr should contain "missing argument"
@@ -6,9 +6,9 @@ module Uricp::Strategy
6
6
 
7
7
  def validate_cache!
8
8
  raise Uricp::MissingCache,
9
- "No cache found at #{cache_root}. Expected a 'cache' and 'temp' directory" unless cache_exists?
9
+ "no cache found at #{cache_root}. Expected a 'cache' and 'temp' directory" unless cache_exists?
10
10
  raise Uricp::MissingCache,
11
- "No cache name found" unless cache_name
11
+ "no cache name found" unless cache_name
12
12
  end
13
13
 
14
14
  def in_cache?
@@ -20,18 +20,26 @@ module Uricp::Strategy
20
20
  def proposal
21
21
  @proposed_options = options.dup
22
22
  @proposed_options['from_uri'] = PIPE_URI
23
- if options['target-format']
24
- @proposed_options['source-format'] = format_peek
25
- if @proposed_options['source-format'] == @proposed_options['target-format']
23
+ if conversion_required?
24
+ @proposed_options['source-format'] = format_peek
25
+ if @proposed_options['source-format'] == @proposed_options['target-format']
26
26
  @proposed_options.delete('source-format')
27
27
  @proposed_options.delete('target-format')
28
28
  end
29
29
  end
30
+ if options['max-cache'] &&
31
+ size_peek.to_i > options['max-cache'].to_i
32
+ @proposed_options.delete('cache')
33
+ @proposed_options.delete('cache_name')
34
+ @proposed_options.delete('max-cache')
35
+ end
30
36
  self
31
37
  end
32
38
 
33
39
  def format_peek
34
- options['from_uri'].open(headers) { |u| encoding(u) }
40
+ options['from_uri'].open(headers) do |u|
41
+ encoding(u)
42
+ end
35
43
  rescue OpenURI::HTTPError => e
36
44
  case e.io.status[0]
37
45
  when '416'
@@ -43,6 +51,15 @@ module Uricp::Strategy
43
51
  raise SocketError, options['from_uri'].to_s+" inaccessible: "+e.message
44
52
  end
45
53
 
54
+ def size_peek
55
+ options['from_uri'].open(headers) do |u|
56
+ match = %r<bytes\s+(\d+)-(\d+)/(\d+|\*)>i.match(u.meta['content-range'])
57
+ match && match[3].to_i
58
+ end
59
+ rescue SocketError => e
60
+ raise SocketError, options['from_uri'].to_s+" inaccessible: "+e.message
61
+ end
62
+
46
63
  def headers
47
64
  headers={'Range' => 'bytes=0-7'}
48
65
  headers['X-Auth-Token'] = options['authenticator'].call if http_authentication?
data/lib/uricp/version.rb CHANGED
@@ -1,4 +1,4 @@
1
1
  module Uricp
2
- VERSION = "0.0.10"
2
+ VERSION = "0.0.11"
3
3
  DEFAULT_SEGMENT_SIZE = "5 GiB"
4
4
  end
data/lib/uricp.rb CHANGED
@@ -26,6 +26,7 @@ module Uricp
26
26
  UnsupportedURLtype = Class.new(ArgumentError)
27
27
  MissingCache = Class.new(ArgumentError)
28
28
  UnsupportedConversion = Class.new(ArgumentError)
29
+ ConversionRequired = Class.new(ArgumentError)
29
30
 
30
31
  end
31
32
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: uricp
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.10
4
+ version: 0.0.11
5
5
  platform: ruby
6
6
  authors:
7
7
  - Neil Wilson
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-09-10 00:00:00.000000000 Z
11
+ date: 2015-09-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler