-
Notifications
You must be signed in to change notification settings - Fork 7.6k
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
Fix importing module remote using version filters and added tests #4900
Conversation
@@ -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 |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 }; |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 }} |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
@PaulHigin feedback addressed |
BaseMinimumVersion = null; | ||
BaseMaximumVersion = null; | ||
BaseRequiredVersion = null; | ||
try |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
40c9039
to
f6c32e4
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
@SteveL-MSFT Can you run |
f6c32e4
to
ccb7a9e
Compare
@daxian-dbw Fixed. |
@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? |
Oh, and it seems the line 3200 and 3201 are rendered as red incorrectly :)
|
@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
ccb7a9e
to
c6c2f96
Compare
@SteveL-MSFT I don't think those 2 failing tests are related to changes in this PR. I will merge it. |
added tests for remote import-module
fixed issue with remotely importing module where it was checking the version filter incorrectly against the proxy module
Fix #4161