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 #34211 - Hosts - Change content source #9873

Merged
merged 1 commit into from Jan 25, 2022

Conversation

stejskalleos
Copy link
Contributor

@stejskalleos stejskalleos commented Jan 3, 2022

What are the changes introduced in this pull request?

New feature for changing host's content source & generating bash code for configuration on the host machines

Considerations taken when implementing this change?

What are the testing steps for this pull request?

UI:

  • Go to Hosts > All hosts, select hosts and choose Change Content Source option in menu
  • Change the CS
  • Run job invocation (or do it manually)
  • Verify that subscription-manager have been configured properly

API:

  • Call the API endpoint from host machine and run bash code on it
curl -X 'PUT 'http://katello.example.com/api/hosts/change_content_source' \
  --user admin:changeme \
  -H 'Content-Type: application/json' \
  --data '{"environment_id":"0","content_view_id":"0","content_source_id":"0","host_ids":[0]}' | bash

TODO

  • React tests

@theforeman-bot
Copy link

Issues: #34211

@evgeni
Copy link
Member

evgeni commented Jan 4, 2022

[test katello]

@jturel jturel self-assigned this Jan 4, 2022
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.

I've left a lot of feedback here and so I haven't tested it end-to-end yet but overall it looks good.

This really needs some test coverage for the larger pieces (API, primary react components).

end

@content_sources = SmartProxy.authorized(:view_smart_proxies).with_content.includes([:smart_proxy_features])
@environments = KTEnvironment.readable.includes([:organization, :env_priors, :priors]).order(:name)
Copy link
Member

Choose a reason for hiding this comment

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

It looks like this form implies changing organization by being able to select an environment that doesn't belong to the host's current organization, and that's made more complicated if you selected hosts that span organizations. Seems like we'd need to guard against this. What do you think?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hmm, yeah, there should be some checks. I'll look into 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.

I added WithOrganization so now user must select organization

param :content_view_id, :number, required: true, desc: N_("The id of the content view")
param :content_source_id, :number, required: true, desc: N_("The id of the content source")
def change_content_source
hosts = ::Host.where(id: params[:host_ids])
Copy link
Member

Choose a reason for hiding this comment

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

Do we have an "editable" scope or something similar for Host?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

There is a check for edit_hosts permission when calling the endpoint:

        def action_permission
          case params[:action]
          when 'host_collections'
            'edit'
          when 'change_content_source'
            'edit'
          else
            super
          end
        end

app/helpers/katello/content_source_helper.rb Outdated Show resolved Hide resolved
app/views/foreman/hosts/change_content_source.erb Outdated Show resolved Hide resolved
webpack/index.js Outdated Show resolved Hide resolved
webpack/scenes/ChangeContentSource/actions.js Outdated Show resolved Hide resolved
webpack/scenes/ChangeContentSource/components/cs_form.js Outdated Show resolved Hide resolved
webpack/scenes/ChangeContentSource/components/cs_form.js Outdated Show resolved Hide resolved
@stejskalleos stejskalleos marked this pull request as draft January 7, 2022 13:10
@stejskalleos stejskalleos marked this pull request as ready for review January 10, 2022 14:49
@stejskalleos
Copy link
Contributor Author

@jturel updated, now requires selected organization prior to the change of content source.
@jeremylenz could please do the review of the .js code?

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 @stejskalleos

JS code looks mostly fine; left some comments below. (please note this is code review only and I haven't tested functionality.)

webpack/scenes/Hosts/ChangeContentSource/helpers.js Outdated Show resolved Hide resolved
webpack/scenes/Hosts/ChangeContentSource/helpers.js Outdated Show resolved Hide resolved
webpack/scenes/Hosts/ChangeContentSource/helpers.js Outdated Show resolved Hide resolved
webpack/scenes/Hosts/ChangeContentSource/helpers.js Outdated Show resolved Hide resolved
webpack/scenes/Hosts/ChangeContentSource/index.js Outdated Show resolved Hide resolved
@jturel
Copy link
Member

jturel commented Jan 14, 2022

Just started testing but I seem to be getting stuck (button is disabled)

image

@stejskalleos
Copy link
Contributor Author

Just started testing but I seem to be getting stuck (button is disabled)

Oh sorry my bad, did quick refactoring of formIsValid() function and didn't test it properly. Now it should work + rebased.

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 doing the JSX refactoring I suggested! Found a couple more places that still need to be updated :)

@jturel
Copy link
Member

jturel commented Jan 24, 2022

@jeremylenz has all of your feedback been addressed? If so I can start testing again

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.

@jturel JS changes look good, thanks @stejskalleos! Left one more wording comment below, but please feel free to commence testing!

webpack/scenes/Hosts/ChangeContentSource/index.js Outdated Show resolved Hide resolved
@jturel
Copy link
Member

jturel commented Jan 24, 2022

@stejskalleos this looks and works great! nice work.

There's one thing I wanna bring to your attention:

  • Select my host and go into Change Content Source
  • Change the organization from the org switcher at the top
  • I can see and set all the fields but I can't apply the change - which is good

It may be better to not show the any of the selection fields in this scenario and instead show some kind of message about the host not belonging to the selected organization. What do you think?

@jeremylenz
Copy link
Member

It may be better to not show the any of the selection fields in this scenario and instead show some kind of message about the host not belonging to the selected organization

You can use webpack/components/WithOrganization/withOrganization.js for this

@jturel
Copy link
Member

jturel commented Jan 24, 2022

It may be better to not show the any of the selection fields in this scenario and instead show some kind of message about the host not belonging to the selected organization

You can use webpack/components/WithOrganization/withOrganization.js for this

I thought withOrganization enforces that an organization is selected rather than ensuring that the selected organization contains the current resource on the page. Or maybe you meant that as a first step in shoring up the issue?

@jeremylenz
Copy link
Member

I thought withOrganization enforces that an organization is selected rather then ensuring that the selected organization contains the current resource on the page.

Ah, you're right. Been a while. Delete that comment 😄

@stejskalleos
Copy link
Contributor Author

@jeremylenz @jturel fixed the wording and disabled fields when there are no hosts to configure (that case with changing the organization)

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

@jeremylenz I'll merge once this has your approval as well

Thanks @stejskalleos !

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.

ACK 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
5 participants