foreman_rh_cloud 1.0.6 → 2.0.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (59) hide show
  1. checksums.yaml +4 -4
  2. data/lib/foreman_inventory_upload/async/shell_process.rb +1 -3
  3. data/lib/foreman_inventory_upload/async/upload_report_job.rb +1 -5
  4. data/lib/foreman_inventory_upload/generators/fact_helpers.rb +0 -13
  5. data/lib/foreman_inventory_upload/generators/queries.rb +0 -1
  6. data/lib/foreman_inventory_upload/generators/slice.rb +8 -12
  7. data/lib/foreman_rh_cloud/engine.rb +1 -1
  8. data/lib/foreman_rh_cloud/version.rb +1 -1
  9. data/package.json +20 -100
  10. data/test/factories/inventory_upload_factories.rb +13 -13
  11. data/test/unit/archived_report_generator_test.rb +0 -1
  12. data/test/unit/slice_generator_test.rb +20 -74
  13. data/webpack/ForemanInventoryUpload/Components/AccountList/AccountList.stories.js +5 -14
  14. data/webpack/ForemanInventoryUpload/Components/AccountList/Components/EmptyState/__tests__/EmptyState.test.js +1 -1
  15. data/webpack/ForemanInventoryUpload/Components/AccountList/Components/ErrorState/__tests__/ErrorState.test.js +1 -1
  16. data/webpack/ForemanInventoryUpload/Components/AccountList/Components/ListItem/__tests__/ListItem.test.js +1 -1
  17. data/webpack/ForemanInventoryUpload/Components/AccountList/Components/ListItemStatus/__tests__/ListItemStatus.test.js +1 -1
  18. data/webpack/ForemanInventoryUpload/Components/AccountList/__tests__/AccountList.test.js +1 -1
  19. data/webpack/ForemanInventoryUpload/Components/AccountList/__tests__/AccountListActions.test.js +1 -1
  20. data/webpack/ForemanInventoryUpload/Components/AccountList/__tests__/AccountListIntegration.test.js +1 -1
  21. data/webpack/ForemanInventoryUpload/Components/AccountList/__tests__/AccountListReducer.test.js +1 -1
  22. data/webpack/ForemanInventoryUpload/Components/AccountList/__tests__/AccountListSelectors.test.js +1 -1
  23. data/webpack/ForemanInventoryUpload/Components/AutoUploadSwitcher/__tests__/AutoUploadSwitcher.test.js +1 -1
  24. data/webpack/ForemanInventoryUpload/Components/AutoUploadSwitcher/__tests__/AutoUploadSwitcherActions.test.js +1 -1
  25. data/webpack/ForemanInventoryUpload/Components/Dashboard/Dashboard.fixtures.js +13 -9
  26. data/webpack/ForemanInventoryUpload/Components/Dashboard/Dashboard.stories.js +5 -15
  27. data/webpack/ForemanInventoryUpload/Components/Dashboard/__tests__/Dashboard.test.js +1 -2
  28. data/webpack/ForemanInventoryUpload/Components/Dashboard/__tests__/DashboardActions.test.js +15 -2
  29. data/webpack/ForemanInventoryUpload/Components/Dashboard/__tests__/DashboardIntegration.test.js +1 -1
  30. data/webpack/ForemanInventoryUpload/Components/Dashboard/__tests__/DashboardReducer.test.js +1 -1
  31. data/webpack/ForemanInventoryUpload/Components/Dashboard/__tests__/DashboardSelectors.test.js +1 -1
  32. data/webpack/ForemanInventoryUpload/Components/FileDownload/__tests__/FileDownload.test.js +1 -1
  33. data/webpack/ForemanInventoryUpload/Components/FullScreenModal/__tests__/FullScreenModal.test.js +1 -1
  34. data/webpack/ForemanInventoryUpload/Components/NavContainer/NavContainer.fixtures.js +5 -2
  35. data/webpack/ForemanInventoryUpload/Components/NavContainer/__tests__/NavContainer.test.js +1 -2
  36. data/webpack/ForemanInventoryUpload/Components/NavContainer/__tests__/__snapshots__/NavContainer.test.js.snap +1 -1
  37. data/webpack/ForemanInventoryUpload/Components/PageHeader/__tests__/PageHeader.test.js +1 -1
  38. data/webpack/ForemanInventoryUpload/Components/ReportGenerate/__tests__/ReportGenerate.test.js +1 -1
  39. data/webpack/ForemanInventoryUpload/Components/ReportUpload/__tests__/ReportUpload.test.js +1 -1
  40. data/webpack/ForemanInventoryUpload/Components/ScheduledRun/__tests__/ScheduledRun.test.js +1 -1
  41. data/webpack/ForemanInventoryUpload/Components/StatusChart/__tests__/StatusChart.test.js +1 -1
  42. data/webpack/ForemanInventoryUpload/Components/TabBody/__tests__/TabBody.test.js +1 -1
  43. data/webpack/ForemanInventoryUpload/Components/TabContainer/__tests__/TabContainer.test.js +1 -1
  44. data/webpack/ForemanInventoryUpload/Components/TabFooter/__tests__/TabFooter.test.js +1 -1
  45. data/webpack/ForemanInventoryUpload/Components/TabHeader/__tests__/TabHeader.test.js +1 -1
  46. data/webpack/ForemanInventoryUpload/Components/Terminal/Terminal.js +1 -1
  47. data/webpack/ForemanInventoryUpload/Components/Terminal/__tests__/Terminal.test.js +1 -2
  48. data/webpack/ForemanInventoryUpload/ForemanInventoryUpload.test.js +1 -1
  49. metadata +2 -14
  50. data/lib/foreman_inventory_upload/async/async_helpers.rb +0 -13
  51. data/test/unit/fact_helpers_test.rb +0 -29
  52. data/test/unit/slice_generator_test.rb.orig +0 -280
  53. data/webpack/stories/ForemanInventoryUploadReducers.js +0 -3
  54. data/webpack/stories/configureStore.js +0 -15
  55. data/webpack/stories/decorators/index.js +0 -1
  56. data/webpack/stories/decorators/withCardsDecorator.js +0 -14
  57. data/webpack/stories/index.js +0 -10
  58. data/webpack/stories/index.scss +0 -7
  59. data/webpack/test_setup.js +0 -6
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 58cd71785dedf35f475e09a442c930ba6e703c03a0dcf292a6786efa4b57d6c5
4
- data.tar.gz: 0f87e840488f7381b2797012175d5be8a5cb1eae89febbea1c246e46fd2b8fcf
3
+ metadata.gz: aa962e3bc67676bb6d21b2196824ddef35ece66d0b24dad52658605446c39dfb
4
+ data.tar.gz: 8ee5a01dda9593c05b2babe5f65ee31a8a88dded967b159972351b5ee07e518a
5
5
  SHA512:
6
- metadata.gz: c11c234bfbf1349223411b242317987a972aeb343fdeb4dfcc7fe4de8207b111c1bd2c4a5f10b86410e967a4d466b51fa6060670c220129e811f6c0af8b7cbea
7
- data.tar.gz: 49d3ca3734f72c765c756c691cad4b66a33491e5772348f63a4358741a11c223348aa2cccd4d96537a2b03ee85c07e364eebbb223a2276972e3b1c17b150d41d
6
+ metadata.gz: 6d766ae3c9edec7b7041c73058a80c1e268e5dd2323a049fe66963ab7f313e9ce54e4e6f677b022f2c630944b9b8278bac30207fe4b1cf278cd8db3bdaa393cf
7
+ data.tar.gz: 4e4b112121137835a8a54dd3831ff293e7ba172458a1de2adb310a73afcbb605fc48bfe80456fc7e640218a051d419a98d5e0537f5fa4455ed619de110632fa8
@@ -3,13 +3,11 @@ require 'open3'
3
3
  module ForemanInventoryUpload
4
4
  module Async
5
5
  class ShellProcess < ::ApplicationJob
6
- include AsyncHelpers
7
-
8
6
  def perform(instance_label)
9
7
  klass_name = self.class.name
10
8
  logger.debug("Starting #{klass_name} with label #{instance_label}")
11
9
  progress_output = ProgressOutput.register(instance_label)
12
- Open3.popen2e(hash_to_s(env), command) do |_stdin, stdout_stderr, wait_thread|
10
+ Open3.popen2e(env, command) do |_stdin, stdout_stderr, wait_thread|
13
11
  progress_output.status = "Running in pid #{wait_thread.pid}"
14
12
 
15
13
  stdout_stderr.each do |out_line|
@@ -37,11 +37,7 @@ module ForemanInventoryUpload
37
37
  end
38
38
 
39
39
  def http_proxy_string
40
- @http_proxy_string ||= begin
41
- if Setting[:content_default_http_proxy]
42
- HttpProxy.unscoped.find_by(name: Setting[:content_default_http_proxy])&.full_url
43
- end
44
- end
40
+ @http_proxy_string ||= HttpProxy.default_global_content_proxy&.full_url
45
41
  end
46
42
 
47
43
  def rh_credentials
@@ -13,19 +13,6 @@ module ForemanInventoryUpload
13
13
  def kilobytes_to_bytes(kilobytes)
14
14
  kilobytes * 1024
15
15
  end
16
-
17
- def account_id(organization)
18
- @organization_accounts ||= {}
19
- @organization_accounts[organization.id] ||= organization.pools.where.not(account_number: nil).pluck(:account_number).first
20
- end
21
-
22
- def golden_ticket?(organization)
23
- result = organization.try(:golden_ticket?)
24
- result = organization.content_access_mode == 'org_environment' if result.nil?
25
-
26
- @organization_golden_tickets ||= {}
27
- @organization_golden_tickets[organization.id] ||= result
28
- end
29
16
  end
30
17
  end
31
18
  end
@@ -19,7 +19,6 @@ module ForemanInventoryUpload
19
19
  'lscpu::flags',
20
20
  'distribution::version',
21
21
  'distribution::id',
22
- 'virt::is_guest',
23
22
  ]).pluck(:name, :id)
24
23
  ]
25
24
  end
@@ -26,7 +26,7 @@ module ForemanInventoryUpload
26
26
  @stream.array_field('hosts', :last) do
27
27
  first = true
28
28
  hosts_batch.each do |host|
29
- next unless host&.subscription_facet
29
+ next unless host&.subscription_facet&.pools&.first
30
30
  @stream.comma unless first
31
31
  if report_host(host)
32
32
  first = false
@@ -39,10 +39,11 @@ module ForemanInventoryUpload
39
39
 
40
40
  def report_host(host)
41
41
  @stream.object do
42
+ @stream.simple_field('display_name', host.name)
42
43
  @stream.simple_field('fqdn', host.fqdn)
43
- @stream.simple_field('account', account_id(host.organization).to_s)
44
- @stream.simple_field('subscription_manager_id', host.subscription_facet&.uuid)
45
- @stream.simple_field('satellite_id', host.subscription_facet&.uuid)
44
+ @stream.simple_field('account', host.subscription_facet.pools.where.not(account_number: nil).first&.account_number&.to_s)
45
+ @stream.simple_field('subscription_manager_id', host.subscription_facet.uuid)
46
+ @stream.simple_field('satellite_id', host.subscription_facet.uuid)
46
47
  @stream.simple_field('bios_uuid', fact_value(host, 'dmi::system::uuid'))
47
48
  @stream.simple_field('vm_uuid', fact_value(host, 'virt::uuid'))
48
49
  @stream.array_field('ip_addresses') do
@@ -122,10 +123,6 @@ module ForemanInventoryUpload
122
123
  @stream.simple_field('subscription_status', host.subscription_status_label)
123
124
  @stream.simple_field('katello_agent_running', host.content_facet&.katello_agent_installed?)
124
125
  @stream.simple_field('satellite_managed', true)
125
- @stream.simple_field(
126
- 'infrastructure_type',
127
- ActiveModel::Type::Boolean.new.cast(fact_value(host, 'virt::is_guest')) ? 'virtual' : 'physical'
128
- )
129
126
  unless (installed_products = host.subscription_facet&.installed_products).empty?
130
127
  @stream.array_field('installed_products') do
131
128
  @stream.raw(installed_products.map do |product|
@@ -146,16 +143,15 @@ module ForemanInventoryUpload
146
143
  end
147
144
 
148
145
  def report_satellite_facts(host)
149
- @stream.simple_field('virtual_host_name', host.subscription_facet&.hypervisor_host&.name)
150
- @stream.simple_field('virtual_host_uuid', host.subscription_facet&.hypervisor_host&.subscription_facet&.uuid)
146
+ @stream.simple_field('virtual_host_name', host.subscription_facet.hypervisor_host&.name)
147
+ @stream.simple_field('virtual_host_uuid', host.subscription_facet.hypervisor_host&.subscription_facet&.uuid)
151
148
  if defined?(ForemanThemeSatellite)
152
149
  @stream.simple_field('satellite_version', ForemanThemeSatellite::SATELLITE_VERSION)
153
150
  end
154
151
  @stream.simple_field('system_purpose_usage', host.subscription_facet.purpose_usage)
155
152
  @stream.simple_field('system_purpose_role', host.subscription_facet.purpose_role)
156
153
  @stream.simple_field('distribution_version', fact_value(host, 'distribution::version'))
157
- @stream.simple_field('satellite_instance_id', Foreman.try(:instance_id))
158
- @stream.simple_field('is_simple_content_access', golden_ticket?(host.organization))
154
+ @stream.simple_field('satellite_instance_id', Foreman.respond_to?(:instance_id) ? Foreman.instance_id : nil)
159
155
  @stream.simple_field('organization_id', host.organization_id, :last)
160
156
  end
161
157
 
@@ -26,7 +26,7 @@ module ForemanRhCloud
26
26
 
27
27
  initializer 'foreman_rh_cloud.register_plugin', :before => :finisher_hook do |_app|
28
28
  Foreman::Plugin.register :foreman_rh_cloud do
29
- requires_foreman '~> 1.24.0'
29
+ requires_foreman '> 1.24'
30
30
 
31
31
  # Add permissions
32
32
  security_block :foreman_rh_cloud do
@@ -1,3 +1,3 @@
1
1
  module ForemanRhCloud
2
- VERSION = '1.0.6'.freeze
2
+ VERSION = '2.0.5'.freeze
3
3
  end
@@ -4,14 +4,14 @@
4
4
  "description": "Inventory Upload =============",
5
5
  "main": "index.js",
6
6
  "scripts": {
7
- "lint": "./node_modules/.bin/eslint -c .eslintrc webpack/",
8
- "test": "node node_modules/.bin/jest --no-cache",
9
- "test:watch": "node node_modules/.bin/jest --watchAll",
10
- "test:current": "node node_modules/.bin/jest --watch",
11
- "coveralls": "cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js",
12
- "storybook": "start-storybook -p 6006",
13
- "storybook:build": "node --max_old_space_size=2048 ./node_modules/.bin/build-storybook --config-dir .storybook --output-dir .storybook-dist",
14
- "storybook:deploy": "surge --project .storybook-dist"
7
+ "lint": "tfm-lint --plugin -d /webpack",
8
+ "test": "tfm-test --plugin",
9
+ "test:watch": "tfm-test --plugin --watchAll",
10
+ "test:current": "tfm-test --plugin --watch",
11
+ "publish-coverage": "tfm-publish-coverage",
12
+ "stories": "tfm-stories --plugin",
13
+ "stories:build": "tfm-build-stories --plugin",
14
+ "stories:deploy": "surge --project .storybook-dist"
15
15
  },
16
16
  "repository": {
17
17
  "type": "git",
@@ -20,106 +20,26 @@
20
20
  "bugs": {
21
21
  "url": "http://projects.theforeman.org/projects/foreman_rh_cloud/issues"
22
22
  },
23
- "optionalDependencies": {
24
- "babel-plugin-module-resolver": "^3.2.0"
23
+ "peerDependencies": {
24
+ "@theforeman/vendor": ">= 4.0.2"
25
25
  },
26
26
  "devDependencies": {
27
- "@storybook/addon-actions": "^5.0.1",
28
- "@storybook/addon-knobs": "^5.0.1",
29
- "@storybook/react": "^5.0.1",
30
- "babel-cli": "^6.10.1",
31
- "babel-core": "^6.26.3",
32
- "babel-eslint": "^8.2.3",
33
- "babel-jest": "^23.6.0",
34
- "babel-loader": "^7.1.1",
35
- "babel-plugin-dynamic-import-node": "^2.0.0",
36
- "babel-plugin-lodash": "^3.3.4",
37
- "babel-plugin-syntax-dynamic-import": "^6.18.0",
38
- "babel-plugin-transform-class-properties": "^6.24.1",
39
- "babel-plugin-transform-object-assign": "^6.8.0",
40
- "babel-plugin-transform-object-rest-spread": "^6.8.0",
41
- "babel-preset-env": "^1.7.0",
42
- "babel-preset-react": "^6.5.0",
43
- "coveralls": "^3.0.0",
44
- "enzyme": "^3.4.0",
45
- "enzyme-adapter-react-16": "^1.4.0",
46
- "enzyme-to-json": "^3.2.1",
47
- "eslint": "^4.10.0",
48
- "eslint-import-resolver-babel-module": "^4.0.0",
49
- "eslint-plugin-patternfly-react": "0.2.0",
50
- "identity-obj-proxy": "^3.0.0",
51
- "jed": "^1.1.1",
52
- "jest-cli": "^23.6.0",
53
- "jest-prop-type-error": "^1.1.0",
54
- "node-sass": "^4.5.0",
55
- "patternfly": "^3.58.0",
27
+ "@babel/core": "^7.7.0",
28
+ "@theforeman/builder": "^4.0.2",
29
+ "@theforeman/stories": "^4.0.2",
30
+ "@theforeman/test": "^4.0.2",
31
+ "@theforeman/vendor-dev": "^4.0.2",
32
+ "@theforeman/eslint-plugin-foreman": "^4.0.2",
33
+ "babel-eslint": "^10.0.0",
34
+ "eslint": "^6.7.2",
56
35
  "prettier": "^1.13.5",
57
36
  "raf": "^3.4.0",
58
- "react-redux-test-utils": "^0.1.1",
59
- "react-remarkable": "^1.1.3",
60
- "sass-loader": "^6.0.7",
61
37
  "stylelint": "^9.3.0",
62
38
  "stylelint-config-standard": "^18.0.0",
63
39
  "surge": "^0.20.3"
64
40
  },
65
41
  "dependencies": {
66
- "babel-polyfill": "^6.26.0",
67
- "classnames": "^2.2.5",
68
- "lodash": "^4.17.10",
69
- "patternfly-react": "^2.19.1",
70
- "prop-types": "^15.6.0",
71
- "react": "^16.4.0",
72
- "react-dom": "^16.4.0",
73
- "react-intl": "^2.8.0",
74
- "react-redux": "^5.0.6",
75
- "redux": "^3.6.0",
76
- "redux-thunk": "^2.2.0",
77
- "reselect": "^3.0.1",
78
- "seamless-immutable": "^7.1.2",
79
- "urijs": "^1.18.10",
80
- "uuid": "^3.0.1"
81
- },
82
- "jest": {
83
- "automock": true,
84
- "verbose": true,
85
- "testMatch": [
86
- "**/*.test.js"
87
- ],
88
- "testURL": "http://localhost/",
89
- "collectCoverage": true,
90
- "collectCoverageFrom": [
91
- "webpack/**/*.js",
92
- "!webpack/index.js",
93
- "!webpack/test_setup.js",
94
- "!webpack/**/bundle*",
95
- "!webpack/stories/**",
96
- "!webpack/**/*stories.js"
97
- ],
98
- "coverageReporters": [
99
- "lcov"
100
- ],
101
- "unmockedModulePathPatterns": [
102
- "webpack/",
103
- "react",
104
- "node_modules/"
105
- ],
106
- "moduleNameMapper": {
107
- "^.+\\.(png|gif|css|scss)$": "identity-obj-proxy"
108
- },
109
- "globals": {
110
- "__testing__": true
111
- },
112
- "transform": {
113
- "^.+\\.js$": "babel-jest"
114
- },
115
- "moduleDirectories": [
116
- "node_modules",
117
- "webpack"
118
- ],
119
- "setupFiles": [
120
- "raf/polyfill",
121
- "jest-prop-type-error",
122
- "./webpack/test_setup.js"
123
- ]
42
+ "jed": "^1.1.1",
43
+ "react-intl": "^2.8.0"
124
44
  }
125
45
  }
@@ -1,16 +1,16 @@
1
1
  # redefine katello factories, as long as katello is not compatible with dynamic properties
2
2
  FactoryBot.define do
3
3
  factory :katello_organization, :class => "Organization" do
4
- type {"Organization"}
4
+ type { "Organization" }
5
5
  sequence(:name) { |n| "Organization#{n}" }
6
6
  sequence(:label) { |n| "org#{n}" }
7
7
  sequence(:id) { |n| n }
8
8
 
9
9
  trait :acme_corporation do
10
- name {"ACME_Corporation"}
11
- type {"Organization"}
12
- description {"This is the first Organization."}
13
- label {"acme_corporation_label"}
10
+ name { "ACME_Corporation" }
11
+ type { "Organization" }
12
+ description { "This is the first Organization." }
13
+ label { "acme_corporation_label" }
14
14
  end
15
15
 
16
16
  trait :with_library do
@@ -24,11 +24,11 @@ end
24
24
  FactoryBot.define do
25
25
  factory :katello_content_view, :class => Katello::ContentView do
26
26
  sequence(:name) { |n| "Database#{n}" }
27
- description {"This content view is for database content"}
27
+ description { "This content view is for database content" }
28
28
  association :organization, :factory => :katello_organization
29
29
 
30
30
  trait :composite do
31
- composite {true}
31
+ composite { true }
32
32
  end
33
33
  end
34
34
  end
@@ -50,23 +50,23 @@ end
50
50
  FactoryBot.define do
51
51
  factory :katello_subscription_facets, :aliases => [:subscription_facet], :class => ::Katello::Host::SubscriptionFacet do
52
52
  sequence(:uuid) { |n| "uuid-#{n}-#{rand(500)}" }
53
- facts { {'memory.memtotal' => "12 GB"} }
53
+ facts { { 'memory.memtotal' => "12 GB" } }
54
54
  end
55
55
  end
56
56
 
57
57
  FactoryBot.define do
58
58
  factory :katello_pool, :class => Katello::Pool do
59
- active {true}
60
- end_date {Date.today + 1.year}
59
+ active { true }
60
+ end_date { Date.today + 1.year }
61
61
  end
62
62
  end
63
63
 
64
64
  FactoryBot.modify do
65
65
  factory :host do
66
66
  transient do
67
- content_view {nil}
68
- lifecycle_environment {nil}
69
- content_source {nil}
67
+ content_view { nil }
68
+ lifecycle_environment { nil }
69
+ content_source { nil }
70
70
  end
71
71
 
72
72
  trait :with_content do
@@ -49,7 +49,6 @@ class ArchivedReportGeneratorTest < ActiveSupport::TestCase
49
49
  test_org = FactoryBot.create(:organization)
50
50
 
51
51
  ForemanInventoryUpload::Generators::Queries.expects(:for_org).with(test_org.id).returns(batches)
52
- ForemanInventoryUpload::Generators::Slice.any_instance.stubs(:golden_ticket?).returns(false)
53
52
  Dir.mktmpdir do |tmpdir|
54
53
  target = File.join(tmpdir, 'test.tar.gz')
55
54
  generator = ForemanInventoryUpload::Generators::ArchivedReport.new(target, Logger.new(STDOUT))
@@ -16,7 +16,7 @@ class ReportGeneratorTest < ActiveSupport::TestCase
16
16
  organization: env.organization
17
17
  )
18
18
 
19
- @host.organization.pools << FactoryBot.create(:katello_pool, account_number: '1234', cp_id: 1)
19
+ @host.subscription_facet.pools << FactoryBot.create(:katello_pool, account_number: '1234', cp_id: 1)
20
20
 
21
21
  ForemanInventoryUpload::Generators::Queries.instance_variable_set(:@fact_names, nil)
22
22
  end
@@ -37,7 +37,6 @@ class ReportGeneratorTest < ActiveSupport::TestCase
37
37
  'distribution::name',
38
38
  'distribution::version',
39
39
  'distribution::id',
40
- 'virt::is_guest',
41
40
  ]
42
41
  end
43
42
 
@@ -51,13 +50,14 @@ class ReportGeneratorTest < ActiveSupport::TestCase
51
50
 
52
51
  test 'generates a report for a single host' do
53
52
  batch = Host.where(id: @host.id).in_batches.first
54
- generator = create_generator(batch)
53
+ generator = ForemanInventoryUpload::Generators::Slice.new(batch, [], 'slice_123')
55
54
 
56
55
  json_str = generator.render
57
56
  actual = JSON.parse(json_str.join("\n"))
58
57
 
59
58
  assert_equal 'slice_123', actual['report_slice_id']
60
59
  assert_not_nil(actual_host = actual['hosts'].first)
60
+ assert_equal @host.name, actual_host['display_name']
61
61
  assert_equal @host.fqdn, actual_host['fqdn']
62
62
  assert_equal '1234', actual_host['account']
63
63
  assert_equal 1, generator.hosts_count
@@ -66,7 +66,7 @@ class ReportGeneratorTest < ActiveSupport::TestCase
66
66
  test 'generates a report with satellite facts' do
67
67
  Foreman.expects(:instance_id).twice.returns('satellite-id')
68
68
  batch = Host.where(id: @host.id).in_batches.first
69
- generator = create_generator(batch)
69
+ generator = ForemanInventoryUpload::Generators::Slice.new(batch, [], 'slice-123')
70
70
 
71
71
  json_str = generator.render
72
72
  actual = JSON.parse(json_str.join("\n"))
@@ -77,11 +77,11 @@ class ReportGeneratorTest < ActiveSupport::TestCase
77
77
  assert_equal 'satellite-id', satellite_facts['satellite_instance_id']
78
78
  assert_equal @host.organization_id, satellite_facts['organization_id']
79
79
 
80
- instance_id_tag = actual['hosts'].first['tags'].find { |tag| tag['namespace'] == 'satellite' && tag['key'] == 'satellite_instance_id'}
80
+ instance_id_tag = actual['hosts'].first['tags'].find { |tag| tag['namespace'] == 'satellite' && tag['key'] == 'satellite_instance_id' }
81
81
  assert_not_nil instance_id_tag
82
82
  assert_equal 'satellite-id', instance_id_tag['value']
83
83
 
84
- org_id_tag = actual['hosts'].first['tags'].find { |tag| tag['namespace'] == 'satellite' && tag['key'] == 'organization_id'}
84
+ org_id_tag = actual['hosts'].first['tags'].find { |tag| tag['namespace'] == 'satellite' && tag['key'] == 'organization_id' }
85
85
  assert_not_nil org_id_tag
86
86
  assert_equal @host.organization_id.to_s, org_id_tag['value']
87
87
 
@@ -107,13 +107,14 @@ class ReportGeneratorTest < ActiveSupport::TestCase
107
107
  @host.save!
108
108
 
109
109
  batch = Host.where(id: @host.id).in_batches.first
110
- generator = create_generator(batch)
110
+ generator = ForemanInventoryUpload::Generators::Slice.new(batch, [], 'slice_123')
111
111
 
112
112
  json_str = generator.render
113
113
  actual = JSON.parse(json_str.join("\n"))
114
114
 
115
115
  assert_equal 'slice_123', actual['report_slice_id']
116
116
  assert_not_nil(actual_host = actual['hosts'].first)
117
+ assert_equal @host.name, actual_host['display_name']
117
118
  assert_equal @host.fqdn, actual_host['fqdn']
118
119
  assert_not_nil(host_facts = actual_host['facts']&.first)
119
120
  assert_equal 'satellite', host_facts['namespace']
@@ -128,13 +129,14 @@ class ReportGeneratorTest < ActiveSupport::TestCase
128
129
  @host.subscription_facet.save!
129
130
 
130
131
  batch = Host.where(id: @host.id).in_batches.first
131
- generator = create_generator(batch)
132
+ generator = ForemanInventoryUpload::Generators::Slice.new(batch, [], 'slice_123')
132
133
 
133
134
  json_str = generator.render
134
135
  actual = JSON.parse(json_str.join("\n"))
135
136
 
136
137
  assert_equal 'slice_123', actual['report_slice_id']
137
138
  assert_not_nil(actual_host = actual['hosts'].first)
139
+ assert_equal @host.name, actual_host['display_name']
138
140
  assert_equal @host.fqdn, actual_host['fqdn']
139
141
  assert_not_nil(host_facts = actual_host['facts']&.first)
140
142
  assert_equal 'satellite', host_facts['namespace']
@@ -143,22 +145,6 @@ class ReportGeneratorTest < ActiveSupport::TestCase
143
145
  assert_equal 'test_role', fact_values['system_purpose_role']
144
146
  end
145
147
 
146
- test 'generates a report for a golden ticket' do
147
- batch = Host.where(id: @host.id).in_batches.first
148
- generator = create_generator(batch) do |generator|
149
- generator.stubs(:golden_ticket?).returns(true)
150
- end
151
-
152
- json_str = generator.render
153
- actual = JSON.parse(json_str.join("\n"))
154
-
155
- assert_equal 'slice_123', actual['report_slice_id']
156
- assert_not_nil(actual_host = actual['hosts'].first)
157
- assert_equal @host.fqdn, actual_host['fqdn']
158
- assert_equal '1234', actual_host['account']
159
- assert_equal 1, generator.hosts_count
160
- end
161
-
162
148
  test 'skips hosts without subscription' do
163
149
  a_host = FactoryBot.create(
164
150
  :host,
@@ -167,13 +153,14 @@ class ReportGeneratorTest < ActiveSupport::TestCase
167
153
 
168
154
  # make a_host last
169
155
  batch = Host.where(id: [@host.id, a_host.id]).order(:name).in_batches.first
170
- generator = create_generator(batch)
156
+ generator = ForemanInventoryUpload::Generators::Slice.new(batch, [], 'slice_123')
171
157
 
172
158
  json_str = generator.render
173
159
  actual = JSON.parse(json_str.join("\n"))
174
160
 
175
161
  assert_equal 'slice_123', actual['report_slice_id']
176
162
  assert_not_nil(actual_host = actual['hosts'].first)
163
+ assert_equal @host.name, actual_host['display_name']
177
164
  assert_equal @host.fqdn, actual_host['fqdn']
178
165
  assert_equal '1234', actual_host['account']
179
166
  assert_equal 1, generator.hosts_count
@@ -183,7 +170,7 @@ class ReportGeneratorTest < ActiveSupport::TestCase
183
170
  FactoryBot.create(:fact_value, fact_name: fact_names['memory::memtotal'], value: '1', host: @host)
184
171
 
185
172
  batch = Host.where(id: @host.id).in_batches.first
186
- generator = create_generator(batch)
173
+ generator = ForemanInventoryUpload::Generators::Slice.new(batch, [], 'slice_123')
187
174
 
188
175
  json_str = generator.render
189
176
  actual = JSON.parse(json_str.join("\n"))
@@ -195,14 +182,15 @@ class ReportGeneratorTest < ActiveSupport::TestCase
195
182
  end
196
183
 
197
184
  test 'reports an account for hosts with multiple pools' do
198
- first_pool = @host.organization.pools.first
185
+ first_pool = @host.subscription_facet.pools.first
199
186
  second_pool = FactoryBot.create(:katello_pool, account_number: nil, cp_id: 2)
200
- new_org = FactoryBot.create(:organization, pools: [first_pool, second_pool])
201
- @host.organization = new_org
202
- @host.save!
187
+ @host.subscription_facet.pools = []
188
+ @host.subscription_facet.save!
189
+ @host.subscription_facet.pools << first_pool
190
+ @host.subscription_facet.pools << second_pool
203
191
 
204
192
  batch = Host.where(id: @host.id).in_batches.first
205
- generator = create_generator(batch)
193
+ generator = ForemanInventoryUpload::Generators::Slice.new(batch, [], 'slice_123')
206
194
 
207
195
  json_str = generator.render
208
196
  actual = JSON.parse(json_str.join("\n"))
@@ -219,7 +207,7 @@ class ReportGeneratorTest < ActiveSupport::TestCase
219
207
  FactoryBot.create(:fact_value, fact_name: fact_names['distribution::id'], value: 'TestId', host: @host)
220
208
 
221
209
  batch = Host.where(id: @host.id).in_batches.first
222
- generator = create_generator(batch)
210
+ generator = ForemanInventoryUpload::Generators::Slice.new(batch, [], 'slice_123')
223
211
 
224
212
  json_str = generator.render
225
213
  actual = JSON.parse(json_str.join("\n"))
@@ -229,46 +217,4 @@ class ReportGeneratorTest < ActiveSupport::TestCase
229
217
  assert_not_nil(actual_profile = actual_host['system_profile'])
230
218
  assert_equal 'Red Hat Test Linux 7.1 (TestId)', actual_profile['os_release']
231
219
  end
232
-
233
- test 'sets infrastructure_type to "virtual" based on virt.is_guest fact' do
234
- FactoryBot.create(:fact_value, fact_name: fact_names['virt::is_guest'], value: true, host: @host)
235
-
236
- batch = Host.where(id: @host.id).in_batches.first
237
- generator = create_generator(batch)
238
-
239
- json_str = generator.render
240
- actual = JSON.parse(json_str.join("\n"))
241
-
242
- assert_equal 'slice_123', actual['report_slice_id']
243
- assert_not_nil(actual_host = actual['hosts'].first)
244
- assert_not_nil(actual_profile = actual_host['system_profile'])
245
- assert_equal 'virtual', actual_profile['infrastructure_type']
246
- end
247
-
248
- test 'sets infrastructure_type to "physical" based on virt.is_guest fact' do
249
- FactoryBot.create(:fact_value, fact_name: fact_names['virt::is_guest'], value: false, host: @host)
250
-
251
- batch = Host.where(id: @host.id).in_batches.first
252
- generator = create_generator(batch)
253
-
254
- json_str = generator.render
255
- actual = JSON.parse(json_str.join("\n"))
256
-
257
- assert_equal 'slice_123', actual['report_slice_id']
258
- assert_not_nil(actual_host = actual['hosts'].first)
259
- assert_not_nil(actual_profile = actual_host['system_profile'])
260
- assert_equal 'physical', actual_profile['infrastructure_type']
261
- end
262
-
263
- private
264
-
265
- def create_generator(batch, name = 'slice_123')
266
- generator = ForemanInventoryUpload::Generators::Slice.new(batch, [], name)
267
- if block_given?
268
- yield(generator)
269
- else
270
- generator.stubs(:golden_ticket?).returns(false)
271
- end
272
- generator
273
- end
274
220
  end