-
Notifications
You must be signed in to change notification settings - Fork 52
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
(NETDEV-29) Enhance ntp_config and ntp_server #542
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
# ntp_auth_key | ||
--- | ||
key: | ||
multiple: true | ||
default_value: [] | ||
nexus: | ||
get_command: "show running-config all | include 'ntp authentication-key'" | ||
# Returns <key>, <algorithm>, <password>, <mode> | ||
get_value: '/^ntp authentication-key (\d+) (\w+) (\S+) (\d)/' | ||
set_value: '<state> ntp authentication-key <key> <algorithm> <password> <mode>' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
# NTP Authentication key provider class | ||
# | ||
# Rick Sherman et al., April 2017 | ||
# | ||
# Copyright (c) 2014-2017 Cisco and/or its affiliates. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
require_relative 'node' | ||
|
||
module Cisco | ||
# NtpAuthKey - node utility class for NTP authentication-key management | ||
class NtpAuthKey < NodeUtil | ||
attr_reader :algorithm, :mode, :password | ||
|
||
def initialize(opts, instantiate=true) | ||
@algorithm = opts['algorithm'].nil? ? 'md5' : opts['algorithm'] | ||
@key = opts['name'] | ||
@mode = opts['mode'].nil? ? '7' : opts['mode'] | ||
@password = opts['password'] | ||
|
||
create if instantiate | ||
end | ||
|
||
def self.ntpkeys | ||
keys = %w(name algorithm password mode) | ||
hash = {} | ||
ntp_auth_key_list = config_get('ntp_auth_key', 'key') | ||
return hash if ntp_auth_key_list.empty? | ||
|
||
ntp_auth_key_list.each do |id| | ||
hash[id[0]] = NtpAuthKey.new(Hash[keys.zip(id)], false) | ||
end | ||
|
||
hash | ||
end | ||
|
||
def ==(other) | ||
name == other.name | ||
end | ||
|
||
def create | ||
config_set('ntp_auth_key', 'key', state: '', key: @key, | ||
algorithm: @algorithm, password: @password, mode: @mode) | ||
end | ||
|
||
def destroy | ||
# There appears to be a bug in NXOS that requires the password be passed | ||
config_set('ntp_auth_key', 'key', state: 'no', key: @key, | ||
algorithm: @algorithm, password: @password, mode: @mode) | ||
end | ||
|
||
def name | ||
@key | ||
end | ||
end # class | ||
end # module |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
# | ||
# Minitest for NtpAuthKey class | ||
# | ||
# Copyright (c) 2014-2017 Cisco and/or its affiliates. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
require_relative 'ciscotest' | ||
require_relative '../lib/cisco_node_utils/ntp_auth_key' | ||
|
||
# TestNtpAuthKey - Minitest for NtpAuthKey node utility. | ||
class TestNtpAuthKey < CiscoTestCase | ||
def setup | ||
# setup runs at the beginning of each test | ||
super | ||
no_ntpkey | ||
end | ||
|
||
def teardown | ||
# teardown runs at the end of each test | ||
no_ntpkey | ||
super | ||
end | ||
|
||
def no_ntpkey | ||
# Turn the feature off for a clean test. | ||
config('no ntp authentication-key 111 md5 test 7', | ||
'no ntp authentication-key 999 md5 test 7') | ||
end | ||
|
||
# TESTS | ||
|
||
def test_create_defaults | ||
id = '111' | ||
options = { 'name' => id, 'password' => 'test' } | ||
refute_includes(Cisco::NtpAuthKey.ntpkeys, id) | ||
|
||
key = Cisco::NtpAuthKey.new(options, true) | ||
assert_includes(Cisco::NtpAuthKey.ntpkeys, id) | ||
assert_equal(key, Cisco::NtpAuthKey.ntpkeys[id]) | ||
|
||
assert_equal(id, Cisco::NtpAuthKey.ntpkeys[id].name) | ||
assert_equal('md5', Cisco::NtpAuthKey.ntpkeys[id].algorithm) | ||
assert_equal('7', Cisco::NtpAuthKey.ntpkeys[id].mode) | ||
|
||
key.destroy | ||
refute_includes(Cisco::NtpAuthKey.ntpkeys, id) | ||
end | ||
|
||
def test_create_options | ||
id = '999' | ||
options = { 'name' => id, 'password' => 'test', 'algorithm' => 'md5', | ||
'mode' => '7' } | ||
refute_includes(Cisco::NtpAuthKey.ntpkeys, id) | ||
|
||
key = Cisco::NtpAuthKey.new(options, true) | ||
assert_includes(Cisco::NtpAuthKey.ntpkeys, id) | ||
assert_equal(key, Cisco::NtpAuthKey.ntpkeys[id]) | ||
|
||
assert_equal(id, Cisco::NtpAuthKey.ntpkeys[id].name) | ||
assert_equal('md5', Cisco::NtpAuthKey.ntpkeys[id].algorithm) | ||
assert_equal('7', Cisco::NtpAuthKey.ntpkeys[id].mode) | ||
|
||
key.destroy | ||
refute_includes(Cisco::NtpAuthKey.ntpkeys, id) | ||
end | ||
end |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe you may be able to simplify the
destroy
method and only specify the@ntpserver_id
. I did some quick testing and I was able to remove the config without specifying any of the other parameters.config_set('ntp_server', state: 'no', ip: @ntpserver_id)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I get an exception without it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, that's because the other properties need to get passed in as empty string. I suppose this is fine.