machinery-tool 1.4.0 → 1.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (41) hide show
  1. checksums.yaml +4 -4
  2. data/NEWS +7 -0
  3. data/bin/machinery +3 -1
  4. data/helpers/default_filters.json +24 -0
  5. data/helpers/yum_repositories.py +8 -2
  6. data/lib/autoyast.rb +8 -3
  7. data/lib/changed_rpm_files_helper.rb +34 -7
  8. data/lib/cli.rb +149 -101
  9. data/lib/element_filter.rb +45 -0
  10. data/lib/exceptions.rb +3 -2
  11. data/lib/filter.rb +121 -0
  12. data/lib/inspect_task.rb +25 -4
  13. data/lib/kiwi_config.rb +11 -0
  14. data/lib/list_task.rb +53 -26
  15. data/lib/local_system.rb +1 -1
  16. data/lib/machinery.rb +2 -0
  17. data/lib/manifest.rb +3 -2
  18. data/lib/migration.rb +2 -2
  19. data/lib/system_description.rb +33 -4
  20. data/lib/tarball.rb +5 -5
  21. data/lib/version.rb +1 -1
  22. data/lib/zypper.rb +12 -17
  23. data/man/generated/machinery.1.gz +0 -0
  24. data/man/generated/machinery.1.html +21 -4
  25. data/plugins/docs/changed_managed_files.md +3 -1
  26. data/plugins/docs/config_files.md +3 -2
  27. data/plugins/inspect/changed_managed_files_inspector.rb +8 -2
  28. data/plugins/inspect/config_files_inspector.rb +1 -1
  29. data/plugins/inspect/groups_inspector.rb +3 -1
  30. data/plugins/inspect/os_inspector.rb +2 -2
  31. data/plugins/inspect/packages_inspector.rb +1 -1
  32. data/plugins/inspect/patterns_inspector.rb +1 -1
  33. data/plugins/inspect/repositories_inspector.rb +1 -1
  34. data/plugins/inspect/services_inspector.rb +1 -1
  35. data/plugins/inspect/unmanaged_files_inspector.rb +17 -42
  36. data/plugins/inspect/users_inspector.rb +1 -1
  37. data/plugins/schema/v3/system-description-changed-managed-files.schema.json +1 -1
  38. data/plugins/schema/v3/system-description-config-files.schema.json +1 -1
  39. data/plugins/schema/v3/system-description-repositories.schema.json +1 -1
  40. data/schema/v3/system-description-global.schema.json +12 -0
  41. metadata +5 -2
@@ -25,26 +25,26 @@ class Tarball
25
25
  output = LoggedCheetah.run("tar", "tvf", @file, :stdout => :capture)
26
26
 
27
27
  output.lines.map do |line|
28
- mode, user_and_group, size, date, time, *rest = line.split(" ")
28
+ mode, user_and_group, size, _date, _time, rest = line.split(" ", 6)
29
29
 
30
30
  case mode[0]
31
31
  when "l"
32
32
  type = :link
33
33
  # This may fail for files with "->" in their name, but there is no way
34
34
  # how to avoid this when using "tar".
35
- path = rest.join(" ").split(" -> ").first
35
+ path = rest.split(" -> ").first
36
36
  when "h"
37
37
  type = :file
38
38
  # This may fail for files with "link to" in their name, but there is no way
39
39
  # how to avoid this when using "tar" unless we use the parameter
40
40
  # --hard-dereference with tar to get rid of hard links
41
- path = rest.join(" ").split(" link to ").first
41
+ path = rest.split(" link to ").first
42
42
  when "d"
43
43
  type = :dir
44
- path = rest.join(" ")[0..-2] # Strip trailing "/".
44
+ path = rest.chomp("/\n")
45
45
  else
46
46
  type = :file
47
- path = rest.join(" ")
47
+ path = rest.chomp
48
48
  end
49
49
 
50
50
  user, group = user_and_group.split("/")
@@ -17,6 +17,6 @@
17
17
 
18
18
  module Machinery
19
19
 
20
- VERSION = "1.4.0"
20
+ VERSION = "1.5.0"
21
21
 
22
22
  end
@@ -27,22 +27,21 @@ class Zypper
27
27
 
28
28
  class <<self
29
29
  def isolated(options = {}, &block)
30
- zypper_base = Dir.mktmpdir("machinery_zypper")
31
- zypper = Zypper.new
30
+ Dir.mktmpdir("machinery_zypper") do |zypper_base|
31
+ zypper = Zypper.new
32
32
 
33
- zypper.zypper_options = [
34
- "--non-interactive",
35
- "--no-gpg-checks",
36
- "--root", zypper_base
37
- ]
33
+ zypper.zypper_options = [
34
+ "--non-interactive",
35
+ "--no-gpg-checks",
36
+ "--root", zypper_base
37
+ ]
38
38
 
39
- if options[:arch]
40
- zypper.zypp_config = create_zypp_config(zypper_base, options[:arch])
41
- end
39
+ if options[:arch]
40
+ zypper.zypp_config = create_zypp_config(zypper_base, options[:arch])
41
+ end
42
42
 
43
- block.call(zypper)
44
- ensure
45
- cleanup(zypper_base)
43
+ block.call(zypper)
44
+ end
46
45
  end
47
46
 
48
47
  private
@@ -60,10 +59,6 @@ class Zypper
60
59
 
61
60
  zypp_config
62
61
  end
63
-
64
- def cleanup(base)
65
- LoggedCheetah.run("rm", "-r", base)
66
- end
67
62
  end
68
63
 
69
64
  def add_repo(url, repo_alias)
Binary file
@@ -240,14 +240,17 @@ scope to <code>packages</code>. This will output only the requested information.
240
240
  <li><p>changed-managed-files</p>
241
241
 
242
242
  <p>Contains the names and contents of all non-configuration files which have
243
- been changed compared to the files in the package.</p></li>
243
+ been changed compared to the files in the package. A file change is reported
244
+ if its content or its attributes like Linux permission bits or ownership
245
+ have changed.</p></li>
244
246
  <li><p>config-files</p>
245
247
 
246
248
  <p>Contains all configuration files which have been changed since they were
247
249
  installed.
248
250
  Configuration files are all those files which are marked as such in the
249
- package which has installed them. A configuration file is considered changed
250
- if either its content or its Linux permission bits have changed.</p></li>
251
+ package which has installed them. A configuration file change is reported
252
+ if its content or its attributes like Linux permission bits or ownership
253
+ have changed.</p></li>
251
254
  <li><p>groups</p>
252
255
 
253
256
  <p>Contains information about the system groups such as group attributes and the
@@ -853,6 +856,16 @@ Shortcut for the combination of <code>--extract-changed-config-files</code>,
853
856
  <dt><code>--extract-changed-config-files</code> (optional)</dt><dd><p>Extract changed configuration files from the inspected system.</p></dd>
854
857
  <dt><code>--extract-unmanaged-files</code> (optional)</dt><dd><p>Extract unmanaged files from the inspected system.</p></dd>
855
858
  <dt><code>--extract-changed-managed-files</code> (optional)</dt><dd><p>Extract changed managed files from inspected system.</p></dd>
859
+ <dt><code>--skip-files</code> (optional)</dt><dd><p>Do not consider given files or directories during inspection. Either provide
860
+ one file or directory name or a list of names separated by commas. You can
861
+ also point to a file which contains a list of files to filter (one per line)
862
+ by adding an '@' before the path, e.g.</p>
863
+
864
+ <p> $ <code>machinery</code> inspect --skip-files=@/path/to/filter_file myhost</p>
865
+
866
+ <p>If a filename contains a comma it needs to be escaped, e.g.</p>
867
+
868
+ <p> $ <code>machinery</code> inspect --skip-files=/file\,with_comma myhost</p></dd>
856
869
  </dl>
857
870
 
858
871
 
@@ -917,6 +930,7 @@ scopes for each system.</p>
917
930
  <dl>
918
931
  <dt><code>--verbose</code> (optional)</dt><dd>Print additional information about the origin of scopes.
919
932
  Currently displays [HOSTNAME] and (DATE).</dd>
933
+ <dt><code>--short</code> (optional)</dt><dd>List only descripton names.</dd>
920
934
  </dl>
921
935
 
922
936
 
@@ -929,6 +943,9 @@ Currently displays [HOSTNAME] and (DATE).</dd>
929
943
  <dt>Same as previous command, but additionally prints the date of each scope:</dt><dd><p></p>
930
944
 
931
945
  <p>$ <code>machinery</code> list --verbose</p></dd>
946
+ <dt>Lists all available system description names without any additional details:</dt><dd><p></p>
947
+
948
+ <p>$ <code>machinery</code> list --short</p></dd>
932
949
  </dl>
933
950
 
934
951
 
@@ -1145,7 +1162,7 @@ manually editing it.</p>
1145
1162
 
1146
1163
  <ol class='man-decor man-foot man foot'>
1147
1164
  <li class='tl'></li>
1148
- <li class='tc'>February 2015</li>
1165
+ <li class='tc'>March 2015</li>
1149
1166
  <li class='tr'>machinery(1)</li>
1150
1167
  </ol>
1151
1168
 
@@ -1,2 +1,4 @@
1
1
  Contains the names and contents of all non-configuration files which have
2
- been changed compared to the files in the package.
2
+ been changed compared to the files in the package. A file change is reported
3
+ if its content or its attributes like Linux permission bits or ownership
4
+ have changed.
@@ -1,5 +1,6 @@
1
1
  Contains all configuration files which have been changed since they were
2
2
  installed.
3
3
  Configuration files are all those files which are marked as such in the
4
- package which has installed them. A configuration file is considered changed
5
- if either its content or its Linux permission bits have changed.
4
+ package which has installed them. A configuration file change is reported
5
+ if its content or its attributes like Linux permission bits or ownership
6
+ have changed.
@@ -18,7 +18,7 @@
18
18
  class ChangedManagedFilesInspector < Inspector
19
19
  include ChangedRpmFilesHelper
20
20
 
21
- def inspect(system, description, options = {})
21
+ def inspect(system, description, _filter, options = {})
22
22
  system.check_requirement("rsync", "--version") if options[:extract_changed_managed_files]
23
23
 
24
24
  @system = system
@@ -29,7 +29,13 @@ class ChangedManagedFilesInspector < Inspector
29
29
  file_store.remove
30
30
  if options[:extract_changed_managed_files]
31
31
  file_store.create
32
- existing_files = changed_files.reject { |f| f.changes.nil? || f.changes.include?("deleted") }
32
+
33
+ existing_files = changed_files.reject do |f|
34
+ f.changes.nil? ||
35
+ f.changes.include?("deleted") ||
36
+ f.name == "/"
37
+ end
38
+
33
39
  system.retrieve_files(existing_files.map(&:name), file_store.path)
34
40
  end
35
41
 
@@ -82,7 +82,7 @@ class ConfigFilesInspector < Inspector
82
82
  end
83
83
  end
84
84
 
85
- def inspect(system, description, options = {})
85
+ def inspect(system, description, _filter, options = {})
86
86
  do_extract = options[:extract_changed_config_files]
87
87
  check_requirements(system, do_extract)
88
88
 
@@ -16,7 +16,7 @@
16
16
  # you may find current contact information at www.suse.com
17
17
 
18
18
  class GroupsInspector < Inspector
19
- def inspect(system, description, options = {})
19
+ def inspect(system, description, _filter, _options = {})
20
20
  group_content = system.read_file("/etc/group")
21
21
 
22
22
  groups = group_content ? parse_groups(group_content) : []
@@ -29,6 +29,8 @@ class GroupsInspector < Inspector
29
29
 
30
30
  def parse_groups(content)
31
31
  content.lines.map do |line|
32
+ # prevent split from ignoring the last entry if it is empty and there is no newline
33
+ line += "\n" if line.end_with?(":")
32
34
  name, password, gid, users = line.split(":").map(&:chomp)
33
35
 
34
36
  gid = Machinery::is_int?(gid) ? gid.to_i : nil
@@ -38,7 +38,7 @@ class OsInspector < Inspector
38
38
  special_version ? " #{special_version.gsub(/[0-9]{1,2}/," \\0")}" : ""
39
39
  end
40
40
 
41
- def inspect(system, description, _options = {})
41
+ def inspect(system, description, _filter, _options = {})
42
42
  system.check_requirement("cat", "--version") if system.is_a?(RemoteSystem)
43
43
 
44
44
  os = get_os(system)
@@ -79,7 +79,7 @@ class OsInspector < Inspector
79
79
  return if !os_release
80
80
 
81
81
  result = Hash.new
82
- key_value_pairs = Hash[os_release.split("\n").map { |l| l.split("=") }]
82
+ key_value_pairs = Hash[os_release.split("\n").reject(&:empty?).map { |l| l.split("=") }]
83
83
  key_value_pairs.each_pair do |k,v|
84
84
  result[k.downcase] = v.strip.gsub(/^"|"$/,"")
85
85
  end
@@ -16,7 +16,7 @@
16
16
  # you may find current contact information at www.suse.com
17
17
 
18
18
  class PackagesInspector < Inspector
19
- def inspect(system, description, options = {})
19
+ def inspect(system, description, _filter, _options = {})
20
20
  system.check_requirement("rpm", "--version")
21
21
 
22
22
  packages = Array.new
@@ -16,7 +16,7 @@
16
16
  # you may find current contact information at www.suse.com
17
17
 
18
18
  class PatternsInspector < Inspector
19
- def inspect(system, description, options = {})
19
+ def inspect(system, description, _filter, _options = {})
20
20
  if system.has_command?("zypper")
21
21
  inspect_with_zypper(system, description)
22
22
  else
@@ -16,7 +16,7 @@
16
16
  # you may find current contact information at www.suse.com
17
17
 
18
18
  class RepositoriesInspector < Inspector
19
- def inspect(system, description, options = {})
19
+ def inspect(system, description, _filter, _options = {})
20
20
  if system.has_command?("zypper")
21
21
  description.repositories, summary = inspect_zypp_repositories(system)
22
22
  elsif system.has_command?("yum")
@@ -16,7 +16,7 @@
16
16
  # you may find current contact information at www.suse.com
17
17
 
18
18
  class ServicesInspector < Inspector
19
- def inspect(system, description, options = {})
19
+ def inspect(system, description, _filter, _options = {})
20
20
  if system.has_command?("systemctl")
21
21
  result = ServicesScope.new(
22
22
  init_system: "systemd",
@@ -218,7 +218,7 @@ class UnmanagedFilesInspector < Inspector
218
218
  3
219
219
  end
220
220
 
221
- def inspect(system, description, options = nil)
221
+ def inspect(system, description, filter, options = {})
222
222
  do_extract = options && options[:extract_unmanaged_files]
223
223
  check_requirements(system, do_extract)
224
224
 
@@ -227,40 +227,6 @@ class UnmanagedFilesInspector < Inspector
227
227
 
228
228
  mount_points = MountPoints.new(system)
229
229
 
230
- ignore_list = [
231
- "tmp",
232
- "var/tmp",
233
- "lost+found",
234
- "var/run",
235
- "var/lib/rpm",
236
- ".snapshots",
237
- description.store.base_path.sub(/^\//, ""),
238
- "proc",
239
- "boot"
240
- ]
241
-
242
- # Information about users and groups are extracted by the according inspector
243
- ignore_list += [
244
- "etc/passwd",
245
- "etc/shadow",
246
- "etc/group"
247
- ]
248
-
249
- # Information about services is extracted by the ServicesInspector, so
250
- # we ignore the links representing the same information when inspecting
251
- # unmanaged files.
252
- ignore_list += [
253
- "etc/init.d/boot.d",
254
- "etc/init.d/rc0.d",
255
- "etc/init.d/rc1.d",
256
- "etc/init.d/rc2.d",
257
- "etc/init.d/rc3.d",
258
- "etc/init.d/rc4.d",
259
- "etc/init.d/rc5.d",
260
- "etc/init.d/rc6.d",
261
- "etc/init.d/rcS.d"
262
- ]
263
-
264
230
  rpm_files, rpm_dirs = extract_rpm_database(system)
265
231
 
266
232
  # Btrfs subvolumes and local mounts need to be inspected separately because
@@ -273,9 +239,16 @@ class UnmanagedFilesInspector < Inspector
273
239
  unmanaged_links = {}
274
240
  remote_dirs = mount_points.remote
275
241
  special_dirs = mount_points.special
276
- ignore_list.each do |ignore|
277
- remote_dirs.delete_if { |e| e.start_with?(File.join("/", ignore, "/")) }
278
- end
242
+
243
+ file_filter = filter.element_filter_for("/unmanaged_files/files/name") if filter
244
+ file_filter ||= ElementFilter.new("/unmanaged_files/files/name")
245
+ file_filter.add_matchers(description.store.base_path)
246
+
247
+ # Add a recursive pendant to each ignored element
248
+ file_filter.add_matchers(file_filter.matchers.map { |entry| File.join(entry, "/*") })
249
+
250
+ remote_dirs.delete_if { |e| file_filter.matches?(e) }
251
+
279
252
  excluded_files += remote_dirs
280
253
  excluded_files += special_dirs
281
254
 
@@ -315,10 +288,12 @@ class UnmanagedFilesInspector < Inspector
315
288
  local_filesystems.reject! { |mp| dirs.has_key?(mp) }
316
289
  end
317
290
  if find_dir == "/"
318
- ignore_list.each do |d|
319
- td_with_slash = d + "/"
320
- dirs.reject! {|p| p == d || p.start_with?(td_with_slash) }
321
- files.reject! {|p| p == d || p.start_with?(td_with_slash) }
291
+ dirs.reject! do |dir|
292
+ file_filter.matches?("/" + dir)
293
+ end
294
+
295
+ files.reject! do |dir|
296
+ file_filter.matches?("/" + dir)
322
297
  end
323
298
  end
324
299
  managed, unmanaged = dirs.keys.partition{ |d| rpm_dirs.has_key?(find_dir + d) }
@@ -16,7 +16,7 @@
16
16
  # you may find current contact information at www.suse.com
17
17
 
18
18
  class UsersInspector < Inspector
19
- def inspect(system, description, options = {})
19
+ def inspect(system, description, _filter, _options = {})
20
20
  passwd = system.read_file("/etc/passwd")
21
21
  shadow = system.read_file("/etc/shadow")
22
22
 
@@ -51,7 +51,7 @@
51
51
  "changes": {
52
52
  "type": "array",
53
53
  "items": {
54
- "enum": ["mode", "md5", "group", "user", "replaced"]
54
+ "enum": ["size", "mode", "md5", "device_number", "link_path", "user", "group", "time", "capabilities", "replaced", "other_rpm_changes"]
55
55
  },
56
56
  "minItems": 1
57
57
  },
@@ -51,7 +51,7 @@
51
51
  "changes": {
52
52
  "type": "array",
53
53
  "items": {
54
- "enum": ["mode", "md5", "group", "user", "replaced"]
54
+ "enum": ["size", "mode", "md5", "device_number", "link_path", "user", "group", "time", "capabilities", "replaced", "other_rpm_changes"]
55
55
  },
56
56
  "minItems": 1
57
57
  },
@@ -4,7 +4,7 @@
4
4
  "type": "array",
5
5
  "items" : {
6
6
  "type" : "object",
7
- "required": ["alias", "name", "url", "type", "enabled", "gpgcheck"],
7
+ "required": ["alias", "name", "url", "type", "enabled", "gpgcheck", "package_manager"],
8
8
  "properties": {
9
9
  "alias": {
10
10
  "type": "string",
@@ -10,6 +10,18 @@
10
10
  "format_version": {
11
11
  "type": "integer",
12
12
  "minimum": 1
13
+ },
14
+ "filters": {
15
+ "type": "object",
16
+ "required": ["inspect"],
17
+ "properties": {
18
+ "inspect": {
19
+ "type": "array",
20
+ "items": {
21
+ "type": "string"
22
+ }
23
+ }
24
+ }
13
25
  }
14
26
  },
15
27
  "additionalProperties": {
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: machinery-tool
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.4.0
4
+ version: 1.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - SUSE
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-02-18 00:00:00.000000000 Z
11
+ date: 2015-03-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: cheetah
@@ -197,6 +197,7 @@ files:
197
197
  - export_helpers/unmanaged_files_autoyast_excludes
198
198
  - export_helpers/unmanaged_files_kiwi_excludes
199
199
  - helpers/changed_managed_files.sh
200
+ - helpers/default_filters.json
200
201
  - helpers/filter-packages-for-build.yaml
201
202
  - helpers/yum_repositories.py
202
203
  - html/assets/arrow_down.png
@@ -248,10 +249,12 @@ files:
248
249
  - lib/copy_task.rb
249
250
  - lib/current_user.rb
250
251
  - lib/deploy_task.rb
252
+ - lib/element_filter.rb
251
253
  - lib/exceptions.rb
252
254
  - lib/export_task.rb
253
255
  - lib/exporter.rb
254
256
  - lib/file_validator.rb
257
+ - lib/filter.rb
255
258
  - lib/generate_html_task.rb
256
259
  - lib/helper.rb
257
260
  - lib/hint.rb