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

Adding scan_results table for ScanResult model #57

Merged

Conversation

enoodle
Copy link

@enoodle enoodle commented Aug 29, 2017

To support reporting and displaying the last OpenSCAP scan result for container images, as requested in ManageIQ/manageiq-providers-kubernetes#100

@Fryguy
Copy link
Member

Fryguy commented Aug 29, 2017

Migration looks good to me, but I believe this needs an update to the db/schema.yml

Will wait on approval from @simon3z with respect to ManageIQ/manageiq-providers-kubernetes#100 before merging.

@simon3z
Copy link
Contributor

simon3z commented Aug 30, 2017

Will wait on approval from @simon3z with respect to ManageIQ/manageiq-providers-kubernetes#100 before merging.

@Fryguy @enoodle yeah before merging we definitely have to finalize ManageIQ/manageiq-providers-kubernetes#100
Thanks.

@enoodle enoodle force-pushed the last_oscap_status_for_container_image branch from a94350e to 7dcda5e Compare September 5, 2017 12:55
@enoodle
Copy link
Author

enoodle commented Sep 7, 2017

@moolitayer @simon3z It seems that we got to a decision in
ManageIQ/manageiq-providers-kubernetes#100 So you should ack this PR as well.

Copy link

@moolitayer moolitayer left a comment

Choose a reason for hiding this comment

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

LGTM 👍

@simon3z
Copy link
Contributor

simon3z commented Sep 11, 2017

@enoodle @roliveri are we sure we want to keep these per object?

Should we have instead a new table with a polymorphic association so that we can keep in a single place regardless to what object they refer to? (VMs, Images, Container Images, etc.).

@roliveri
Copy link
Member

@simon3z As we discussed, I think you're right. We can have a scan_status table used to store the scan status and last scan time. I would also suggest it should contain a scan_type field, so we can differentiate between different types of scans going forward (standard vs oscap for example).

@enoodle enoodle force-pushed the last_oscap_status_for_container_image branch from 7dcda5e to 9568a18 Compare September 13, 2017 10:13
@enoodle enoodle changed the title Adding last_oscap_status/message column for ContainerImage Adding last_scan_results table for LastScanResult model Sep 13, 2017
@enoodle
Copy link
Author

enoodle commented Sep 13, 2017

@simon3z @roliveri @moolitayer PTAL I have added the new table last_scan_results

@simon3z
Copy link
Contributor

simon3z commented Sep 13, 2017

@miq-bot assign @Fryguy

@roliveri can you explicitly ack this if it looks good to you?

@roliveri
Copy link
Member

We may want to add a scan_type field, so we can differentiate when we have multiple types of scans for the same resource (OSCAP and legacy for example), that can be preformed independently.

create_table :last_scan_results do |t|
t.string :last_scan_status
t.string :last_scan_message
t.belongs_to :resource, :polymorphic => true, :type => :bigint

Choose a reason for hiding this comment

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

I would link this to the job that created the status. We could get the target resource through that. Is that enough to have the needed info of scan_type @roliveri ?
(I know that for ContainerManager::Scanning::Job we always have OpenSCAP AND package analysis)

Copy link
Member

Choose a reason for hiding this comment

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

I don't think so. Assuming the scan type based on the resource won't be enough. As I mentioned, going forward, different scans may be performed independently for the same resource, so they may be performed by different jobs. Even if we could obtain the scan type through the job, do job objects persist after the jobs have completed? If not, the link to the job could go stale while the scan results are still linked to the resource.

Choose a reason for hiding this comment

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

Can we have different scan types in a vm scanning job? Anyway regardless the new table might be a better place to keep the scan_type (and anything related to scan and not directly to job)

I still think the a link to the job would serve us (for example if we want to show last job info in container image screens). I don't see a purge or something that would delete job records but I might be missing something.

Copy link
Member

Choose a reason for hiding this comment

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

We haven't had different scan types until now, so there's no concept of type in the scan job. However, I think we may need to rely on subclasses of Job more than we do now. The Job subclass could not only indicate the resource being scanned, but the type of scan as well. If the scanning process is significantly different for some types, it makes sense for them to have their own Job subclass.

I'm not saying we shouldn't link to Job. Only that we should make sure it will be there when we need it.

@enoodle
Copy link
Author

enoodle commented Sep 25, 2017

I updated this with scan_type field. @moolitayer @roliveri I think we should keep it simple in this patch and link to the Job in a different set of PRs.

Copy link
Member

@roliveri roliveri left a comment

Choose a reason for hiding this comment

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

Looks good to me.
Once the tests are green, should be ok to merge.

@enoodle enoodle force-pushed the last_oscap_status_for_container_image branch from 5ed20ff to a59e78d Compare September 25, 2017 15:54
it belongs to an isomorphic "resource"
@enoodle enoodle force-pushed the last_oscap_status_for_container_image branch from a59e78d to ec53a4c Compare September 27, 2017 15:09
@enoodle
Copy link
Author

enoodle commented Sep 27, 2017

So apparently the tables in db/schema.yaml have to be ordered alphabetically or you get this unhelpful error:

       vmdb_test is not structured as expected.
       Schema validation failed for host localhost:
     
       Expected schema table order does not match sorted current tables.
       Use 'rake db:write_schema' to generate the new expected schema when making changes.
     
       Refer to http://talk.manageiq.org/t/new-schema-specs-for-new-replication/1404 for detail
     # ./plugins/manageiq-schema/spec/replication/util/schema_structure_spec.rb:13:in `block (2 levels) in <top (required)>'

and rake doesn't really know how to build this task so it won't work to fix it.
Super annoying.

I ordered the table now, hopefully this will make the test green.

@miq-bot
Copy link
Member

miq-bot commented Sep 27, 2017

Checked commit enoodle@ec53a4c with ruby 2.2.6, rubocop 0.47.1, and haml-lint 0.20.0
1 file checked, 0 offenses detected
Everything looks fine. 🍪

@Fryguy
Copy link
Member

Fryguy commented Sep 27, 2017

Use 'rake db:write_schema' to generate the new expected schema when making changes.

Does rake db:write_schema not work for you?

@enoodle
Copy link
Author

enoodle commented Sep 27, 2017

@Fryguy No, Maybe I am not running it well. I tried from the main ManageIQ directory but it couldn't build the task. From the manageiq-schema plugin directory I got ActiveRecord::NoDatabaseError: FATAL: database "dummy_development" does not exist. linking "spec/manageiq" temporarily didn't help either.

@Fryguy
Copy link
Member

Fryguy commented Sep 27, 2017

You need a fully raked up database to do it. If you've done rake spec:setup, then you can use test database with:

RAILS_ENV=test bundle exec rake db:write_schema

@enoodle
Copy link
Author

enoodle commented Sep 28, 2017

@Fryguy Thanks, this was working for me now.
This patch is green now, can we merge it?

@Fryguy Fryguy changed the title Adding last_scan_results table for LastScanResult model Adding scan_results table for ScanResult model Sep 28, 2017
@Fryguy Fryguy merged commit b60d072 into ManageIQ:master Sep 28, 2017
@Fryguy Fryguy added this to the Sprint 70 Ending Oct 2, 2017 milestone Sep 28, 2017
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.

6 participants