public inbox for pve-devel@lists.proxmox.com
 help / color / mirror / Atom feed
From: Stefan Lendl <s.lendl@proxmox.com>
To: Max Carrara <m.carrara@proxmox.com>,
	Proxmox VE development discussion <pve-devel@lists.proxmox.com>
Subject: Re: [pve-devel] [PATCH pve-network 8/8] test(vnets): add test_vnets_blackbox
Date: Mon, 18 Mar 2024 15:14:04 +0100	[thread overview]
Message-ID: <87plvrk4pf.fsf@gmail.com> (raw)
In-Reply-To: <CZWVTNGOZPCY.12553VXSMMEQC@proxmox.com>

"Max Carrara" <m.carrara@proxmox.com> writes:

> On Wed Jan 3, 2024 at 4:37 PM CET, Stefan Lendl wrote:
>> Add several tests for Vnets. State setup as well as testing results is
>> done only via the API to test on the API boundaries not not against the
>> internal state. Internal state is mocked to avoid requiring access to
>> system files or pmxcfs.
>>
>> Mocking is done by reading and writing to a hash that holds the entire
>> state of SDN. The state is reset after every test run.
>>
>> Testing is done via helper functions: nic_join and nic_start.
>> When a nic joins a Vnet, currently it always - and only - calls
>> add_next_free_cidr(). The same is true if a nic starts on Vnet, which
>> only calles add_dhcp_mapping.
>>
>> These test functions homogenize the parameter list in contrast to the
>> current calls to the current functions.  These functions should move to
>> Vnets.pm to be called from QemuServer and LXC!
>>
>> The run_test function takes a function pointer and passes the rest of
>> the arguments to the test functions after resetting the test state.
>> This allows fine-grained parameterization per-test directly in the code
>> instead of separated files that require the entire state to be passed
>> in.
>>
>> The tests setup the SDN by creating a simple zone and a simple vnet. The
>> nic_join and nic_start function is called with different subnet
>> configuration wiht and without a dhcp-range configured and with or
>> without an already present IP in the IPAM.
>
> I really like where this is going! Now that I've read through this
> patch, it's become clear why you factored so many calls to commands etc.
> into their own `sub`s.
>
> Since you mentioned that this is more of an RFC off-list, I get why
> there are a bunch of lines that are commented out at the moment. Those
> obviously shouldn't be committed later on.
>
>>
>> Several of the tests fail and uncovers bugs, that shall be fixed in
>> subsequent commits.
>
> Would be nice to perhaps also have those in the final series though ;)

Yes agreed will uncomment them in a follow-up.

>
> Another thing that stood out to me is that some cases could be
> declarative, e.g. the cases for `test_nic_join` and `test_nic_start`
> could be declared in an array for each. You could then just loop over
> the cases - that makes it easier to `plan` those cases later on.
>

I totally agree it would be nice to have it like that.
I tried to get it there but found unrolling the calls to be more
readable and making the test sub body simpler not requiring to loop in
the test or a setup sub.

If this approach would be refactored further with some Perl-magic™ this
would be nice but I chose this deliberatly for simplicity and readability.

> That being said, you could perhaps structure the whole script so that
> you call a `sub` named e.g. `setup` where you - well - set up all the
> required logic and perform checks for the necessary pre-conditions, then
> another `sub` that runs the tests (and optionally one that cleans things
> up if necessary).

Yes, agreed as well. Also tried that but chose a "simpler" version for
the first iteration.

I found that it is sometimes simpler to have dedicated test functions
for example if you have a dhcp-range instead of if-casing whether a a
property is present in the hash.

I will re-consider a dedicated setup sub for a follow-up.

>
> Though, please note that this is not a strict necessity from my side,
> just something I wanted to mention! I like the way you've written your
> tests a lot, it's just that I personally tend to prefer a more
> declarative approach. So, it's okay if you just leave the structure as
> it is right now, if you prefer it that way.
>
> There are some more comments inline that give a little more context
> regarding the above, but otherwise, LGTM - pretty good to see more
> testing to be done!
>

Thanks for the review. 




  reply	other threads:[~2024-03-18 14:14 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-01-03 15:37 [pve-devel] [PATCH pve-network 0/8] SDN Vnet blackbox testing Stefan Lendl
2024-01-03 15:37 ` [pve-devel] [PATCH pve-network 1/8] refactor(sdn): extract cfs_read_file(datacenter.cfg) Stefan Lendl
2024-01-03 15:37 ` [pve-devel] [PATCH pve-network 2/8] refactor(dnsmasq): extract systemctl_service function Stefan Lendl
2024-01-03 15:37 ` [pve-devel] [PATCH pve-network 3/8] refactor(dnsmasq): extract ethers_file function Stefan Lendl
2024-01-03 15:37 ` [pve-devel] [PATCH pve-network 4/8] refactor(dnsmasq): extract update_lease function Stefan Lendl
2024-01-03 15:37 ` [pve-devel] [PATCH pve-network 5/8] refactor(controllers): extract read_etc_network_interfaces Stefan Lendl
2024-01-03 15:37 ` [pve-devel] [PATCH pve-network 6/8] refactor(evpn): extract read_local_frr_config Stefan Lendl
2024-01-03 15:37 ` [pve-devel] [PATCH pve-network 7/8] refactor(api): extract create_etc_interfaces_sdn_dir Stefan Lendl
2024-01-03 15:37 ` [pve-devel] [PATCH pve-network 8/8] test(vnets): add test_vnets_blackbox Stefan Lendl
2024-03-18 12:41   ` Max Carrara
2024-03-18 14:14     ` Stefan Lendl [this message]
2024-03-18 15:00       ` Max Carrara
2024-03-18 12:41 ` [pve-devel] [PATCH pve-network 0/8] SDN Vnet blackbox testing Max Carrara
2024-04-02 16:10   ` Stefan Lendl

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87plvrk4pf.fsf@gmail.com \
    --to=s.lendl@proxmox.com \
    --cc=m.carrara@proxmox.com \
    --cc=pve-devel@lists.proxmox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal