Skip to content

Commit

Permalink
Merge branch 'email_not_required'
Browse files Browse the repository at this point in the history
* email_not_required:
  Skip unit tests on 1 of the CentOS7 builds since it's in
  Had incorrect path
  env issue
  Test email, document the dependency change
  start working on email
  First cut at removing MTA dependency and integration testing without it
  • Loading branch information
wied03 committed Aug 3, 2016
2 parents 8ab52b9 + 76a359e commit 81f120e
Show file tree
Hide file tree
Showing 11 changed files with 57 additions and 19 deletions.
6 changes: 4 additions & 2 deletions .travis.yml
Expand Up @@ -11,8 +11,10 @@ matrix:

include:
- env: CENTOS="centos66"
- env: CENTOS="centos67"
- env: CENTOS="centos7"
- env: CENTOS="centos67" SKIP_UNIT="true"
# email vs stdout only differs re: integration
- env: CENTOS="centos7_email" SKIP_UNIT="true"
- env: CENTOS="centos7_stdout"

# Docker related permissions issues on Travis
before_install:
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
@@ -1,6 +1,7 @@
# 1.0.8 (in development)
* Fix issue with encoding (#9)
* Fix issue with --skipold argument (#8). It's now inverted and named --forceold. Supplying the argument will ignore previously sent notices and send you everything.
* Email MTA has been removed from the RPM dependencies to allow easier stdout/Docker usage

# 1.0.7
* Improve rpmspec (test on CentOS 6.6, 6.7, and 7 with Travis)
Expand Down
2 changes: 2 additions & 0 deletions README.md
Expand Up @@ -71,6 +71,8 @@ centos-package-cron --email_to sysadmin@stuff.com --email_from dev@somebox.com
# See centos-package-cron -h for options
```

NOTE: You must have an MTA (e.g. postfix) configured listening on localhost if you use the email output option.

## License
Copyright (c) 2016, BSW Technology Consulting LLC
All rights reserved.
Expand Down
25 changes: 10 additions & 15 deletions Rakefile
@@ -1,5 +1,13 @@
require 'rspec/core/rake_task'

build_var = ENV['CENTOS'] || 'centos7_stdout'
ENV['NO_EMAIL'] = '1' unless build_var.include?('email')
version_var = build_var.include?('centos7') ? 'centos7' : 'centos6'
image_src_integration = "docker/#{build_var}/integration"
image_src_unit = "docker/#{build_var}/unit"
ENV['IMAGE_INTEGRATION'] = image_tag_integration = "wied03/#{build_var}_int"
image_tag_unit = "wied03/#{build_var}_unit"

desc 'Run serverspec integration tests'
RSpec::Core::RakeTask.new(:integration => :build)

Expand All @@ -9,13 +17,6 @@ task :clean do
rm_rf 'centos-package-cron.spec'
end

build_var = ENV['CENTOS'] || 'centos7'
version_var = build_var.include?('centos7') ? 'centos7' : 'centos6'
image_src_integration = "docker/#{build_var}/integration"
image_src_unit = "docker/#{build_var}/unit"
ENV['IMAGE_INTEGRATION'] = image_tag_integration = "wied03/#{build_var}_int"
image_tag_unit = "wied03/#{build_var}_unit"

file 'centos-package-cron.spec' do
cp 'centos-package-cron.spec.in', 'centos-package-cron.spec'
# initial installation
Expand All @@ -42,20 +43,14 @@ task :build => ['centos-package-cron.spec', :integration_image] do
end

task :unit_image do
if build_var == 'centos67'
# no 6.7 tests right now
next
end
next if ENV['SKIP_UNIT']

sh "docker build -t #{image_tag_unit} #{image_src_unit}"
end

desc 'Runs Python unit tests'
task :unit => :unit_image do
if build_var == 'centos67'
# no 6.7 tests right now
next
end
next if ENV['SKIP_UNIT']

sh "docker run --rm=true -e \"CENTOS=#{version_var}\" -v `pwd`:/code -w /code -u nonrootuser -t #{image_tag_unit} ./setup.py test"
end
1 change: 0 additions & 1 deletion centos-package-cron.spec.in
Expand Up @@ -14,7 +14,6 @@ Requires: python-setuptools >= 0.6.10
Requires: python >= 2.6
Requires: yum >= 3.2
Requires: yum-plugin-changelog >= 1.1.30
Requires: MTA
Requires: python-sqlalchemy >= 0.5.5
Requires: sqlite >= 3.6
# Python 2.7 has this built in but CentOS6 is using Python 2.6, so need a separate package
Expand Down
Expand Up @@ -12,4 +12,4 @@ rm -f /lib/systemd/system/basic.target.wants/*;\
rm -f /lib/systemd/system/anaconda.target.wants/*;
RUN useradd -m nonrootuser -G wheel
RUN echo "nonrootuser ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers
RUN yum -y --disablerepo=updates install rpm-build yum-utils sudo rpmlint
RUN yum -y --disablerepo=updates install rpm-build yum-utils sudo rpmlint postfix
File renamed without changes.
5 changes: 5 additions & 0 deletions docker/centos7_stdout/integration/Dockerfile
@@ -0,0 +1,5 @@
FROM centos:7.0.1406
MAINTAINER Brady Wied <brady@bswtechconsulting.com>
RUN useradd -m nonrootuser -G wheel
RUN echo "nonrootuser ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers
RUN yum -y --disablerepo=updates install rpm-build yum-utils sudo rpmlint
9 changes: 9 additions & 0 deletions docker/centos7_stdout/unit/Dockerfile
@@ -0,0 +1,9 @@
FROM centos:7.0.1406
MAINTAINER Brady Wied <brady@bswtechconsulting.com>
RUN yum -y --disablerepo=updates install python-setuptools git epel-release yum-utils
RUN yum -y --disablerepo=updates install python-pip mailx python-sqlalchemy sudo
RUN pip install ipython
# Newer versions of mock need setuptools > 17.0
RUN pip install setuptools --upgrade
RUN useradd -m nonrootuser -G wheel
RUN echo "nonrootuser ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers
22 changes: 22 additions & 0 deletions spec/output_spec.rb
Expand Up @@ -30,4 +30,26 @@
its(:content) { is_expected.to match /The following security advisories exist.*/m }
end
end

context 'email' do
let(:centos_cmd) { command('centos-package-cron --output email') }

if ENV['NO_EMAIL']
it 'fails correctly' do
expect(centos_cmd.exit_status).to eq 1
expect(centos_cmd.stderr).to match /.*Connection refused.*/m
end
else

before do
expect(command('sudo /usr/libexec/postfix/aliasesdb; sudo /usr/libexec/postfix/chroot-update; sudo /usr/sbin/postfix start').exit_status).to eq 0
end

it 'emails correctly' do
expect(centos_cmd.exit_status).to eq 0
expect(centos_cmd.stdout).to_not match /The following security advisories exist.*/m
expect(command('sudo cat /var/spool/mail/root').stdout).to match /.*Subject: CentOS Update Check.*/m
end
end
end
end
3 changes: 3 additions & 0 deletions spec/spec_helper.rb
Expand Up @@ -33,5 +33,8 @@
output = command('rm -rfv /var/lib/centos-package-cron/*.sqlite').stdout
puts "**** DB cleanup results: #{output.strip} ****"
end

config.filter_run_including focus: true
config.run_all_when_everything_filtered = true
end

0 comments on commit 81f120e

Please sign in to comment.