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

Disable merging of chocolatey searches #14327

Merged

Conversation

jaymzjulian
Copy link
Contributor

@jaymzjulian jaymzjulian commented Apr 10, 2024

(Note from @tpowell-progress ... this maps back to CHEF-10654)

Description

There was a time when the following worked:

choco list -r firefox wireshark
choco search -r firefox wireshark

However, it turns out this only worked by accident, not by spec - and this has stopped working now. It's known to not work, see chocolatey/choco#2116 . Additionally, the other potential workarounds are also not well supported. So instead, we tighten the caching a little to at least avoid multiple API requests for the same package, and drop back to single package at a time searches for now, since that's what upstream chocolatey demands. Once we can fix the issue in chocolatey itself, then we can bring this feature back.

(if you have just teh right server versions, which I did when I was testing, it does work - I was able to reproduce it as a regression, but it turns out what I considered "working" was, in fact, the bug and not the correct behaviour)

Note that this means now you see in debug:

[2024-04-10T00:36:54-07:00] INFO: Fetching chocolatey package list
[2024-04-10T00:36:54-07:00] DEBUG: Choco List Command: ["search", "-r", "firefox"]
[2024-04-10T00:36:55-07:00] DEBUG: Choco List Command: ["search", "-r", "wireshark"]
[2024-04-10T00:36:58-07:00] INFO: chocolatey_package[wireshark, firefox] upgraded(allow_downgrade) ["wireshark"] to ["3.0.1"]

which is correct per chocolatey spec, sadly.

Related Issue

[This exists, but I don't have it myself - it was reported to me by @johnmccrae

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Chore (non-breaking change that does not add functionality or fix an issue)

Checklist:

  • I have read the CONTRIBUTING document.
  • I have run the pre-merge tests locally and they pass.
  • I have updated the documentation accordingly.
  • I have added tests to cover my changes.
  • If Gemfile.lock has changed, I have used --conservative to do it and included the full output in the Description above.
  • All new and existing tests passed.
  • All commits have been signed-off for the Developer Certificate of Origin.

@jaymzjulian jaymzjulian requested review from a team as code owners April 10, 2024 08:02
@jaymzjulian jaymzjulian force-pushed the jj/no-more-choco-search-merging branch from c82da2f to 306427e Compare April 10, 2024 08:30
@jaymzjulian
Copy link
Contributor Author

The kitchen failure seems to be an issue with the test suite:

Run actionshub/chef-install@3.0.0
C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -command ". { iwr -useb https://omnitruck.chef.io/install.ps1 } | iex; install -channel stable -project chef-workstation"

ModuleType Version    Name                                ExportedCommands                                             
---------- -------    ----                                ----------------                                             
Script     0.0        Omnitruck                           {Get-ProjectMetadata, Install-Project, install}              
Installing chef-workstation from C:\Users\RUNNER~1\AppData\Local\Temp\chef-workstation-24.2.[10](https://github.com/chef/chef/actions/runs/8627935942/job/23648911921#step:3:11)58-1-x64.msi
This installation package could not be opened.  Contact the application vendor to verify that this is a valid Windows Installer package.

I don't think i can force it to re-run myself

@johnmccrae
Copy link
Contributor

@jaymzjulian what sets walk_resource_tree: true

@jaymzjulian
Copy link
Contributor Author

jaymzjulian commented Apr 10, 2024 via email

@johnmccrae
Copy link
Contributor

@jaymzjulian Hi, can i ask for a bit more documentation on the walk_resource_tree variable and when we might use it so we have a richer future context?

There was a time when the following worked:

```
choco list -r firefox wireshark
choco search -r firefox wireshark
```

However, it turns out this only worked by accident, not by spec - and this has stopped working now.  It's known to not work, see chocolatey/choco#2116 .  Additionally, the other potential workarounds are also not well supported.  So instead, we tighten the caching a little to at least avoid multiple API requests for the same package, and drop back to single package at a time searches for now, since that's what upstream chocolatey demands.  Once we can fix the issue in chocolatey itself, then we can bring this feature back.

(if you have just teh right server versions, which I did when I was testing, it does work - I was able to reproduce it as a regression, but it turns out what I considered "working" was, in fact, the bug and not the correct behaviour)

Note that this means now you see in debug:
```
[2024-04-10T00:36:54-07:00] INFO: Fetching chocolatey package list
[2024-04-10T00:36:54-07:00] DEBUG: Choco List Command: ["search", "-r", "firefox"]
[2024-04-10T00:36:55-07:00] DEBUG: Choco List Command: ["search", "-r", "wireshark"]
[2024-04-10T00:36:58-07:00] INFO: chocolatey_package[wireshark, firefox] upgraded(allow_downgrade) ["wireshark"] to ["3.0.1"]
```

which is correct per chocolatey spec, sadly.

Signed-off-by: Jaymz Julian <jaymzjulian@meta.com>
@jaymzjulian jaymzjulian force-pushed the jj/no-more-choco-search-merging branch from 306427e to 66138f9 Compare April 10, 2024 18:54
@jaymzjulian
Copy link
Contributor Author

jaymzjulian commented Apr 10, 2024 via email

@johnmccrae
Copy link
Contributor

The 2 failures are related to a yum configuration issue and have nothing to do with the code at hand.

@johnmccrae
Copy link
Contributor

@jaymzjulian I keep getting a failure when I try to add 4 packages. The first package is Babyftp. My recipe block is in the middle of this error. What am I doing wrong?

 bundle exec chef-apply .\choco_tester.rb
ffi-libarchive could not be loaded, libarchive is probably not installed on system, archive_file will not be available
Recipe: (chef-apply cookbook)::(chef-apply recipe)
  * chocolatey_package[install all the things] action install

    ================================================================================
    Error executing action `install` on resource 'chocolatey_package[install all the things]'
    ================================================================================

    Mixlib::ShellOut::ShellCommandFailed
    ------------------------------------
    Expected process to exit with [0, 2], but received '1'
    ---- Begin output of ["C:\\ProgramData\\chocolatey/bin/choco.exe", "install", "-y", "babyftp", "firefox", "winscp", "wireshark"] ----
    STDOUT: Chocolatey v2.2.2
    Installing the following packages:
    babyftp;firefox;winscp;wireshark
    By installing, you accept licenses for the packages.
Progress: Downloading babyftp 1.24... 100%

    babyftp v1.24.0 [Approved]
    babyftp package files install completed. Performing other installation steps.
    babyftp not installed. An error occurred during installation:
     Item has already been added. Key in dictionary: 'PATH'  Key being added: 'Path'

    Chocolatey installed 0/0 packages.
     See the log for details (C:\ProgramData\chocolatey\logs\chocolatey.log).
    The process cannot access the file 'C:\ProgramData\chocolatey\lib\babyftp\.chocolateyPending' because it is being used by another process.
    STDERR:
    ---- End output of ["C:\\ProgramData\\chocolatey/bin/choco.exe", "install", "-y", "babyftp", "firefox", "winscp", "wireshark"] ----
    Ran ["C:\\ProgramData\\chocolatey/bin/choco.exe", "install", "-y", "babyftp", "firefox", "winscp", "wireshark"] returned 1

    Resource Declaration:
    ---------------------
    # In .\choco_tester.rb

      1: chocolatey_package 'install all the things' do
      2:     package_name ['babyftp', 'firefox', 'winscp', 'wireshark']
      3:     action :install
      4: end

    Compiled Resource:
    ------------------
    # Declared in .\choco_tester.rb:1:in `run_chef_recipe'

    chocolatey_package("install all the things") do
      package_name ["babyftp", "firefox", "winscp", "wireshark"]
      action [:install]
      default_guard_interpreter :default
      declared_type :chocolatey_package
      cookbook_name "(chef-apply cookbook)"
      recipe_name "(chef-apply recipe)"
      returns [0, 2]
    end

    System Info:
    ------------
    chef_version=18.4.34
    platform=windows
    platform_version=10.0.22631
    ruby=ruby 3.1.2p20 (2022-04-12 revision 4491bb740a) [x64-mingw-ucrt]
    program_name=C:/Users/JohnMcCrae/AppData/Local/chef/gem/ruby/3.1.0/bin/chef-apply
    executable=C:/Users/JohnMcCrae/AppData/Local/chef/gem/ruby/3.1.0/bin/chef-apply

[2024-04-11T07:31:29-07:00] FATAL: Stacktrace dumped to C:/chef/cache/chef-stacktrace.out
[2024-04-11T07:31:29-07:00] FATAL: ---------------------------------------------------------------------------------------
[2024-04-11T07:31:29-07:00] FATAL: PLEASE PROVIDE THE CONTENTS OF THE stacktrace.out FILE (above) IF YOU FILE A BUG REPORT
[2024-04-11T07:31:29-07:00] FATAL: ---------------------------------------------------------------------------------------
[2024-04-11T07:31:29-07:00] FATAL: Mixlib::ShellOut::ShellCommandFailed: chocolatey_package[install all the things] ((chef-apply cookbook)::(chef-apply recipe) line 1) had an error: Mixlib::ShellOut::ShellCommandFailed: Expected process to exit with [0, 2], but received '1'
---- Begin output of ["C:\\ProgramData\\chocolatey/bin/choco.exe", "install", "-y", "babyftp", "firefox", "winscp", "wireshark"] ----
STDOUT: Chocolatey v2.2.2
Installing the following packages:
babyftp;firefox;winscp;wireshark
By installing, you accept licenses for the packages.
Progress: Downloading babyftp 1.24... 100%

babyftp v1.24.0 [Approved]
babyftp package files install completed. Performing other installation steps.
babyftp not installed. An error occurred during installation:
 Item has already been added. Key in dictionary: 'PATH'  Key being added: 'Path'

Chocolatey installed 0/0 packages.
 See the log for details (C:\ProgramData\chocolatey\logs\chocolatey.log).
The process cannot access the file 'C:\ProgramData\chocolatey\lib\babyftp\.chocolateyPending' because it is being used by another process.
STDERR:
---- End output of ["C:\\ProgramData\\chocolatey/bin/choco.exe", "install", "-y", "babyftp", "firefox", "winscp", "wireshark"] ----
Ran ["C:\\ProgramData\\chocolatey/bin/choco.exe", "install", "-y", "babyftp", "firefox", "winscp", "wireshark"] returned 1

@jaymzjulian
Copy link
Contributor Author

@jaymzjulian I keep getting a failure when I try to add 4 packages. The first package is Babyftp. My recipe block is in the middle of this error. What am I doing wrong?

[... omitted...]

babyftp v1.24.0 [Approved]
babyftp package files install completed. Performing other installation steps.
babyftp not installed. An error occurred during installation:
Item has already been added. Key in dictionary: 'PATH' Key being added: 'Path'

Chocolatey installed 0/0 packages.
See the log for details (C:\ProgramData\chocolatey\logs\chocolatey.log).
The process cannot access the file 'C:\ProgramData\chocolatey\lib\babyftp.chocolateyPending' because it is being used by another process.
STDERR:
---- End output of ["C:\ProgramData\chocolatey/bin/choco.exe", "install", "-y", "babyftp", "firefox", "winscp", "wireshark"] ----
Ran ["C:\ProgramData\chocolatey/bin/choco.exe", "install", "-y", "babyftp", "firefox", "winscp", "wireshark"] returned 1

Thisn is actually a chocolatey bug - you can see that it's doing the right command in your stderr (that's the log bit i left in), but chocolatey nis tripping over itself. Usually it's because the C:\ProgramData\chocolatey\lib\babyftp.chocolateyPending file is left over from an aborted process.

as for the Item has already been added. Key in dictionary: 'PATH' Key being added: 'Path', that error is actually what it says on the box, would you believe - there is an env variable defgined for your user already caled 'Path', but chocolatey wants to use the fully upper case 'PATH'. I don't acutally know why this happens, but I do see it happen regularly as well. To be completly honest, my answe at that point ends up being "clean up your user env variables"

@johnmccrae
Copy link
Contributor

I guess I should have added, @jaymzjulian, that I get that babyftp error the first time I try to add it. Choco leaves garbage behind, I choco uninstall it, I nuke the babyftp directory from the choco cache and try it again and I get the same error.,

@johnmccrae
Copy link
Contributor

This works correctly from a powershell prompt:
choco install -y babyftp firefox winscp wireshark

@jaymzjulian
Copy link
Contributor Author

This works correctly from a powershell prompt: choco install -y babyftp firefox winscp wireshark

Oh that's really interesting - obviously the same command should yield the same result in and out of chef - particular if you can have it happen reliably!

I'll see if I can reproduce this here - one question is if you leave out babyftp, does it work through chef then? I.e. is this babyftp metadata related

@jaymzjulian
Copy link
Contributor Author

chocolatey_package 'install all the things' do
    package_name ['babyftp', 'firefox', 'winscp', 'wireshark']
    action :install
end

results in:

PS C:\Users\jaymzjulianadmin> chef-apply .\testme.rb -l debug
[2024-04-12T01:12:49+01:00] DEBUG: Reading products and relationships...
[2024-04-12T01:12:49+01:00] DEBUG: Successfully read products and relationships
[2024-04-12T01:12:49+01:00] DEBUG: Searching for the following licenses: ["infra-client", "inspec"]
[2024-04-12T01:12:49+01:00] DEBUG: Found license chef_infra_client at C:/Users/jaymzjulianadmin/.chef/accepted_licenses/chef_infra_client
[2024-04-12T01:12:49+01:00] DEBUG: Found license inspec at C:/Users/jaymzjulianadmin/.chef/accepted_licenses/inspec
[2024-04-12T01:12:49+01:00] DEBUG: Missing licenses remaining: []
[2024-04-12T01:12:49+01:00] DEBUG: All licenses present
[2024-04-12T01:12:49+01:00] DEBUG: Running Ohai with the following configuration: {:logger=>#<Mixlib::Log::Child:0x00000000070678c0 @parent=Chef::Log, @metadata={:system=>"ohai", :version=>"17.3.1"}>}
[2024-04-12T01:12:49+01:00] DEBUG: Running Ohai with the following configuration: {:logger=>#<Mixlib::Log::Child:0x00000000070678c0 @parent=Chef::Log, @metadata={:system=>"ohai", :version=>"17.3.1"}>}
C:/opscode/chef/embedded/lib/ruby/gems/3.0.0/gems/ohai-17.3.1/lib/ohai/plugins/hostname.rb:194:in `gethostbyname': warning: Socket.gethostbyname is deprecated; use Addrinfo.getaddrinfo instead. (StructuredWarnings::BuiltInWarning)
[2024-04-12T01:12:56+01:00] DEBUG: Extracting run list from JSON attributes provided on command line
[2024-04-12T01:12:56+01:00] DEBUG: Applying attributes from json file
[2024-04-12T01:12:56+01:00] DEBUG: Platform is windows version 10.0.20348
[2024-04-12T01:12:56+01:00] INFO: Run List is []
[2024-04-12T01:12:56+01:00] INFO: Run List expands to []
Recipe: (chef-apply cookbook)::(chef-apply recipe)
  * chocolatey_package[install all the things] action install[2024-04-12T01:12:56+01:00] INFO: Processing chocolatey_package[install all the things] action install ((chef-apply cookbook)::(chef-apply recipe) line 1)
[2024-04-12T01:12:56+01:00] INFO: Fetching chocolatey package list
[2024-04-12T01:12:57+01:00] DEBUG: Choco List Command: ["search", "-r", "babyftp"]
[2024-04-12T01:12:59+01:00] DEBUG: Choco List Command: ["search", "-r", "firefox"]
[2024-04-12T01:13:02+01:00] DEBUG: Choco List Command: ["search", "-r", "winscp"]
[2024-04-12T01:13:06+01:00] DEBUG: Choco List Command: ["search", "-r", "wireshark"]
[2024-04-12T01:15:00+01:00] INFO: chocolatey_package[install all the things] installed ["babyftp", "firefox", "winscp", "wireshark"] at ["1.24.0", "124.0.2", "5.19.6.1", "3.0.1"]

    - install version 1.24.0 of package babyftp
    - install version 124.0.2 of package firefox
    - install version 5.19.6.1 of package winscp
    - install version 3.0.1 of package wireshark
[2024-04-12T01:15:00+01:00] DEBUG: Exiting

On a fresh windows box with chocolatey 2.2.2. So I do think the issue you're experiencing there is isolated to your system, at least somewhat :(. (which is to say: the initial issue is totally legit!)

@jaymzjulian
Copy link
Contributor Author

action :upgrade also seems to work for me in the same configuration

Copy link
Contributor

@tpowell-progress tpowell-progress left a comment

Choose a reason for hiding this comment

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

I'm going to try @johnmccrae's test a couple of places to double-check

Copy link
Contributor

@tpowell-progress tpowell-progress left a comment

Choose a reason for hiding this comment

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

Also "on" -> "true" suggestion.

@johnmccrae
Copy link
Contributor

@jaymzjulian Hi, can you please fix the DCO bits and take a look at the Windows functional tests. All the choco package stuff is failing there.

Co-authored-by: Thomas Powell <104777878+tpowell-progress@users.noreply.github.com>

Signed-off-by: Jaymz Julian <jaymzjulian@meta.com>
@jaymzjulian jaymzjulian force-pushed the jj/no-more-choco-search-merging branch from cb58ab3 to 1128e85 Compare April 17, 2024 04:29
Copy link

sonarcloud bot commented Apr 17, 2024

Quality Gate Passed Quality Gate passed

Issues
0 New issues
0 Accepted issues

Measures
0 Security Hotspots
No data about Coverage
0.0% Duplication on New Code

See analysis details on SonarCloud

@jaymzjulian
Copy link
Contributor Author

@jaymzjulian Hi, can you please fix the DCO bits and take a look at the Windows functional tests. All the choco package stuff is failing there.

huh, TIL that accepting a correction in github breaks DCO :(

looking at why windows functional tests are failing now - weirdly they weren't earlier in the week!

@jaymzjulian
Copy link
Contributor Author

@jaymzjulian Hi, can you please fix the DCO bits and take a look at the Windows functional tests. All the choco package stuff is failing there.

huh, TIL that accepting a correction in github breaks DCO :(

looking at why windows functional tests are failing now - weirdly they weren't earlier in the week!

Looks like every case passed after re-pushing with the DCO fix. THat said, I did notice something in the logs - i don't think that affects this, but.... just as an FYI as much as anything - this is from win2002 integration in buildkite:

By upgrading, you accept licenses for the packages.
 
You have chocolatey v1.4.0 installed. Version 2.2.2 is available based on your source(s).
Progress: Downloading chocolatey 2.2.2... 100%
 
chocolatey v2.2.2
chocolatey package files upgrade completed. Performing other installation steps.
The registry key for .Net 4.8 was not found or this is forced
Downloading 'https://download.visualstudio.microsoft.com/download/pr/2d6bb6b2-226a-4baa-bdec-798822606ff1/8494001c276a4b96804cde7829c04d7f/ndp48-x86-x64-allos-enu.exe' to 'C:\Users\ContainerAdministrator\AppData\Local\Temp\chocolatey\ndp48-x86-x64-allos-enu.exe' - the installer is 100+ MBs, so this could take a while on a slow connection.
Installing 'C:\Users\ContainerAdministrator\AppData\Local\Temp\chocolatey\ndp48-x86-x64-allos-enu.exe' - this may take awhile with no output.
ERROR: .NET Framework 4.8 was installed, but a reboot is required.
 Please reboot the system and try to install/upgrade Chocolatey again.
The upgrade of chocolatey was NOT successful.
Error while running 'C:\ProgramData\chocolatey\lib\chocolatey\tools\chocolateyInstall.ps1'.
 See log for details.
 
Chocolatey upgraded 0/1 packages. 1 packages failed.
 See the log for details (C:\ProgramData\chocolatey\logs\chocolatey.log).

Other tests are succesfully upgrading to choco2 though, so it's sitll getting exercised at least. I don't know enough about the build kite stuff to easily fix the test :(.

@jaymzjulian
Copy link
Contributor Author

Just checking this isn't waiting on me anymore - is there something else needed here?

@tpowell-progress
Copy link
Contributor

@jaymzjulian the choco install errors are due to the image not having .NET 4.8, so not related to your changes. However, I am not a bit concerned with how well choco is being tested/covered.

@tpowell-progress tpowell-progress merged commit 6a78cc6 into chef:main May 2, 2024
54 checks passed
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.

None yet

4 participants