8000 Fix importing module remote using version filters and added tests by SteveL-MSFT · Pull Request #4900 · PowerShell/PowerShell · GitHub
[go: up one dir, main page]

Skip to content

Fix importing module remote using version filters and added tests #4900

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

Merged
merged 3 commits into from
Sep 26, 2017

Conversation

SteveL-MSFT
Copy link
Member

added tests for remote import-module
fixed issue with remotely importing module where it was checking the version filter incorrectly against the proxy module

  • the filters are applied when importing the module remotely
  • after proxy module is generated it always has a module version of 1.0, so the filters will always fail when importing the proxy locally

Fix #4161

@@ -989,6 +989,10 @@ private PSModuleInfo ImportModule_LocallyViaName(ImportModuleOptions importModul
try
{
this.ArgumentList = new object[] { psSession };
// since we already applied these filters remotely, we don't want to apply it locally where the generated module is always 1.0
Copy link
Contributor

Choose a reason for hiding this comment

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

I am a little worried about changing these object properties here permanently. It looks like this method is called within a loop of many kinds of different modules, including CIM and remote modules. I think we should change and restore in the try/finally to be safe.

This is pretty confusing and I wonder if we can add a clearer comment? Something like: "The correct module version has been imported from the remote session and created locally. The locally created module always has a version of 1.0 regardless of the actual module version imported from the remote session, and version checking is no longer needed and will not work while importing this created local module".

I suppose the right thing to do is to ensure the generated module has the same version info as the module imported from the remote session. But that is a much bigger change and can be handled in a separate issue.

Copy link
Member Author

Choose a reason for hiding this comment

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

I'll update the comment with your suggestion.

I initially looked to see about updating the proxy module version, but there were a couple of problems. Not only was it not trivial to update the module version, based on my reading of the code, because you can export-pssession multiple modules, you actually don't have a single module version to use so from that perspective 1.0 makes sense. Of course, we could special case single modules to have the same version number, but a bunch of plumbing code would be needed.

Copy link
Member Author

Choose a reason for hiding this comment

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

As far as I could tell, it seemed safe to change it, but I can store it and change it back.

@@ -989,6 +989,10 @@ private PSModuleInfo ImportModule_LocallyViaName(ImportModuleOptions importModul
try
{
this.ArgumentList = new object[] { psSession };
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't understand why the PSSession is added/reverted from the ArgumentList here. The remote session has already been imported (via the Export-PSSession Cmdlet) and is no longer needed. It looks like this can be removed.

Copy link
Contributor

Choose a reason for hiding this comment

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

Actually this does need to be here. It is used to fill the PSSession property on the module info.

@{parameter = "Prefix" ; value = "Hello"},
@{parameter = "Name" ; value = "foo","bar"},
@{parameter = "FullyQualifiedName" ; value = @{ModuleName='foo';RequiredVersion='0.0'},@{ModuleName='bar';RequiredVersion='1.1'}},
@{parameter = "Assembly" ; script = { [System.AppDomain]::CurrentDomain.GetAssemblies() | Select-Object -First 2 }}
Copy link
Contributor

Choose a reason for hiding this comment

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

Can't the Assembly array be pre-computed and passed in as a "value" parameter? Then you wouldn't need the special case for "script" parameter.

Copy link
Member Author

Choose a reason for hiding this comment

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

My thinking is that if we add new test cases here, we can reuse script even though it's only used once here. Also, I don't like having variables defined at the top of the script in a BeforeAll statement if it's only used once for a specific It, prefer to have it closer to the code where it's being used.

@SteveL-MSFT
Copy link
Member Author

@PaulHigin feedback addressed

@vors vors removed their request for review September 25, 2017 00:39
BaseMinimumVersion = null;
BaseMaximumVersion = null;
BaseRequiredVersion = null;
try
Copy link
Contributor

Choose a reason for hiding this comment

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

You can just use the existing try/catch (for this.ArgumentList). I don't think a new one is needed.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, didn't notice that. Will fix.

Copy link
Contributor
@PaulHigin PaulHigin left a comment

Choose a reason for hiding this comment

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

LGTM

@daxian-dbw
Copy link
Member

@SteveL-MSFT Can you run git submodule update? The PR has changs to Pester files.

@SteveL-MSFT
Copy link
Member Author

@daxian-dbw Fixed.

@daxian-dbw
Copy link
Member

@SteveL-MSFT there are 2 test failures in AppVeyor run. Maybe they are not related to your changes but can you please take a look?

@daxian-dbw
Copy link
Member

Oh, and it seems the line 3200 and 3201 are rendered as red incorrectly :)

Describing Validate Invoke-WebRequest and Invoke-RestMethod -InFile
   Context InFile parameter negative tests

@SteveL-MSFT
Copy link
Member Author

@daxian-dbw webcmdlets are failing on two tests and it's affecting two of my PRs, trying a rebase to see if changes in master fixed something

added tests for remote import-module
fixed issue with remotely importing module where it was checking the version filter incorrectly against the proxy module
  - the filters are applied when importing the module remotely
  - after proxy module is generated it always has a module version of 1.0, so the filters will always fail when importing the proxy locally
address PR feedback from Paul
@daxian-dbw
Copy link
Member

@SteveL-MSFT I don't think those 2 failing tests are related to changes in this PR. I will merge it.

@daxian-dbw daxian-dbw merged commit efbdea5 into PowerShell:master Sep 26, 2017
@SteveL-MSFT SteveL-MSFT deleted the import-module-remote branch September 26, 2017 04:39
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.

Add tests for Import-Module / Get-Module over remoting
4 participants
0