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

EL9 RPM Sqlite3 DB support #201

Merged
merged 13 commits into from
Feb 4, 2025
Merged

Conversation

agrare
Copy link
Member

@agrare agrare commented Oct 31, 2024

@Fryguy
Copy link
Member

Fryguy commented Oct 31, 2024

I'd be happy merging specs as is ahead of actually implementing anything.

@Fryguy Fryguy self-assigned this Oct 31, 2024
it "returns a list of rpm packages" do
result = described_class.new(fs)

expect(result.instance_variable_get(:@packages).count).to eq(690)
Copy link
Member Author

Choose a reason for hiding this comment

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

I'm not sure why we don't have an attr_reader for @packages here, toXml and toString are the only "interface" methods but I think access to packages would be handy also

}

#
# Nubbers on disk are in network byte order.
Copy link
Member

Choose a reason for hiding this comment

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

LOL nubbers

@agrare agrare force-pushed the miq_rpm_packages_el9 branch 2 times, most recently from cd7f0b9 to 654c48a Compare November 4, 2024 16:35
@@ -63,7 +63,7 @@ def decodeSchema
return if @type != "table" || @name[0..6] == "sqlite_" # Names beginning with sqlite_ are internal to engine
@columns = []
sql = @sql.gsub(/[\n\r]/, "")
re1 = /\s*CREATE\s+TABLE\s+(\w+)\s*\((.*)\)\s*/
re1 = /\s*CREATE\s+TABLE\s+'?(\w+)'?\s*\((.*)\)\s*/
Copy link
Member

Choose a reason for hiding this comment

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

That's interesting - I've never seen quotes before. Also note that technically the table name could have a . in it as well (i.e. <schema_name>.<table_name>)

@Fryguy
Copy link
Member

Fryguy commented Nov 4, 2024

@agrare More out of curiosity, what's the approach here? I'm seeing refactoring into separate modules + specs...is the plan to do an initial refactor, then merge, then add the new DB support?

@agrare
Copy link
Member Author

agrare commented Nov 4, 2024

@Fryguy so I see this as two high level issues,

  1. MiqSqlite3DB can't currently load the rpmdb.sqlite database
  2. MiqRpmPackages can't currently process a rpmdb.sqlite file

So the plan is:

  1. Get MiqSqlite3DB::Sqlite3 able to load the rpmdb.sqlite file and list tables
  2. Get MiqSqlite3DB::Sqlite3Table able to list rows in the Packages table (this is also broken currently)
  3. Get MiqLinux::MiqRpmPackages able to understand the contents of the rpmdb.sqlite database (this PR)

So I'm rebasing this on top of the sqlite3 fixes

@Fryguy
Copy link
Member

Fryguy commented Nov 4, 2024

Moving forward I wonder if it's better to use the sqlite library instead of rolling our own. Not sure if that is with investigation or not. I'd rather do whats more expedient at this time, but I'm also wondering what bugs will lurk in the corners.

@agrare
Copy link
Member Author

agrare commented Nov 4, 2024

Moving forward I wonder if it's better to use the sqlite library instead of rolling our own

Yes I did look into that originally, but I don't think that will work with the way that we handle loading the filesystem via MiqFs in SSA. We'd need a "real" file since the interface is a path and all of the loading of the database is done in C-ext code.

(Another reason I'd like to use FUSE instead eventually so that we could "mount" the filesystem and use more standardized tools based on files/paths)

@agrare agrare force-pushed the miq_rpm_packages_el9 branch 2 times, most recently from 6adc493 to 37ca67f Compare November 4, 2024 18:05
@agrare agrare force-pushed the miq_rpm_packages_el9 branch from 37ca67f to 500fdc0 Compare January 9, 2025 20:58
@Fryguy
Copy link
Member

Fryguy commented Jan 16, 2025

Nice - tests went green.

@agrare
Copy link
Member Author

agrare commented Jan 16, 2025

Okay checklist of things that we need for this to be merged:

  • ruby-rpm-ffi support for rpm 4.14+ (mostly working in master, but no release cut) so that requiring the gem doesn't blow up with librpm.so.8+
  • ruby-rpm-ffi add detection of librpm.so.9 and librpm.so.10 (we can work around this by installing rpm-devel so ruby-rpm-ffi picks up on librpm.so but that is sub-optimal)

@agrare agrare force-pushed the miq_rpm_packages_el9 branch from eaed4dd to 001598b Compare February 3, 2025 17:34
Copy link
Member Author

Choose a reason for hiding this comment

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

@Fryguy I took the rpmdb.sqlite from one of the ruby-rpm-ffi tests where it installs a single dummy package so that we can actually test the package parser code above instead of just expect(result.packages.count).to eq(0)

@agrare
Copy link
Member Author

agrare commented Feb 3, 2025

I've updated this to use the forked gem, trying to figure out why this is red on CI but green locally

@agrare agrare force-pushed the miq_rpm_packages_el9 branch 3 times, most recently from 42c42bf to 05b2b28 Compare February 4, 2025 16:28
@agrare agrare mentioned this pull request Feb 4, 2025
1 task
@agrare
Copy link
Member Author

agrare commented Feb 4, 2025

Okay taking out of WIP as this is passing specs with a populated rpmdb.sqlite database, we can figure out the behavior of the _dbpath on mac now or in a follow-up

@agrare agrare force-pushed the miq_rpm_packages_el9 branch from 4f594eb to acd4bb3 Compare February 4, 2025 17:53
rpmp.each { |p| @packages << p }
rpmp.close

rpmp = MiqRpmPackages.new(@fs, dbDir)
Copy link
Member

Choose a reason for hiding this comment

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

Eventually we should add a block form of this that auto-closes

@agrare agrare force-pushed the miq_rpm_packages_el9 branch from b0ef951 to 9917ffc Compare February 4, 2025 18:00
@agrare agrare force-pushed the miq_rpm_packages_el9 branch 2 times, most recently from 8e9df24 to 3db66ef Compare February 4, 2025 18:10
@agrare agrare force-pushed the miq_rpm_packages_el9 branch from 3db66ef to e261933 Compare February 4, 2025 18:12
@agrare
Copy link
Member Author

agrare commented Feb 4, 2025

NOTE in order to support EL10 we'll need to check /var/lib/rpm as well as /usr/lib/sysimage/rpm

@Fryguy
Copy link
Member

Fryguy commented Feb 4, 2025

NOTE in order to support EL10 we'll need to check /var/lib/rpm as well as /usr/lib/sysimage/rpm

would that be covered by _dbpath?

s = getStringVal(data, cpos)
ra << s
cpos += (s.length + 1)
orig_new(fs, dbDir)
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 we can use a super pattern here instead of the orig_new

Copy link
Member

Choose a reason for hiding this comment

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

Even so, I will merge without this.

Copy link
Member Author

Choose a reason for hiding this comment

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

I pulled this pattern from linux_admin, if this isn't the best way to do it we should probably change both then

@agrare
Copy link
Member Author

agrare commented Feb 4, 2025

RPM["_dbpath"] covers where the local system thinks the db should be, when we look to the system that we're scanning the db path could be one or the other depending on the version of that system.

@Fryguy Fryguy merged commit 67de160 into ManageIQ:master Feb 4, 2025
3 of 4 checks passed
@agrare agrare deleted the miq_rpm_packages_el9 branch February 4, 2025 19:25
agrare added a commit that referenced this pull request Feb 4, 2025
Added
* Support scanning RPM packages on EL8/EL9 (#201)
* Test with ruby 3.3 (#208)
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.

2 participants