Help creating Foreman Plugin

Copied from the Foreman Users group as per a suggestion I got.

On a fresh VM install of Ubuntu 14.04 and a fresh install of foreman 1.8
(dev environment), when I run the commands from 'How to create a foreman
plugin' I get this error after the 'bundle install' and subsequent
'service apache2 restart'.

some permissions were not found (ArgumentError)
/usr/share/foreman/app/models/role.rb:131:in add_permissions' /usr/share/foreman/app/models/role.rb:146:in add_permissions!'
/usr/share/foreman/app/services/foreman/plugin.rb:198:in `block in role'

/usr/share/foreman/vendor/ruby/1.9.1/gems/activerecord-3.2.21/lib/active_record/connection_adapters/abstract/database_statements.rb:192:in
`transaction'

/usr/share/foreman/vendor/ruby/1.9.1/gems/activerecord-3.2.21/lib/active_record/transactions.rb:208:in
transaction' /usr/share/foreman/app/services/foreman/plugin.rb:196:in role'
/home/emanners/git/my_plugin/lib/my_plugin/engine.rb:27:in block (2 levels) in <class:Engine>' /usr/share/foreman/app/services/foreman/plugin.rb:62:in instance_eval'
/usr/share/foreman/app/services/foreman/plugin.rb:62:in register' /home/emanners/git/my_plugin/lib/my_plugin/engine.rb:18:in block in
<class:Engine>'

/usr/share/foreman/vendor/ruby/1.9.1/gems/railties-3.2.21/lib/rails/initializable.rb:30:in
`instance_exec'

/usr/share/foreman/vendor/ruby/1.9.1/gems/railties-3.2.21/lib/rails/initializable.rb:30:in
`run'

/usr/share/foreman/vendor/ruby/1.9.1/gems/railties-3.2.21/lib/rails/initializable.rb:55:in
`block in run_initializers'

/usr/share/foreman/vendor/ruby/1.9.1/gems/railties-3.2.21/lib/rails/initializable.rb:54:in
`each'

/usr/share/foreman/vendor/ruby/1.9.1/gems/railties-3.2.21/lib/rails/initializable.rb:54:in
`run_initializers'

/usr/share/foreman/vendor/ruby/1.9.1/gems/railties-3.2.21/lib/rails/application.rb:136:in
`initialize!'

/usr/share/foreman/vendor/ruby/1.9.1/gems/railties-3.2.21/lib/rails/railtie/configurable.rb:30:in
method_missing&#39; /usr/share/foreman/config/environment.rb:12:in <top (required)>'
config.ru:3:in require&#39; config.ru:3:in block in <main>'

/usr/share/foreman/vendor/ruby/1.9.1/gems/rack-1.4.5/lib/rack/builder.rb:51:in
`instance_eval'

/usr/share/foreman/vendor/ruby/1.9.1/gems/rack-1.4.5/lib/rack/builder.rb:51:in
initialize&#39; config.ru:1:in new'
config.ru:1:in &lt;main&gt;&#39; /usr/share/passenger/helper-scripts/rack-preloader.rb:112:in eval'
/usr/share/passenger/helper-scripts/rack-preloader.rb:112:in preload_app&#39; /usr/share/passenger/helper-scripts/rack-preloader.rb:158:in <module:App>'
/usr/share/passenger/helper-scripts/rack-preloader.rb:29:in
&lt;module:PhusionPassenger&gt;&#39; /usr/share/passenger/helper-scripts/rack-preloader.rb:28:in <main>'

The reply that I got was:
You'll probably have to customzie the engine.rb. If it's just the
default after running rename.rb you probably have a line like this on
27:

role "ForemanMyPlugin", [:view_my_plugin]

The error is telling you that :view_my_plugin permission doesn't exist,
which should've been created just a few lines above. That might help
narrow down the problem, but we'd really have to see the code to help
more.

The engine file is attached. It looks like those permissions were created
but I'm new to Ruby so …

engine.rb (2.71 KB)

Hello,

I think you defined your permission with invalid action, so it wasn't saved.
Then later when you try to create role with this permission, permission can't
be found.

Line 23
permission :view_my_plugin, {:'my_plugin/hosts' => [:new_action] }

the key should be name of controller, so if your controller is
hosts_controller.rb then the key should be just 'hosts'.

If it's not the case then try finding all permissions of name 'view_my_plugin'
in your database. There should be exactly one record.

Hope this helps

··· -- Marek

On Monday 18 of May 2015 17:12:19 Edson Manners wrote:

Copied from the Foreman Users group as per a suggestion I got.

On a fresh VM install of Ubuntu 14.04 and a fresh install of foreman 1.8
(dev environment), when I run the commands from ‘How to create a foreman
plugin’ I get this error after the ‘bundle install’ and subsequent
’service apache2 restart’.

some permissions were not found (ArgumentError)
/usr/share/foreman/app/models/role.rb:131:in add_permissions' /usr/share/foreman/app/models/role.rb:146:inadd_permissions!’
/usr/share/foreman/app/services/foreman/plugin.rb:198:in `block in role’

/usr/share/foreman/vendor/ruby/1.9.1/gems/activerecord-3.2.21/lib/active_rec
ord/connection_adapters/abstract/database_statements.rb:192:in `transaction’

/usr/share/foreman/vendor/ruby/1.9.1/gems/activerecord-3.2.21/lib/active_rec
ord/transactions.rb:208:in transaction' /usr/share/foreman/app/services/foreman/plugin.rb:196:inrole’
/home/emanners/git/my_plugin/lib/my_plugin/engine.rb:27:in block (2 levels) in <class:Engine>' /usr/share/foreman/app/services/foreman/plugin.rb:62:ininstance_eval’
/usr/share/foreman/app/services/foreman/plugin.rb:62:in register' /home/emanners/git/my_plugin/lib/my_plugin/engine.rb:18:inblock in
class:Engine

/usr/share/foreman/vendor/ruby/1.9.1/gems/railties-3.2.21/lib/rails/initiali
zable.rb:30:in `instance_exec’

/usr/share/foreman/vendor/ruby/1.9.1/gems/railties-3.2.21/lib/rails/initiali
zable.rb:30:in `run’

/usr/share/foreman/vendor/ruby/1.9.1/gems/railties-3.2.21/lib/rails/initiali
zable.rb:55:in `block in run_initializers’

/usr/share/foreman/vendor/ruby/1.9.1/gems/railties-3.2.21/lib/rails/initiali
zable.rb:54:in `each’

/usr/share/foreman/vendor/ruby/1.9.1/gems/railties-3.2.21/lib/rails/initiali
zable.rb:54:in `run_initializers’

/usr/share/foreman/vendor/ruby/1.9.1/gems/railties-3.2.21/lib/rails/applicat
ion.rb:136:in `initialize!’

/usr/share/foreman/vendor/ruby/1.9.1/gems/railties-3.2.21/lib/rails/railtie/
configurable.rb:30:in method_missing' /usr/share/foreman/config/environment.rb:12:in<top (required)>'
config.ru:3:in require' config.ru:3:inblock in ’

/usr/share/foreman/vendor/ruby/1.9.1/gems/rack-1.4.5/lib/rack/builder.rb:51:
in `instance_eval’

/usr/share/foreman/vendor/ruby/1.9.1/gems/rack-1.4.5/lib/rack/builder.rb:51:
in initialize' config.ru:1:innew’
config.ru:1:in <main>' /usr/share/passenger/helper-scripts/rack-preloader.rb:112:ineval’
/usr/share/passenger/helper-scripts/rack-preloader.rb:112:in preload_app' /usr/share/passenger/helper-scripts/rack-preloader.rb:158:inmodule:App
/usr/share/passenger/helper-scripts/rack-preloader.rb:29:in
<module:PhusionPassenger>' /usr/share/passenger/helper-scripts/rack-preloader.rb:28:in

The reply that I got was:
You’ll probably have to customzie the engine.rb. If it’s just the
default after running rename.rb you probably have a line like this on
27:

role “ForemanMyPlugin”, [:view_my_plugin]

The error is telling you that :view_my_plugin permission doesn’t exist,
which should’ve been created just a few lines above. That might help
narrow down the problem, but we’d really have to see the code to help
more.

The engine file is attached. It looks like those permissions were created
but I’m new to Ruby so …

Marek,
Thanks for the feedback. I'm new to Ruby (but not programming) and Foreman
plugins so I gotta take some time to look around and digest this. However
there were 2 permissions in the permissions DB so thanks for that. Once I
removed one the plugin worked as expected.

The only other thing to add for anyone who comes behind me is that I
followed the instructions for creating a dummy foreman plugin without
deviating at all and got this error. Hopefully anyone else who runs into
this problem can find the answer here.

··· On Tuesday, May 19, 2015 at 2:49:48 AM UTC-4, Marek Hulan wrote: > > Hello, > > I think you defined your permission with invalid action, so it wasn't > saved. > Then later when you try to create role with this permission, permission > can't > be found. > > Line 23 > permission :view_my_plugin, {:'my_plugin/hosts' => [:new_action] } > > the key should be name of controller, so if your controller is > hosts_controller.rb then the key should be just 'hosts'. > > If it's not the case then try finding all permissions of name > 'view_my_plugin' > in your database. There should be exactly one record. > > Hope this helps > > -- > Marek > > On Monday 18 of May 2015 17:12:19 Edson Manners wrote: > > Copied from the Foreman Users group as per a suggestion I got. > > > > On a fresh VM install of Ubuntu 14.04 and a fresh install of foreman 1.8 > > (dev environment), when I run the commands from 'How to create a foreman > > plugin' I get this error after the 'bundle install' and subsequent > > 'service apache2 restart'. > > > > some permissions were not found (ArgumentError) > > /usr/share/foreman/app/models/role.rb:131:in `add_permissions' > > /usr/share/foreman/app/models/role.rb:146:in `add_permissions!' > > /usr/share/foreman/app/services/foreman/plugin.rb:198:in `block in > role' > > > > > /usr/share/foreman/vendor/ruby/1.9.1/gems/activerecord-3.2.21/lib/active_rec > > > ord/connection_adapters/abstract/database_statements.rb:192:in > `transaction' > > > > > /usr/share/foreman/vendor/ruby/1.9.1/gems/activerecord-3.2.21/lib/active_rec > > > ord/transactions.rb:208:in `transaction' > > /usr/share/foreman/app/services/foreman/plugin.rb:196:in `role' > > /home/emanners/git/my_plugin/lib/my_plugin/engine.rb:27:in `block (2 > > levels) in ' > > /usr/share/foreman/app/services/foreman/plugin.rb:62:in > `instance_eval' > > /usr/share/foreman/app/services/foreman/plugin.rb:62:in `register' > > /home/emanners/git/my_plugin/lib/my_plugin/engine.rb:18:in `block in > > ' > > > > > /usr/share/foreman/vendor/ruby/1.9.1/gems/railties-3.2.21/lib/rails/initiali > > > zable.rb:30:in `instance_exec' > > > > > /usr/share/foreman/vendor/ruby/1.9.1/gems/railties-3.2.21/lib/rails/initiali > > > zable.rb:30:in `run' > > > > > /usr/share/foreman/vendor/ruby/1.9.1/gems/railties-3.2.21/lib/rails/initiali > > > zable.rb:55:in `block in run_initializers' > > > > > /usr/share/foreman/vendor/ruby/1.9.1/gems/railties-3.2.21/lib/rails/initiali > > > zable.rb:54:in `each' > > > > > /usr/share/foreman/vendor/ruby/1.9.1/gems/railties-3.2.21/lib/rails/initiali > > > zable.rb:54:in `run_initializers' > > > > > /usr/share/foreman/vendor/ruby/1.9.1/gems/railties-3.2.21/lib/rails/applicat > > > ion.rb:136:in `initialize!' > > > > > /usr/share/foreman/vendor/ruby/1.9.1/gems/railties-3.2.21/lib/rails/railtie/ > > > configurable.rb:30:in `method_missing' > > /usr/share/foreman/config/environment.rb:12:in `' > > config.ru:3:in `require' > > config.ru:3:in `block in ' > > > > > /usr/share/foreman/vendor/ruby/1.9.1/gems/rack-1.4.5/lib/rack/builder.rb:51: > > > in `instance_eval' > > > > > /usr/share/foreman/vendor/ruby/1.9.1/gems/rack-1.4.5/lib/rack/builder.rb:51: > > > in `initialize' > > config.ru:1:in `new' > > config.ru:1:in `' > > /usr/share/passenger/helper-scripts/rack-preloader.rb:112:in `eval' > > /usr/share/passenger/helper-scripts/rack-preloader.rb:112:in > `preload_app' > > /usr/share/passenger/helper-scripts/rack-preloader.rb:158:in > > `' > > /usr/share/passenger/helper-scripts/rack-preloader.rb:29:in > > `' > > /usr/share/passenger/helper-scripts/rack-preloader.rb:28:in `' > > > > The reply that I got was: > > You'll probably have to customzie the engine.rb. If it's just the > > default after running rename.rb you probably have a line like this on > > 27: > > > > role "ForemanMyPlugin", [:view_my_plugin] > > > > The error is telling you that :view_my_plugin permission doesn't exist, > > which should've been created just a few lines above. That might help > > narrow down the problem, but we'd really have to see the code to help > > more. > > > > The engine file is attached. It looks like those permissions were > created > > but I'm new to Ruby so .... > >