-
Notifications
You must be signed in to change notification settings - Fork 35
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
(MODULES-6845) Allow provider to read / modify V2 tasks #27
Conversation
4f50c60
to
502bc4b
Compare
77dbb8b
to
79c2135
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.
Not sure where this leaves the provider as it's no longer an adapter
@@ -28,7 +28,11 @@ def initialize(work_item = nil, trigger = nil) | |||
def enum | |||
@tasksched.enum_task_names(PuppetX::PuppetLabs::ScheduledTask::TaskScheduler2::ROOT_FOLDER, | |||
include_child_folders: false, | |||
include_compatibility: [PuppetX::PuppetLabs::ScheduledTask::TaskScheduler2::TASK_COMPATIBILITY_V2]).map do |item| | |||
include_compatibility: [ |
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.
So now that we can show V2 tasks, does mean we should be enabling child folders, not just the root folder?
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.
Yeah probably... not sure if that's worth a separate ticket or not.
7a5f725
to
eeb5bc0
Compare
I have a few issues with this PR. The TaskScheduler2V1Task was meant to mimic the V1 provider so we maintained backwards compatibility. This PR breaks that contract as it now returns V2, V1 and AT tasks for enum. This is also borne out in the spec tests where it runs the sames tests over the provider for both the original implementation and the V2 adapter. And because that contract is broken I expect spec tests to be failing. I would've thought it would make more sense to;
This means now the V1 style provider still uses the V2 API for it's underlying work and can be used for backwards compatiblity and that the V2 provider can |
Thanks for the feedback @glennsarti - I'm still working on a more comprehensive explanation of the thought process here, because it's a little complicated. In the interim, here are a few bits about where we were coming from:
Anyhow - this was quick off the head stuff - let's chat in person soon. |
Yeah I think we're mostly on the same page. Just need to define the direction of the older
In addition to that point, I would like to ditch the V1 API calls and use the V2 API calls instead because; Pros:
Cons:
More than likely. I used an overloaded word.
100% agree
In my mind the fact that they're almost the same right now is expected. All we've really done so far is all "tech debt"/backend work. Now that that's all been done we're adding features and this where they'll being to diverge.
I assume you're talking V1 API here
Saw that. +1
Agreed! |
I think the APIs are about the same after the Trigger code was refactored out. However, it wasn't factored out of the existing
+1
It turns out that most of the work here is in the Trigger nonsense, which caused the adapter to go on a 300-400 line diet. But I agree it would be nice to leverage the work invested in the adapter.
Yes, we will have to carry this until the point at which Puppet itself trashes it to make sure that it is not the default provider.
My thinking here is that we don't touch it either way anyhow. If a user has a problem with what's "in the box" for Puppet, then they must install the module, at which point they get a new default provider. Any "fixes" they need go against api2. A user would have to have the module and opt in to the old provider to use that code path, which seems unlikely, and hopefully never happens. With any luck, we never touch
That was just me thinking about further into the future. Not something that necessarily needs to be done.
The methods on the provider that the type calls are
We're not sure yet, but we suspect much of the divergent behavior is going to end up in the factored out Trigger helpers, rather than in the providers... which is what had us thinking about this. We can always revisit at a later date when we do some additional cleanup.
Not ... exactly. I mean some of the Trigger helper code and our "internal representation" of triggers. Right now, we do some things that were appropriate at initial implementation, but have become clearly unnecessary now after refactoring.
For ingress manifest hash definitions, I would like to see the V1-esque representation removed completely (in addition to cleaning up comparison and prefetch logic), which we've now realized cannot be done without migrating So to summarize, I think we're going to migrate the code from |
Prior to this commit the spec for the providers iterated over the helpers used. This causes some problems with plans to copy the new provider into the old as both providers will temporarily use the same provider. This commit changes the spec logic to iterate over the providers and map the appropriate helpers to them. No tests are changed or affected.
Prior to this commit the code relied on the Win32::TaskScheduler class to provide the DISABLED constant, indicating a task is disabled. This required loading that class and caused puppet resource calls to fail. This commit adds the task flag constants to the `TaskScheduler2` class and bypasses the need to load the Win32::TaskScheduler at all. It then replaces all calls for that constant to the appropriate call to those defined in `TaskScheduler2`.
@michaeltlombardi I resumed your PR at #34 here... however, there are a few things not working right (as of 2nd to last commit 0a0228c).
I suspect this may have to do with the I've been messing around with this basic manifest and scheduled_task { 'test':
ensure => 'present',
command => 'c:\\windows\\system32\\notepad.exe',
# compatibility => 2,
enabled => 'true',
trigger => [
{
'schedule' => 'once',
# 'start_date' => '1899-12-30',
'start_date' => '2018-04-30',
'start_time' => '00:00',
'minutes_interval' => 0,
'minutes_duration' => 0,
}],
# provider => 'win32_taskscheduler'
} |
RE: Compatibility, as you discovered, it's because the V2 helper creates the task with a compat level of 2. Unless the compat level is specified, however, it will try to default back to 1, preventing idempotency. This means we created a situation in which not specifying compatibility at all will create an initially non-idempotent task, although this will resolved after two runs. To fix this, we'll need to have it to be able to pass through the compat level to
|
@michaeltlombardi / @glennsarti ready for another review - almost there, but not quite. |
- Previously, specs were hardcoded to use the Win32::TaskScheduler helper during some retrieval and creation style tests, when they should be switching the class based on the appropriate helper, either PuppetX::PuppetLabs::ScheduledTask::TaskScheduler2V1Task OR Win32::TaskScheduler. This creates a minor discrepancy in a subsequent commit when additional testing is added for compatibility, which is implemented only in TaskScheduler2V1Task and *not* Win32::TaskScheduler
- The initial V2 implementation of compatbility in the V2 provider did not properly use the attribute to set the compatibility level when constructing new task instances. Remove the hardcoded setter that pushes through V2 and instead call the property setter for `compatibility` the same way as is done for other providers. - Add additional validations through tests to demonstrate this behavior, noting the old Win32_TaskScheduler provider does not follow this same behavior.
Prior to this commit the Win32 provider in this module was a near mirror of the existing provider in core Puppet. In order to more easily maintain the new module, to debug it, and to onboard team members to maintaining it, this commit copies over the code from the new provider into the old one. As the new provider was made to keep in parity with the old one and the tests already existed to verify this, the change is determined to be low risk. In a future commit the V2 provider will be updated to manage scheduled tasks of all compatibility modes and will be the code which gets all new features and improvements. The legacy provider will be frozen at a point in the near future for all changes except for security and critical bug fixes. This commit also updates the test suite to verify the changes and removes unneccessary logic from the tests which were needed when the providers did not share helper code. However, in this iteration, the tests only run over the legacy provider and not the V2 provider, though they are using the same helper at this time. In a future commit, when the V2 provider is updated to use the new V2 helper, the test suite will again run for both. Note also that references to the compatibility property were removed from the win32_taskscheduler code because only the taskscheduler_api2 supports it.
- Prior to this commit both the win32 (legacy) and api2 (new) providers leveraged the adapter code in `TaskScheduler2V1Task` to manage scheduled tasks. This commit updates the API2 provider to use the TaskScheduler2Task helper, allowing us to freeze work on the adapter code and begin to add new features to the API2 helper. At this point in time, only the helper has been swapped out, the provider itself has not been meaningfully altered. - Make sure the helper queries for all task compatibility levels including 3 (2008R2), 4 (2012R2 / 2016), 6 (Windows 10) in addition to just V1 and AT as the old provider did. This ensures that `puppet resource` returns all tasks on the system even if they cannot be configured yet.
- To fully support reading / writing v2 tasks requires allowing the compatibility value in the scheduled_task type to be anything valid, including 1, 2, 3, 4 and 6. 1 - 2003, XP, 2000 2 - Vista / 2008 3 - 7, 2008R2 4 - 8, 2012R2, 2016 6 - 10
@glennsarti we went through each commit individually and are satisfied with how this seems to be working (including in-place upgrading / downgrading compatibility level) Want to give this one last pass and merge? Thanks! |
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
No description provided.