Skip to content

Commit 35ed172

Browse files
committed
Adds ability to configure ODL user/pass
Signed-off-by: Tim Rozet <[email protected]>
1 parent 72146d9 commit 35ed172

File tree

12 files changed

+230
-0
lines changed

12 files changed

+230
-0
lines changed

README.markdown

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -382,6 +382,22 @@ Default: `'-Djava.net.preferIPv4Stack=true'`
382382

383383
Valid options: A string of valid Java options.
384384

385+
##### `username`
386+
387+
Specifies the username to set for admin role in ODL.
388+
389+
Default: `'admin'`
390+
391+
Valid options: A username string.
392+
393+
##### `password`
394+
395+
Specifies the password to set for admin role in ODL.
396+
397+
Default: `'admin'`
398+
399+
Valid options: A password string.
400+
385401
## Limitations
386402

387403
- Tested on Fedora 22, 23, CentOS 7 and Ubuntu 16.04.
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
Puppet::Type.type(:odl_user).provide(:idm) do
2+
3+
commands :java => 'java'
4+
5+
def odl_path
6+
'/opt/opendaylight'
7+
end
8+
9+
def idm_cmd(*args)
10+
java('-jar', "#{odl_path}/bin/aaa-cli-jar-0.5.0-SNAPSHOT.jar", '--dbd', odl_path, *args)
11+
end
12+
13+
def create
14+
idm_cmd('--newUser', @resource[:username], '-p', @resource[:password])
15+
end
16+
17+
def destroy
18+
idm_cmd('--deleteUser', @resource[:username])
19+
end
20+
21+
def exists?
22+
output = idm_cmd('-l').split("\n")
23+
output.each do |line|
24+
if line.eql? @resource[:username]
25+
return true
26+
end
27+
end
28+
return false
29+
end
30+
31+
def password
32+
return false
33+
end
34+
35+
def password=(password)
36+
destroy
37+
idm_cmd('--newUser', @resource[:username], '-p', password)
38+
end
39+
40+
end

lib/puppet/type/odl_user.rb

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
Puppet::Type.newtype(:odl_user) do
2+
3+
ensurable
4+
5+
newparam(:username, :namevar => true) do
6+
desc "Username to configure in ODL IDM with admin role"
7+
newvalues(/^\w+$/)
8+
end
9+
10+
newproperty(:password) do
11+
desc "Password for this user"
12+
validate do |value|
13+
if !value.is_a?(String)
14+
raise ArgumentError, "Passwords must be a string"
15+
end
16+
end
17+
18+
def change_to_s(current, desire)
19+
"Password changed"
20+
end
21+
end
22+
23+
end

manifests/config.pp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,4 +108,10 @@
108108
match => '^routing-node=.*$',
109109
}
110110
}
111+
112+
# Configure username/password
113+
odl_user { $::opendaylight::username:
114+
password => $::opendaylight::password,
115+
before => Service['opendaylight'],
116+
}
111117
}

manifests/init.pp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@
5353
$vpp_routing_node = $::opendaylight::params::vpp_routing_node,
5454
$java_opts = $::opendaylight::params::java_opts,
5555
$manage_repositories = $::opendaylight::params::manage_repositories,
56+
$username = $::opendaylight::params::username,
57+
$password = $::opendaylight::params::password,
5658
) inherits ::opendaylight::params {
5759

5860
# Validate OS family

manifests/params.pp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,6 @@
2222
$vpp_routing_node = ''
2323
$java_opts = '-Djava.net.preferIPv4Stack=true'
2424
$manage_repositories = true
25+
$username = 'admin'
26+
$password = 'admin'
2527
}

spec/acceptance/class_spec.rb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,4 +122,16 @@
122122
log_level_validations(log_levels: custom_log_levels)
123123
end
124124
end
125+
126+
describe 'testing odl username/password' do
127+
context 'using default username/password' do
128+
context 'using default log levels' do
129+
# Call specialized helper fn to install OpenDaylight
130+
install_odl
131+
132+
# Call specialized helper fn for username/password validations
133+
username_password_validations
134+
end
135+
end
136+
end
125137
end

spec/classes/opendaylight_spec.rb

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -734,4 +734,52 @@
734734
end
735735
end
736736

737+
# ODL username/password tests
738+
describe 'ODL username/password tests' do
739+
# Non-OS-type tests assume CentOS 7
740+
# See issue #43 for reasoning:
741+
# https://github.com/dfarrell07/puppet-opendaylight/issues/43#issue-57343159
742+
osfamily = 'RedHat'
743+
operatingsystem = 'CentOS'
744+
operatingsystemmajrelease = '7'
745+
context 'using default username/password' do
746+
let(:facts) {{
747+
:osfamily => osfamily,
748+
:operatingsystem => operatingsystem,
749+
:operatingsystemmajrelease => operatingsystemmajrelease,
750+
}}
751+
752+
let(:params) {{ }}
753+
754+
# Run shared tests applicable to all supported OSs
755+
# Note that this function is defined in spec_helper
756+
generic_tests
757+
758+
# Run test that specialize in checking username/password config
759+
# Note that this function is defined in spec_helper
760+
username_password_tests('admin','admin')
761+
end
762+
763+
context 'specifying non-default username/password' do
764+
let(:facts) {{
765+
:osfamily => osfamily,
766+
:operatingsystem => operatingsystem,
767+
:operatingsystemmajrelease => operatingsystemmajrelease,
768+
}}
769+
770+
let(:params) {{
771+
:username => 'test',
772+
:password => 'test'
773+
}}
774+
775+
# Run shared tests applicable to all supported OSs
776+
# Note that this function is defined in spec_helper
777+
generic_tests
778+
779+
# Run test that specialize in checking routing-node config
780+
# Note that this function is defined in spec_helper
781+
username_password_tests('test', 'test')
782+
end
783+
end
784+
737785
end

spec/spec_helper.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -361,3 +361,13 @@ def vpp_routing_node_tests(options = {})
361361
}
362362
end
363363
end
364+
365+
# ODL username/password tests
366+
def username_password_tests(username, password)
367+
368+
it {
369+
should contain_odl_user(username).with(
370+
:password => password
371+
)
372+
}
373+
end

spec/spec_helper_acceptance.rb

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,8 @@ def install_odl(options = {})
7171
enable_ha = options.fetch(:enable_ha, false)
7272
ha_node_ips = options.fetch(:ha_node_ips, [])
7373
ha_node_index = options.fetch(:ha_node_index, 0)
74+
username = options.fetch(:username, 'admin')
75+
password = options.fetch(:password, 'admin')
7476

7577
# Build script for consumption by Puppet apply
7678
it 'should work idempotently with no errors' do
@@ -85,6 +87,8 @@ class { 'opendaylight':
8587
ha_node_ips=> #{ha_node_ips},
8688
ha_node_index=> #{ha_node_index},
8789
log_levels=> #{log_levels},
90+
username=> #{username},
91+
password=> #{password},
8892
}
8993
EOS
9094

@@ -330,3 +334,21 @@ def deb_validations()
330334
it { should be_installed }
331335
end
332336
end
337+
338+
# Shared function for validations related to username/password
339+
def username_password_validations(options = {})
340+
# NB: This param default should match the one used by the opendaylight
341+
# class, which is defined in opendaylight::params
342+
# TODO: Remove this possible source of bugs^^
343+
odl_username = options.fetch(:username, 'admin')
344+
odl_password = options.fetch(:password, 'admin')
345+
odl_check_url = 'http://127.0.0.1:8080/restconf'
346+
347+
describe file('/opt/opendaylight/idmlight.db.mv.db') do
348+
it { should be_file }
349+
end
350+
351+
describe command("curl -o /dev/null --fail --silent --head -u #{odl_username}:#{odl_password} #{odl_check_url}") do
352+
its(:exit_status) { should eq 0 }
353+
end
354+
end

0 commit comments

Comments
 (0)