dsccommunity / FailoverClusterDsc

This module contains DSC resources for deployment and configuration of Windows Server Failover Cluster.
MIT License
60 stars 54 forks source link

ClusterIPAddress: New Resource to add IP Addresses to clusters #270

Closed nickgw closed 2 years ago

nickgw commented 2 years ago

Pull Request (PR) description

ClusterIPAddress

This Pull Request (PR) fixes the following issues

Task list


This change is Reviewable

codecov[bot] commented 2 years ago

Codecov Report

Merging #270 (d138ea5) into main (605481d) will not change coverage. The diff coverage is 100%.

Impacted file tree graph

@@         Coverage Diff          @@
##           main   #270    +/-   ##
====================================
  Coverage   100%   100%            
====================================
  Files         7      8     +1     
  Lines       460    611   +151     
====================================
+ Hits        460    611   +151     
Impacted Files Coverage Δ
...ces/DSC_ClusterIPAddress/DSC_ClusterIPAddress.psm1 100% <100%> (ø)
nickgw commented 2 years ago

I think I've resolved everything in your comments. Just futzing with tests now. I think I'm having issues figuring out how to mock the foreach loop in Get-ClusterIPResourceFromIPAddress.

As for your two questions:

  1. I'm curious, can this potentially remove the IP address that is added by the resource ClusterNetwork if a configuration is passing 'Absent' for the same IP address with this new resource?

Yes, it will remove that IP address, leaving the cluster in an offline state. I don't know why anyone would want to do that, and if you think it's the right path I can write some logic to throw when there is only one IP address and DSC is trying to remove it.

  1. Since netmask is mandatory parameter should it not also look that the netmask is correct. But maybe there is not possible to add the same IP adress with multiple netmasks, so maybe thatis why it only checks for IP address? 🤔

I think generally, the IP address is what matters to be added. If you try and add an IP address that falls in the same address scope as an already added network, but with a different AddressMask, Test-ClusterNetwork will catch that in Set and throw.

  1. Instead of assigning to a variable that is then never used, can be output to null instead? (In Test-IPAddress)

I'm assigning it a variable because otherwise the System.Net.IPAddress object is returned. The resource doesn't care about that information, just that the IP address String passed is able to be casted to an IPAddress object.

I don't know best practices here, but I just tested quickly and [System.Net.IPAddress]::Parse($IPAddress) | Out-Null serves the same purpose as assigning a variable and never using it. Let me know what you think here.

johlju commented 2 years ago

I think I'm having issues figuring out how to mock the foreach loop in Get-ClusterIPResourceFromIPAddress

Debugging the test it was that you wanted to return a hashtable, but the return statement was on one row and hashtable on the next line, so it just ran return and never returned the hashtable. 🙂 But when debugging the tests I had to fix a few extra things, so they are in a PR here for you to merge if you like: https://github.com/nickgw/FailOverClusterDsc/pull/1

johlju commented 2 years ago

Yes, it will remove that IP address, leaving the cluster in an offline state. I don't know why anyone would want to do that, and if you think it's the right path I can write some logic to throw when there is only one IP address and DSC is trying to remove it.

I think I misunderstood the purpose of ClusterNetwork - after digging in further it does not create anything new, just update an existing network. So my initial thought that these will collide in some way was not true. So no need to do anything. 🙂

johlju commented 2 years ago

I think generally, the IP address is what matters to be added. If you try and add an IP address that falls in the same address scope as an already added network, but with a different AddressMask, Test-ClusterNetwork will catch that in Set and throw.

Sounds good, lets go with that.

johlju commented 2 years ago

I don't know best practices here, but I just tested quickly and [System.Net.IPAddress]::Parse($IPAddress) | Out-Null serves the same purpose as assigning a variable and never using it. Let me know what you think here.

Using either | Out-Null or $null = ... will avoid getting the lint error "variable is assigned but never used". So rather see we either assign it or pipe it to null.

johlju commented 2 years ago

@nickgw I won't have time to look over this tonight or tomorrow. So will look at it after a workday next week.

nickgw commented 2 years ago

@johlju no worries! I think I've updated everything, and am ready for hopefully your final review! I appreciate all the time you've spent on this.