vagrant-registration 0.0.19 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +6 -0
- data/Gemfile +4 -0
- data/README.md +19 -0
- data/lib/vagrant-registration.rb +5 -9
- data/lib/vagrant-registration/action.rb +4 -4
- data/lib/vagrant-registration/action/register.rb +36 -10
- data/lib/vagrant-registration/action/unregister_on_destroy.rb +7 -7
- data/lib/vagrant-registration/action/unregister_on_halt.rb +7 -7
- data/lib/vagrant-registration/config.rb +13 -11
- data/lib/vagrant-registration/plugin.rb +5 -5
- data/lib/vagrant-registration/version.rb +2 -1
- data/plugins/guests/redhat/cap/registration.rb +16 -2
- data/plugins/guests/redhat/cap/subscription_manager.rb +29 -2
- data/plugins/guests/redhat/plugin.rb +42 -27
- data/vagrant-registration.gemspec +16 -17
- metadata +2 -6
- data/tests/helpers.sh +0 -128
- data/tests/run.sh +0 -59
- data/tests/vagrantfiles/Vagrantfile.rhel_multi_machine +0 -19
- data/tests/vagrantfiles/Vagrantfile.rhel_wrong_credentials +0 -14
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 36a083fba5976bcd3746308acac0b76e47eb753f
|
4
|
+
data.tar.gz: 159ddc274e1fe121bb7615ff69db99157b4970b5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 68583118bac63262c52bf17b7c56c5c8821d722b10ad5bd8a604984d29fe33b6203d43e1299d9d18f1ce4695a157e1da4275ad73edb9e45a61dcf4ec658a4fe5
|
7
|
+
data.tar.gz: 8bb6d909ee3d08d2972b1e648cb8280f8c8b56a4eb3c0701b5d9c5fe8f682f05afbabacd5d94bafd6551596b482443c45daa81d1a16e5822f1a6e05e01089df6
|
data/CHANGELOG.md
CHANGED
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -111,6 +111,10 @@ Note that the `auto_attach` option is set to false when using org/activationkey
|
|
111
111
|
# Asset Manager, defaults to Customer Portal Subscription Management)
|
112
112
|
config.registration.serverurl
|
113
113
|
|
114
|
+
# A path to a CA certificate, this file would be copied to /etc/rhsm/ca and
|
115
|
+
# if the file does not have .pem extension, it will be automatically added
|
116
|
+
config.registration.ca_cert
|
117
|
+
|
114
118
|
# Give the hostname of the content delivery server to use to receive updates
|
115
119
|
# (required for Satellite 6)
|
116
120
|
config.registration.baseurl
|
@@ -150,6 +154,21 @@ Note that the `auto_attach` option is set to false when using org/activationkey
|
|
150
154
|
config.registration.skip
|
151
155
|
```
|
152
156
|
|
157
|
+
## Tests
|
158
|
+
|
159
|
+
Tests currently test the plugin with `subscription-manager` on RHEL 7.1 guest
|
160
|
+
and Fedora host. You need an imported RHEL 7.1 Vagrant box named `rhel-7.1`.
|
161
|
+
|
162
|
+
To run them:
|
163
|
+
|
164
|
+
```
|
165
|
+
export VAGRANT_REGISTRATION_USERNAME=
|
166
|
+
export VAGRANT_REGISTRATION_PASSWORD=
|
167
|
+
export VAGRANT_REGISTRATION_ORG=
|
168
|
+
export VAGRANT_REGISTRATION_ACTIVATIONKEY=
|
169
|
+
./tests/run.sh
|
170
|
+
```
|
171
|
+
|
153
172
|
## Acknowledgements
|
154
173
|
|
155
174
|
The project would like to make sure we thank [purpleidea](https://github.com/purpleidea/), [humaton](https://github.com/humaton/), [strzibny](https://github.com/strzibny), [scollier](https://github.com/scollier/), [puzzle](https://github.com/puzzle), [voxik](https://github.com/voxik), [lukaszachy](https://github.com/lukaszachy) and [goern](https://github.com/goern) (in no particular order) for their contributions of ideas, code and testing for this project.
|
data/lib/vagrant-registration.rb
CHANGED
@@ -1,18 +1,14 @@
|
|
1
|
-
require
|
2
|
-
|
3
|
-
require "vagrant-registration/plugin"
|
1
|
+
require 'pathname'
|
2
|
+
require 'vagrant-registration/plugin'
|
4
3
|
|
5
4
|
module VagrantPlugins
|
6
5
|
module Registration
|
7
|
-
lib_path = Pathname.new(File.expand_path(
|
8
|
-
autoload :Action, lib_path.join(
|
9
|
-
#autoload :Errors, lib_path.join("errors")
|
6
|
+
lib_path = Pathname.new(File.expand_path('../vagrant-registration', __FILE__))
|
7
|
+
autoload :Action, lib_path.join('action')
|
10
8
|
|
11
9
|
# This returns the path to the source of this plugin.
|
12
|
-
#
|
13
|
-
# @return [Pathname]
|
14
10
|
def self.source_root
|
15
|
-
@source_root ||= Pathname.new(File.expand_path(
|
11
|
+
@source_root ||= Pathname.new(File.expand_path('../../', __FILE__))
|
16
12
|
end
|
17
13
|
|
18
14
|
# Temporally load the extra capability files for Red Hat
|
@@ -20,10 +20,10 @@ module VagrantPlugins
|
|
20
20
|
end
|
21
21
|
end
|
22
22
|
|
23
|
-
action_root = Pathname.new(File.expand_path(
|
24
|
-
autoload :Register, action_root.join(
|
25
|
-
autoload :UnregisterOnHalt, action_root.join(
|
26
|
-
autoload :UnregisterOnDestroy, action_root.join(
|
23
|
+
action_root = Pathname.new(File.expand_path('../action', __FILE__))
|
24
|
+
autoload :Register, action_root.join('register')
|
25
|
+
autoload :UnregisterOnHalt, action_root.join('unregister_on_halt')
|
26
|
+
autoload :UnregisterOnDestroy, action_root.join('unregister_on_destroy')
|
27
27
|
end
|
28
28
|
end
|
29
29
|
end
|
@@ -5,9 +5,9 @@ module VagrantPlugins
|
|
5
5
|
module Action
|
6
6
|
# This registers the guest if the guest plugin supports it
|
7
7
|
class Register
|
8
|
-
def initialize(app,
|
8
|
+
def initialize(app, _)
|
9
9
|
@app = app
|
10
|
-
@logger = Log4r::Logger.new(
|
10
|
+
@logger = Log4r::Logger.new('vagrant_registration::action::register')
|
11
11
|
end
|
12
12
|
|
13
13
|
def call(env)
|
@@ -19,13 +19,14 @@ module VagrantPlugins
|
|
19
19
|
guest = env[:machine].guest
|
20
20
|
|
21
21
|
if should_register?(machine)
|
22
|
-
env[:ui].info(
|
22
|
+
env[:ui].info('Registering box with vagrant-registration...')
|
23
|
+
check_configuration_options(machine, env[:ui])
|
23
24
|
|
24
25
|
unless credentials_provided? machine
|
25
|
-
@logger.debug(
|
26
|
+
@logger.debug('Credentials for registration not provided')
|
26
27
|
|
27
28
|
# Offer to register ATM or skip
|
28
|
-
register_now = env[:ui].ask(
|
29
|
+
register_now = env[:ui].ask('Would you like to register the system now (default: yes)? [y|n]')
|
29
30
|
|
30
31
|
if register_now == 'n'
|
31
32
|
config.skip = true
|
@@ -33,10 +34,10 @@ module VagrantPlugins
|
|
33
34
|
config = register_on_screen(machine, env[:ui])
|
34
35
|
end
|
35
36
|
end
|
36
|
-
guest.capability(:registration_register) unless config.skip
|
37
|
+
guest.capability(:registration_register, env[:ui]) unless config.skip
|
37
38
|
end
|
38
39
|
|
39
|
-
@logger.debug(
|
40
|
+
@logger.debug('Registration is skipped due to the configuration') if config.skip
|
40
41
|
end
|
41
42
|
|
42
43
|
private
|
@@ -49,6 +50,31 @@ module VagrantPlugins
|
|
49
50
|
!machine.guest.capability(:registration_registered?)
|
50
51
|
end
|
51
52
|
|
53
|
+
# Issues warning if an unsupported option is used and displays
|
54
|
+
# a list of supported options
|
55
|
+
def check_configuration_options(machine, ui)
|
56
|
+
manager = machine.guest.capability(:registration_manager).to_s
|
57
|
+
available_options = machine.guest.capability(:registration_options)
|
58
|
+
options = machine.config.registration.conf.each_pair.map { |pair| pair[0] }
|
59
|
+
|
60
|
+
if unsupported_options_provided?(manager, available_options, options, ui)
|
61
|
+
ui.warn("WARNING: #{manager} supports only the following options:" +
|
62
|
+
"\nWARNING: " + available_options.join(', '))
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
# Return true if there are any unsupported options
|
67
|
+
def unsupported_options_provided?(manager, available_options, options, ui)
|
68
|
+
warned = false
|
69
|
+
options.each do |option|
|
70
|
+
unless available_options.include? option
|
71
|
+
ui.warn("WARNING: #{option} option is not supported for " + manager)
|
72
|
+
warned = true
|
73
|
+
end
|
74
|
+
end
|
75
|
+
warned
|
76
|
+
end
|
77
|
+
|
52
78
|
# Check if registration capabilities are available
|
53
79
|
def capabilities_provided?(guest)
|
54
80
|
if guest.capability?(:registration_register) &&
|
@@ -56,7 +82,7 @@ module VagrantPlugins
|
|
56
82
|
guest.capability?(:registration_registered?)
|
57
83
|
true
|
58
84
|
else
|
59
|
-
@logger.debug(
|
85
|
+
@logger.debug('Registration is skipped due to the missing guest capability')
|
60
86
|
false
|
61
87
|
end
|
62
88
|
end
|
@@ -66,7 +92,7 @@ module VagrantPlugins
|
|
66
92
|
if guest.capability(:registration_manager_installed)
|
67
93
|
true
|
68
94
|
else
|
69
|
-
@logger.debug(
|
95
|
+
@logger.debug('Registration manager not found on guest')
|
70
96
|
false
|
71
97
|
end
|
72
98
|
end
|
@@ -112,7 +138,7 @@ module VagrantPlugins
|
|
112
138
|
unless machine.config.registration.send(option)
|
113
139
|
echo = !(secrets(machine).include? option)
|
114
140
|
response = ui.ask("#{option}: ", echo: echo)
|
115
|
-
machine.config.registration.send("#{option
|
141
|
+
machine.config.registration.send("#{option}=".to_sym, response)
|
116
142
|
end
|
117
143
|
end
|
118
144
|
machine.config.registration
|
@@ -1,4 +1,4 @@
|
|
1
|
-
require
|
1
|
+
require 'log4r'
|
2
2
|
|
3
3
|
module VagrantPlugins
|
4
4
|
module Registration
|
@@ -7,7 +7,7 @@ module VagrantPlugins
|
|
7
7
|
class UnregisterOnDestroy
|
8
8
|
def initialize(app, env)
|
9
9
|
@app = app
|
10
|
-
@logger = Log4r::Logger.new(
|
10
|
+
@logger = Log4r::Logger.new('vagrant_registration::action::unregister_on_destroy')
|
11
11
|
end
|
12
12
|
|
13
13
|
def call(env)
|
@@ -15,17 +15,17 @@ module VagrantPlugins
|
|
15
15
|
guest = env[:machine].guest
|
16
16
|
|
17
17
|
if capabilities_provided?(guest) && manager_installed?(guest) && !config.skip
|
18
|
-
env[:ui].info(
|
18
|
+
env[:ui].info('Unregistering box with vagrant-registration...')
|
19
19
|
guest.capability(:registration_unregister)
|
20
20
|
end
|
21
21
|
|
22
|
-
@logger.debug(
|
22
|
+
@logger.debug('Unregistration is skipped due to the configuration') if config.skip
|
23
23
|
@app.call(env)
|
24
24
|
|
25
25
|
# Guest might not be available after halting, so log the exception and continue
|
26
26
|
rescue => e
|
27
27
|
@logger.info(e)
|
28
|
-
@logger.debug(
|
28
|
+
@logger.debug('Guest is not available, ignore unregistration')
|
29
29
|
@app.call(env)
|
30
30
|
end
|
31
31
|
|
@@ -36,7 +36,7 @@ module VagrantPlugins
|
|
36
36
|
if guest.capability?(:registration_unregister) && guest.capability?(:registration_manager_installed)
|
37
37
|
true
|
38
38
|
else
|
39
|
-
@logger.debug(
|
39
|
+
@logger.debug('Unregistration is skipped due to the missing guest capability')
|
40
40
|
false
|
41
41
|
end
|
42
42
|
end
|
@@ -46,7 +46,7 @@ module VagrantPlugins
|
|
46
46
|
if guest.capability(:registration_manager_installed)
|
47
47
|
true
|
48
48
|
else
|
49
|
-
@logger.debug(
|
49
|
+
@logger.debug('Registration manager not found on guest')
|
50
50
|
false
|
51
51
|
end
|
52
52
|
end
|
@@ -7,7 +7,7 @@ module VagrantPlugins
|
|
7
7
|
class UnregisterOnHalt
|
8
8
|
def initialize(app, env)
|
9
9
|
@app = app
|
10
|
-
@logger = Log4r::Logger.new(
|
10
|
+
@logger = Log4r::Logger.new('vagrant_registration::action::unregister_on_halt')
|
11
11
|
end
|
12
12
|
|
13
13
|
def call(env)
|
@@ -15,18 +15,18 @@ module VagrantPlugins
|
|
15
15
|
guest = env[:machine].guest
|
16
16
|
|
17
17
|
if capabilities_provided?(guest) && manager_installed?(guest) && !config.skip && config.unregister_on_halt
|
18
|
-
env[:ui].info(
|
18
|
+
env[:ui].info('Unregistering box with vagrant-registration...')
|
19
19
|
guest.capability(:registration_unregister)
|
20
20
|
end
|
21
21
|
|
22
|
-
@logger.debug(
|
23
|
-
@logger.debug(
|
22
|
+
@logger.debug('Unregistration is skipped due to the configuration') if config.skip
|
23
|
+
@logger.debug('Unregistration is skipped on halt due to the configuration') if !config.unregister_on_halt
|
24
24
|
@app.call(env)
|
25
25
|
|
26
26
|
# Guest might not be available after halting, so log the exception and continue
|
27
27
|
rescue => e
|
28
28
|
@logger.info(e)
|
29
|
-
@logger.debug(
|
29
|
+
@logger.debug('Guest is not available, ignore unregistration')
|
30
30
|
@app.call(env)
|
31
31
|
end
|
32
32
|
|
@@ -37,7 +37,7 @@ module VagrantPlugins
|
|
37
37
|
if guest.capability?(:registration_unregister) && guest.capability?(:registration_manager_installed)
|
38
38
|
true
|
39
39
|
else
|
40
|
-
@logger.debug(
|
40
|
+
@logger.debug('Unregistration is skipped due to the missing guest capability')
|
41
41
|
false
|
42
42
|
end
|
43
43
|
end
|
@@ -47,7 +47,7 @@ module VagrantPlugins
|
|
47
47
|
if guest.capability(:registration_manager_installed)
|
48
48
|
true
|
49
49
|
else
|
50
|
-
@logger.debug(
|
50
|
+
@logger.debug('Registration manager not found on guest')
|
51
51
|
false
|
52
52
|
end
|
53
53
|
end
|
@@ -3,10 +3,12 @@ require "ostruct"
|
|
3
3
|
|
4
4
|
module VagrantPlugins
|
5
5
|
module Registration
|
6
|
-
class Config < Vagrant.plugin(
|
6
|
+
class Config < Vagrant.plugin('2', :config)
|
7
|
+
attr_reader :conf
|
8
|
+
|
7
9
|
def initialize(region_specific=false)
|
8
10
|
@conf = UNSET_VALUE
|
9
|
-
@logger = Log4r::Logger.new(
|
11
|
+
@logger = Log4r::Logger.new('vagrant_registration::config')
|
10
12
|
end
|
11
13
|
|
12
14
|
def finalize!
|
@@ -26,16 +28,16 @@ module VagrantPlugins
|
|
26
28
|
|
27
29
|
private
|
28
30
|
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
31
|
+
# Don't set @conf to OpenStruct in initialize
|
32
|
+
# to preserve config hierarchy
|
33
|
+
def get_config
|
34
|
+
@conf = OpenStruct.new if @conf == UNSET_VALUE
|
35
|
+
end
|
34
36
|
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
37
|
+
def adjust_arguments(args)
|
38
|
+
return '' if args.size < 1
|
39
|
+
args.map { |a| a.is_a?(String) ? "'#{a}'" : a }.join(',')
|
40
|
+
end
|
39
41
|
end
|
40
42
|
end
|
41
43
|
end
|
@@ -6,13 +6,13 @@ end
|
|
6
6
|
|
7
7
|
# This is a sanity check to make sure no one is attempting to install
|
8
8
|
# this into an early Vagrant version.
|
9
|
-
if Vagrant::VERSION <
|
10
|
-
|
9
|
+
if Vagrant::VERSION < '1.2.0'
|
10
|
+
fail 'The Vagrant RHEL plugin is only compatible with Vagrant 1.2+.'
|
11
11
|
end
|
12
12
|
|
13
13
|
module VagrantPlugins
|
14
14
|
module Registration
|
15
|
-
class Plugin < Vagrant.plugin(
|
15
|
+
class Plugin < Vagrant.plugin('2')
|
16
16
|
class << self
|
17
17
|
def register(hook)
|
18
18
|
setup_logging
|
@@ -31,7 +31,7 @@ module VagrantPlugins
|
|
31
31
|
end
|
32
32
|
end
|
33
33
|
|
34
|
-
name
|
34
|
+
name 'Registration'
|
35
35
|
description <<-DESC
|
36
36
|
This plugin adds register and unregister functionality to Vagrant Guests that
|
37
37
|
support the capability
|
@@ -64,7 +64,7 @@ module VagrantPlugins
|
|
64
64
|
# Some constants, such as "true" resolve to booleans, so the
|
65
65
|
# above error checking doesn't catch it. This will check to make
|
66
66
|
# sure that the log level is an integer, as Log4r requires.
|
67
|
-
level = nil
|
67
|
+
level = nil unless level.is_a?(Integer)
|
68
68
|
# Set the logging level on all "vagrant" namespaced
|
69
69
|
# logs as long as we have a valid level.
|
70
70
|
if level
|
@@ -1,6 +1,9 @@
|
|
1
1
|
module VagrantPlugins
|
2
2
|
module GuestRedHat
|
3
3
|
module Cap
|
4
|
+
# Common configuration options for all managers
|
5
|
+
DEFAULT_CONFIGURATION_OPTIONS = [:skip, :unregister_on_halt]
|
6
|
+
|
4
7
|
# This provides registration capabilities for vagrant-registration
|
5
8
|
#
|
6
9
|
# As we might support more registration options (managers), this
|
@@ -18,10 +21,10 @@ module VagrantPlugins
|
|
18
21
|
end
|
19
22
|
|
20
23
|
# Register the given machine
|
21
|
-
def self.registration_register(machine)
|
24
|
+
def self.registration_register(machine, ui)
|
22
25
|
cap = "#{self.registration_manager(machine).to_s}_register".to_sym
|
23
26
|
if machine.guest.capability?(cap)
|
24
|
-
machine.guest.capability(cap,
|
27
|
+
machine.guest.capability(cap, ui)
|
25
28
|
else
|
26
29
|
false
|
27
30
|
end
|
@@ -62,6 +65,17 @@ module VagrantPlugins
|
|
62
65
|
end
|
63
66
|
end
|
64
67
|
|
68
|
+
# Return all available options for a given registration manager together
|
69
|
+
# with general options available to any.
|
70
|
+
def self.registration_options(machine)
|
71
|
+
cap = "#{self.registration_manager(machine).to_s}_options".to_sym
|
72
|
+
if machine.guest.capability?(cap)
|
73
|
+
DEFAULT_CONFIGURATION_OPTIONS + machine.guest.capability(cap)
|
74
|
+
else
|
75
|
+
DEFAULT_CONFIGURATION_OPTIONS
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
65
79
|
# Return secret options for the registration manager
|
66
80
|
def self.registration_secrets(machine)
|
67
81
|
cap = "#{self.registration_manager(machine).to_s}_secrets".to_sym
|
@@ -15,11 +15,28 @@ module VagrantPlugins
|
|
15
15
|
end
|
16
16
|
|
17
17
|
# Register the machine using 'register' option, config is (Open)Struct
|
18
|
-
def self.subscription_manager_register(machine,
|
19
|
-
|
18
|
+
def self.subscription_manager_register(machine, ui)
|
19
|
+
subscription_manager_upload_certificate(machine, ui) if machine.config.registration.ca_cert
|
20
|
+
command = "subscription-manager register #{configuration_to_options(machine.config.registration)}"
|
20
21
|
machine.communicate.execute("cmd=$(#{command}); if [ \"$?\" != \"0\" ]; then echo $cmd | grep 'This system is already registered' || (echo $cmd 1>&2 && exit 1) ; fi", sudo: true)
|
21
22
|
end
|
22
23
|
|
24
|
+
# Upload provided CA cert to the standard /etc/rhsm/ca path on the guest
|
25
|
+
#
|
26
|
+
# Since subscription-manager recognizes only .pem files, we rename those
|
27
|
+
# files not ending with '.pem' extension.
|
28
|
+
def self.subscription_manager_upload_certificate(machine, ui)
|
29
|
+
ui.info("Uploading CA certificate from #{machine.config.registration.ca_cert}...")
|
30
|
+
if File.exist?(machine.config.registration.ca_cert)
|
31
|
+
cert_file_content = File.read(machine.config.registration.ca_cert)
|
32
|
+
cert_file_name = File.basename(machine.config.registration.ca_cert)
|
33
|
+
cert_file_name = "#{cert_file_name}.pem" unless cert_file_name.end_with? '.pem'
|
34
|
+
machine.communicate.execute("echo '#{cert_file_content}' > /etc/rhsm/ca/#{cert_file_name}", sudo: true)
|
35
|
+
else
|
36
|
+
ui.warn("WARNING: Provided CA certificate file #{machine.config.registration.ca_cert} does not exist, skipping")
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
23
40
|
# Unregister the machine using 'unregister' option
|
24
41
|
def self.subscription_manager_unregister(machine)
|
25
42
|
machine.communicate.execute("subscription-manager unregister || :", sudo: true)
|
@@ -30,6 +47,16 @@ module VagrantPlugins
|
|
30
47
|
[[:username, :password], [:org, :activationkey]]
|
31
48
|
end
|
32
49
|
|
50
|
+
# Return all available options for subscription-manager
|
51
|
+
#
|
52
|
+
# ca_cert is not part of 'register' command API, but it's needed
|
53
|
+
# in conjuntion with serverurl option.
|
54
|
+
def self.subscription_manager_options(machine)
|
55
|
+
[:username, :password, :serverurl, :baseurl, :org, :environment,
|
56
|
+
:name, :auto_attach, :activationkey, :servicelevel, :release,
|
57
|
+
:force, :type, :ca_cert]
|
58
|
+
end
|
59
|
+
|
33
60
|
# Return secret options for subscription-manager
|
34
61
|
def self.subscription_manager_secrets(machine)
|
35
62
|
[:password]
|
@@ -1,70 +1,85 @@
|
|
1
|
-
require
|
1
|
+
require 'vagrant'
|
2
2
|
|
3
3
|
module VagrantPlugins
|
4
4
|
module GuestRedHat
|
5
|
-
class Plugin < Vagrant.plugin(
|
6
|
-
guest_capability(
|
7
|
-
require_relative
|
5
|
+
class Plugin < Vagrant.plugin('2')
|
6
|
+
guest_capability('redhat', 'registration_registered?') do
|
7
|
+
require_relative 'cap/registration'
|
8
8
|
Cap::Registration
|
9
9
|
end
|
10
10
|
|
11
|
-
guest_capability(
|
12
|
-
require_relative
|
11
|
+
guest_capability('redhat', 'registration_register') do
|
12
|
+
require_relative 'cap/registration'
|
13
13
|
Cap::Registration
|
14
14
|
end
|
15
15
|
|
16
|
-
guest_capability(
|
17
|
-
require_relative
|
16
|
+
guest_capability('redhat', 'registration_unregister') do
|
17
|
+
require_relative 'cap/registration'
|
18
18
|
Cap::Registration
|
19
19
|
end
|
20
20
|
|
21
|
-
guest_capability(
|
22
|
-
require_relative
|
21
|
+
guest_capability('redhat', 'registration_manager_installed') do
|
22
|
+
require_relative 'cap/registration'
|
23
23
|
Cap::Registration
|
24
24
|
end
|
25
25
|
|
26
|
-
guest_capability(
|
27
|
-
require_relative
|
26
|
+
guest_capability('redhat', 'registration_credentials') do
|
27
|
+
require_relative 'cap/registration'
|
28
28
|
Cap::Registration
|
29
29
|
end
|
30
30
|
|
31
|
-
guest_capability(
|
32
|
-
require_relative
|
31
|
+
guest_capability('redhat', 'registration_options') do
|
32
|
+
require_relative 'cap/registration'
|
33
33
|
Cap::Registration
|
34
34
|
end
|
35
35
|
|
36
|
-
guest_capability(
|
37
|
-
require_relative
|
36
|
+
guest_capability('redhat', 'registration_secrets') do
|
37
|
+
require_relative 'cap/registration'
|
38
38
|
Cap::Registration
|
39
39
|
end
|
40
40
|
|
41
|
-
guest_capability(
|
42
|
-
require_relative
|
41
|
+
guest_capability('redhat', 'registration_manager') do
|
42
|
+
require_relative 'cap/registration'
|
43
|
+
Cap::Registration
|
44
|
+
end
|
45
|
+
|
46
|
+
guest_capability('redhat', 'subscription_manager') do
|
47
|
+
require_relative 'cap/subscription_manager'
|
43
48
|
Cap::SubscriptionManager
|
44
49
|
end
|
45
50
|
|
46
|
-
guest_capability(
|
47
|
-
require_relative
|
51
|
+
guest_capability('redhat', 'subscription_manager_registered?') do
|
52
|
+
require_relative 'cap/subscription_manager'
|
48
53
|
Cap::SubscriptionManager
|
49
54
|
end
|
50
55
|
|
51
|
-
guest_capability(
|
52
|
-
require_relative
|
56
|
+
guest_capability('redhat', 'subscription_manager_register') do
|
57
|
+
require_relative 'cap/subscription_manager'
|
53
58
|
Cap::SubscriptionManager
|
54
59
|
end
|
55
60
|
|
56
|
-
guest_capability(
|
61
|
+
guest_capability('redhat', 'subscription_manager_upload_certificate') do
|
57
62
|
require_relative "cap/subscription_manager"
|
58
63
|
Cap::SubscriptionManager
|
59
64
|
end
|
60
65
|
|
61
|
-
guest_capability(
|
62
|
-
require_relative
|
66
|
+
guest_capability('redhat', 'subscription_manager_unregister') do
|
67
|
+
require_relative 'cap/subscription_manager'
|
63
68
|
Cap::SubscriptionManager
|
64
69
|
end
|
65
70
|
|
66
|
-
guest_capability(
|
67
|
-
require_relative
|
71
|
+
guest_capability('redhat', 'subscription_manager_credentials') do
|
72
|
+
require_relative 'cap/subscription_manager'
|
73
|
+
Cap::SubscriptionManager
|
74
|
+
end
|
75
|
+
|
76
|
+
guest_capability('redhat', 'subscription_manager_options') do
|
77
|
+
require_relative 'cap/subscription_manager'
|
78
|
+
Cap::SubscriptionManager
|
79
|
+
end
|
80
|
+
|
81
|
+
guest_capability('redhat', 'subscription_manager_secrets') do
|
82
|
+
require_relative 'cap/subscription_manager'
|
68
83
|
Cap::SubscriptionManager
|
69
84
|
end
|
70
85
|
end
|
@@ -1,29 +1,28 @@
|
|
1
|
-
|
2
|
-
require
|
1
|
+
$LOAD_PATH.unshift File.expand_path('../lib', __FILE__)
|
2
|
+
require 'vagrant-registration/version'
|
3
3
|
|
4
4
|
Gem::Specification.new do |s|
|
5
|
-
s.name =
|
5
|
+
s.name = 'vagrant-registration'
|
6
6
|
s.version = VagrantPlugins::Registration::VERSION
|
7
7
|
s.platform = Gem::Platform::RUBY
|
8
|
-
s.license =
|
9
|
-
s.authors = [
|
10
|
-
s.email = [
|
11
|
-
s.summary =
|
12
|
-
s.description =
|
13
|
-
s.homepage =
|
14
|
-
s.required_rubygems_version =
|
8
|
+
s.license = 'GPL-2.0'
|
9
|
+
s.authors = ['Langdon White', 'Josef Strzibny', 'et al']
|
10
|
+
s.email = ['langdon@fedoraproject.org', 'strzibny@strzibny.name']
|
11
|
+
s.summary = 'Automatic guest registration for Vagrant'
|
12
|
+
s.description = 'Enables guests to be registered automatically which is especially useful for RHEL or SLES guests.'
|
13
|
+
s.homepage = 'https://github.com/projectatomic/adb-vagrant-registration'
|
14
|
+
s.required_rubygems_version = '>= 1.3.6'
|
15
15
|
|
16
16
|
# Note that the entire gitignore(5) syntax is not supported, specifically
|
17
|
-
# the
|
17
|
+
# the '!' syntax, but it should mostly work correctly.
|
18
18
|
root_path = File.dirname(__FILE__)
|
19
19
|
all_files = Dir.chdir(root_path) {
|
20
|
-
Dir.glob(
|
21
|
-
Dir.glob(
|
22
|
-
Dir.glob("tests/**/{*,.*}") +
|
20
|
+
Dir.glob('lib/**/{*,.*}') +
|
21
|
+
Dir.glob('plugins/**/{*,.*}') +
|
23
22
|
['Rakefile', 'Gemfile', 'README.md', 'CHANGELOG.md', 'LICENSE.md', 'vagrant-registration.gemspec']
|
24
23
|
}
|
25
|
-
all_files.reject! { |file| [
|
26
|
-
gitignore_path = File.join(root_path,
|
24
|
+
all_files.reject! { |file| ['.', '..'].include?(File.basename(file)) }
|
25
|
+
gitignore_path = File.join(root_path, '.gitignore')
|
27
26
|
gitignore = File.readlines(gitignore_path)
|
28
27
|
gitignore.map! { |line| line.chomp.strip }
|
29
28
|
gitignore.reject! { |line| line.empty? || line =~ /^(#|!)/ }
|
@@ -42,7 +41,7 @@ Gem::Specification.new do |s|
|
|
42
41
|
#
|
43
42
|
gitignore.any? do |ignore|
|
44
43
|
File.fnmatch(ignore, file, File::FNM_PATHNAME) ||
|
45
|
-
|
44
|
+
File.fnmatch(ignore, File.basename(file), File::FNM_PATHNAME)
|
46
45
|
end
|
47
46
|
end
|
48
47
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: vagrant-registration
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Langdon White
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2015-
|
13
|
+
date: 2015-11-10 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: yard
|
@@ -51,10 +51,6 @@ files:
|
|
51
51
|
- plugins/guests/redhat/cap/registration.rb
|
52
52
|
- plugins/guests/redhat/cap/subscription_manager.rb
|
53
53
|
- plugins/guests/redhat/plugin.rb
|
54
|
-
- tests/helpers.sh
|
55
|
-
- tests/run.sh
|
56
|
-
- tests/vagrantfiles/Vagrantfile.rhel_multi_machine
|
57
|
-
- tests/vagrantfiles/Vagrantfile.rhel_wrong_credentials
|
58
54
|
- vagrant-registration.gemspec
|
59
55
|
homepage: https://github.com/projectatomic/adb-vagrant-registration
|
60
56
|
licenses:
|
data/tests/helpers.sh
DELETED
@@ -1,128 +0,0 @@
|
|
1
|
-
# Set up test environment
|
2
|
-
function setup_tests() {
|
3
|
-
check_credentials
|
4
|
-
install_dependencies
|
5
|
-
|
6
|
-
# Test results that should be printed at the end
|
7
|
-
TEST_RESULTS=''
|
8
|
-
FAILED=0
|
9
|
-
SUCCEDED=0
|
10
|
-
EXIT_CODE=0
|
11
|
-
}
|
12
|
-
|
13
|
-
# Print test results
|
14
|
-
function print_results() {
|
15
|
-
if [ "$TEST_RESULTS" != "" ]; then
|
16
|
-
printf "\n$TEST_RESULTS\n"
|
17
|
-
fi
|
18
|
-
printf "\n$SUCCEDED succeded, $FAILED failed.\n"
|
19
|
-
exit $EXIT_CODE
|
20
|
-
}
|
21
|
-
|
22
|
-
# Clean up before each test
|
23
|
-
function clean_up() {
|
24
|
-
# Clean up Vagrant metadata
|
25
|
-
rm -rf $DIR/.vagrant
|
26
|
-
}
|
27
|
-
|
28
|
-
# Check that we have credentials to run the test suite
|
29
|
-
function check_credentials() {
|
30
|
-
if [ "$VAGRANT_REGISTRATION_USERNAME" = "" ] || [ "$VAGRANT_REGISTRATION_PASSWORD" = "" ]; then
|
31
|
-
echo "VAGRANT_REGISTRATION_USERNAME and VAGRANT_REGISTRATION_PASSWORD needs to be provided."
|
32
|
-
exit 1
|
33
|
-
fi
|
34
|
-
if [ "$VAGRANT_REGISTRATION_ORG" = "" ] || [ "$VAGRANT_REGISTRATION_ACTIVATIONKEY" = "" ]; then
|
35
|
-
echo "VAGRANT_REGISTRATION_ORG and VAGRANT_REGISTRATION_ACTIVATIONKEY needs to be provided."
|
36
|
-
exit 1
|
37
|
-
fi
|
38
|
-
}
|
39
|
-
|
40
|
-
# Install vagrant and vagrant-registration
|
41
|
-
function install_dependencies() {
|
42
|
-
# Install Vagrant if it's not present
|
43
|
-
PLUGIN_INSTALLED=$(vagrant --help)
|
44
|
-
if [ $? -ne 0 ]; then
|
45
|
-
sudo yum install vagrant-libvirt -y
|
46
|
-
fi
|
47
|
-
|
48
|
-
# Uninstall vagrant-registration if installed
|
49
|
-
# TODO: Uninstall RPM package if needed
|
50
|
-
PLUGIN_INSTALLED=$(vagrant plugin list | grep vagrant-registration)
|
51
|
-
if [ -z "$PLUGIN_INSTALLED" ]; then
|
52
|
-
vagrant plugin uninstall vagrant-registration
|
53
|
-
fi
|
54
|
-
|
55
|
-
# Install vagrant-registration from current sources
|
56
|
-
rm -rf pkg
|
57
|
-
rake build
|
58
|
-
vagrant plugin install pkg/vagrant-registration*.gem
|
59
|
-
}
|
60
|
-
|
61
|
-
# Test that command succeded
|
62
|
-
#
|
63
|
-
# Usage:
|
64
|
-
#
|
65
|
-
# test_success TEST_NAME COMMAND_TO_RUN
|
66
|
-
#
|
67
|
-
# Example:
|
68
|
-
#
|
69
|
-
# test_success "ls won't fail" "ls -all"
|
70
|
-
function test_success() {
|
71
|
-
eval $2 >&1 >/dev/null
|
72
|
-
if [ $? -ne 0 ]; then
|
73
|
-
printf "F"
|
74
|
-
FAILED=$((FAILED + 1))
|
75
|
-
EXIT_CODE=1
|
76
|
-
TEST_RESULTS="$TEST_RESULTS\nTest '$1' failed with command:"
|
77
|
-
TEST_RESULTS="$TEST_RESULTS\n $2"
|
78
|
-
else
|
79
|
-
SUCCEDED=$((SUCCEDED + 1))
|
80
|
-
printf '.'
|
81
|
-
fi
|
82
|
-
}
|
83
|
-
|
84
|
-
# Test that command failed
|
85
|
-
#
|
86
|
-
# Usage:
|
87
|
-
#
|
88
|
-
# test_failure TEST_NAME COMMAND_TO_RUN
|
89
|
-
#
|
90
|
-
# Example:
|
91
|
-
#
|
92
|
-
# test_failure "this should fail" "echoo"
|
93
|
-
function test_failure() {
|
94
|
-
eval $2 >&1 >/dev/null
|
95
|
-
if [ $? -ne 0 ]; then
|
96
|
-
SUCCEDED=$((SUCCEDED + 1))
|
97
|
-
printf '.'
|
98
|
-
else
|
99
|
-
printf "F"
|
100
|
-
FAILED=$((FAILED + 1))
|
101
|
-
EXIT_CODE=1
|
102
|
-
TEST_RESULTS="$TEST_RESULTS\nTest '$1' dit not fail with command:"
|
103
|
-
TEST_RESULTS="$TEST_RESULTS\n $2"
|
104
|
-
fi
|
105
|
-
}
|
106
|
-
|
107
|
-
# Test that command produced an expected output
|
108
|
-
#
|
109
|
-
# Usage:
|
110
|
-
#
|
111
|
-
# test_output TEST_NAME COMMAND_TO_RUN EXPECTED_OUTPUT
|
112
|
-
#
|
113
|
-
# Example:
|
114
|
-
#
|
115
|
-
# test_output "echo abc outputs abc" "echo 'abc'" "abc"
|
116
|
-
function test_output() {
|
117
|
-
eval $2 >&1| grep "$3" >/dev/null
|
118
|
-
if [ $? -ne 0 ]; then
|
119
|
-
printf "F"
|
120
|
-
FAILED=$((FAILED + 1))
|
121
|
-
EXIT_CODE=1
|
122
|
-
TEST_RESULTS="$TEST_RESULTS\nTest '$1' failed with command:"
|
123
|
-
TEST_RESULTS="$TEST_RESULTS\n $2 | grep '$3'"
|
124
|
-
else
|
125
|
-
SUCCEDED=$((SUCCEDED + 1))
|
126
|
-
printf '.'
|
127
|
-
fi
|
128
|
-
}
|
data/tests/run.sh
DELETED
@@ -1,59 +0,0 @@
|
|
1
|
-
#!/bin/bash
|
2
|
-
|
3
|
-
# This tests test vagrant-registration plugin running on Fedora
|
4
|
-
# with libvirt. If you do not have Vagrant installed or if you
|
5
|
-
# have vagrant-libvirt package on your system, Vagrant will be
|
6
|
-
# installed or vagrant-libvirt removed respectively. In that case
|
7
|
-
# you need sudo to run the tests. If you do not run Fedora, make
|
8
|
-
# sure you have Vagrant installed (any provider should do if you
|
9
|
-
# add RHEL box called 'rhel-7').
|
10
|
-
#
|
11
|
-
# IMPORTANT: Tests need valid credentials to actually test
|
12
|
-
# registration. This can be provided in form of environment
|
13
|
-
# variables.
|
14
|
-
#
|
15
|
-
# NOTE: This will install a development version of
|
16
|
-
# vagrant-registration on your system.
|
17
|
-
#
|
18
|
-
# == subscription-manager
|
19
|
-
#
|
20
|
-
# For testing subscription-manager on RHEL export
|
21
|
-
# VAGRANT_REGISTRATION_USERNAME with VAGRANT_REGISTRATION_PASSWORD
|
22
|
-
# for username/password registration and VAGRANT_REGISTRATION_ORG
|
23
|
-
# with VAGRANT_REGISTRATION_ACTIVATIONKEY for org/activationkey one.
|
24
|
-
#
|
25
|
-
|
26
|
-
DIR=$(dirname $(readlink -f "$0"))
|
27
|
-
|
28
|
-
# Import test helpers
|
29
|
-
. $DIR/helpers.sh
|
30
|
-
|
31
|
-
setup_tests
|
32
|
-
|
33
|
-
# Test correct username/password and org/activationkey credentials in a multi-machine setup
|
34
|
-
clean_up
|
35
|
-
export VAGRANT_VAGRANTFILE=$DIR/vagrantfiles/Vagrantfile.rhel_multi_machine
|
36
|
-
|
37
|
-
test_success 'vagrant up on RHEL multi_machine setup' 'vagrant up rhel1-valid-credentials'
|
38
|
-
|
39
|
-
test_output 'first machine is registered with given username/password' \
|
40
|
-
'vagrant ssh rhel1-valid-credentials -c '\''sudo subscription-manager register'\''' \
|
41
|
-
'This system is already registered.'
|
42
|
-
|
43
|
-
test_success 'vagrant halt on RHEL multi_machine setup' 'vagrant halt rhel1-valid-credentials'
|
44
|
-
test_success 'vagrant halt on RHEL multi_machine setup' 'vagrant destroy'
|
45
|
-
test_success 'vagrant up on RHEL multi_machine setup' 'vagrant up rhel2-valid-credentials'
|
46
|
-
|
47
|
-
test_output 'second machine is registered with given org/activationkey' \
|
48
|
-
'vagrant ssh rhel2-valid-credentials -c '\''sudo subscription-manager register'\''' \
|
49
|
-
'This system is already registered.'
|
50
|
-
|
51
|
-
test_success 'vagrant halt on RHEL multi_machine setup' 'vagrant destroy'
|
52
|
-
|
53
|
-
# Test wrong credentials
|
54
|
-
clean_up
|
55
|
-
export VAGRANT_VAGRANTFILE=$DIR/vagrantfiles/Vagrantfile.rhel_wrong_credentials
|
56
|
-
test_failure 'vagrant up on RHEL with wrong credentials should fail' 'vagrant up'
|
57
|
-
test_success 'vagrant destroy on RHEL with wrong credentials' 'vagrant destroy'
|
58
|
-
|
59
|
-
print_results
|
@@ -1,19 +0,0 @@
|
|
1
|
-
# Spin 3 RHEL machines that will be registered
|
2
|
-
|
3
|
-
ENV['VAGRANT_DEFAULT_PROVIDER'] ||= 'libvirt'
|
4
|
-
ENV['VAGRANT_REGISTRATION_RHEL_BOX'] ||= 'rhel-7.0'
|
5
|
-
|
6
|
-
Vagrant.configure('2') do |config|
|
7
|
-
config.vm.box = ENV['VAGRANT_REGISTRATION_RHEL_BOX']
|
8
|
-
|
9
|
-
config.vm.define "rhel1-valid-credentials" do |c|
|
10
|
-
c.registration.username = ENV['VAGRANT_REGISTRATION_USERNAME']
|
11
|
-
c.registration.password = ENV['VAGRANT_REGISTRATION_PASSWORD']
|
12
|
-
end
|
13
|
-
|
14
|
-
config.vm.define "rhel2-valid-credentials" do |c|
|
15
|
-
c.registration.org = ENV['VAGRANT_REGISTRATION_ORG']
|
16
|
-
c.registration.activationkey = ENV['VAGRANT_REGISTRATION_ACTIVATIONKEY']
|
17
|
-
end
|
18
|
-
|
19
|
-
end
|
@@ -1,14 +0,0 @@
|
|
1
|
-
# Spin 1 RHEL machine with wrong credentials
|
2
|
-
|
3
|
-
ENV['VAGRANT_DEFAULT_PROVIDER'] ||= 'libvirt'
|
4
|
-
ENV['VAGRANT_REGISTRATION_RHEL_BOX'] ||= 'rhel-7.0'
|
5
|
-
|
6
|
-
Vagrant.configure('2') do |config|
|
7
|
-
config.vm.box = ENV['VAGRANT_REGISTRATION_RHEL_BOX']
|
8
|
-
|
9
|
-
config.vm.define "rhel1-wrong-credentials" do |c|
|
10
|
-
c.registration.username = 'wrong_username'
|
11
|
-
c.registration.password = 'wrong_password'
|
12
|
-
end
|
13
|
-
|
14
|
-
end
|