Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes #33852 - Content - Errata - Add REX actions #9766

Merged
merged 5 commits into from
Nov 18, 2021
Merged

Conversation

parthaa
Copy link
Contributor

@parthaa parthaa commented Nov 5, 2021

What are the changes introduced in this pull request?

On the new host errata page

  • Added support for installing both individual and multiple errata (including select all) via Katello Agent or Rex
  • Updated the errata install template with new added fields to support Select All and excludes
  • For applicable errata you will be able to go to the appropriate Apply Erratum page when you click on the kebab.

What are the testing steps for this pull request?

On the dev env
  • Go to Hosts -> Job Templates
  • Unlock the Install Errata - Katello SSH Default template using the Actions Dropdown
  • Run this from the rails console
    JobTemplate.without_auditing do
      template_files = Dir[File.join("#{Katello::Engine.root}/app/views/foreman/job_templates/**/*.erb")]
      template_files.reject! { |file| file.end_with?('_ansible_default.erb') } unless Katello.with_ansible?
      template_files.each do |template|
        sync = !Rails.env.test? && Setting[:remote_execution_sync_templates]
        # import! was renamed to import_raw! around 1.3.1
        if JobTemplate.respond_to?('import_raw!')
          template = JobTemplate.import_raw!(File.read(template), :default => true, :lock => true, :update => sync)
        else
          template = JobTemplate.import!(File.read(template), :default => true, :lock => true, :update => sync)
        end

        template.organizations << Organization.unscoped.all if template&.organizations&.empty?
        template.locations << Location.unscoped.all if template&.locations&.empty?
      end
    end
  • This should update the install errata erb template.
  • In the UI Go to Hosts -> Job Templates
  • Click on Install Errata - Katello SSH Default template
  • Click on the Inputs tab. You should see 3 inputs with name Filte Errata, Inclusion Type, and errata
Set up the host

These steps will give you both Applicable and Installable errata on the host.

  1. Create and Sync this repo -> https://partha.fedorapeople.org/test-repos/multi-errata/
  2. Create another repo in the same product. Leave the feed empty
  3. Create a Dev lifecycle environment
  4. Create a content view with the repos created in steps 1 and 2
  5. Publish and Promote it to dev
  6. Create an activation that points dev/cv. Make sure the subscriptions are turned on
  7. Register a rhel7/centos7 with that activation key
  8. On client yum install armadillo-0.1-1.noarch
  9. Also rpm -ivh https://jlsherrill.fedorapeople.org/fake-repos/needed-errata/walrus-0.71-1.noarch.rpm https://jlsherrill.fedorapeople.org/fake-repos/needed-errata/whale-0.2-1.noarch.rpm https://jlsherrill.fedorapeople.org/fake-repos/needed-errata/shark-0.1-1.noarch.rpm https://jlsherrill.fedorapeople.org/fake-repos/needed-errata/stork-0.12-2.noarch.rpm
  10. Now edit the repo in step 2 and add the feed url -> https://jlsherrill.fedorapeople.org/fake-repos/needed-errata/
  11. Sync this repo
  12. Now you should have 38 Applicable Errata and 37 installable errata
  13. Go to Hosts -> New Host Details -> Content -> Errata tab

Now there are 4 bulk apply operations available on this page

  1. Apply by Katello Agent
  2. Apply by Remote Execution
  3. Apply by Customized Remote Execution
  4. Apply button - if remote_execution_by default is enabled then it will use rex. Else it 'll use katello-agent to install the errata.

01-bulk-errata

There are also 3 apply operations available on each installable errata

  1. Apply by Katello Agent
  2. Apply by Remote Execution
  3. Apply by Customized Remote Execution

01-single-errata

On Applicable errata we should see an Apply Erratum link that should take you to Errata - Apply to Content Hosts page.

01-bulk-errata

  • Select All Errata

  • Select Apply by Customized Remote Execution

  • You should be redirected to the Job Invocations errata install page, where you shoud be able to see elements of the new template
    01-select all

  • Notice the Inclusion Type entry saying Include all errata EXCEPT below . The select all resolves to this

  • On same page Filter Errata will get populated if you have search query set and done a Select All

  • Try out different errata operations and make sure they get applied correctly on the host.

Guidelines for Code Review

Backend Changes

  • Moved Bulk operations to a BulkItemsHelper class so that Errata/Traces can make use of the select all.
  • Updated the install_errata.erb template. Added inputs to handle bulk selection operations.
  • Added an advisory_helpers method in host managed extensions to aid with the new template.

Front End Changes

  • In ErrataTab mainly added functionality for errata Apply operations.

@theforeman-bot
Copy link

Issues: #33852

@parthaa parthaa changed the title [WIP] Fixes #33852 - Content - Errata - Add REX actions Fixes #33852 - Content - Errata - Add REX actions Nov 8, 2021
@parthaa
Copy link
Contributor Author

parthaa commented Nov 8, 2021

03-ApplicableButNotInstallable
01-single-errata
01-bulk-errata

@parthaa parthaa closed this Nov 8, 2021
@parthaa parthaa reopened this Nov 8, 2021
app/views/foreman/job_templates/install_errata.erb Outdated Show resolved Hide resolved
app/views/foreman/job_templates/install_errata.erb Outdated Show resolved Hide resolved
@@ -25,6 +25,14 @@ child :content_facet => :content_facet_attributes do
node :katello_tracer_installed do |content_facet|
content_facet.tracer_installed?
end

node :katello_agent_enabled do
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know as a dev it's easy to add these here our sake but it feels a bit weird. Random idea: could the /katello/api/v2 (or similar endpoint) expose some amount of configuration? Multiple places may need this info and a content facet may not be in scope at that point (I don't have an example off the top of my head)?

Or maybe Foreman or other plugin has established something we can use?

Copy link
Contributor Author

@parthaa parthaa Nov 10, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was discussed also. I could get the configuration separately but having that information embedded in the host details made best sense for me. Given we already have katello_tracer_installed and katello_agent_installed there. I dont see why adding katello_agent_enabled and remote_execution_by_default attributes should be a red flag. Considering these are details pertinent to this host?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The examples you gave are reflective of the state of the content host - whether tracer or agent is installed. The fields you've added are related to the configuration of Katello which I guess is pertinent but also has nothing to do with the content facet itself. If you and Jeremy are good then let's go with it

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think ForemanContext would be the ideal place to have something like this. It already contains other global app settings. The problem is that adding values there requires Foreman code changes, and also we'd be adding Katello-specific data. Until we can come up with a way to address both of those issues, I think adding it here is... okay but not great. Adding to the / API endpoint is an interesting idea too, but then we'd have to make an additional API call.

I think going with what we have is fine for now, because at least it's an API call that we're already making. Unless someone can think of another brilliant idea :)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

First time I've seen ForemanContext and it really does seem like the right place. I'm surprised that component wasn't designed with plugin extensibility in mind. That is something we should look into in the future!

@parthaa
Copy link
Contributor Author

parthaa commented Nov 12, 2021

@jturel @jeremylenz Updated this PR and tests to use the Errata Search Query. Check the latest commit.

Copy link
Member

@jeremylenz jeremylenz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looking great!

webpack/components/Table/TableHooks.js Outdated Show resolved Hide resolved
Copy link
Member

@jeremylenz jeremylenz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Haven't been able to test select all yet but I tested the REX actions and they work as expected.

a few comments below :)

@@ -6,10 +6,10 @@ description_format: 'Install errata %{errata}'
feature: katello_errata_install
provider_type: SSH
template_inputs:
- name: errata
description: A comma separated list of errata to install
- name: Errata Search Query
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
- name: Errata Search Query
- name: Errata search query

On all the new pages we've been instructed to use this style of capitalization.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this broke the display of the job name. All my tasks now say

Install errata ''

but they should say the errata ID:

Install errata '2021-blahblah-30148u'

I think if you change line 5 above to

description_format: 'Install errata %{Errata search query}'

it will maybe hopefully fix it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

@@ -19,6 +19,8 @@ foreign_input_sets:
<% advisories = input(:errata).split(',').join(' ') %>
<%= render_template('Package Action - SSH Default', :action => 'install -n -t patch', :package => advisories) %>
<% else %>
<% advisories = input(:errata).split(',').map { |e| "--advisory=#{e}" }.join(' ') %>
<% advisory_ids = @host.advisory_ids(search: input("Errata Search Query")) %>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
<% advisory_ids = @host.advisory_ids(search: input("Errata Search Query")) %>
<% advisory_ids = @host.advisory_ids(search: input("Errata search query")) %>

webpack/components/Table/TableHooks.js Outdated Show resolved Hide resolved
Comment on lines +333 to +334
if (isInstallable) {
rowActions = [
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For non-installable errata, I think these items should still be there, just disabled.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Its a different list for non installable but applicable.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not sure what you mean here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For applicable errata you want to show Apply Erratum which takes em to errata page.
For installable you want to show Apply vi Katello agent etc.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ahhh gotcha.

Update webpack/components/extensions/HostDetails/Tabs/__tests__/errataTab.test.js

Co-authored-by: Jeremy Lenz <jlenz@redhat.com>

Refs #33852  - Addressed comments
Copy link
Member

@jturel jturel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ACK from code perspective. Looks great and the updates appear to map to the meeting we had last week all while maintaining backward compatibility with the existing REX template. That's awesome!

Copy link
Member

@jeremylenz jeremylenz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your patience @parthaa

everything seems to work great! Just a couple Katello agent comments

{ errata_ids: [id] },
));

const apply = () => (contentFacet.remoteExecutionByDefault ? applyViaRemoteExecution() :
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Apply button uses different logic to decide whether to use Katello agent, compared to the dropdown items. This uses

 contentFacet.remoteExecutionByDefault

whereas the dropdowns use

contentFacet.katelloAgentInstalled && contentFacet.katelloAgentEnabled

Was this intended? In my environment, the Apply button tries to use Katello agent, but I don't have any Katello agent actions in the dropdowns. This could be confusing.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed this condition a little. (contentFacet.remoteExecutionByDefault || !katelloAgentAvailable)
So if the thing cant be installed via katello agent it will still try rex (even if you have rexByDefault false).

app/views/foreman/job_templates/install_errata.erb Outdated Show resolved Hide resolved
Co-authored-by: Jeremy Lenz <jlenz@redhat.com>

Update webpack/components/extensions/HostDetails/Tabs/ErrataTab.js

Co-authored-by: Jeremy Lenz <jlenz@redhat.com>

Update app/views/foreman/job_templates/install_errata.erb

Co-authored-by: Jeremy Lenz <jlenz@redhat.com>

more
Copy link
Member

@jeremylenz jeremylenz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changes LGTM

APJ 👍

@parthaa
Copy link
Contributor Author

parthaa commented Nov 17, 2021

[test katello]

1 similar comment
@parthaa
Copy link
Contributor Author

parthaa commented Nov 18, 2021

[test katello]

@parthaa parthaa merged commit 0e7f14c into Katello:master Nov 18, 2021
@parthaa parthaa deleted the rex4 branch November 18, 2021 01:17
chris1984 pushed a commit that referenced this pull request Nov 29, 2021
* Fixes #33852 - Content - Errata - Add REX actions

(cherry picked from commit 0e7f14c)
chris1984 pushed a commit that referenced this pull request Nov 29, 2021
* Fixes #33852 - Content - Errata - Add REX actions

(cherry picked from commit 0e7f14c)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants