dannf / ubuntu-server-netboot

Other
43 stars 9 forks source link

test(pytest): bootstrap function test #21

Closed tai271828 closed 3 years ago

tai271828 commented 3 years ago

Types of changes

Description

Bootstrap the first test case with pytest.

Checklist:

Steps to Test This Pull Request

  1. poetry run pytest if you are not in the python virtual environment built by poetry
  2. Or, pytest if you have been in your python virtual environment

Expected behavior

All test cases pass. Currently there is only 1 test case.

======================================================================================================= test session starts ========================================================================================================
platform linux -- Python 3.6.9, pytest-6.2.4, py-1.10.0, pluggy-0.13.1
rootdir: /home/tai271828/work/shwe/netboot-server-automation/ubuntu-server-netboot
collected 1 item                                                                                                                                                                                                                   

usn/tests/test_grub_cfg.py .                                                                                                                                                                                                 [100%]

======================================================================================================== 1 passed in 0.11s =========================================================================================================
tai271828 commented 3 years ago

@dannf this pull request is ready to review. I don't have the permission of this repository to request reviewer, so let me mention you directly.

dannf commented 3 years ago

Thanks @tai271828 for creating this - automated testing will definitely be valuable!

Would it be feasible/reasonable to dynamically create a mock 20.04.2 ISO - with just the required files - instead of downloading a full one each time? That would avoid consuming bandwidth, make the test run faster, and avoid failures that would occur when e.g. 20.04.2 gets replaced by 20.04.3.

tai271828 commented 3 years ago

Certainly yes. Python mock module could mock url request, so we could serve the required files with our pre-prepared data instead. What else is worthy of testing in your mind? Some of them come into my mind:

- pxelinux configuration files
- output number and file names of the generated `/tmpxxx`
- file integrity by comparing the hash or content of binaries (I am not sure if this is a good idea yet)

Furthermore, if we don't want to commit so many binaries (used for testing) into our repository, we may consider to use the feature of git submodule or git lfs, which is similar to submodule but used for "large files storage". Only people who want to develop and test the code need/want to fetch the binaries for testing.

Please notice the current test case does not download anything but serving grub.cfg that I manually extracted from iso. It's a one-off task for each new iso release.

Thanks @tai271828 for creating this - automated testing will definitely be valuable!

Would it be feasible/reasonable to dynamically create a mock 20.04.2 ISO - with just the required files - instead of downloading a full one each time? That would avoid consuming bandwidth, make the test run faster, and avoid failures that would occur when e.g. 20.04.2 gets replaced by 20.04.3.

dannf commented 3 years ago

Certainly yes. Python mock module could mock url request, so we could serve the required files with our pre-prepared data instead. What else is worthy of testing in your mind? Some of them come into my mind:


- pxelinux configuration files

Definitely

  • output number and file names of the generated /tmpxxx

+1

  • file integrity by comparing the hash or content of binaries (I am not sure if this is a good idea yet)

Yeah, I'm not sure of that one either.



Furthermore, if we don't want to commit so many binaries (used for testing) into our repository, we may consider to use the feature of `git submodule` or `git lfs`, which is similar to submodule but used for "large files storage". Only people who want to develop and test the code need/want to fetch the binaries for testing.

Please notice the current test case does not download anything but serving `grub.cfg` that I manually extracted from iso. It's a one-off task for each new iso release.

Oh, I misunderstood the code. I just ran it and it is very fast. So please ignore the "mock ISO" request! I think I'll go ahead and merge.