simp-beaker-helpers 1.14.3 → 1.14.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ba93253298e41c596d16c45a60499e585a242fada303797e01d4ce6476c2b340
4
- data.tar.gz: ac9c8518c54d380601c78bfa0e6916ef5cb0c368b1719ddb6bb33ed9e09f9aac
3
+ metadata.gz: ba5339c4600187e836c0c82d19171e7029cf0e54bb9a270782fcb386872008c4
4
+ data.tar.gz: fae18efeed173a2c5a6496ec56e739ab13ef1bb4160c742058800444bf3a7fe6
5
5
  SHA512:
6
- metadata.gz: 5a928d8e06a885b8f22acb5ebfd31216d1b2053b1868fd97c20e58abe6ea89a6108fd43e82aefc8e5bdc48b582239d4bd1893b18bff68bc679e19fe2f5f4eeba
7
- data.tar.gz: 4eb3da178ba7fd3fcc74ce0dc5346214f3133628dade8e96ad6dd93988ce40c983a26f79f5b0a25fa2d22237911eecdbfe49c44d85fa681a076ad7a20bb2dc3b
6
+ metadata.gz: dc4a6c9c5c7ee3f0ae60a434626af3929ff67f1bc55c7b6411b9f5d888fd975f8cd6a19ac79912562f97802c6dfba620b30511620bc11efb20e9fc23ae1b8473
7
+ data.tar.gz: 324893d60834b6ea71eb0804bd4c8c8a531f0a689ae1ac8283bef94f55a24e03c295c7e2c5812d12a5b55516195ba95947dab219a5641e45dac3ede37e027a5c
@@ -149,3 +149,15 @@ windows:
149
149
  script:
150
150
  - bundle exec rake spec_clean
151
151
  - bundle exec rake beaker:suites[windows]
152
+
153
+ snapshot:
154
+ stage: acceptance
155
+ tags:
156
+ - beaker
157
+ <<: *cache_bundler
158
+ <<: *setup_bundler_env
159
+ variables:
160
+ BEAKER_simp_snapshot: 'yes'
161
+ script:
162
+ - bundle exec rake spec_clean
163
+ - bundle exec rake beaker:suites[snapshot]
data/.rspec CHANGED
@@ -1,3 +1,4 @@
1
1
  --format documentation
2
+ --fail-fast
2
3
  --color
3
4
  --order default
@@ -1,3 +1,6 @@
1
+ ### 1.14.4 / 2019-07-26
2
+ * Bump the version of Highline to 2.0+ due to bugs in the latest 1.X series
3
+
1
4
  ### 1.14.3 / 2019-06-24
2
5
  * Add RPM-GPG-KEY-SIMP-6 to the SIMP dependencies repo created
3
6
  by install_simp_repo.
data/README.md CHANGED
@@ -45,6 +45,14 @@ Methods to assist beaker acceptance tests for SIMP.
45
45
  * [Examples](#examples)
46
46
  * [Prep OS, Generate and copy PKI certs to each SUT](#prep-os-generate-and-copy-pki-certs-to-each-sut)
47
47
  * [Specify the version of Puppet to run in the SUTs](#specify-the-version-of-puppet-to-run-in-the-suts)
48
+ * [Experimental Features](#experimental-features)
49
+ * [Snapshot Support](#snapshot-support)
50
+ * [Running Tests with Snapshots](#running-tests-with-snapshots)
51
+ * [Adding Snapshots to your Tests](#adding-snapshots-to-your-tests)
52
+ * [Taking a Snapshot](#taking-a-snapshot)
53
+ * [Base Snapshots](#base-snapshots)
54
+ * [Restoring a Snapshot](#restoring-a-snapshot)
55
+ * [Listing Snapshots](#listing-snapshots)
48
56
  * [License](#license)
49
57
 
50
58
  <!-- vim-markdown-toc -->
@@ -439,5 +447,73 @@ PUPPET_VERSION="5" bundle exec rake beaker:suites
439
447
  bundle exec rake beaker:suites
440
448
  ```
441
449
 
450
+ ## Experimental Features
451
+
452
+ ### Snapshot Support
453
+
454
+ Rudimentary support for snapshotting VMs has been added. This currently only
455
+ works for local `vagrant` systems and relies on the underlying `vagrant
456
+ snapshot` command working for the underlying hypervisor. VirtualBox is highly
457
+ recommended and `libvirt` is known to not work due to limitiations in
458
+ `vagrant`.
459
+
460
+ This was added to attempt to be able to restart tests from given checkpoints
461
+ that encompass extremely long running test segments. This is particularly
462
+ relevant when you are trying to set up a large support infrastructure but need
463
+ to debug later stages of your tests over time.
464
+
465
+ #### Running Tests with Snapshots
466
+
467
+ To enable snapshots during your initial test runs, run your test as follows:
468
+
469
+ ```bash
470
+ BEAKER_destroy=no BEAKER_simp_snapshot=yes rake beaker:suites
471
+ ```
472
+
473
+ Then, on subsequent runs, run your test as follows:
474
+
475
+ ```bash
476
+ BEAKER_provision=no BEAKER_destroy=no BEAKER_simp_snapshot=yes rake beaker:suites
477
+ ```
478
+ #### Adding Snapshots to your Tests
479
+
480
+ The following demonstrates the general idea behind using snapshots. Note, the
481
+ decision to directly call the module methods was made to ensure that people
482
+ knew explicitly when this capability was being called since it affects the
483
+ underlying OS configuration.
484
+
485
+ ##### Taking a Snapshot
486
+
487
+ `Simp::BeakerHelpers::Snapshot.save(sut, '<name of snapshot>')` will save a
488
+ snapshot with the given name. If the snapshot already exists, it will be
489
+ forceably overwritten.
490
+
491
+
492
+ ##### Base Snapshots
493
+
494
+ Any time a snapshot is saved, if an initial base snapshot doesn't exist, one
495
+ will be created. You can restore back to the base snapshot using
496
+ `Simp::BeakerHelpers::Snapshot.restore_to_base(sut)`.
497
+
498
+ These are specifically created to ensure that we don't run into issues with
499
+ trying to remove the parent of all snapshots since some hypervisors do not
500
+ allow this.
501
+
502
+ ##### Restoring a Snapshot
503
+
504
+ `Simp::BeakerHelpers::Snapshot.restore(sut, '<name of snapshot>)` will restore
505
+ to the named snapshot.
506
+
507
+ Attempting to restore to a snapshot that doesn't exist is an error.
508
+
509
+ ##### Listing Snapshots
510
+
511
+ `Simp::BeakerHelpers::Snapshot.list(sut)` will return an Array of all snapshot
512
+ names for that system.
513
+
514
+ `Simp::BeakerHelpers::Snapshot.exist?(sut, '<name of snapshot>')` will return a
515
+ Boolean based on whether or not the snapshot with the given name is present on
516
+ the system.
517
+
442
518
  ## License
443
519
  See [LICENSE](LICENSE)
@@ -1,13 +1,16 @@
1
1
  require 'beaker-puppet'
2
+ require 'bundler'
2
3
 
3
4
  module Simp; end
4
5
 
5
6
  module Simp::BeakerHelpers
6
7
  include BeakerPuppet
7
8
 
8
- require 'simp/beaker_helpers/version'
9
+ require 'simp/beaker_helpers/constants'
9
10
  require 'simp/beaker_helpers/inspec'
11
+ require 'simp/beaker_helpers/snapshot'
10
12
  require 'simp/beaker_helpers/ssg'
13
+ require 'simp/beaker_helpers/version'
11
14
 
12
15
  # Stealing this from the Ruby 2.5 Dir::Tmpname workaround from Rails
13
16
  def self.tmpname
@@ -15,12 +18,6 @@ module Simp::BeakerHelpers
15
18
  "simp-beaker-helpers-#{t}-#{$$}-#{rand(0x100000000).to_s(36)}.tmp"
16
19
  end
17
20
 
18
- # This is the *oldest* version that the latest release of SIMP supports
19
- #
20
- # This is done so that we know if some new thing that we're using breaks the
21
- # oldest system that we support.
22
- DEFAULT_PUPPET_AGENT_VERSION = '~> 5.0'
23
-
24
21
  # We can't cache this because it may change during a run
25
22
  def fips_enabled(sut)
26
23
  return on( sut,
@@ -0,0 +1,25 @@
1
+ module Simp; end
2
+
3
+ module Simp::BeakerHelpers
4
+ # This is the *oldest* puppet-agent version that the latest release of SIMP supports
5
+ #
6
+ # This is done so that we know if some new thing that we're using breaks the
7
+ # oldest system that we support
8
+ DEFAULT_PUPPET_AGENT_VERSION = '~> 5.0'
9
+
10
+ SSG_REPO_URL = ENV['BEAKER_ssg_repo'] || 'https://github.com/ComplianceAsCode/content.git'
11
+
12
+ if ['true','yes'].include?(ENV['BEAKER_online'])
13
+ ONLINE = true
14
+ elsif ['false','no'].include?(ENV['BEAKER_online'])
15
+ ONLINE = false
16
+ else
17
+ require 'open-uri'
18
+
19
+ begin
20
+ ONLINE = true if open('http://google.com')
21
+ rescue
22
+ ONLINE = false
23
+ end
24
+ end
25
+ end
@@ -1,4 +1,6 @@
1
1
  module Simp::BeakerHelpers
2
+ require 'simp/beaker_helpers/constants'
3
+
2
4
  # Helpers for working with Inspec
3
5
  class Inspec
4
6
 
@@ -0,0 +1,158 @@
1
+ module Simp::BeakerHelpers
2
+ # Helpers for working with the SCAP Security Guide
3
+ class Snapshot
4
+ # The name of the base snapshot that is created if no snapshots currently exist
5
+ BASE_NAME = '_simp_beaker_base'
6
+
7
+ # Save a snapshot
8
+ #
9
+ # @param host [Beaker::Host]
10
+ # The SUT to work on
11
+ #
12
+ # @param snapshot_name [String]
13
+ # The string to add to the snapshot
14
+ #
15
+ def self.save(host, snapshot_name)
16
+ if enabled?
17
+ vdir = vagrant_dir(host)
18
+
19
+ if vdir
20
+ Dir.chdir(vdir) do
21
+ unless exist?(host, BASE_NAME)
22
+ save(host, BASE_NAME)
23
+ end
24
+
25
+ snap = "#{host.name}_#{snapshot_name}"
26
+
27
+ output = %x(vagrant snapshot save --force #{host.name} "#{snap}")
28
+
29
+ logger.notify(output)
30
+
31
+ retry_on(
32
+ host,
33
+ %(echo "saving snapshot '#{snap}'" > /dev/null),
34
+ :max_retries => 30,
35
+ :retry_interval => 1
36
+ )
37
+ end
38
+ end
39
+ end
40
+ end
41
+
42
+ # Whether or not a named snapshot exists
43
+ #
44
+ # @param host [Beaker::Host]
45
+ # The SUT to work on
46
+ #
47
+ # @param snapshot_name [String]
48
+ # The string to add to the snapshot
49
+ #
50
+ # @return [Boolean]
51
+ def self.exist?(host, name)
52
+ list(host).include?(name)
53
+ end
54
+
55
+ # List all snapshots for the given host
56
+ #
57
+ # @parma host [Beaker::Host]
58
+ # The SUT to work on
59
+ #
60
+ # @return [Array[String]]
61
+ # A list of snapshot names for the host
62
+ def self.list(host)
63
+ output = []
64
+ vdir = vagrant_dir(host)
65
+
66
+ if vdir
67
+ Dir.chdir(vdir) do
68
+ output = %x(vagrant snapshot list #{host.name}).lines
69
+ output.map! do |x|
70
+ x.split(/^#{host.name}_/).last.strip
71
+ end
72
+ end
73
+ end
74
+
75
+ output
76
+ end
77
+
78
+ # Restore a snapshot
79
+ #
80
+ # @param host [Beaker::Host]
81
+ # The SUT to work on
82
+ #
83
+ # @param snapshot_name [String]
84
+ # The name that was added to the snapshot
85
+ #
86
+ def self.restore(host, snapshot_name)
87
+ if enabled?
88
+ vdir = vagrant_dir(host)
89
+
90
+ if vdir
91
+ Dir.chdir(vdir) do
92
+ snap = "#{host.name}_#{snapshot_name}"
93
+
94
+ output = %x(vagrant snapshot restore #{host.name} "#{snap}" 2>&1)
95
+
96
+ if (output =~ /error/i) && (output =~ /child/)
97
+ raise output
98
+ end
99
+
100
+ if (output =~ /snapshot.*not found/)
101
+ raise output
102
+ end
103
+
104
+ logger.notify(output)
105
+
106
+ retry_on(
107
+ host,
108
+ %(echo "restoring snapshot '#{snap}'" > /dev/null),
109
+ :max_retries => 30,
110
+ :retry_interval => 1
111
+ )
112
+ end
113
+ end
114
+ end
115
+ end
116
+
117
+ # Restore all the way back to the base image
118
+ #
119
+ # @param host [Beaker::Host]
120
+ # The SUT to work on
121
+ #
122
+ def self.restore_to_base(host)
123
+ if exist?(host, BASE_NAME)
124
+ restore(host, BASE_NAME)
125
+ else
126
+ save(host, BASE_NAME)
127
+ end
128
+ end
129
+
130
+ private
131
+
132
+ def self.enabled?
133
+ enabled = ENV['BEAKER_simp_snapshot'] == 'yes'
134
+
135
+ unless enabled
136
+ logger.warn('Snapshotting not enabled, set BEAKER_simp_snapshot=yes to enable')
137
+ end
138
+
139
+ return enabled
140
+ end
141
+
142
+ def self.vagrant_dir(host)
143
+ tgt_dir = nil
144
+
145
+ if host && host.options && host.options[:hosts_file]
146
+ vdir = File.join('.vagrant', 'beaker_vagrant_files', File.basename(host.options[:hosts_file]))
147
+
148
+ if File.directory?(vdir)
149
+ tgt_dir = vdir
150
+ else
151
+ logger.notify("Could not find local vagrant dir at #{vdir}")
152
+ end
153
+ end
154
+
155
+ return tgt_dir
156
+ end
157
+ end
158
+ end
@@ -1,10 +1,14 @@
1
1
  module Simp::BeakerHelpers
2
+ require 'simp/beaker_helpers/constants'
3
+
2
4
  # Helpers for working with the SCAP Security Guide
3
5
  class SSG
4
6
 
5
7
  if ENV['BEAKER_ssg_repo']
6
8
  GIT_REPO = ENV['BEAKER_ssg_repo']
7
9
  else
10
+ fail('You are offline: Set BEAKER_ssg_repo to point to the git repo that hosts the SSG content') unless ONLINE
11
+
8
12
  GIT_REPO = 'https://github.com/ComplianceAsCode/content.git'
9
13
  end
10
14
 
@@ -1,5 +1,5 @@
1
1
  module Simp; end
2
2
 
3
3
  module Simp::BeakerHelpers
4
- VERSION = '1.14.3'
4
+ VERSION = '1.14.4'
5
5
  end
@@ -24,7 +24,7 @@ Gem::Specification.new do |s|
24
24
  s.add_runtime_dependency 'beaker-docker' , '~> 0.3'
25
25
  s.add_runtime_dependency 'beaker-vagrant' , '~> 0.5'
26
26
  s.add_runtime_dependency 'beaker-puppet_install_helper', '~> 0.9'
27
- s.add_runtime_dependency 'highline' , '~> 1.6'
27
+ s.add_runtime_dependency 'highline' , '~> 2.0'
28
28
  s.add_runtime_dependency 'nokogiri' , '~> 1.8'
29
29
 
30
30
  # Because net-telnet dropped support for Ruby < 2.3.0
@@ -0,0 +1,165 @@
1
+ require 'spec_helper_acceptance'
2
+
3
+ describe 'Offline mode' do
4
+ hosts.each do |host|
5
+ context "on #{host}" do
6
+ let(:vagrant_version) { '2.2.5' }
7
+ let(:vagrant_rpm) { "https://releases.hashicorp.com/vagrant/#{vagrant_version}/vagrant_#{vagrant_version}_x86_64.rpm" }
8
+ let(:virtualbox_repo) { 'http://download.virtualbox.org/virtualbox/rpm/el/virtualbox.repo' }
9
+ let(:build_user) { 'build_user' }
10
+ let(:build_user_cmd) { "runuser #{build_user} -l -c" }
11
+
12
+ # Not sure if this is a QEMU thing with the image or something else
13
+ it 'works around a CentOS curl bug with libvirt' do
14
+ on(host, %(touch /etc/sysconfig/64bit_strstr_via_64bit_strstr_sse2_unaligned))
15
+ end
16
+
17
+ it 'adds the build user' do
18
+ on(host, %(useradd -b /home -G wheel -m -c "Build User" -s /bin/bash -U #{build_user}))
19
+
20
+ # Allow the build user to perform privileged operations
21
+ on(host, %(echo 'Defaults:build_user !requiretty' >> /etc/sudoers))
22
+ end
23
+
24
+ it 'installs required packages' do
25
+ host.install_package('epel-release')
26
+
27
+ required_packages = [
28
+ 'augeas-devel',
29
+ 'autoconf',
30
+ 'automake',
31
+ 'bison',
32
+ 'createrepo',
33
+ 'curl',
34
+ 'dkms',
35
+ 'initscripts',
36
+ 'gcc',
37
+ 'gcc-c++',
38
+ 'genisoimage',
39
+ 'git',
40
+ 'glibc-devel',
41
+ 'glibc-headers',
42
+ 'gnupg2',
43
+ 'kernel-devel',
44
+ 'libffi-devel',
45
+ 'libicu-devel',
46
+ 'libtool',
47
+ 'libvirt',
48
+ 'libvirt-client',
49
+ 'libvirt-devel',
50
+ 'libxml2',
51
+ 'libxml2-devel',
52
+ 'libxslt',
53
+ 'libxslt-devel',
54
+ 'libyaml-devel',
55
+ 'make',
56
+ 'ntpdate',
57
+ 'openssl',
58
+ 'openssl-devel',
59
+ 'qemu',
60
+ 'readline-devel',
61
+ 'rpm-build',
62
+ 'rpm-sign',
63
+ 'rpmdevtools',
64
+ 'ruby-devel',
65
+ 'rubygems',
66
+ 'seabios',
67
+ 'sqlite-devel',
68
+ 'util-linux',
69
+ 'which'
70
+ ]
71
+
72
+ on(host, %(yum -y install #{required_packages.join(' ')}))
73
+ on(host, %(yum -y update))
74
+ end
75
+
76
+ it 'removes limits from the system' do
77
+ # Remove system limits
78
+ on(host, %(rm -rf /etc/security/limits.d/*.conf))
79
+ end
80
+
81
+ it 'installs the latest VirtualBox' do
82
+ on(host, %(curl "#{virtualbox_repo}" -o /etc/yum.repos.d/virtualbox.repo))
83
+ on(host, 'yum -y install $(yum -y list | grep VirtualBox | sort | tail -1 | cut -f 1 -d " ")')
84
+ end
85
+
86
+ it 'installs the VirtualBox extension pack' do
87
+ on(host, 'VERSION=$(VBoxManage --version | tail -1 | cut -f 1 -d "r") && curl -Lo ${TMPDIR}/Oracle_VM_VirtualBox_Extension_Pack-${VERSION}.vbox-extpack http://download.virtualbox.org/virtualbox/${VERSION}/Oracle_VM_VirtualBox_Extension_Pack-${VERSION}.vbox-extpack && yes | VBoxManage extpack install ${TMPDIR}/Oracle_VM_VirtualBox_Extension_Pack-${VERSION}.vbox-extpack && rm -rf ${TMPDIR}/Oracle_VM_VirtualBox_Extension_Pack-${VERSION}.vbox-extpack')
88
+ end
89
+
90
+ it 'adds the build user to the vboxusers group' do
91
+ on(host, %(usermod -a -G vboxusers #{build_user}))
92
+ end
93
+
94
+ it 'reboots the system to finalize VirtualBox' do
95
+ host.reboot
96
+ end
97
+
98
+ it 'installs RPM for the build user' do
99
+ # Install RVM
100
+ on(host, %(#{build_user_cmd} "for i in {1..5}; do { gpg2 --keyserver hkp://pgp.mit.edu --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3 || gpg2 --keyserver hkp://keys.gnupg.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3 || gpg2 --keyserver hkp://keys.gnupg.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3; } && { gpg2 --keyserver hkp://pgp.mit.edu --recv-keys 7D2BAF1CF37B13E2069D6956105BD0E739499BDB || gpg2 --keyserver hkp://keys.gnupg.net --recv-keys 7D2BAF1CF37B13E2069D6956105BD0E739499BDB; } && break || sleep 1; done"))
101
+ on(host, %(#{build_user_cmd} "gpg2 --refresh-keys"))
102
+ on(host, %(#{build_user_cmd} "curl -sSL https://raw.githubusercontent.com/rvm/rvm/stable/binscripts/rvm-installer -o rvm-installer && curl -sSL https://raw.githubusercontent.com/rvm/rvm/stable/binscripts/rvm-installer.asc -o rvm-installer.asc && gpg2 --verify rvm-installer.asc rvm-installer && bash rvm-installer"))
103
+ on(host, %(#{build_user_cmd} "rvm install 2.4.4 --disable-binary"))
104
+ on(host, %(#{build_user_cmd} "rvm use --default 2.4.4"))
105
+ on(host, %(#{build_user_cmd} "rvm all do gem install bundler -v '~> 1.16' --no-document"))
106
+ end
107
+
108
+ it 'installs vagrant' do
109
+ on(host, %(yum -y install #{vagrant_rpm}))
110
+ end
111
+
112
+ it 'preps for testing by downloading boxes for tests' do
113
+ on(host, %(#{build_user_cmd} "vagrant box add --provider virtualbox centos/6"))
114
+ on(host, %(#{build_user_cmd} "vagrant box add --provider virtualbox centos/7"))
115
+ end
116
+
117
+ it 'runs a simple nested virt test' do
118
+ build_user_homedir = on(host, "readlink -f ~#{build_user}").output.strip
119
+ vagrant_testdir = "#{build_user_homedir}/vagrant_test"
120
+
121
+ vagrant_test_file = <<-EOM
122
+ Vagrant.configure("2") do |c|
123
+ c.vm.define 'test' do |v|
124
+ v.vm.hostname = 'centos7.test.net'
125
+ v.vm.box = 'centos/7'
126
+ v.vm.box_check_update = 'false'
127
+ end
128
+ end
129
+ EOM
130
+
131
+ host.mkdir_p(vagrant_testdir)
132
+
133
+ create_remote_file(host, "#{vagrant_testdir}/Vagrantfile", vagrant_test_file)
134
+
135
+ on(host, %(chown -R #{build_user} #{vagrant_testdir}))
136
+
137
+ on(host, %(#{build_user_cmd} "cd #{vagrant_testdir} && vagrant up"))
138
+ on(host, %(#{build_user_cmd} "cd #{vagrant_testdir} && vagrant destroy -f"))
139
+ end
140
+
141
+ # We're testing a real module since that has the widest set of
142
+ # repercussions for reaching out to the internet
143
+ it 'downloads a module to test' do
144
+ on(host, %(#{build_user_cmd} "git clone https://github.com/simp/pupmod-simp-at"))
145
+ end
146
+
147
+ it 'preps the module for building' do
148
+ on(host, %(#{build_user_cmd} "cd pupmod-simp-at; bundle update"))
149
+ end
150
+
151
+ it 'runs a network-connected test' do
152
+ on(host, %(#{build_user_cmd} "cd pupmod-simp-at; rake beaker:suites"))
153
+ end
154
+
155
+ it 'disables all internet network traffic via iptables' do
156
+ on(host, %(iptables -I OUTPUT -d `ip route | awk '/default/ {print $3}'`/16 -j ACCEPT))
157
+ on(host, 'iptables -A OUTPUT -j DROP')
158
+ end
159
+
160
+ xit 'runs a network-disconnected test' do
161
+ on(host, %(#{build_user_cmd} "cd pupmod-simp-at; rake beaker:suites"))
162
+ end
163
+ end
164
+ end
165
+ end
@@ -0,0 +1,2 @@
1
+ This, very odd, test should NEVER be run by default because it runs docker in
2
+ privileged mode and may cause horriffic unintended side effects on your system.
@@ -0,0 +1,26 @@
1
+ HOSTS:
2
+ el7:
3
+ platform: el-7-x86_64
4
+ box: centos/7
5
+ # This doesn't work with any other hypervisor
6
+ hypervisor: 'vagrant_libvirt'
7
+ vagrant_memsize: 3072
8
+ vagrant_cpus: 4
9
+ # Necessary to prevent network overlap inside the spawned test set
10
+ ip: '172.16.251.111'
11
+ netmask: '255.255.255.0'
12
+
13
+ CONFIG:
14
+ log_level: verbose
15
+ type: aio
16
+ <% if ENV['BEAKER_PUPPET_COLLECTION'] -%>
17
+ puppet_collection: <%= ENV['BEAKER_PUPPET_COLLECTION'] %>
18
+ <% end -%>
19
+ libvirt:
20
+ # Ensure that we use the best option available
21
+ 'cpu_mode': 'host-passthrough'
22
+ # Make sure that vagrant knows that we're rolling nested virt
23
+ 'nested': true
24
+ # Necessary to prevent network overlap inside the spawned test set
25
+ 'management_network_name': 'beaker-mgmt'
26
+ 'management_network_address': '172.16.250.1/24'
@@ -0,0 +1,82 @@
1
+ require 'spec_helper_acceptance'
2
+
3
+ hosts.each do |host|
4
+ describe 'take a snapshot' do
5
+ context "on #{host}" do
6
+ it 'creates a file that should be saved' do
7
+ on(host, 'echo "keep" > /root/keep')
8
+ end
9
+
10
+ it 'takes a snapshot' do
11
+ Simp::BeakerHelpers::Snapshot.save(host, 'test')
12
+ end
13
+
14
+ it 'creates a file that should be removed' do
15
+ on(host, 'echo "trash" > /root/trash')
16
+ end
17
+
18
+ it 'restores a snapshot' do
19
+ Simp::BeakerHelpers::Snapshot.restore(host, 'test')
20
+ end
21
+
22
+ it 'should have the keep file' do
23
+ expect(host.file_exist?('/root/keep')).to be true
24
+ end
25
+
26
+ it 'should not have the trash file' do
27
+ expect(host.file_exist?('/root/trash')).to be false
28
+ end
29
+
30
+ it 'creates a second file that should be saved' do
31
+ on(host, 'echo "keep2" > /root/keep2')
32
+ end
33
+
34
+ it 'takes a snapshot with the same name' do
35
+ Simp::BeakerHelpers::Snapshot.save(host, 'test')
36
+ end
37
+
38
+ it 'creates a file that should be removed' do
39
+ on(host, 'echo "trash" > /root/trash')
40
+ end
41
+
42
+ it 'restores a snapshot' do
43
+ Simp::BeakerHelpers::Snapshot.restore(host, 'test')
44
+ end
45
+
46
+ it 'should have all keep files' do
47
+ expect(host.file_exist?('/root/keep')).to be true
48
+ expect(host.file_exist?('/root/keep2')).to be true
49
+ end
50
+
51
+ it 'should not have the trash file' do
52
+ expect(host.file_exist?('/root/trash')).to be false
53
+ end
54
+
55
+ it 'takes a snapshot with a different name' do
56
+ Simp::BeakerHelpers::Snapshot.save(host, 'test2')
57
+ end
58
+
59
+ it 'can list the snapshots' do
60
+ expect(Simp::BeakerHelpers::Snapshot.list(host)).to eq ['test', 'test2']
61
+ end
62
+
63
+ it 'can query for a specific snapshot' do
64
+ expect(Simp::BeakerHelpers::Snapshot.exist?(host, 'test')).to eq true
65
+ expect(Simp::BeakerHelpers::Snapshot.exist?(host, 'test2')).to eq true
66
+ expect(Simp::BeakerHelpers::Snapshot.exist?(host, 'nope')).to eq false
67
+ end
68
+
69
+ it 'restores to the internal base' do
70
+ Simp::BeakerHelpers::Snapshot.restore_to_base(host)
71
+ end
72
+
73
+ it 'creates a file that should be saved' do
74
+ on(host, 'echo "keep" > /root/keep')
75
+ end
76
+
77
+ it 'creates a handoff snapshot for further tests' do
78
+ Simp::BeakerHelpers::Snapshot.save(host, 'handoff')
79
+ end
80
+ end
81
+ end
82
+ end
@@ -0,0 +1,56 @@
1
+ require 'spec_helper_acceptance'
2
+
3
+ hosts.each do |host|
4
+ describe 'snapshot workflow' do
5
+ context "on #{host}" do
6
+ shared_examples_for 'a snapshot test' do
7
+ let(:snapshots) { Simp::BeakerHelpers::Snapshot.list(host) }
8
+
9
+ it 'restores from the initial snapshot' do
10
+ if snapshots.include?(init_snapshot)
11
+ Simp::BeakerHelpers::Snapshot.restore(host, init_snapshot)
12
+ end
13
+ end
14
+
15
+ it 'adds the keep file if necessary' do
16
+ if init_snapshot == 'missing'
17
+ on(host, 'echo "keep" > /root/keep')
18
+ end
19
+ end
20
+
21
+ it 'adds a tracking file' do
22
+ on(host, 'echo "tracking" > /root/tracking')
23
+ end
24
+
25
+ it 'restores the snapshot' do
26
+ if init_snapshot == 'missing'
27
+ expect { Simp::BeakerHelpers::Snapshot.restore(host, init_snapshot) }.to raise_error(/not found/)
28
+ Simp::BeakerHelpers::Snapshot.restore_to_base(host)
29
+ else
30
+ Simp::BeakerHelpers::Snapshot.restore(host, init_snapshot)
31
+ end
32
+ end
33
+
34
+ it 'should have the keep file' do
35
+ expect(host.file_exist?('/root/keep')).to be true
36
+ end
37
+
38
+ it 'should not have the tracking file' do
39
+ expect(host.file_exist?('/root/tracking')).to be false
40
+ end
41
+ end
42
+
43
+ context 'existing snapshot' do
44
+ let(:init_snapshot) { 'handoff' }
45
+
46
+ include_examples 'a snapshot test'
47
+ end
48
+
49
+ context 'missing snapshot' do
50
+ let(:init_snapshot) { 'missing' }
51
+
52
+ include_examples 'a snapshot test'
53
+ end
54
+ end
55
+ end
56
+ end
@@ -0,0 +1 @@
1
+ spec/acceptance/suites/snapshot/../../nodesets
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: simp-beaker-helpers
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.14.3
4
+ version: 1.14.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chris Tessmer
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2019-06-25 00:00:00.000000000 Z
12
+ date: 2019-07-30 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: beaker
@@ -101,14 +101,14 @@ dependencies:
101
101
  requirements:
102
102
  - - "~>"
103
103
  - !ruby/object:Gem::Version
104
- version: '1.6'
104
+ version: '2.0'
105
105
  type: :runtime
106
106
  prerelease: false
107
107
  version_requirements: !ruby/object:Gem::Requirement
108
108
  requirements:
109
109
  - - "~>"
110
110
  - !ruby/object:Gem::Version
111
- version: '1.6'
111
+ version: '2.0'
112
112
  - !ruby/object:Gem::Dependency
113
113
  name: nokogiri
114
114
  requirement: !ruby/object:Gem::Requirement
@@ -160,7 +160,9 @@ files:
160
160
  - files/pki/template_host.cnf
161
161
  - files/puppet-agent-versions.yaml
162
162
  - lib/simp/beaker_helpers.rb
163
+ - lib/simp/beaker_helpers/constants.rb
163
164
  - lib/simp/beaker_helpers/inspec.rb
165
+ - lib/simp/beaker_helpers/snapshot.rb
164
166
  - lib/simp/beaker_helpers/ssg.rb
165
167
  - lib/simp/beaker_helpers/version.rb
166
168
  - lib/simp/rake/beaker.rb
@@ -177,9 +179,15 @@ files:
177
179
  - spec/acceptance/suites/fips_from_fixtures/00_default_spec.rb
178
180
  - spec/acceptance/suites/fips_from_fixtures/metadata.yml
179
181
  - spec/acceptance/suites/fips_from_fixtures/nodesets
182
+ - spec/acceptance/suites/offline/00_default_spec.rb
183
+ - spec/acceptance/suites/offline/README
184
+ - spec/acceptance/suites/offline/nodesets/default.yml
180
185
  - spec/acceptance/suites/puppet_collections/00_default_spec.rb
181
186
  - spec/acceptance/suites/puppet_collections/metadata.yml
182
187
  - spec/acceptance/suites/puppet_collections/nodesets/default.yml
188
+ - spec/acceptance/suites/snapshot/00_snapshot_test_spec.rb
189
+ - spec/acceptance/suites/snapshot/10_general_usage_spec.rb
190
+ - spec/acceptance/suites/snapshot/nodesets
183
191
  - spec/acceptance/suites/windows/00_default_spec.rb
184
192
  - spec/acceptance/suites/windows/metadata.yml
185
193
  - spec/acceptance/suites/windows/nodesets/default.yml