From a608f561c48bf247e313f383e6f806f10d70f253 Mon Sep 17 00:00:00 2001 From: Oliver Tappe Date: Tue, 8 Jan 2008 10:28:49 +0000 Subject: * added new DB-table 'installed_plugin', moving schema version to 0.21 * added functionality to DB-layer for adding, removing and fetching plugins that have been installed into a vendor-OS. * added a set of tests related to installed plugins. git-svn-id: http://svn.openslx.org/svn/openslx/trunk@1447 95ad53e4-c205-0410-b2fa-d234c58c8868 --- config-db/OpenSLX/ConfigDB.pm | 97 +++++++++++++++++++++++++++++++++++++++++ config-db/OpenSLX/DBSchema.pm | 35 ++++++++++++++- config-db/OpenSLX/MetaDB/DBI.pm | 47 ++++++++++++++++++++ config-db/t/10-vendor-os.t | 58 ++++++++++++++++++++++++ 4 files changed, 236 insertions(+), 1 deletion(-) (limited to 'config-db') diff --git a/config-db/OpenSLX/ConfigDB.pm b/config-db/OpenSLX/ConfigDB.pm index 0879ba02..f563619e 100644 --- a/config-db/OpenSLX/ConfigDB.pm +++ b/config-db/OpenSLX/ConfigDB.pm @@ -356,6 +356,41 @@ sub fetchVendorOSByID return wantarray() ? @vendorOS : shift @vendorOS; } +=item C + +Returns the names of all plugins that have been installed into the given +vendor-OS. + +=over + +=item Param C + +The id of the vendor-OS whose plugins you are interested in + +=item Param C [Optional] + +The name of a specific plugin you are interested in + +=item Return Value + +An array with the plugin names. + +=back + +=cut + +sub fetchInstalledPlugins +{ + my $self = shift; + my $vendorOSID = shift; + my $pluginName = shift; + + return map { + $_->{plugin_name} + } + $self->{'meta-db'}->fetchInstalledPlugins($vendorOSID, $pluginName); +} + =item C Fetches and returns information about all exports that match the given @@ -1028,6 +1063,68 @@ sub changeVendorOS return $self->{'meta-db'}->changeVendorOS($vendorOSIDs, $valRows); } +=item C + +Adds a freshly installed plugin to a vendor-OS. + +=over + +=item Param C + +The id of the vendor-OS the given plugin has been installed into + +=item Param C + +The name of the plugin that has been installed + +=item Return Value + +The ID of the new reference entry, C if the creation failed. + +=back + +=cut + +sub addInstalledPlugin +{ + my $self = shift; + my $vendorOSID = shift; + my $pluginName = shift; + + return $self->{'meta-db'}->addInstalledPlugin($vendorOSID, $pluginName); +} + +=item C + +Removes a uninstalled plugin for a vendor-OS. + +=over + +=item Param C + +The id of the vendor-OS the given plugin has been uninstalled from + +=item Param C + +The name of the plugin that has been uninstalled + +=item Return Value + +1 if it worked, C if it didn't. + +=back + +=cut + +sub removeInstalledPlugin +{ + my $self = shift; + my $vendorOSID = shift; + my $pluginName = shift; + + return $self->{'meta-db'}->removeInstalledPlugin($vendorOSID, $pluginName); +} + =item C Adds one or more export to the database. diff --git a/config-db/OpenSLX/DBSchema.pm b/config-db/OpenSLX/DBSchema.pm index cd92c07e..dc55b1b7 100644 --- a/config-db/OpenSLX/DBSchema.pm +++ b/config-db/OpenSLX/DBSchema.pm @@ -38,7 +38,7 @@ use POSIX qw(locale_h); my $lang = setlocale(LC_MESSAGES); my $country = $lang =~ m[^\w\w_(\w\w)] ? lc($1) : 'us'; -my $VERSION = 0.2; +my $VERSION = 0.21; my $DbSchema = { 'version' => $VERSION, @@ -152,6 +152,19 @@ my $DbSchema = { 'system_id:fk', # foreign key ], }, + 'installed_plugin' => { + # holds the plugins that have been installed into a specific + # vendor-OS + 'cols' => [ + 'id:pk', # primary key + 'vendor_os_id:fk', # foreign key + 'plugin_name:s.64', # name of installed plugin + # (e.g. suse-9.3-kde, debian-3.1-ppc, + # suse-10.2-cloned-from-kiwi). + # This is used as the folder name for the + # corresponding stage1, too. + ], + }, 'meta' => { # information about the database as such 'cols' => [ @@ -630,4 +643,24 @@ sub _upgradeDBTo0_2 return 1; } +sub _upgradeDBTo0_21 +{ + my $self = shift; + my $metaDB = shift; + + # move attributes into separate tables ... + # + # ... system attributes ... + $metaDB->schemaAddTable( + 'installed_plugin', + [ + 'id:pk', + 'vendor_os_id:fk', + 'plugin_name:s.64', + ] + ); + + return 1; +} + 1; diff --git a/config-db/OpenSLX/MetaDB/DBI.pm b/config-db/OpenSLX/MetaDB/DBI.pm index 94d92188..e709038b 100644 --- a/config-db/OpenSLX/MetaDB/DBI.pm +++ b/config-db/OpenSLX/MetaDB/DBI.pm @@ -201,6 +201,25 @@ sub fetchVendorOSByID return $self->_doSelect($sql); } +sub fetchInstalledPlugins +{ + my $self = shift; + my $vendorOSID = shift; + my $pluginName = shift; + + return if !$vendorOSID; + my $nameClause + = defined $pluginName + ? "AND plugin_name = '$pluginName'" + : ''; + my $sql = unshiftHereDoc(<<" End-of-Here"); + SELECT * FROM installed_plugin + WHERE vendor_os_id = '$vendorOSID' + $nameClause + End-of-Here + return $self->_doSelect($sql); +} + sub fetchExportByFilter { my $self = shift; @@ -682,6 +701,34 @@ sub changeVendorOS return $self->_doUpdate('vendor_os', $vendorOSIDs, $valRows); } +sub addInstalledPlugin +{ + my $self = shift; + my $vendorOSID = shift; + my $pluginName = shift; + + return if !$vendorOSID || !$pluginName; + + return if $self->fetchInstalledPlugins($vendorOSID, $pluginName); + return $self->_doInsert('installed_plugin', [ { + vendor_os_id => $vendorOSID, + plugin_name => $pluginName, + } ] ); +} + +sub removeInstalledPlugin +{ + my $self = shift; + my $vendorOSID = shift; + my $pluginName = shift; + + return if !$vendorOSID || !$pluginName; + + my $plugin = $self->fetchInstalledPlugins($vendorOSID, $pluginName); + return if !$plugin; + return $self->_doDelete('installed_plugin', [ $plugin->{id} ] ); +} + sub addExport { my $self = shift; diff --git a/config-db/t/10-vendor-os.t b/config-db/t/10-vendor-os.t index 04aa4f2e..f2d11302 100644 --- a/config-db/t/10-vendor-os.t +++ b/config-db/t/10-vendor-os.t @@ -190,6 +190,64 @@ ok( ok(! $configDB->changeVendorOS(1, { id => 23 }), 'changing id should fail'); +# test adding & removing of installed plugins +is( + $configDB->fetchInstalledPlugins(3), + 0, 'there should be no installed plugins' +); +ok($configDB->addInstalledPlugin(3, 'Example'), 'adding installed plugin'); +is( + my @plugins = $configDB->fetchInstalledPlugins(3), + 1, + 'should have 1 installed plugin' +); +ok( + !$configDB->addInstalledPlugin(3, 'Example'), + 'adding plugin again should fail (but do not harm)' +); +is( + @plugins = $configDB->fetchInstalledPlugins(3), + 1, + 'should have 1 installed plugin' +); +is($plugins[0], 'Example', 'should have got plugin "Example"'); +ok($configDB->addInstalledPlugin(3, 'Test'), 'adding a second plugin'); +is( + @plugins = $configDB->fetchInstalledPlugins(3), + 2, + 'should have 2 installed plugin' +); +ok( + !$configDB->removeInstalledPlugin(3, 'xxx'), + 'removing unknown plugin should fail' +); +ok( + @plugins = $configDB->fetchInstalledPlugins(3, 'Example'), + 'fetching specific plugin' +); +is($plugins[0], 'Example', 'should have got plugin "Example"'); +ok( + @plugins = $configDB->fetchInstalledPlugins(3, 'Test'), + 'fetching another specific plugin' +); +is($plugins[0], 'Test', 'should have got plugin "Test"'); +is( + @plugins = $configDB->fetchInstalledPlugins(3, 'xxx'), 0, + 'fetching unknown specific plugin' +); +ok($configDB->removeInstalledPlugin(3, 'Example'), 'removing installed plugin'); +is( + @plugins = $configDB->fetchInstalledPlugins(3), + 1, + 'should have 1 installed plugin' +); +ok($configDB->removeInstalledPlugin(3, 'Test'), 'removing second plugin'); +is( + @plugins = $configDB->fetchInstalledPlugins(3), + 0, + 'should have no installed plugins' +); + # now remove a vendor-OS and check if that worked ok($configDB->removeVendorOS(3), 'removing vendor-OS 3 should be ok'); is($configDB->fetchVendorOSByID(3, 'id'), undef, 'vendor-OS 3 should be gone'); -- cgit v1.2.3-55-g7522