hybrid_platforms_conductor 33.8.4 → 33.9.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b18c3901744a84b3c1c820a8bc8af074cecdc78d56b7802186d9d6751c5b78ed
4
- data.tar.gz: ef312bf22ddcdd7473d3c606d665e3eec5760a842822b0fb36dedf7ce840fa6b
3
+ metadata.gz: d88a5c946d63351586ef1b77ec9840e13e84af48c210bc8dfd1004abc27f547d
4
+ data.tar.gz: 8d04e563077d81cc72d5c3dc883f0010205a3880a255c1fb229ff3ba11771b49
5
5
  SHA512:
6
- metadata.gz: 543a74c57e08edde95103dff97af8c90360908e87e2d7be1c1c79a53dc85cb314f26b23b8591dabaeb88efb6415c2b3a5909ed8ca392a2dc0e3a61dabfb3b781
7
- data.tar.gz: 87f5bb43a345cb9373d43211ffbea8e47c08de26a7256f0f2b51ff2660b6021bc251a448ba51006c34ca02c88d442d88c2d027d1b15638a7e2fb396c2336423f
6
+ metadata.gz: 211847acef3bff5d8e2e554a6262c783230989c3877b830cdbf4a3c5ff8a0fdb414669c891b9bf102f8adf26aed4000189df7565a1e33e93094ee384a577cbd1
7
+ data.tar.gz: 1faa911b27e3fdda61c605711de26598c6bac9a533519a4b2d583da479f1be9ea32265433d34cf9d8c6aaeee06d45e83b80e648c013ed2342df728a83f9bb6cf
data/CHANGELOG.md CHANGED
@@ -1,3 +1,15 @@
1
+ # [v33.9.0](https://github.com/sweet-delights/hybrid-platforms-conductor/compare/v33.8.4...v33.9.0) (2021-08-24 13:15:44)
2
+
3
+ ## Global changes
4
+ ### Patches
5
+
6
+ * [[Feature(platform_handler)] [#102] Add the name option when declaring platforms to set the platform name](https://github.com/sweet-delights/hybrid-platforms-conductor/commit/13ada7687f08b3f970521320e2b26ea42d9a6d7f)
7
+
8
+ ## Changes for platform_handler
9
+ ### Features
10
+
11
+ * [[Feature(platform_handler)] [#102] Add the name option when declaring platforms to set the platform name](https://github.com/sweet-delights/hybrid-platforms-conductor/commit/13ada7687f08b3f970521320e2b26ea42d9a6d7f)
12
+
1
13
  # [v33.8.4](https://github.com/sweet-delights/hybrid-platforms-conductor/compare/v33.8.3...v33.8.4) (2021-08-20 15:45:41)
2
14
 
3
15
  ## Global changes
data/docs/config_dsl.md CHANGED
@@ -28,19 +28,25 @@ This DSL can also be completed by plugins. Check [the plugins documentations](pl
28
28
  Declare a new platform of type `<platform_type>`, providing either a local path to it (using `path: '/path/to/files'`) or a git repository to it (using `git: 'git_url'`). The possible platform types are the names of the [`platform_handler` plugins](plugins.md#platform_handler).
29
29
 
30
30
  Git branches can also be specified using `branch: 'branch_name'`.
31
+
32
+ The name of the platform (as used for example by the [`for_nodes`](#for_nodes) DSL) defaults to the base name of the directory in case of a local path, or the base name of the first remote in case of a git repository. It can be enforced to a given name using `name: 'platform_name'` (useful to avoid name conflicts and keep consistency with the rest of your configuration among the team).
33
+
31
34
  An optional code block taking the local repository path as parameter can also be specified to add configuration that is specific to this platform.
32
35
 
33
36
  Examples:
34
37
  ```ruby
35
- # Declare a platform of type Chef, located in a distant git repository
38
+ # Declare a platform of type Chef, located in a distant git repository (its name will be my-chef-repo)
36
39
  chef_platform git: 'https://my-git.domain.com/project/my-chef-repo.git'
37
40
 
38
- # Declare a platform located in a local path
39
- chef_platform path: '/path/to/my-chef-repo'
41
+ # Declare a platform located in a local path (its name will be my-other-chef-repo)
42
+ chef_platform path: '/path/to/my-other-chef-repo'
43
+
44
+ # Declare a platform located in a local path and forces its name (its name will be my-platform)
45
+ chef_platform path: '/path/to/my-repo', name: 'my-platform'
40
46
 
41
47
  # Declare a platform from a git branch, and apply some configuration to it
42
48
  chef_platform(
43
- git: 'https://my-git.domain.com/project/my-chef-repo.git',
49
+ git: 'https://my-git.domain.com/project/devops-chef-repo.git',
44
50
  branch: 'my-branch'
45
51
  ) do |path|
46
52
  # Here path will be a local path containing a checkout of the branch my-branch of the git repo.
@@ -47,24 +47,10 @@ module HybridPlatformsConductor
47
47
  end
48
48
  extend_config_dsl_with MyDSLExtension, :init_serverless_chef
49
49
 
50
- # Constructor
51
- #
52
- # Parameters::
53
- # * *platform_type* (Symbol): Platform type
54
- # * *repository_path* (String): Repository path
55
- # * *logger* (Logger): Logger to be used [default: Logger.new(STDOUT)]
56
- # * *logger_stderr* (Logger): Logger to be used for stderr [default: Logger.new(STDERR)]
57
- # * *config* (Config): Config to be used. [default: Config.new]
58
- # * *cmd_runner* (CmdRunner): Command executor to be used. [default: CmdRunner.new]
59
- def initialize(
60
- platform_type,
61
- repository_path,
62
- logger: Logger.new($stdout),
63
- logger_stderr: Logger.new($stderr),
64
- config: Config.new,
65
- cmd_runner: CmdRunner.new
66
- )
67
- super
50
+ # Initialize a new instance of this platform handler.
51
+ # [API] - This method is optional.
52
+ # [API] - @cmd_runner is accessible.
53
+ def init
68
54
  # Mutex for getting the full recipes tree
69
55
  @recipes_tree_mutex = Mutex.new
70
56
  end
@@ -17,13 +17,13 @@ module HybridPlatformsConductor
17
17
  # Make sure we define automatically a helper for such a platform
18
18
  mixin = Module.new
19
19
  platform_type = subclass.name.split('::').last.gsub(/([a-z\d])([A-Z\d])/, '\1_\2').downcase.to_sym
20
- mixin.define_method("#{platform_type}_platform".to_sym) do |path: nil, git: nil, branch: 'master', &platform_config_code|
20
+ mixin.define_method("#{platform_type}_platform".to_sym) do |path: nil, git: nil, branch: 'master', name: nil, &platform_config_code|
21
21
  repository_path =
22
22
  if !path.nil?
23
23
  path
24
24
  elsif !git.nil?
25
25
  # Clone in a local repository
26
- local_repository_path = "#{@git_platforms_dir}/#{File.basename(git)[0..-File.extname(git).size - 1]}"
26
+ local_repository_path = "#{@git_platforms_dir}/#{name.nil? ? File.basename(git)[0..-File.extname(git).size - 1] : name}"
27
27
  unless File.exist?(local_repository_path)
28
28
  branch = "refs/heads/#{branch}" unless branch.include?('/')
29
29
  local_ref = "refs/remotes/origin/#{branch.split('/').last}"
@@ -37,8 +37,10 @@ module HybridPlatformsConductor
37
37
  else
38
38
  raise 'The platform has to be defined with either a path or a git URL'
39
39
  end
40
- @platform_dirs[platform_type] = [] unless @platform_dirs.key?(platform_type)
41
- @platform_dirs[platform_type] << repository_path
40
+ @platforms_info[platform_type] = {} unless @platforms_info.key?(platform_type)
41
+ raise "Platform repository path #{repository_path} is declared several times." if @platforms_info.values.any? { |known_platforms_info| known_platforms_info.key?(repository_path) }
42
+
43
+ @platforms_info[platform_type][repository_path] = name.nil? ? {} : { name: name }
42
44
  platform_config_code&.call(repository_path)
43
45
  end
44
46
  # Register this new mixin in the Config DSL
@@ -66,18 +68,21 @@ module HybridPlatformsConductor
66
68
  # * *logger_stderr* (Logger): Logger to be used for stderr [default: Logger.new(STDERR)]
67
69
  # * *config* (Config): Config to be used. [default: Config.new]
68
70
  # * *cmd_runner* (CmdRunner): Command executor to be used. [default: CmdRunner.new]
71
+ # * *name* (String or nil): Platform name, or nil for defaults (based on path or git remote) [default: nil]
69
72
  def initialize(
70
73
  platform_type,
71
74
  repository_path,
72
75
  logger: Logger.new($stdout),
73
76
  logger_stderr: Logger.new($stderr),
74
77
  config: Config.new,
75
- cmd_runner: CmdRunner.new
78
+ cmd_runner: CmdRunner.new,
79
+ name: nil
76
80
  )
77
81
  super(logger: logger, logger_stderr: logger_stderr, config: config)
78
82
  @platform_type = platform_type
79
83
  @repository_path = repository_path
80
84
  @cmd_runner = cmd_runner
85
+ @name = name
81
86
  init if respond_to?(:init)
82
87
  end
83
88
 
@@ -142,7 +147,12 @@ module HybridPlatformsConductor
142
147
  git_status = git.status
143
148
  git_commit = git.log.first
144
149
  {
145
- repo_name: git.remotes.empty? ? File.basename(@repository_path) : File.basename(git.remotes.first.url).gsub(/\.git$/, ''),
150
+ repo_name:
151
+ if @name.nil?
152
+ git.remotes.empty? ? File.basename(@repository_path) : File.basename(git.remotes.first.url).gsub(/\.git$/, '')
153
+ else
154
+ @name
155
+ end,
146
156
  commit: {
147
157
  id: git_commit.sha,
148
158
  ref: git_commit.name,
@@ -162,7 +172,7 @@ module HybridPlatformsConductor
162
172
  }
163
173
  else
164
174
  {
165
- repo_name: File.basename(@repository_path)
175
+ repo_name: @name.nil? ? File.basename(@repository_path) : @name
166
176
  }
167
177
  end
168
178
  end
@@ -9,13 +9,14 @@ module HybridPlatformsConductor
9
9
  # Add some config DSL
10
10
  module ConfigDSLExtension
11
11
 
12
- # List of platforms repository directories, per platform type
13
- # Hash<Symbol, Array<String> >
14
- attr_reader :platform_dirs
12
+ # List of platforms repository directories and their associated info, per platform type
13
+ # Hash<Symbol, Hash<String, Hash<Symbol,Object> > >
14
+ # Hash<platform_type, Hash<repository_path, Hash<Symbol,Object> > >
15
+ attr_reader :platforms_info
15
16
 
16
17
  # Mixin initializer
17
18
  def init_platforms_handler
18
- @platform_dirs = {}
19
+ @platforms_info = {}
19
20
  # Directory in which platforms are cloned
20
21
  @git_platforms_dir = "#{@hybrid_platforms_dir}/cloned_platforms"
21
22
  end
@@ -46,15 +47,16 @@ module HybridPlatformsConductor
46
47
  # Hash<Symbol, Array<PlatformHandler> >
47
48
  @platform_handlers = {}
48
49
  # Read all platforms from the config
49
- @config.platform_dirs.each do |platform_type, repositories|
50
- repositories.each do |repository_path|
50
+ @config.platforms_info.each do |platform_type, repositories_info|
51
+ repositories_info.each do |repository_path, repository_info|
51
52
  platform_handler = @platform_types[platform_type].new(
52
53
  platform_type,
53
54
  repository_path,
54
55
  logger: @logger,
55
56
  logger_stderr: @logger_stderr,
56
57
  config: @config,
57
- cmd_runner: @cmd_runner
58
+ cmd_runner: @cmd_runner,
59
+ name: repository_info[:name]
58
60
  )
59
61
  # Check that this platform has unique name
60
62
  raise "Platform name #{platform_handler.name} is declared several times." if @platform_handlers.values.flatten.any? { |known_platform| known_platform.name == platform_handler.name }
@@ -1,5 +1,5 @@
1
1
  module HybridPlatformsConductor
2
2
 
3
- VERSION = '33.8.4'
3
+ VERSION = '33.9.0'
4
4
 
5
5
  end
@@ -15,6 +15,10 @@ describe HybridPlatformsConductor::NodesHandler do
15
15
  },
16
16
  'platform2' => {
17
17
  nodes: { 'node4' => {}, 'node5' => { services: %w[service3 service1] }, 'node6' => {} }
18
+ },
19
+ 'platform3' => {
20
+ nodes: { 'node7' => {} },
21
+ name: 'other_platform'
18
22
  }
19
23
  },
20
24
  &block
@@ -24,12 +28,13 @@ describe HybridPlatformsConductor::NodesHandler do
24
28
  # List all tests of nodes selectors, and the corresponding nodes list they should be resolved into
25
29
  {
26
30
  [] => [],
27
- [{ all: true }] => %w[node1 node2 node3 node4 node5 node6],
31
+ [{ all: true }] => %w[node1 node2 node3 node4 node5 node6 node7],
28
32
  'node1' => %w[node1],
29
33
  '/node[12]/' => %w[node1 node2],
30
34
  [{ list: 'nodeslist1' }] => %w[node1 node3],
31
35
  [{ list: 'nodeslist2' }] => %w[node1 node2],
32
36
  [{ platform: 'platform2' }] => %w[node4 node5 node6],
37
+ [{ platform: 'other_platform' }] => %w[node7],
33
38
  [{ service: 'service1' }] => %w[node2 node5],
34
39
  ['/node[12]/', { service: 'service1' }] => %w[node1 node2 node5],
35
40
  [{ git_diff: { platform: 'platform2' } }] => %w[node4 node5 node6]
@@ -45,13 +50,13 @@ describe HybridPlatformsConductor::NodesHandler do
45
50
 
46
51
  it 'fails when selecting unknown nodes' do
47
52
  with_test_platform_for_nodes do
48
- expect { test_nodes_handler.select_nodes('node1', 'node7') }.to raise_error(RuntimeError, 'Unknown nodes: node7')
53
+ expect { test_nodes_handler.select_nodes('node1', 'unknown_node') }.to raise_error(RuntimeError, 'Unknown nodes: unknown_node')
49
54
  end
50
55
  end
51
56
 
52
57
  it 'ignore unknown nodes when asked' do
53
58
  with_test_platform_for_nodes do
54
- expect(test_nodes_handler.select_nodes(%w[node1 node7], ignore_unknowns: true).sort).to eq %w[node1 node7].sort
59
+ expect(test_nodes_handler.select_nodes(%w[node1 unknown_node], ignore_unknowns: true).sort).to eq %w[node1 unknown_node].sort
55
60
  end
56
61
  end
57
62
 
@@ -105,7 +110,7 @@ describe HybridPlatformsConductor::NodesHandler do
105
110
 
106
111
  it 'considers all nodes for en empty nodes selector stack' do
107
112
  with_test_platform_for_nodes do
108
- expect(test_nodes_handler.select_from_nodes_selector_stack([]).sort).to eq %w[node1 node2 node3 node4 node5 node6].sort
113
+ expect(test_nodes_handler.select_from_nodes_selector_stack([]).sort).to eq %w[node1 node2 node3 node4 node5 node6 node7].sort
109
114
  end
110
115
  end
111
116
 
@@ -2,22 +2,22 @@ describe HybridPlatformsConductor::PlatformsHandler do
2
2
 
3
3
  context 'when checking config specific DSL' do
4
4
 
5
- it 'returns platform directories along with platform types' do
5
+ it 'returns platforms info' do
6
6
  with_test_platforms(
7
7
  {
8
8
  'platform1' => { platform_type: :test },
9
9
  'platform2' => { platform_type: :test_2 },
10
- 'platform3' => { platform_type: :test }
10
+ 'platform3' => { platform_type: :test, name: 'other_platform' }
11
11
  }
12
12
  ) do |repositories|
13
- expect(test_config.platform_dirs.keys.sort).to eq %i[test test_2].sort
14
- expect(test_config.platform_dirs[:test].sort).to eq [
15
- repositories['platform1'],
16
- repositories['platform3']
17
- ].sort
18
- expect(test_config.platform_dirs[:test_2].sort).to eq [
19
- repositories['platform2']
20
- ].sort
13
+ expect(test_config.platforms_info.keys.sort).to eq %i[test test_2].sort
14
+ expect(test_config.platforms_info[:test]).to eq(
15
+ repositories['platform1'] => {},
16
+ repositories['platform3'] => { name: 'other_platform' }
17
+ )
18
+ expect(test_config.platforms_info[:test_2]).to eq(
19
+ repositories['platform2'] => {}
20
+ )
21
21
  end
22
22
  end
23
23
 
@@ -55,27 +55,57 @@ describe HybridPlatformsConductor::PlatformsHandler do
55
55
  {
56
56
  'platform1' => { platform_type: :test },
57
57
  'platform2' => { platform_type: :test_2 },
58
- 'platform3' => { platform_type: :test }
58
+ 'platform3' => { platform_type: :test, name: 'other_platform' }
59
59
  }
60
60
  ) do
61
- expect(test_platforms_handler.known_platforms.map(&:name).sort).to eq %w[platform1 platform2 platform3].sort
61
+ expect(test_platforms_handler.known_platforms.map(&:name).sort).to eq %w[platform1 platform2 other_platform].sort
62
62
  end
63
63
  end
64
64
 
65
65
  it 'fails if several platforms share the same name' do
66
66
  with_repository('platform1') do |repository|
67
+ FileUtils.mkdir_p "#{repository}/platform1"
67
68
  with_test_platforms(
68
69
  {
69
70
  'platform1' => { platform_type: :test },
70
71
  'platform2' => { platform_type: :test_2 }
71
72
  },
72
- additional_config: "test_2_platform path: \'#{repository}\'"
73
+ additional_config: "test_2_platform path: \'#{repository}/platform1\'"
73
74
  ) do
74
75
  expect { test_platforms_handler.known_platforms }.to raise_error 'Platform name platform1 is declared several times.'
75
76
  end
76
77
  end
77
78
  end
78
79
 
80
+ it 'fails if several platforms share the same path' do
81
+ with_repository('platform1') do |repository|
82
+ with_test_platforms(
83
+ {
84
+ 'platform1' => { platform_type: :test },
85
+ 'platform2' => { platform_type: :test_2 }
86
+ },
87
+ additional_config: "test_2_platform path: \'#{repository}\', name: 'other_platform'"
88
+ ) do
89
+ expect { test_platforms_handler.known_platforms }.to raise_error "Platform repository path #{repository} is declared several times."
90
+ end
91
+ end
92
+ end
93
+
94
+ it 'can differentiate several platforms sharing the same path ending but with different explicit names' do
95
+ with_repository('platform1') do |repository|
96
+ FileUtils.mkdir_p "#{repository}/platform1"
97
+ with_test_platforms(
98
+ {
99
+ 'platform1' => { platform_type: :test },
100
+ 'platform2' => { platform_type: :test_2 }
101
+ },
102
+ additional_config: "test_platform path: \'#{repository}/platform1\', name: 'other_platform'"
103
+ ) do
104
+ expect(test_platforms_handler.known_platforms.map(&:name).sort).to eq %w[platform1 platform2 other_platform].sort
105
+ end
106
+ end
107
+ end
108
+
79
109
  it 'returns defined platforms filtered by platform type' do
80
110
  with_test_platforms(
81
111
  {
@@ -73,7 +73,9 @@ module HybridPlatformsConductorTest
73
73
  # Clean-up at the end.
74
74
  #
75
75
  # Parameters::
76
- # * *platforms_info* (Hash<String,Object>): Platforms info for the test platform
76
+ # * *platforms_info* (Hash<String,Object>): Platforms info for the test platform:
77
+ # * *platform_type* (Symbol): Name of the platform handler plugin for this platform
78
+ # * *name* (String): Optional name to give the platform [optional]
77
79
  # * *as_git* (Boolean): Do we initialize those repositories as Git repositories? [default: false]
78
80
  # * *additional_config* (String): Additional config to be added [default: '']
79
81
  # * Proc: Code called with the environment ready
@@ -86,7 +88,7 @@ module HybridPlatformsConductorTest
86
88
  repositories.map do |platform, dir|
87
89
  platform_type = platforms_info[platform].key?(:platform_type) ? platforms_info[platform][:platform_type] : :test
88
90
  platform_types << platform_type unless platform_types.include?(platform_type)
89
- "#{platform_type}_platform path: '#{dir}'"
91
+ "#{platform_type}_platform path: '#{dir}'#{platforms_info[platform].key?(:name) ? ", name: '#{platforms_info[platform][:name]}'" : ''}"
90
92
  end.join("\n") + "\n#{additional_config}"
91
93
  ) do
92
94
  register_platform_handlers(platform_types.map do |platform_type|
@@ -200,10 +200,11 @@ module HybridPlatformsConductorTest
200
200
  # Result::
201
201
  # * Hash<Symbol, Object>: Platform info (check TestPlatformHandler#platforms_info to know about properties)
202
202
  def platform_info
203
+ _repo_base_name, found_platform_info = HybridPlatformsConductorTest::PlatformHandlerPlugins::Test.platforms_info.find { |search_repo_base_name, search_platform_info| (search_platform_info[:name] || search_repo_base_name) == name }
203
204
  {
204
205
  nodes: {},
205
206
  nodes_lists: {}
206
- }.merge(HybridPlatformsConductorTest::PlatformHandlerPlugins::Test.platforms_info[name])
207
+ }.merge(found_platform_info)
207
208
  end
208
209
 
209
210
  # Return the node info of a given node
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hybrid_platforms_conductor
3
3
  version: !ruby/object:Gem::Version
4
- version: 33.8.4
4
+ version: 33.9.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Muriel Salvan
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-08-20 00:00:00.000000000 Z
11
+ date: 2021-08-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: range_operators