mixlib-install 1.0.10 → 1.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: 03929d3bab7753839718857039be870546202ee5
4
- data.tar.gz: cc933994d3a8c50a20cf6fcaa328ddf97475e68d
3
+ metadata.gz: 2b2ddb2bee9fa02b5c0835109b73ee0234a5b69f
4
+ data.tar.gz: 7b699b07eea1499dff69661e9321ed147eb55312
5
5
  SHA512:
6
- metadata.gz: d83a3f88f72136251caf55268d7729f02e03ec135963794b29183c5d4d72c1439a8d7e06939a9447a41cea18dffb39da42f8ffbeca3ed85945edcefd06fd7690
7
- data.tar.gz: 1a1af862a6b4f89e22c58102abc504f3ce2852b41203edee62e35a8f0d729d8ea11eeda662e4e59c2842327f02825e5d1988ba0b57a76482836433376d5c2c5f
6
+ metadata.gz: 5e659140f51abfdb1c348cb15adacb514bf2aafcfad2d80de79b701fb026fa41a8206b63b48f28c038b51a7f59edcb7f551ea741b00de1cf7a6e38dfee534624
7
+ data.tar.gz: f10c4a2d8ae90e47a41c3ccafbd48b727ffe6e8fee49b4c92f90e3500fa8f21136750c2b018803e6a5f0a115d52fcc0bc93b26a8c194dd90ae66e5da3c4797de
@@ -1,5 +1,8 @@
1
1
  # Change Log
2
2
 
3
+ ## [1.0.11]
4
+ - Add `platform_version_compatibility_mode` option which makes mixlib-install select an artifact built for an earlier version of a platform when set.
5
+
3
6
  ## [1.0.10]
4
7
  - Correctly parse architecture for ppc64el.
5
8
  - Return chef.bintray.com based urls for solaris9 and solaris10.
data/README.md CHANGED
@@ -49,6 +49,24 @@ artifact.platform # => "mac_os_x"
49
49
  artifact.platform_version # => "10.10"
50
50
  ```
51
51
 
52
+ ### Use an artifact released for an earlier version of the platform
53
+ ```ruby
54
+ options = {
55
+ channel: :current,
56
+ product_name: 'chef',
57
+ product_version: :latest,
58
+ platform: 'ubuntu',
59
+ platform_version: '15.04',
60
+ architecture: 'x86_64',
61
+ platform_version_compatibility_mode: true
62
+ }
63
+
64
+ artifact = Mixlib::Install.new(options).artifact_info
65
+
66
+ artifact.platform # => "ubuntu"
67
+ artifact.platform_version # => "14.04"
68
+ ```
69
+
52
70
  ## Unstable channel
53
71
  The `:unstable` channel is currently only available when connected to Chef's internal network.
54
72
 
@@ -42,25 +42,12 @@ module Mixlib
42
42
  #
43
43
  # @return [Array<ArtifactInfo>] list of artifacts for the configured
44
44
  # channel, product name, and product version.
45
- # @return [ArtifactInfo] arifact info for the configured
46
- # channel, product name, product version and platform info
47
- #
48
- def info
49
- artifacts = if options.latest_version?
50
- artifactory_latest
51
- else
52
- artifactory_artifacts(options.product_version)
53
- end
54
-
55
- if options.platform
56
- artifacts.select! do |a|
57
- a.platform == options.platform &&
58
- a.platform_version == options.platform_version &&
59
- a.architecture == options.architecture
60
- end
45
+ def available_artifacts
46
+ if options.latest_version?
47
+ artifactory_latest
48
+ else
49
+ artifactory_artifacts(options.product_version)
61
50
  end
62
-
63
- artifacts.length == 1 ? artifacts.first : artifacts
64
51
  end
65
52
 
66
53
  #
@@ -26,13 +26,86 @@ module Mixlib
26
26
  @options = options
27
27
  end
28
28
 
29
+ #
30
+ # Returns the list of artifacts from the configured backend based on the
31
+ # configured product_name, product_version and channel.
32
+ #
33
+ # @abstract Subclasses should define this method.
34
+ #
35
+ # @return Array<ArtifactInfo>
36
+ # List of ArtifactInfo objects for the available artifacts.
37
+ def available_artifacts
38
+ raise "Must implement available_artifacts method that returns Array<ArtifactInfo>"
39
+ end
40
+
41
+ #
42
+ # See #filter_artifacts
29
43
  def info
30
- raise "Must implement info method that returns ArtifactInfo or Array<ArtifactInfo>"
44
+ filter_artifacts(available_artifacts)
45
+ end
46
+
47
+ #
48
+ # Returns true if platform filters are available, false otherwise.
49
+ #
50
+ # Note that we assume #set_platform_info method is used on the Options
51
+ # class to set the platform options.
52
+ #
53
+ # @return TrueClass, FalseClass
54
+ def platform_filters_available?
55
+ !options.platform.nil?
31
56
  end
32
57
 
33
- def endpoint
34
- raise "Must implement endpoint method that returns endpoint String"
58
+ #
59
+ # Filters and returns the available artifacts based on the configured
60
+ # platform filtering options.
61
+ #
62
+ # @return ArtifactInfo, Array<ArtifactInfo>, []
63
+ # If the result is a single artifact, this returns ArtifactInfo.
64
+ # If the result is a list of artifacts, this returns Array<ArtifactInfo>.
65
+ # If no suitable artifact is found, this returns [].
66
+ def filter_artifacts(artifacts)
67
+ return artifacts unless platform_filters_available?
68
+
69
+ # First filter the artifacts based on the platform and architecture
70
+ artifacts.select! do |a|
71
+ a.platform == options.platform && a.architecture == options.architecture
72
+ end
73
+
74
+ # Now we are going to filter based on platform_version.
75
+ # We will return the artifact with an exact match if available.
76
+ # Otherwise we will search for a compatible artifact and return it
77
+ # if the compat options is set.
78
+ closest_compatible_artifact = nil
79
+
80
+ artifacts.each do |a|
81
+ return a if a.platform_version == options.platform_version
82
+
83
+ # We skip the artifacts produced for windows since their platform
84
+ # version is always set to 2008r2 which breaks our `to_f` comparison.
85
+ next if a.platform == "windows"
86
+
87
+ # Calculate the closest compatible version.
88
+ # For an artifact to be compatible it needs to be smaller than the
89
+ # platform_version specified in options.
90
+ # To find the closest compatible one we keep a max of the compatible
91
+ # artifacts.
92
+ if closest_compatible_artifact.nil? ||
93
+ (a.platform_version.to_f > closest_compatible_artifact.platform_version.to_f &&
94
+ a.platform_version.to_f < options.platform_version.to_f )
95
+ closest_compatible_artifact = a
96
+ end
97
+ end
98
+
99
+ # If the compat flag is set and if we have found a compatible artifact
100
+ # we are going to use it.
101
+ if options.platform_version_compatibility_mode && closest_compatible_artifact
102
+ return closest_compatible_artifact
103
+ end
104
+
105
+ # Otherwise, we return an empty array indicating we do not have any matching artifacts
106
+ return []
35
107
  end
108
+
36
109
  end
37
110
  end
38
111
  end
@@ -51,27 +51,6 @@ module Mixlib
51
51
  @endpoint ||= ENV.fetch("BINTRAY_ENDPOINT", ENDPOINT)
52
52
  end
53
53
 
54
- # Create filtered list of artifacts
55
- #
56
- # @return [Array<ArtifactInfo>] list of artifacts for the configured
57
- # channel, product name, and product version.
58
- # @return [ArtifactInfo] arifact info for the configured
59
- # channel, product name, product version and platform info
60
- #
61
- def info
62
- artifacts = bintray_artifacts
63
-
64
- if options.platform
65
- artifacts.select! do |a|
66
- a.platform == options.platform &&
67
- a.platform_version == options.platform_version &&
68
- a.architecture == options.architecture
69
- end
70
- end
71
-
72
- artifacts.length == 1 ? artifacts.first : artifacts
73
- end
74
-
75
54
  #
76
55
  # Makes a GET request to bintray for the given path.
77
56
  #
@@ -111,7 +90,7 @@ module Mixlib
111
90
  #
112
91
  # @return [Array<ArtifactInfo>] Array of info about found artifacts
113
92
  #
114
- def bintray_artifacts
93
+ def available_artifacts
115
94
  version = options.latest_version? ? latest_version : options.product_version
116
95
  begin
117
96
  results = bintray_get("#{options.channel}/#{options.product_name}/versions/#{version}/files")
@@ -31,7 +31,7 @@ module Mixlib
31
31
  @endpoint ||= ENV.fetch("OMNITRUCK_ENDPOINT", ENDPOINT)
32
32
  end
33
33
 
34
- def info
34
+ def available_artifacts
35
35
  # If we are querying a single platform we need to call metadata
36
36
  # endpoint otherwise we need to call versions endpoint in omnitruck
37
37
  if options.platform
@@ -39,6 +39,7 @@ module Mixlib
39
39
  :product_name,
40
40
  :product_version,
41
41
  :shell_type,
42
+ :platform_version_compatibility_mode,
42
43
  ]
43
44
 
44
45
  def initialize(options)
@@ -107,6 +108,7 @@ module Mixlib
107
108
  def default_options
108
109
  {
109
110
  shell_type: :sh,
111
+ platform_version_compatibility_mode: false,
110
112
  }
111
113
  end
112
114
 
@@ -1,5 +1,5 @@
1
1
  module Mixlib
2
2
  class Install
3
- VERSION = "1.0.10"
3
+ VERSION = "1.0.11"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mixlib-install
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.10
4
+ version: 1.0.11
5
5
  platform: ruby
6
6
  authors:
7
7
  - Thom May
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2016-04-26 00:00:00.000000000 Z
12
+ date: 2016-04-27 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: artifactory