-
Notifications
You must be signed in to change notification settings - Fork 898
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
Add Alert Definition Profiles (MiqAlertSet) REST API support #14438
Conversation
@miq-bot add_label enhancement, api, control |
@moolitayer @zeari @simon3z @abellotti please review |
b367c9a
to
20a08c5
Compare
@moolitayer I think you should review this one given that it is directly related to your work on alerts (and what we need for dwh). |
REQUIRED_FIELDS = %w(description mode).freeze | ||
|
||
def create_resource(type, id, data = {}) | ||
assert_id_not_specified(data, type) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Safe to remove this as it is called in api::base_controller:generic (I checked :beer:)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done, thanks!
module AlertDefinitions | ||
def alert_definitions_query_resource(object) | ||
return {} unless object.respond_to?(:miq_alerts) | ||
object.miq_alerts |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That would give us a MiqPolicySet's MiqPolicies but will not give us a VM MiqPolicies.
Is that intentional?
If you need that you should call get_policies (see miq_policy_mixin.rb)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you mean MiqAlertSet
and MiqAlert
right?
Are you sure about it? seemed to me it returns the object's miq_alerts
, regarding of the set type.
BTW, to the best of my knowledge, there is no miq_alert_mixin.rb
to offer get_alerts
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry I was confused with policies (I keep thinking of the two together). This looks good, we only need to get the miq alerts belonging to a miq alert profile
:identifier: alert_definition_profile_delete | ||
:delete: | ||
- :name: delete | ||
:identifier: alert_definition_profile_delete |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we need two kinds of assign here:
Assign to object and assign a policy to this profile.
(we cannot assign to object through an object subcollection since the target entities we need have no rest endpoints for example container_node.rb)
@abellotti me and @dkorn were discussing this and weren't sure how to do it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's wait for @abellotti 's suggestion :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
are we talking about assigning an MiqPolicy to a CI as well as an alert_definition_profile ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes. assigning miq alert to miq alert profile seems straight forward. Assigning miq alert profile to object is more complex. You can assign a miq alert profile to a specific object, all object of a provider or all object in the system ("the Enterprise"). And the UI currently has the information of which alerts can be assigned to what (based on the target type, some can be assign only to one object others only to all the objects in the system)
I don't think this would be easy to get at one shot but what we need most urgent is to assign MA to MAP and MAP to all container nodes in the system. Of course the design should allow growing other examples next
Adding CRUD actions support to alert definition profile API endpoint
20a08c5
to
4067acb
Compare
@abellotti, @moolitayer and I tried to find an implementation for assigning policies to a policy profile (to take example from) but couldn't find it. |
MiqPolicySet does not have the add_policy method exposed to it, so I'd say not supported today. Also, could't find functionality in the UI. |
@abellotti If you go to Control -> Explorer -> Policy Profiles you can add policies to an existing policy profile or create a new one and select policies to it (@moolitayer keep me honest here). @abellotti Is there a reason not to expose adding |
@dkorn I think you're right, in my DB I only had a read-only policy profile. looks like I can attempt POST /api/policy_profiles/:id/policies in the API, with the assign and unassign actions like the other CI's, however I'm getting undefine method 'add_policy' and 'remove_policy'. So it would be good to know what methods the UI uses for this, and why we can't expose add_policy and remove_policy so it will work like like the other CI's. Also, some of the policy_profiles cannot be edited so we need to support the same and only expose the actions when in effect (driven by validate_action options in api.yml). |
@abellotti the UI works with the MiqSet I submitted a PR to expose these actions in case the object to assign the policies to is a policy profile: #14575 |
@abellotti can we progress with this PR (alert profiles CRUD) without the assigning of alerts to alerts profiles? (which is also discussed regarding policies in another PR of mine #14575) |
@abellotti bumping this one up |
@abellotti Hi Alberto, we need your help on this one.. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @dkorn, this looks good, a couple of minor changes. Thanks !!
/cc @Loicavenel
module AlertDefinitions | ||
def alert_definitions_query_resource(object) | ||
return {} unless object.respond_to?(:miq_alerts) | ||
object.miq_alerts |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
probably should return [], above 2 lines can just be:
object.respond_to?(:miq_alerts) ? object.miq_alerts : []
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done, thanks!
@@ -143,3 +144,115 @@ | |||
expect(alert_definitions.second.reload.description).to eq("Updated Test Alert 2") | |||
end | |||
end | |||
|
|||
describe "Alerts Definition Profiles API" do | |||
it "reads 2 alert definition profiles as a collection" do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let's add a test for accessing without appropriate role and expect the forbidden error. Thanks.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added, thanks!
api_basic_authorize action_identifier(:alert_definition_profiles, :delete, :resource_actions, :post) | ||
alert_definition_profile = FactoryGirl.create(:miq_alert_set) | ||
run_post(alert_definition_profiles_url(alert_definition_profile.id), gen_request(:delete)) | ||
expect(response).to have_http_status(:ok) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just esthetics/grouping, if you can add a blank line between the run_* commands and the expects, here and the tests below. Thanks.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done, thanks!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is looking great, minor update to api.yml and we're good. Thanks!!
config/api.yml
Outdated
:identifier: alert_definition_profile | ||
:options: | ||
- :collection | ||
- :subcollection |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I didn't see alert_definition_profiles declared as a subcollection of others, so probably drop line 96.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done, thanks!
* added tests for accessing without appropriate role * small refactor to the subcollection controller * esthetic changes in specs
9c76216
to
f509b39
Compare
Checked commits dkorn/manageiq@4067acb~...f509b39 with ruby 2.2.6, rubocop 0.47.1, and haml-lint 0.20.0 |
Thanks @dkorn for the update, this looks great!! 👍 |
Adding CRUD actions support to alert definition profile API endpoint