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

How to Run Tests document needs amater-friendly updates #283

Open
bschonec opened this issue Mar 21, 2023 · 12 comments
Open

How to Run Tests document needs amater-friendly updates #283

bschonec opened this issue Mar 21, 2023 · 12 comments

Comments

@bschonec
Copy link

I'm beginning my journey with voxpupulii and am trying to run tests on a self-hosted RHEL 8 server.

The how to run tests procedure makes all kinds of assumptions regarding the state of the testing machine.

On a basic RHEL 8 server, I had to install:

ruby-devel
rubygems-devel
rubygem-bundler
rubygem-rake
gcc

just to be able to run "bundle install". Unfortunately, the 'bundle install' command failed a few seconds into its run with some not-so-helpful error messages:

/usr/share/ruby/mkmf.rb:456:in `try_do': The compiler failed to generate an executable file. (RuntimeError)
You have to install development tools first.
To see why this extension failed to compile, please check the mkmf.log which can be found here:

  /tmp/bundler20230321-30083-1k34vfjnio4r-2.5.8/extensions/x86_64-linux/2.5.0/nio4r-2.5.8/mkmf.log

extconf failed, exit code 1

and

Fetching nio4r 2.5.8
Installing nio4r 2.5.8 with native extensions
Gem::Ext::BuildError: ERROR: Failed to build gem native extension.

    current directory: /tmp/bundler20230321-52387-n7bxsonio4r-2.5.8/gems/nio4r-2.5.8/ext/nio4r
/usr/bin/ruby -r ./siteconf20230321-52387-zdzvq0.rb extconf.rb
checking for unistd.h... *** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of necessary
libraries and/or headers.  Check the mkmf.log file for more details.  You may
need configuration options.

Provided configuration options:
        --with-opt-dir
        --without-opt-dir
        --with-opt-include
        --without-opt-include=${opt-dir}/include
        --with-opt-lib
        --without-opt-lib=${opt-dir}/lib64
        --with-make-prog
        --without-make-prog
        --srcdir=.
        --curdir
        --ruby=/usr/bin/$(RUBY_BASE_NAME)
/usr/share/ruby/mkmf.rb:456:in `try_do': The compiler failed to generate an executable file. (RuntimeError)
You have to install development tools first.
        from /usr/share/ruby/mkmf.rb:590:in `try_cpp'
        from /usr/share/ruby/mkmf.rb:1098:in `block in have_header'
        from /usr/share/ruby/mkmf.rb:948:in `block in checking_for'
        from /usr/share/ruby/mkmf.rb:350:in `block (2 levels) in postpone'
        from /usr/share/ruby/mkmf.rb:320:in `open'
        from /usr/share/ruby/mkmf.rb:350:in `block in postpone'
        from /usr/share/ruby/mkmf.rb:320:in `open'
        from /usr/share/ruby/mkmf.rb:346:in `postpone'
        from /usr/share/ruby/mkmf.rb:947:in `checking_for'
        from /usr/share/ruby/mkmf.rb:1097:in `have_header'
        from extconf.rb:15:in `<main>'

To see why this extension failed to compile, please check the mkmf.log which can be found here:

  /tmp/bundler20230321-52387-n7bxsonio4r-2.5.8/extensions/x86_64-linux/2.5.0/nio4r-2.5.8/mkmf.log

extconf failed, exit code 1

Gem files will remain installed in /tmp/bundler20230321-52387-n7bxsonio4r-2.5.8/gems/nio4r-2.5.8 for inspection.
Results logged to /tmp/bundler20230321-52387-n7bxsonio4r-2.5.8/extensions/x86_64-linux/2.5.0/nio4r-2.5.8/gem_make.out

An error occurred while installing nio4r (2.5.8), and Bundler cannot continue.
Make sure that `gem install nio4r -v '2.5.8'` succeeds before bundling.

In Gemfile:
  github_changelog_generator was resolved to 1.16.4, which depends on
    async-http-faraday was resolved to 0.11.0, which depends on
      async-http was resolved to 0.59.5, which depends on
        async-io was resolved to 1.34.3, which depends on
          async was resolved to 1.31.0, which depends on
            nio4r

The file ' /tmp/bundler20230321-30083-1k34vfjnio4r-2.5.8/extensions/x86_64-linux/2.5.0/nio4r-2.5.8/mkmf.log
' doesn't even exist and of course, I'm not blaming the documentation for bundle's terrible feedback. The error, 'You have to install development tools first.' implies to me that gcc and/or gcc++ needs to be installed.

It would be great of the documentation would describe the packages required in order to achieve a successful 'bundle install' run on various operating systems.

I'm not sure how I can help contribute to the updated documentation other than to keep trying 'bundle install' until I have the minimum packages installed on my system and then provide a pull request.

@ekohl
Copy link
Member

ekohl commented Mar 21, 2023

Could not create Makefile due to some reason, probably lack of necessary

I think this is the crucial line. You probably don't have make installed. Can you check if that resolves your problem?

@bschonec
Copy link
Author

bschonec commented Mar 21, 2023

nfiiseed@nfiv-schon-03d:~/puppet-limits$ which make
/usr/bin/make
nfiiseed@nfiv-schon-03d:~/puppet-limits$ 
nfiiseed@nfiv-schon-03d:~$ bundle -v
Bundler version 1.16.1
nfiiseed@nfiv-schon-03d:~$ rake --version
rake, version 13.0.6

@ekohl
Copy link
Member

ekohl commented Mar 21, 2023

Oh, then it's probably gcc-c++. I know some people just install the Development Tools group, but I like to be more specific.

@bschonec
Copy link
Author

Those are installed already, too.

nfiiseed@nfiv-schon-03d:~$ rpm -q gcc gcc-c++
gcc-8.5.0-16.el8_7.x86_64
gcc-c++-8.5.0-16.el8_7.x86_64
nfiiseed@nfiv-schon-03d:~$ 

@bschonec
Copy link
Author

Here's some more:

Ignoring bcrypt_pbkdf-1.1.0 because its extensions are not built. Try: gem pristine bcrypt_pbkdf --version 1.1.0
Ignoring ed25519-1.3.0 because its extensions are not built. Try: gem pristine ed25519 --version 1.3.0
Ignoring oga-3.4 because its extensions are not built. Try: gem pristine oga --version 3.4
Ignoring ruby-ll-2.1.2 because its extensions are not built. Try: gem pristine ruby-ll --version 2.1.2
Ignoring bcrypt_pbkdf-1.1.0 because its extensions are not built. Try: gem pristine bcrypt_pbkdf --version 1.1.0
Ignoring ed25519-1.3.0 because its extensions are not built. Try: gem pristine ed25519 --version 1.3.0
Ignoring oga-3.4 because its extensions are not built. Try: gem pristine oga --version 3.4
Ignoring ruby-ll-2.1.2 because its extensions are not built. Try: gem pristine ruby-ll --version 2.1.2
Fetching gem metadata from https://rubygems.org/.......

-- snip ---

Fetching json 2.6.3
Installing json 2.6.3 with native extensions
Gem::Ext::BuildError: ERROR: Failed to build gem native extension.

    current directory: /tmp/bundler20230321-66250-1w0a0a7json-2.6.3/gems/json-2.6.3/ext/json/ext/parser
/usr/bin/ruby -r ./siteconf20230321-66250-1h1afsl.rb extconf.rb
Ignoring bcrypt_pbkdf-1.1.0 because its extensions are not built. Try: gem pristine bcrypt_pbkdf --version 1.1.0
Ignoring ed25519-1.3.0 because its extensions are not built. Try: gem pristine ed25519 --version 1.3.0
Ignoring oga-3.4 because its extensions are not built. Try: gem pristine oga --version 3.4
Ignoring ruby-ll-2.1.2 because its extensions are not built. Try: gem pristine ruby-ll --version 2.1.2
checking for rb_enc_raise() in ruby.h... *** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of necessary
libraries and/or headers.  Check the mkmf.log file for more details.  You may
need configuration options.

Provided configuration options:
        --with-opt-dir
        --without-opt-dir
        --with-opt-include
        --without-opt-include=${opt-dir}/include
        --with-opt-lib
        --without-opt-lib=${opt-dir}/lib64
        --with-make-prog
        --without-make-prog
        --srcdir=.
        --curdir
        --ruby=/usr/bin/$(RUBY_BASE_NAME)
/usr/share/ruby/mkmf.rb:456:in `try_do': The compiler failed to generate an executable file. (RuntimeError)
You have to install development tools first.
        from /usr/share/ruby/mkmf.rb:541:in `try_link0'
        from /usr/share/ruby/mkmf.rb:559:in `try_link'
        from /usr/share/ruby/mkmf.rb:771:in `try_func'
        from /usr/share/ruby/mkmf.rb:1058:in `block in have_func'
        from /usr/share/ruby/mkmf.rb:948:in `block in checking_for'
        from /usr/share/ruby/mkmf.rb:350:in `block (2 levels) in postpone'
        from /usr/share/ruby/mkmf.rb:320:in `open'
        from /usr/share/ruby/mkmf.rb:350:in `block in postpone'
        from /usr/share/ruby/mkmf.rb:320:in `open'
        from /usr/share/ruby/mkmf.rb:346:in `postpone'
        from /usr/share/ruby/mkmf.rb:947:in `checking_for'
        from /usr/share/ruby/mkmf.rb:1057:in `have_func'
        from extconf.rb:4:in `<main>'

To see why this extension failed to compile, please check the mkmf.log which can be found here:

  /tmp/bundler20230321-66250-1w0a0a7json-2.6.3/extensions/x86_64-linux/2.5.0/json-2.6.3/mkmf.log

extconf failed, exit code 1

Gem files will remain installed in /tmp/bundler20230321-66250-1w0a0a7json-2.6.3/gems/json-2.6.3 for inspection.
Results logged to /tmp/bundler20230321-66250-1w0a0a7json-2.6.3/extensions/x86_64-linux/2.5.0/json-2.6.3/gem_make.out

An error occurred while installing json (2.6.3), and Bundler cannot continue.
Make sure that `gem install json -v '2.6.3'` succeeds before bundling.

In Gemfile:
  coveralls was resolved to 0.8.23, which depends on
    simplecov was resolved to 0.16.1, which depends on
      json
nfiiseed@nfiv-schon-03d:~/puppet-limits$

@ekohl
Copy link
Member

ekohl commented Mar 21, 2023

My reproducer on a minimal CentOS Stream 8 machine:

# dnf module enable ruby:2.7 -y
# dnf install ruby-devel rubygems-devel rubygem-bundler rubygem-rake gcc gcc-c++ make git -y
# git clone https://github.com/voxpupuli/puppet-systemd
# cd puppet-systemd
# bundle install

That fails on unf_ext with a similar error. Opening the error log /usr/lib64/gems/ruby/unf_ext-0.0.8.2/mkmf.log has this:

"gcc -o conftest -I/usr/include -I/usr/include/ruby/backward -I/usr/include -I.    -O2 -g -pipe -Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -Wp,-D_GLIBCXX_ASSERTIONS -fexceptions -fstack-protector-strong -grecord-gcc-switches -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -specs=/usr/lib/rpm/redhat/redhat-annobin-cc1 -mtune=generic -fasynchronous-unwind-tables -fstack-clash-protection -fcf-protection -fPIC conftest.c  -L. -L/usr/lib64 -L. -Wl,-z,relro  -Wl,-z,now -specs=/usr/lib/rpm/redhat/redhat-hardened-ld -fstack-protector-strong -rdynamic -Wl,-export-dynamic  -m64   -lruby  -lm   -lc"
gcc: error: /usr/lib/rpm/redhat/redhat-hardened-cc1: No such file or directory
checked program was:
/* begin */
1: #include "ruby.h"
2:
3: int main(int argc, char **argv)
4: {
5:   return !!argv[argc];
6: }
/* end */

The crucial bit is /usr/lib/rpm/redhat/redhat-hardened-cc1. dnf install /usr/lib/rpm/redhat/redhat-hardened-cc1 wants to install redhat-rpm-config. Perhaps that's the missing bit for you?

@bschonec
Copy link
Author

Still no luck. I started up a fedora:latest docker container and it seems to perform better than any Red Hat image. However, I can't get past the linting stage with Fedora. The vospupuli docs make this look like it should be pretty hands-off to run the tests but that's not my experience so far.

@ekohl
Copy link
Member

ekohl commented Mar 21, 2023

The "ignoring" part may be relevant, and can point at a broken bundler path.

Where things are installed with Rubygems is honestly speaking very poor. I'd even consider it broken by default.

https://github.com/voxpupuli/modulesync_config/blob/master/moduleroot/.github/CONTRIBUTING.md.erb is a bit more complete (and https://github.com/voxpupuli/puppet-example/blob/master/.github/CONTRIBUTING.md is the rendered version). It recommends setting a bundler path.

That works, but is less efficient if you have multiple modules since you can't reuse gems between repositories. Instead, I have this in my ~/.bashrc:

# https://github.com/rubygems/rubygems/issues/4031
# https://bugzilla.redhat.com/show_bug.cgi?id=1574594
if command -v ruby > /dev/null ; then
        GEM_HOME="$(ruby -e 'print Gem.user_dir')"
        export GEM_HOME
fi

@bschonec
Copy link
Author

So far no luck. Even a brand-new Ubuntu container is failing.

@ekohl
Copy link
Member

ekohl commented Mar 21, 2023

Trying fresh, starting a container with podman run -it --rm centos:stream8

Then:

# dnf module enable ruby:2.7 -y
# dnf install ruby-devel rubygems-devel rubygem-bundler rubygem-rake gcc gcc-c++ make git redhat-rpm-config -y
# adduser user
# su - user
$ GEM_HOME="$(ruby -e 'print Gem.user_dir')"
$ export GEM_HOME
$ git clone https://github.com/voxpupuli/puppet-systemd
$ cd puppet-systemd
$ bundle install
$ bundle exec rake -T
$ bundle exec rake release_checks

This works for me, so I wonder where the failure is for you.

@bschonec
Copy link
Author

So the export GEM_HOME must be the trick. I was able to run 'bundle exec rake release_checks' and all kinds of stuff just wizzed by on my screen with a successful exit code.

Thank you so much for your help.

Shouldn't the documentation be updated to reflect these (Centos/RHEL8) steps so that others can benefit?

@bschonec
Copy link
Author

I was able to get RHEL7 to run all of the spec tests with a combination of the following:

# Enable Red Hat Software collections:
# subscription-manager repos --enable rhel-server-rhscl-7-rpms
# yum -y install rh-ruby27 rh-ruby27-ruby-devel rh-ruby27-rubygems rh-ruby27-rubygems-devel rh-ruby27-ruby
# cd <puppet-project>
# scl enable rh-ruby27 'bundle install'

Documentation on how to use the Red Hat Software Collections is found here, however a Red Hat subscription is required to view the document.

I think this is most useful for people like me who have nearly zero experience with ruby/spec testing and it would be a great addition to the test suite documentation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants