bolt icon indicating copy to clipboard operation
bolt copied to clipboard

A function to delete a file on a target (`delete_file()`)

Open jay7x opened this issue 2 years ago • 11 comments

Use Case

It'd be nice to be able to delete a file from a target. We have upload/download/write functions but there is nothing to delete..

Describe the Solution You Would Like

I'd be happy to have the delete_file() function which deletes the file specified on the targets specified

delete_file($filename, $targets, $options) => ResultSet

Describe Alternatives You've Considered

It's possible to work this around with run_command though it doesn't look great:

run_command("rm -f -- '${filename}'", $targets)

Additional Context

The ability to delete a file was required to cleanup a temporary file which is passed to another program to consume it. The file can be deleted after. So actually maybe we need a mktemp() function too. Or, as proposed in Slack:

with_tempfile() |$file| {
 # ...
}

Here is the discussion related: https://puppetcommunity.slack.com/archives/C7GP57T50/p1675006959793689

jay7x avatar Apr 11 '23 15:04 jay7x

@jay7x If no ones doing this already could I be assigned to this issue?

pdthomson avatar Apr 22 '23 00:04 pdthomson

@jay7x If no ones doing this already could I be assigned to this issue?

Hi @pdthomson! I don't think anyone is working on this at the moment.. Please feel free to do a PR! Thank you!

jay7x avatar Apr 22 '23 07:04 jay7x

Hey @jay7x I have went through the set up documentation on the github repo and was running the tests and getting a lot of failures, I have mocked out some code and wanted to write a delete_file_spec.rb in the bolt-modules/boltlib/spec/functions but I cant get any of those tests to even pass currently and it seems I must be missing something with the initial setup as this is my first contribution.

NameError:
  uninitialized constant PuppetlabsSpec
# ./bolt-modules/boltlib/spec/functions/vars_spec.rb:8:in `block in <top (required)>'
# ./bolt-modules/boltlib/spec/functions/vars_spec.rb:7:in `<top (required)>'

An error occurred while loading ./bolt-modules/boltlib/spec/functions/wait_spec.rb.
Failure/Error: include PuppetlabsSpec::Fixtures

Ive done a bunch of reading on bolt/puppet and scrolled through the slack to find any similar issues, as I am sure I am missing something easy or running a command incorrectly

pdthomson avatar Apr 25 '23 02:04 pdthomson

Hi @pdthomson! Somehow it was fine for me last time few month ago.. 🤔 let me try to setup the environment again. I'll update you here..

jay7x avatar Apr 25 '23 14:04 jay7x

Well.. here is what I did:

bundle install --path=.bundle --with test
bundle exec r10k puppetfile install .
cd bolt-modules/boltlib/
bundle exec rake spec

This way those tests are fine for me on ruby 2.7.7p221 (2022-11-24 revision 168ec2b1e5) [arm64-darwin21].

Though I guess you'll need to change transport-related classes too.. so it seems you need to spin up the docker-compose infra (docker-compose -f spec/docker-compose.yml up -d --build). Though it works for x86_64 arch only.. those containers don't have arm64 versions. So I cannot run it at the moment.

This repo has CI/CD configured which can be used to run the tests for now..

jay7x avatar Apr 25 '23 18:04 jay7x

I asked someone from the Bolt team to have a look here just in case. So you can get the support from them. Feel free to jump in to the #bolt channel on the Puppet Community Slack! And maybe register here for the Puppet Hackathon as you're heading to do things anyway: https://dev.to/puppet/may-the-source-be-with-you-45bi :)

jay7x avatar Apr 25 '23 19:04 jay7x

I experience some breakage now that puppetlabs/puppet has a 8.0.0 tag. Adding gem 'puppet', '< 8.0.0' to the Gemfile somehow helps, but in any case, the whole tests suite does not pass on my machine (some tests have some requirements)!

smortex avatar Apr 25 '23 19:04 smortex

Oh perfect! I went ahead and registered for the Hackathon! I will spin up the docker container again and add gem 'puppet', '< 8.0.0' into the gem file and give it a go. Oh perfect having the CI/CD I can test against that so I should be good to go then.

pdthomson avatar Apr 27 '23 01:04 pdthomson

Aaaand.. I hit this again! :(

@pdthomson By any chance, have you anything done wrt this? Some work-in-progress branch maybe?

jay7x avatar Mar 29 '24 21:03 jay7x

@pdthomson just to check in on this and see if you had any work in progress branch or such like?

davidsandilands avatar Jun 19 '24 14:06 davidsandilands