Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* WIP: Initial commit bootflash_info.py - Initial work to retrieve bootflash info. dcnm_bootflash.py - initial work on skeleton - Query(): sort of working. playbooks/roles/dcnm_bootflash - base files added tests/integration/targets/dcnm_bootflash/* - base files added module_utils/common/api/v1/... /bootflash/bootflash.py - Initial endpoints done * Renaming the module to dcnm_switch_bootflash The original requested name was dcnm_switch_bootflash, but I was using dcnm_bootflash. Have changed the name in all relevamt places. * Refactor _get() * Rename module to dcnm_bootflash After discussing with Shangxin, renaming the module to dcnm_bootflash. Have changed the name in all relevant places. * Fix NDFC-added leading space in ipAddr 1. bootflash_info.py - build_matches(): strip leading space from ipAddr value in NDFC response. - Update and/or add docstrings throughout. - Add match property to return the current matching switch+file information. - Remove unused @Properties.add_params class decorator. 2. dcnm_bootflash.py - Query(): Rewrite to use self.have. 3. tests/integration/targets/dcnm_bootflash/tests/dcnm_bootflash_query.yaml - Rewrite assertions to avoid jinja2 warnings. - Update some of the REQUIREMENTS section. * Deleted(): Initial work to handle deleted state. * BootflashFiles(): Handle switch migration mode. Add infrastructure to easily determine whether files can be deleted on each switch and raise ValueError with appropriate error message if any files cannot be deleted. I suspect there will be more reasons than Migration mode so add capability to handle additional scenarios in the future. * BootflashFiles(): simplify validate_commit_parameters() * BootflashFiles().commit() update docstring. * IT: integration test for deleted state. This requires that files be manually created on switch-under-test bootflash. e.g. echo foo > foo.txt There's just no good, low-overhead, way to add files to a switch bootflash. dcnm_file_upload + dcnm_image_upgrade is (IMHO) way too slow for an integration test. Better just to get on the switch CLI and use echo... * Remove stray pylint directive. * BootflashFiles(): Appease pylint. * BootflashFiles(): Update class docstring. * BootflashFiles(): Add partition property. 1. Add partition property 2. Fix payload to use partition property (rather than file_path) for "partition" value. * BootflashFiles(): Remove unused attributes. BootflashFiles().__init__() - Remove self.response_dict and self.result_dict. - Alphabetize remaining attributes. * dcnm_bootflash.py: simplify error message handling. * Modify playbook structure based on discussion with team Also implement idempotence for files in root directory of flash devices. Idempotence cannot currently be supported for files in directories since the bootflash-info endpoint does not support listing files within directories. * BootflashInfo(): Call bootflash-discovery 1. EpBootflashDiscovery(): new endpoint class. 2. BootflashInfo(): To ensure we have current bootflash information, send EpBootflashDiscovery request before sending EpBootflashInfo request. 3. BootflashInfo(): Refactor stripping of ipAddr in build_matches() info strip_ipaddr_leading_space() 4. BootflashInfo(): change all occurances of bootflash_type to supervisor (new supervisor property returns associated key bootflash_type). 5. BootflashInfo(): update docstrings. 6. imagemgnt.py: Remove EpBootflashInfo() from this file. It already exists in imagemgnt/bootflash/bootflash.py * BootflashFiles(): bootflash_type -> supervisor 1. BootflashFiles(): Rename all occurances of bootflash_type to supervisor. 2. BootflashFiles(): Run through linters. * dcnm_bootflash.py: update DOCUMENTATION, more 1. Update DOCUMENTATION to note that currently we support only files in a partition's root directory. 2. Update EXAMPLES section to remove subdirectories. 3. Update docstrings throughout. 4. Common(): fix error messages to reference the correct vars. 3. * IT: dcnm_bootflash_deleted.yaml: fix filepath Remove directories from all filepath values since we do not support deleting files in directories. * Add method docstrings. * UT: Rename test file to reflect these are bootflash tests. 1. Rename EpBootFlashInfo() everywhere to EpBootflashInfo() 2. Rename test file to reflect that it contains tests for the bootflash endpoints. * BootflashInfo(): Update class and method docstrings * BootflashInfo().validate_refresh_parameters() refactor. * BootflashInfo().__init__(): initialize filter properties * dcnm_bootflash.py: share parse_target() 1. Deleted().parse_target() move to Common() 2. Query(): leverage parse_target() * IT: Update tests to reflect recent commits * dcnm_bootflash.py: Refactor out ParseTarget() 1. ParseTarget(): new class to parse a target dict. 2. dcnm_bootflash.py: Query() and Delete(): Leverage new ParseTargets() class. 3. BootflashInfo(): Only set results.action, results.check_mode, and results.state. Leave it to the caller to set results.current_*. 4. BootflashInfo().populate_property(): Refactor out build_match() 5. BootflashInfo(): Run through linters. 6. ParseTarget(): new class to parse a single target e.g. bootflash:/my.txt into its constituent bootflash-files API parameters. 7. dcnm_bootflash.py: leverage ParseTarget() 8. dcnm_bootflash.py: Remove Common().get_have() in favor of using BootflashInfo() in Query() and Deleted() 9. dcnm_bootflash_query.py - Update integration test expectations based on above changes. * BootflashInfo(): hardening. BootflashInfo().populate_property() return None if property is not found in self.match. Previously we raised ValueError(). * IT: dcnm_bootflash_delete.yaml: update 1. Update asserts based on previous commits. 2. Add expected results for each task. * Support file globbing Modifications to support file globbing syntax for matching files e.g.: # match all .txt files on bootflash: filepath: bootflash:/*.txt # match log files for July 2024 on all partitions filepath: *:/202407??.log * BootflashInfo(): update class docstring, more... 1. Update class docstring with Usage section. 2. Rename two methods: - filter_supervisor_matches() -> match_filter_supervisor() - filter_switch_matches() -> match_filter_switch() 3. New method - match_filter_filepath(): refactored out of build_matches() 4. Rename validate_refresh_parameters().raise_exception() to: - validate_refresh_parameters().raise_value_error_if_not_set() * IT: Update to test wildcards for partition and filepath. * BootflashInfo(): Add method docstring. 2. BootflashInfo().match_filter_filepath(): Add method docstring. * TargetToParams(): Add method docstrings. * FileInfoToTarget(): Fix class docstring * FileInfoToTarget(): Really fix class docstring... The last commit didn't account for recent additions to the infomation of the target dict. Fixed. * FileInfoToTarget().commit(): Update docstring. * Clean up diff results. Optimize payload. * BootflashFiles(): Add method docstrings, more... 1. BootflashFiles(): Add method docstrings 2. Run through linters * Fix sanity errors * BootflashFiles(): Fix var names. 1. BootflashFiles().ep_bootflash_info should be ep_bootflash_files. Fixed. 2. change file_name, file_path, and file_size, to filename, filepath, and filesize. * UT: BootflashFiles().__init__() add unit test. * UT: BootflashInfo().__init__() add unit test. 1. BootflashInfo() - Add class decorator @Properties.add_rest_send 2. BootflashInfo().__init__() - self.action : change from "bootflash_query" to "bootflash_info" - Initialize self._matches rather than self.matches. - Initialize self._rest_send to None * IT: BootflashInfo(): update assert to match action BootflashInfo().action was modified in an earlier commit. Updating the corresponding IT to reflect thsi change. * BootflashFiles().target.setter: raise TypeError 1. BootflashFiles().target modified to raise TypeError if value is not a dict. 2. BootflashFiles(): Update docstrings. * refactor and cleanup 1. bootflash_info.py - Align imports after renaming conversion classes. - Rename conversion class instance from file_info_to_target to convert_file_info_to_target. 2. dcnm_bootflash.py - Deleted().commit(): refactor. - Query().commit(): Remove unused code. - Align imports after renaming conversion classes. 3. convert_file_info_to_target.py - Rename from file_info_to_target.py - FileInfoToTarget(): rename to ConvertFileInfoToTarget() - Update docstrings. 4. convert_target_to_params.py - Rename from target_to_params.py - TargetToParams() rename to ConvertTargetToParams() 5. test_bootflash_files.py - Rename from test_dcnm_bootflash_files.py 6. test_bootflash_info.py - Rename from test_dcnm_bootflash_info.py - Update class instance name to reflect above changes. 6. New unit test files - test_convert_file_into_to_target.py - test_convert_target_to_params.py * UT: BootflashInfo(): test_bootflash_info_00110 1. Add unit test test_bootflash_info_00110 ### Summary - Verify exception is raised if rest_send is not set. ### Test - ValueError is raised when rest_send is not set. 2. BootflashInfo().validate_refresh_parameters().raise_value_error_if_not_set(): ValueError() -> ValueError(msg) 3. Bootflash().switches: Update docstring. * UT: BootflashInfo().refresh() unit tests 1. test_bootflash_info_00100 - Happy path 2. test_bootflash_info_00120 - ValueError is raised when results is not set. 3. test_bootflash_info_00130 - ValueError is raised when switch_details is not set. * UT: Fixtures and utils for bootflash_info unit tests. * utils.py: Fix sanity errors Fix unused imports and too many blank lines. * UT: BootflashInfo(): 88% coverage. 1. BootflashInfo(): Remove multiple unused getter properties. An earlier version of BootflashInfo() provided getter properties for individual items in the file_info dict. Functionality of BootflashInfo() changed from this earlier version such that these getter properties are no longer used. 2. Add unit tests. - test_bootflash_info_00140 - test_bootflash_info_00150 - test_bootflash_info_00200 - test_bootflash_info_00210 - test_bootflash_info_00300 - test_bootflash_info_00310 - test_bootflash_info_00320 - test_bootflash_info_00400 * UT: BootflashInfo(): Add missing assert for 00210 1. test_bootflash_info_00210 was missing the requisite assert. * UT: BootflashInfo(): 91% coverage 1. BootflashInfo(): add test: - test_bootflash_info_00220 2. BootflashInfo().build_matches(): Remove conditional that would never be hit. * BootflashInfo(): remove matches.setter, more... 1. BootflashInfo(): remove unused matches.setter. instance._matches is set internally, so only matches.getter is needed. 2. BootflashInfo().build_matches(): remove check for ip_address since it's verified previously. 3. BootflashInfo(): Update docstrings and comments. * UT: BootflashInfo(): Add test_bootflash_info_00230 1. BootflashInfo(): - test_bootflash_info_00230 2. test_bootflash_info_00100 - Remove 14 of 20 asserts as these are very expensive. Reduced the test time from 30 to 8.4 seconds. * UT: BootflashInfo(): 93% coverage. 1. Add test cases for switch_details.setter: - test_bootflash_info_00500 - test_bootflash_info_00510 * UT: BootflashInfo(): 100% coverage 1. BootflashInfo().switches.setter: improve error messages. 2. test_bootflash_info.py: Add tests for BootflashInfo().switches.setter. - test_bootflash_info_00600 - test_bootflash_info_00610 - test_bootflash_info_00620 * BootflashFiles(): Do not use payload for diff Payload does not have much useful information, so use diff_current to populate the diff. * ConvertTargetToParams(): Add Usage to class docstring * dcnm_bootflash.py: remove unused import * BootflashFiles: Add unit test, more... 1. BootflashFiles: test_bootflash_files_00100 - Verify commit happy path. 2. utils.py: - Remove unused fixtures * UT: BootflashInfo(): remove unused imports. 1. test_bootflash_info.py: remove unused imports. * UT: ConvertFileInfoToTarget(): 100% coverage, more 1. test_convert_file_info_to_target.py - 100% test coverage for ConvertFileInfoToTarget() 2. ConvertFileInfoToTarget() - validate_commit_parameters(): new method - Update docstrings. - commit(): Raise ValueError if ":/" is nto in the resulting filepath. - date.getter: Fix error message. * UT: Fix PurePosixPath version differences Depending on the version of PurePosixPath, the error message differs (see below). Fix by using a general .* regex for the Error detail: portion of the message. argument should be a str or an os.PathLike object where __fspath__ returns a str, not 'int' Versus: expected str, bytes or os.PathLike object, not int' * UT: ConvertTargetToParams: 100% coverage, more... 1. convert_target_to_params.py - Update class docstring with example for file in directory. - ConvertTargetToParams().partition.setter: validate partition - ConvertTargetToParams().supervisor.setter: validate supervisor. 2. targets_BootflashFiles.json - rename to targets.json 3. test_bootflash_files.py - Update import for targets 4. test_convert_file_info_to_target.py - Cleanup docstrings 5. test_convert_target_to_params.py - Add testcases for 100% coverage. 6. utils.py - rename targets_bootflash_files() to targets() * UT: BootflashFiles(): 75% coverage. 1. test_bootflash_files.py - test_bootflash_files_00200 - Verify add_file() raises ValueError if switch mode is either "migration" or "inconsistent". 2. BootflashFiles().add_file() - Improve error message. * UT: BootflashFiles(): 77% coverage. 1. BootflashFiles(). refresh_switch_details() - test_bootflash_files_00300 - Verify ValueError raised if switch_details is not set. - test_bootflash_files_00310 - Verify ValueError raised if rest_send is not set. * IT: Add playbook to create bootflash files. 1. create_files.yaml - Use cisco.nxos.nxos_command module to create files on NX-OS switches. * IT: Add spine1 and spine2 to dcnm_hosts.yaml Add spine1 and spine2 to the inventory for use by create_files.yaml * IT: dcnm_bootflash_query.yaml improvements. 1. Add test case for wildcard query. 2. Retain and expand test case for specific query. 3. Fix assertions. 4. Remove most file objects from Expected output for brevity. * IT: expand dcnm_bootflash_deleted.yaml 1. Delete dcnm_bootflash_deleted.yaml and expand into two test cases. - dcnm_bootflash_deleted_specific.yaml - dcnm_bootflash_deleted_wildcard.yaml 2. dcnm_tests.yaml - Add file vars for dcnm_bootflash tests. - Update list of test cases to include those in 1 above. 3. dcnm_bootflash_query.yaml - Minor update to comments. * IT: dcnm_bootflash_query.yaml update run time. * UT: BootflashFiles(): 94% coverage. * UT: BootflashFiles(): 99% coverage. more... 1. BootflashFiles(): - Update method docstrings. - filesize: Remove unused property. - target.setter: Require target to include filepath, ip_address, serial_number, and supervisor. 2. test_bootflash_files.py - 99% coverage. - Move target dictionaries into targets.json * dcnm_bootflash Common(): remove unused properties. * UT: dcnm_bootflash.py: 29% coverage. * Common().__init__() hardening, more... 1. dcnm_bootflash.py Common().__init__(): added more verifications. 2. test_dcnm_bootflash_common.py - 40% coverage. 3. utils.py - Update params_deleted.config to include targets list. * Common().get_want(): Improve error messages, more 1. dcnm_bootflash.py - Common().get_want(): Improve error messages. - main(): Add TypeError to except tuple when instantiating Log() * UT: Common(): 100% coverage 1. test_bootflash_common.py - 100% coverage of Common() in dcnm_bootflash.py - Remove unused commented imports. * UT: dcnm_bootflash.py: 66% coverage 1. dcnm_bootflash.py - Common().get_want(): Use copy.deepcopy() 2. test_bootflash_deleted.py - Deleted(): Initial unit tests * Deleted(): 68% coverage. 1. test_bootflash_deleted.py - test_bootflash_deleted_02000 - populate_files_to_delete() negative test * BootflashFiles().target: fix exception type 1. BootflashFiles().target should raise TypeError if value is not a dictionary. 2. test_bootflash_files.py - Update corresponding unit tests. * Deleted().update_bootflash_files(): hardening 1. dcnm_bootflash.py - Deleted().update_bootflash_files(): add try/except block around - convert_target_to_params - bootflash_files property setters 2. test_bootflash_deleted.py - Add unit tests for the above * UT: dcnm_bootflash.py: 71% coverage. 1. test_bootflash_deleted.py - Deleted(): 100% coverage * UT: Query(): initial unit tests 1. test_bootflash_query.py - 87% coverage for dcnm_bootlfash.py - test_bootflash_query_00000 - test_bootflash_query_00010 - test_bootflash_query_01000 * Common().__init__(): Fix target handling. more... 1. dcnm_bootflash.py - Common()__init__() - Fix crash when users doesn't include global target. - Query().register_null_result() - new method. 2. Update unit tests to align with changes to Common() above. 3. test_bootflash_query.py - test_bootflash_query_01010 - Add test 4. Run everything through black/isort. * dcnm_bootflash.py: Fix pylint error. * IT: Move query tests into separate files. 1. Move query-state tests into separate files to match deleted-state tests. * IT: Fix deleted-state tests idempotency asserts 1. result.response was changed a couple commits ago. Modifying integration tests to align with those changes. * IT: Remove hard-coded filenames, more... 1. tests/integration/targets/dcnm_bootflash/defaults/main.yaml - Add default filenames here. User can override in dcnm_tests.yaml - Add default wildcard_filepath here. User can override in dcnm_tests.yaml 2. Update inventory to use switch1 and switch2 instead of spine1 and spine2 3. tests/integration/targets/dcnm_bootflash/tests/*.yaml - Change spine1 and spine2 to switch1 and switch2 everywhere - Update REQUIREMENTS section with current set of vars and mention that the default vars can be overridden by uncommenting in dcnm_tests.yaml 4. playbooks/roles/dcnm_bootflash/*.yaml - Update to reflect the above changes. - Remove all vars not used in the dcnm_bootflash integration tests. * IT: create_files.yaml - read vars from file. There doesn't appear to be a way to add create_files as a testcase within dcnm_bootflash role. For now, create_files.yaml is a separate playbook that uses ansible.builtin.include_vars to read nxos_vars.yaml to determine what files to create. 1. playbooks/roles/dcnm_bootflash/create_files.yaml - modify to read vars from nxos_vars.yaml 2. playbooks/roles/dcnm_bootflash/nxos_vars.yaml - contains dictionary nxos_vars defining files to create. * dcnm_bootflash.py: Add wildcard examples. * Fix yamllint error * Fix typo in EXAMPLES section. * Add Docs * Doc updates --------- Co-authored-by: mwiebe <[email protected]>
- Loading branch information