Skip to content
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

Enhancing module #20

Merged
merged 42 commits into from
Mar 27, 2019
Merged

Enhancing module #20

merged 42 commits into from
Mar 27, 2019

Conversation

twerthi
Copy link
Contributor

@twerthi twerthi commented Jan 19, 2018

Added the ability to have all Access variables present, but allow for null or empty.


This change is Reviewable

Shawn Sesna added 2 commits January 18, 2018 17:46
Add checks for null Access parameters and removed from collection if they were null.
Added checks to see if Access parameters were present in the collection but were null or empty.  If they were null or empty, remove the variable from collection so when they are passed to New-SmbShare it wouldn't fail.
@johlju
Copy link
Member

johlju commented May 16, 2018

Review status: 0 of 1 files reviewed at latest revision, all discussions resolved.


DscResources/MSFT_xSmbShare/MSFT_xSmbShare.psm1, line 189 at r1 (raw file):

                Write-Verbose "Parameter ChangeAccess is null or empty, removing from collection."
                # Remove the parameter
                $psboundparameters.Remove("ChangeAccess")

Curious why we need to do this. If the parameter is not passed to Set-TargetResource then is it not already not part of $PSBoundParameters?


Comments from Reviewable

@johlju johlju added the waiting for author response The pull request is waiting for the author to respond to comments in the pull request. label May 16, 2018
@stale
Copy link

stale bot commented Jun 18, 2018

Labeling this pull request (PR) as abandoned since it has gone 14 days or more since the last update. An abandoned PR can be continued by another contributor. The abandoned label will be removed if work on this PR is taken up again.

@stale stale bot added the abandoned The pull request has been abandoned. label Jun 18, 2018
@twerthi
Copy link
Contributor Author

twerthi commented Jun 18, 2018

Holy cow, I did not see that anyone had looked at this! My apologies.

If the parameters were empty or null, the setting was failing completely. If they weren't part of the parameters being passed in, then it safely applied what was being requested.

@johlju
Copy link
Member

johlju commented Jun 19, 2018

Maybe we should use ValidateNotNullOrEmpty instead on the parameters? If we should not allow empty values, that should be changed on both the Set- and Test-TargetResource.

Would that work for the intended behavior?

@johlju johlju removed the abandoned The pull request has been abandoned. label Jun 19, 2018
@johlju
Copy link
Member

johlju commented Jun 19, 2018

Also, is there a scenario where any of the parameters need to be assigned an empty value? So we don't do a breaking change.

@twerthi
Copy link
Contributor Author

twerthi commented Jun 19, 2018

The ValidateNotNullOrEmpty would prevent anyone passing in null or empty. The scenario that I am using is

				xSmbShare "Share-$($Folder.Share.Name)"
				{
					Name = $Folder.Share.Name
					Ensure = "Present"
					FullAccess = $Folder.Share.FullAccess
					ReadAccess = $Folder.Share.ReadAccess
					ChangeAccess = $Folder.Share.ChangeAccess
					Path = $Folder.PhysicalPath
				}

In my data document, I may or may not have anything specified for ChangeAccess, for example, so that would be a null. I wanted the data document to be flexible enough so that you don't have to specify all of the different levels, only the ones you wanted to change. Does that make sense?

@johlju
Copy link
Member

johlju commented Jun 20, 2018

Ah, I see what you are trying to do. I don't think this is the right approach. If a property should not be checked to be in a consistent state it should not be part of the configuration. This way if ChangedAccess on the target node would be anything other than an empty value the configuration would never become in a desired state.
The configuration should be built so that only the properties that should be in desired state is present.

@twerthi
Copy link
Contributor Author

twerthi commented Jun 20, 2018

I think I understand, but I'm going to paraphrase to make sure we're on the same page. Given the scenario where User A has ChangeAccess and we set ChangeAccess to null, the configuration won't do anything with ChangeAccess and User A will retain the permission. Your point is that in this case, User A ChangeAccess should be removed, is that correct?

@johlju
Copy link
Member

johlju commented Jun 21, 2018

I think User A's change access should be removed yes, because that is the desired state we want.

Let say we add a share 'TestShare', and we say the ChangeAccess should be $null (none). Then we want the desired state to be that no one should have change access.
If user A would be added manually to the share for change access. Then our configuration should remove user A, for the configuration to be in desired state.
If we want to keep user A that was added manually, we should not add the property ChangeAccess to the configuration. If the property is not present in the configuration the resource should not determine that properties state.

@twerthi
Copy link
Contributor Author

twerthi commented Jun 21, 2018

Gotcha. You are correct, my solution does not currently handle that. The removing of the parameters is still necessary because the SMS Share cmdlets will fail otherwise. However, I need to change my solution so that users that have existing permissions that are not included in the specified desired state are added to the NoAccess collection, which will then remove their permissions.

Refactored permissions section, moved removal of permissions outside of collection if statements so that permissions are always removed and then re-added if the collections are not null.
@twerthi
Copy link
Contributor Author

twerthi commented Jun 21, 2018

That is incorrect, adding them to the NoAccess list only sets them to an explicit Deny versus removing them from the list. I found that the original author checked to see if collection was null, if it wasn't, they removed all users with that access level and replaced it with the collection. I have moved the removal out of the if statement and have it removing and then adding if the collection has anything in it. This should ensure the correct desired state.

Removed aliases ? and %, and replaced with spelled out operators.
@johlju
Copy link
Member

johlju commented Jun 22, 2018

Review status: 0 of 1 files reviewed, 2 unresolved discussions (waiting on @twerthi)


a discussion (no related file):
There are currently no unit tests for this resource. Could you please add unit tests, for at least the functionality that this change affect?

The unit tests should be added to \Tests\Unit, and the unit test template is here https://github.com/PowerShell/DscResources/blob/master/Tests.Template/unit_template.ps1


Comments from Reviewable

@johlju johlju added waiting for code fix A review left open comments, and the pull request is waiting for changes to be pushed by the author. and removed waiting for author response The pull request is waiting for the author to respond to comments in the pull request. labels Jun 22, 2018
@twerthi
Copy link
Contributor Author

twerthi commented Jun 28, 2018

I've not done these before, so it might take a little while as I work it into my schedule. Thank you for providing the template that should help speed things up :)

Not ready yet.
@twerthi
Copy link
Contributor Author

twerthi commented Jun 28, 2018

@johlju, I'm wondering if I can get a little guidance as I've not done this before. The template calls a function Initialize-TestEnvironment, which isn't included in the script, may I assume it's a known method that creates a test VM of some sort? If so, is there documentation that describes what this VM looks like in terms of drives so that I can perform the setup of a share to test with?

@johlju
Copy link
Member

johlju commented Jun 29, 2018

@twerthi absolutely, happy too! 😃 Let me know if you have any further questions..

Tests are run using AppVeyor - AppVeyor provides build workers (VM's) and if not specified, by using image keyword in the appveyor.yml file in the root of the repository, then the default build worker name is (for now) 'Visual Studio 2015'.
The build worker is a normal Windows Server 2012 R2, with a bunch of tools installed to help building and testing. But see it as a clean Windows Server 2012 R2 for this purpose.

Tests are started by appveyor.yml (AppVeyor control file) and tests is run under the test framework DscResources.Tests which is cloned on run-time (even when you run tests locally with Invoke-Pester). Initialize-TestEnvironment is a helper function in the test environment. So everything in the header and footer of the test templates can safely be ignored, it just to get the prerequisite in place.
The test framework also has some common tests (for all resource modules) that needs to pass.

For example, you can find the test run for your PR if you click 'Details' on this (just below here).

image

In AppVeyor you could create a free account (using your GitHub account) and can connect your fork to AppVeyor (add your fork as a project under Projects in AppVeyor). That way you can test your working branches, and send in PR's when you see they are passing tests.

There are two types of tests - unit test and integration tests. I will only expect you to write a unit test. But if you want to give an integration tests a go it would be much appreciated.
Unit test does not actually perform any actions, it just mocks the calls so it's possible to assert that the call mas wade. Integration tests actually performs the action, for example actually creates the share. Due to the limitations of AppVeyor some integration tests can not be done, for example it is not possible to restart the build worker during testing.

Example of unit tests for a resource: https://github.com/PowerShell/SqlServerDsc/blob/dev/Tests/Unit/MSFT_SqlServerDatabaseMail.Tests.ps1

Example of integration tests for a resource: https://github.com/PowerShell/SqlServerDsc/blob/dev/Tests/Integration/MSFT_SqlServerDatabaseMail.Integration.Tests.ps1 and the accompanying configuration https://github.com/PowerShell/SqlServerDsc/blob/dev/Tests/Integration/MSFT_SqlServerDatabaseMail.config.ps1

I realized that we don't have that much information around this in DSC Resource Kit. But below is what I could find (created an issue to update the documentation).

More information around AppVeyor: https://github.com/PowerShell/DscResources/blob/master/CONTRIBUTING.md#tests-in-appveyor

Test guidelines: https://github.com/PowerShell/DscResources/blob/master/TestsGuidelines.md

Test framework (just for reference, normally only necessary read for new resource modules): https://github.com/PowerShell/DscResource.Tests

@twerthi
Copy link
Contributor Author

twerthi commented Jun 29, 2018

Ah!! Thank you, this helps tremendously!

@twerthi
Copy link
Contributor Author

twerthi commented Jul 5, 2018

The pieces are finally fitting together in my head. I've only been able to work on this sporadically so it wasn't quite clicking. Spent some time on the 4th and I believe I understand now. Sorry it's taking so long.

@johlju
Copy link
Member

johlju commented Jul 6, 2018

@twerthi No worries, take your time. 🙂 If you get stuck, or need pointers, ping me and I try to help the best I can.

@twerthi
Copy link
Contributor Author

twerthi commented Jan 28, 2019

I understand, been trying not to bug you too much since I can see you cover quite a large range of PRs. Think I got all requested changes complete.

@twerthi
Copy link
Contributor Author

twerthi commented Feb 7, 2019

Is this one acceptable?

@stale
Copy link

stale bot commented Feb 21, 2019

Labeling this pull request (PR) as abandoned since it has gone 14 days or more since the last update. An abandoned PR can be continued by another contributor. The abandoned label will be removed if work on this PR is taken up again.

@stale stale bot added the abandoned The pull request has been abandoned. label Feb 21, 2019
Copy link
Member

@johlju johlju left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed 2 of 2 files at r18.
Reviewable status: all files reviewed, 3 unresolved discussions (waiting on @twerthi)


DscResources/MSFT_xSmbShare/MSFT_xSmbShare.psm1, line 402 at r18 (raw file):

Foreach

foreach (lower-case 'f')


DscResources/MSFT_xSmbShare/MSFT_xSmbShare.psm1, line 408 at r18 (raw file):

if (($null -ne $differences) -and ($differences.Length -gt 0))

We should not need to enclose the evaluations in parenthesis?

This should do?

if ($null -ne $differences -and $differences.Length -gt 0)

DscResources/MSFT_xSmbShare/MSFT_xSmbShare.psm1, line 410 at r18 (raw file):

 -Verbose

We should only output verbose messages when the user want it, when they do for example Start-DscConfiguration -Verbose. So it should not default to print the verbose messages. I think we can remove -Verbose here?

@stale stale bot removed the abandoned The pull request has been abandoned. label Feb 22, 2019
Copy link
Contributor Author

@twerthi twerthi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewable status: 1 of 2 files reviewed, 3 unresolved discussions (waiting on @johlju)


DscResources/MSFT_xSmbShare/MSFT_xSmbShare.psm1, line 402 at r18 (raw file):

Previously, johlju (Johan Ljunggren) wrote…
Foreach

foreach (lower-case 'f')

Done.


DscResources/MSFT_xSmbShare/MSFT_xSmbShare.psm1, line 408 at r18 (raw file):

Previously, johlju (Johan Ljunggren) wrote…
if (($null -ne $differences) -and ($differences.Length -gt 0))

We should not need to enclose the evaluations in parenthesis?

This should do?

if ($null -ne $differences -and $differences.Length -gt 0)

I'm used to C# syntax, is this considered bad practice?


DscResources/MSFT_xSmbShare/MSFT_xSmbShare.psm1, line 410 at r18 (raw file):

Previously, johlju (Johan Ljunggren) wrote…
 -Verbose

We should only output verbose messages when the user want it, when they do for example Start-DscConfiguration -Verbose. So it should not default to print the verbose messages. I think we can remove -Verbose here?

In a previous comment, you'd asked that the differences be displayed. I could not find another way to have the data be written to the DSC output from within a function call. If there is another/better way to do this, please let me know and I'll update :)

Copy link
Member

@johlju johlju left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed 1 of 1 files at r19.
Reviewable status: all files reviewed, 1 unresolved discussion (waiting on @twerthi)


DscResources/MSFT_xSmbShare/MSFT_xSmbShare.psm1, line 408 at r18 (raw file):

Previously, twerthi (Shawn Sesna) wrote…

I'm used to C# syntax, is this considered bad practice?

It good as-is.


DscResources/MSFT_xSmbShare/MSFT_xSmbShare.psm1, line 410 at r18 (raw file):

Previously, twerthi (Shawn Sesna) wrote…

In a previous comment, you'd asked that the differences be displayed. I could not find another way to have the data be written to the DSC output from within a function call. If there is another/better way to do this, please let me know and I'll update :)

Sorry, let me explain better this time. It's correct to write out the differences with Write-Verbose, but the parameter -Verbose should not be used. The parameter -Verbose forces the verbose output regardless if the user wants verbose output or not.
If we remove the parameter -Verbose then the verbose output will be seen when the user asks for verbose output.
With my initial comment I meant that this should be written out, but only when the users asks for the output.

Also so now that it was missing the Message named parameter. SO if you change to this, then it's all good,

$differences | ForEach-Object { Write-Verbose -Message $_ }

Changed verbose to message.
Copy link
Contributor Author

@twerthi twerthi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewable status: 1 of 2 files reviewed, 1 unresolved discussion (waiting on @johlju)


DscResources/MSFT_xSmbShare/MSFT_xSmbShare.psm1, line 410 at r18 (raw file):

Previously, johlju (Johan Ljunggren) wrote…

Sorry, let me explain better this time. It's correct to write out the differences with Write-Verbose, but the parameter -Verbose should not be used. The parameter -Verbose forces the verbose output regardless if the user wants verbose output or not.
If we remove the parameter -Verbose then the verbose output will be seen when the user asks for verbose output.
With my initial comment I meant that this should be written out, but only when the users asks for the output.

Also so now that it was missing the Message named parameter. SO if you change to this, then it's all good,

$differences | ForEach-Object { Write-Verbose -Message $_ }

Done.

I had the -Message backwards.
@twerthi
Copy link
Contributor Author

twerthi commented Mar 12, 2019

We all good now?

@twerthi
Copy link
Contributor Author

twerthi commented Mar 26, 2019

Checking in, anything that I'm missing?

@gaelcolas
Copy link
Member

Hi @twerthi,
Thanks for pinging us.
I'll see if @johlju as time for a final review or I'll ask him to fill me in and finish that off.

Do @ me tomorrow if it hasn't moved forward.

@johlju
Copy link
Member

johlju commented Mar 26, 2019

On it.

Copy link
Member

@johlju johlju left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:lgtm:

Reviewed 1 of 1 files at r20.
Reviewable status: :shipit: complete! all files reviewed, all discussions resolved

@johlju
Copy link
Member

johlju commented Mar 26, 2019

@gaelcolas can you merge this one as I have no permission to merge. :)

@gaelcolas
Copy link
Member

gaelcolas commented Mar 26, 2019

@twerthi can you add an entry in the changelog describing your change? In the unreleased section on the reader.md. I'll use it to merge the pr first thing tomorrow.
Thanks

@twerthi
Copy link
Contributor Author

twerthi commented Mar 26, 2019

This project doesn't appear to have a CHANGELOG.md file in the root, do I need to add one or is it located somewhere else?

@johlju
Copy link
Member

johlju commented Mar 26, 2019

@twerthi some repos have not split the change log into a seperate file. Then you find the unreleased section under the header changelog in the file README.md.

Copy link
Member

@gaelcolas gaelcolas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @twerthi, I've made the update to the changelog and made some cosmetic changes (variable capitalization).
I'll merge this after the tests passes.
Thanks again for the PR!

Copy link
Member

@gaelcolas gaelcolas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed 1 of 2 files at r18, 2 of 2 files at r21.
Reviewable status: :shipit: complete! all files reviewed, all discussions resolved

@gaelcolas gaelcolas merged commit 4c74df4 into dsccommunity:dev Mar 27, 2019
@gaelcolas gaelcolas removed the waiting for code fix A review left open comments, and the pull request is waiting for changes to be pushed by the author. label Mar 27, 2019
@twerthi
Copy link
Contributor Author

twerthi commented Mar 27, 2019

Oh! I had fully planned on making the updates as requested, but got busy at work and am prepping for an event. Thank you very much for taking care of that :)

@gaelcolas
Copy link
Member

No worries. Given we're all in different timezone I thought it'd be nice to close it before the monthly release tomorrow.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants