-
Notifications
You must be signed in to change notification settings - Fork 33
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
[ZTP] Improvements to allow in-band zero touch provisioning #39
base: master
Are you sure you want to change the base?
Changes from all commits
99a9e9c
36327a7
e728870
01d1777
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -191,6 +191,7 @@ def test_ztp_dynamic_url_invalid_arg_type(self, tmpdir): | |
"source": "/tmp/test_firmware_%s.json" | ||
} | ||
}, | ||
"pre-ztp-plugin-download": true, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since default for pre-ztp-plugin-download is defined as true I believe this need not be updated on all the test cases. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The way test cases are written, default setting also needs to be set. |
||
"reboot-on-failure": false, | ||
"reboot-on-success": false, | ||
"status": "BOOT", | ||
|
@@ -199,6 +200,7 @@ def test_ztp_dynamic_url_invalid_arg_type(self, tmpdir): | |
"config-fallback": false, | ||
"halt-on-failure": false, | ||
"ignore-result": false, | ||
"pre-ztp-plugin-download": true, | ||
"reboot-on-failure": false, | ||
"reboot-on-success": false, | ||
"restart-ztp-no-config": true, | ||
|
@@ -305,6 +307,7 @@ def test_ztp_non_existent_plugin_section_name(self, tmpdir): | |
"source": "http://localhost:2000/ztp/scripts/post_install.sh" | ||
} | ||
}, | ||
"pre-ztp-plugin-download": true, | ||
"reboot-on-failure": false, | ||
"reboot-on-success": false, | ||
"status": "BOOT", | ||
|
@@ -313,6 +316,7 @@ def test_ztp_non_existent_plugin_section_name(self, tmpdir): | |
"config-fallback": false, | ||
"halt-on-failure": false, | ||
"ignore-result": false, | ||
"pre-ztp-plugin-download": true, | ||
"reboot-on-failure": false, | ||
"reboot-on-success": false, | ||
"restart-ztp-no-config": true, | ||
|
@@ -459,6 +463,7 @@ def test_ztp_url_reusing_plugin(self, tmpdir): | |
"source": "file:///tmp/test_firmware.sh" | ||
} | ||
}, | ||
"pre-ztp-plugin-download": true, | ||
"reboot-on-failure": false, | ||
"reboot-on-success": false, | ||
"status": "BOOT", | ||
|
@@ -467,6 +472,7 @@ def test_ztp_url_reusing_plugin(self, tmpdir): | |
"config-fallback": false, | ||
"halt-on-failure": false, | ||
"ignore-result": false, | ||
"pre-ztp-plugin-download": true, | ||
"reboot-on-failure": false, | ||
"reboot-on-success": false, | ||
"restart-ztp-no-config": true, | ||
|
@@ -526,13 +532,15 @@ def test_ztp_url_reusing_plugin_2(self, tmpdir): | |
"destination": "/tmp/firmware_check.sh" | ||
} | ||
}, | ||
"pre-ztp-plugin-download": true, | ||
"reboot-on-failure": false, | ||
"reboot-on-success": false, | ||
"status": "BOOT", | ||
"timestamp": "2019-04-18 19:49:49" | ||
}, | ||
"halt-on-failure": false, | ||
"ignore-result": false, | ||
"pre-ztp-plugin-download": true, | ||
"reboot-on-failure": false, | ||
"reboot-on-success": false, | ||
"status": "BOOT", | ||
|
@@ -682,13 +690,15 @@ def test_ztp_url_could_not_interpreted(self, tmpdir): | |
"source": "http://localhost:2000/ztp/scripts/post_install.sh" | ||
} | ||
}, | ||
"pre-ztp-plugin-download": true, | ||
"reboot-on-failure": false, | ||
"reboot-on-success": false, | ||
"status": "BOOT", | ||
"timestamp": "2019-04-18 19:49:49" | ||
}, | ||
"halt-on-failure": false, | ||
"ignore-result": false, | ||
"pre-ztp-plugin-download": true, | ||
"reboot-on-failure": false, | ||
"reboot-on-success": false, | ||
"status": None, | ||
|
@@ -765,13 +775,15 @@ def test_ztp_return_another_invalid_url_section(self, tmpdir): | |
"source": "http://localhost:2000/ztp/scripts/post_install.sh" | ||
} | ||
}, | ||
"pre-ztp-plugin-download": true, | ||
"reboot-on-failure": false, | ||
"reboot-on-success": false, | ||
"status": "BOOT", | ||
"timestamp": "2019-04-18 19:49:49" | ||
}, | ||
"halt-on-failure": false, | ||
"ignore-result": false, | ||
"pre-ztp-plugin-download": true, | ||
"reboot-on-failure": false, | ||
"reboot-on-success": false, | ||
"status": None, | ||
|
@@ -813,13 +825,15 @@ def test_ztp_dynamic_url_download(self, tmpdir): | |
} | ||
} | ||
}, | ||
"pre-ztp-plugin-download": true, | ||
"reboot-on-failure": false, | ||
"reboot-on-success": false, | ||
"status": "BOOT", | ||
"timestamp": "2019-04-18 19:49:49" | ||
}, | ||
"halt-on-failure": false, | ||
"ignore-result": false, | ||
"pre-ztp-plugin-download": true, | ||
"reboot-on-failure": false, | ||
"reboot-on-success": false, | ||
"status": "BOOT", | ||
|
@@ -874,13 +888,15 @@ def test_ztp_dynamic_url_download_2(self, tmpdir): | |
} | ||
} | ||
}, | ||
"pre-ztp-plugin-download": true, | ||
"reboot-on-failure": false, | ||
"reboot-on-success": false, | ||
"status": "BOOT", | ||
"timestamp": "2019-04-18 19:49:49" | ||
}, | ||
"halt-on-failure": false, | ||
"ignore-result": false, | ||
"pre-ztp-plugin-download": true, | ||
"reboot-on-failure": false, | ||
"reboot-on-success": false, | ||
"status": "BOOT", | ||
|
@@ -927,6 +943,7 @@ def test_ztp_graphservice_do_not_exist(self, tmpdir): | |
"halt-on-failure": false, | ||
"ignore-result": false, | ||
"plugin": "graphservice", | ||
"pre-ztp-plugin-download": true, | ||
"reboot-on-failure": false, | ||
"reboot-on-success": false, | ||
"status": "BOOT", | ||
|
@@ -935,6 +952,7 @@ def test_ztp_graphservice_do_not_exist(self, tmpdir): | |
"config-fallback": false, | ||
"halt-on-failure": false, | ||
"ignore-result": false, | ||
"pre-ztp-plugin-download": true, | ||
"reboot-on-failure": false, | ||
"reboot-on-success": false, | ||
"restart-ztp-no-config": true, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -448,6 +448,93 @@ def test_ztp_json_ignore_fail(self): | |
self.cfgSet('monitor-startup-config', True) | ||
self.cfgSet('restart-ztp-no-config', True) | ||
|
||
def test_ztp_json_invalid_plugins(self): | ||
'''! | ||
Simple ZTP test with 3-sections, invalid plugin in the second section, ZTP Failed | ||
''' | ||
content = """{ | ||
"ztp": { | ||
"0001-test-plugin": { | ||
"message" : "0001-test-plugin", | ||
"message-file" : "/etc/ztp.results" | ||
}, | ||
"0002-invalid-plugin": { | ||
"pre-ztp-plugin-download" : false | ||
}, | ||
"0003-test-plugin": { | ||
"pre-ztp-plugin-download" : false, | ||
"message" : "0003-test-plugin", | ||
"message-file" : "/etc/ztp.results" | ||
} | ||
} | ||
}""" | ||
expected_result = """0001-test-plugin | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we add another case with ignore_result=true for section 0002? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added a new test case test_ztp_json_invalid_plugins_ignore_result. |
||
0003-test-plugin | ||
""" | ||
self.__init_ztp_data() | ||
self.cfgSet('monitor-startup-config', False) | ||
self.cfgSet('restart-ztp-no-config', False) | ||
self.__write_file("/tmp/ztp_input.json", content) | ||
self.__write_file(self.cfgGet("opt67-url"), "file:///tmp/ztp_input.json") | ||
runCommand(COVERAGE + ZTP_ENGINE_CMD) | ||
runCommand(COVERAGE + ZTP_CMD + ' status -v') | ||
os.remove("/tmp/ztp_input.json") | ||
objJson, jsonDict = JsonReader(self.cfgGet('ztp-json'), indent=4) | ||
assert(jsonDict.get('ztp').get('status') == 'FAILED') | ||
assert(jsonDict.get('ztp').get('0001-test-plugin').get('status') == 'SUCCESS') | ||
assert(jsonDict.get('ztp').get('0002-invalid-plugin').get('status') == 'FAILED') | ||
assert(jsonDict.get('ztp').get('0002-invalid-plugin').get('error') == 'Unable to find or download requested plugin') | ||
result = self.__read_file("/etc/ztp.results") | ||
assert(result == expected_result) | ||
self.cfgSet('monitor-startup-config', True) | ||
self.cfgSet('restart-ztp-no-config', True) | ||
|
||
def test_ztp_json_invalid_plugins_ignore_result(self): | ||
'''! | ||
Simple ZTP test with 3-sections, invalid plugin in the second section but result ignored, | ||
ZTP Success | ||
''' | ||
content = """{ | ||
"ztp": { | ||
"0001-test-plugin": { | ||
"message" : "0001-test-plugin", | ||
"message-file" : "/etc/ztp.results" | ||
}, | ||
"0002-invalid-plugin": { | ||
"plugin" : { | ||
"url" : "file:///no-such-plugin" | ||
}, | ||
"pre-ztp-plugin-download" : false, | ||
"ignore-result" : true | ||
}, | ||
"0003-test-plugin": { | ||
"pre-ztp-plugin-download" : false, | ||
"message" : "0003-test-plugin", | ||
"message-file" : "/etc/ztp.results" | ||
} | ||
} | ||
}""" | ||
expected_result = """0001-test-plugin | ||
0003-test-plugin | ||
""" | ||
self.__init_ztp_data() | ||
self.cfgSet('monitor-startup-config', False) | ||
self.cfgSet('restart-ztp-no-config', False) | ||
self.__write_file("/tmp/ztp_input.json", content) | ||
self.__write_file(self.cfgGet("opt67-url"), "file:///tmp/ztp_input.json") | ||
runCommand(COVERAGE + ZTP_ENGINE_CMD) | ||
runCommand(COVERAGE + ZTP_CMD + ' status -v') | ||
os.remove("/tmp/ztp_input.json") | ||
objJson, jsonDict = JsonReader(self.cfgGet('ztp-json'), indent=4) | ||
assert(jsonDict.get('ztp').get('status') == 'SUCCESS') | ||
assert(jsonDict.get('ztp').get('0001-test-plugin').get('status') == 'SUCCESS') | ||
assert(jsonDict.get('ztp').get('0002-invalid-plugin').get('status') == 'FAILED') | ||
assert(jsonDict.get('ztp').get('0002-invalid-plugin').get('error') == 'Unable to find or download requested plugin') | ||
result = self.__read_file("/etc/ztp.results") | ||
assert(result == expected_result) | ||
self.cfgSet('monitor-startup-config', True) | ||
self.cfgSet('restart-ztp-no-config', True) | ||
|
||
def test_ztp_json_ignore_ztp_success(self): | ||
'''! | ||
Simple ZTP test with 3-sections, Failure in 3 sections but ignore-result set in 2sections, ignore-result set in ztp, ZTP Success | ||
|
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.
Typo: user -> used