Commit Graph
18659 Commits
Author SHA1 Message Date
Lucas Bajolet 615c0a1cf2 packer_test: add PackerCommand on TestDirSpec
Instead of manually invoking ts.PackerCommand().UsePluginDir(), we
introduce a new PackerCommand() function on TestDirSpec which
fast-tracks this common use-case.
2024-08-15 14:28:16 -04:00
Lucas Bajolet 465ec8bae0 packer_test: make PluginTestDir a structure
In order for the creation of a temporary directory to install plugins
into to be simpler to understand and use, we change how the directory is
created, cleaned-up, and installs plugins into.

Now, instead of a tuple of a string (path) and a cleanup function, we
return a structure that comprises the test suite, and the temporary
directory, along with methods to handle those steps independently.
2024-08-15 14:09:33 -04:00
Lucas Bajolet e91558f4d4 packer_test: hide run and introduce Output
When using a PackerCommand, the Run function was made public as a way to
access the contents of an execution.

This was clumsy as it had too many responsabilities, and was not needed
strictly as Assert was performing the executions, as many times as
required.

This could introduce cases in which one run as spent by the caller, then
the remainder were executed through Assert.

Therefore, we change this convention.

Now, run is private to the type, and only through Assert can a command
be executed.
If a test needs access to a command's output, stderr, or error, it can
do so through the Output function, which requires Assert to be called
first.
2024-08-15 10:51:30 -04:00
Lucas Bajolet ae792299dc packer_test: add func to change assert behaviour
When a command asserts its output with checkers, by default it will
register errors through a t.Errorf.

While this works, in some cases we would want to stop execution
immediately if a function's Assert fails, as the rest of the test may
depend on the assertion being valid.

In the current state, this means either getting the result of the run to
check if an error was returned (not fully reliable as if the command was
run multiple times, and the last run succeeded, we won't get an error),
or relying on t.IsFailed() (completely reliable).

Instead, we introduce a new function on packerCommand, that lets users
change how Assert behaves, so that if an error was reported, instead of
logging the error and flagging the test as failed, we can use t.Fatalf,
so that the test immedately fails and stops execution.
2024-08-15 10:51:30 -04:00
Lucas Bajolet c3ef682a8b packer_test: rename/split lib into common/check
The lib name for the common components for writing packer_test suites
was not clear, and did not follow the convention established in Packer
core and plugins.
Therefore this commit does two things: first the lib is renamed into
common as to follow this convention, and clearly document which
components are common to all tests.
Also checkers are placed in a subpackage of common, common/check, so
that it is clearer what is meant to be used as checks for a command's
execution status after it's been run, as part of Assert.
2024-08-15 10:05:27 -04:00
Lucas Bajolet 098737aef9 packer_test: rename core test run function
The function's name was the same as the plugins test suite runner/init
function, making it impossible to differentiate between the two when
looking at the logs, or when attempting to filter which tests to run
using the suite function's name.
2024-08-14 16:19:22 -04:00
Lucas Bajolet 16de9e059c packer_test: reorganise plugins test suite init 2024-08-14 16:18:24 -04:00
Lucas Bajolet 1332690828 packer_test: remove empty defer func in suite init 2024-08-14 16:17:49 -04:00
Lucas Bajolet 7d176daef0 packer_test: split BuildPackerPlugin in build/get
The interface for building a plugin through the test suite was
confusing, as it would build the plugin and return its path, cache the
path for the version built, and return the path regardless if something
was built or not.

While in the current state this is harmless as builds are idempotent,
since the state of the plugin package/module does not change, this will
in the future as we introduce customisation techniques on the plugin's
directory and files, making this double-use potentially dangerous.

Furthermore, the current behaviour is unclear, as the function hides
that caching mechanism, which could come as a surprise for users
attempting to build a plugin for the duration of a test, while the built
plugin is linked to the test suite being run, and not the unit test
being evaluated.

Therefore this commit changes the sequence in which plugins are built
and used. Now the `CompilePlugin` function builds a plugin, and does not
return its path anymore, instead terminating the tests immediately if
they fail.
In normal test usage, a new `GetPluginPath` function is introduced,
which looks-up the path in the suite's cache, failing immediately if
invoked before the plugin is built.

With this change, it is heavily advised to build plugins when
initialising the suite, then in the tests, the GetPluginPath function
should be used to get a plugin's path for interacting with packer
commands.
2024-08-14 16:12:53 -04:00
Lucas Bajolet 728a5fc19e packer_test: replace compiledPlugins by a sync.Map
The compiledPlugins map with a mutex was essentially a glorified
sync.Map, and therefore did not need to be defined as such.
Instead, this commit replaces its uses by a normal sync.Map, and keeps
it in the base test suite.
2024-08-14 16:06:46 -04:00
Lucas Bajolet 950c255d03 packer_test: rename init function for base suite 2024-08-14 15:51:47 -04:00
Lucas Bajolet b4814354c0 packer_test: add convenience func for invert grep
As inverted grep is something we do rather often, we add a convenience
function to create an inverted grep gadget.
2024-08-14 15:50:53 -04:00
Wenfeng Pan 1b160e5df0 Add base64gzip function support to Packer template 2024-08-13 14:53:29 -04:00
Lucas Bajolet ded0500109 packer_test: add plugins used gadget
When testing a packer build or validate, one common use case is to check
which plugins are loaded and used by Packer to run a command.

This is generally done through Grep, but repeating the same pattern can
be redundant, and if the output changes, all those need to be updated.

Therefore, this commit introduces a PluginsUsed gadget, which can be
orchestrated to ensure a plugin is used, or not used, allowing to check
for multiple plugins at once.
2024-08-13 14:52:43 -04:00
Lucas Bajolet 6b158c5c24 packer_test: move some plugin functions to fs.go
As a small reorganisation attempt, this commit moves some file-system
oriented functions from plugin.go into its own file so they are more
logically grouped.
2024-08-13 14:52:43 -04:00
Lucas Bajolet 96b4ae4767 packer_test: move BuildSimplePlugin to plugin.go
In terms of organisation, we keep functions that interact with plugins
into its own file, therefore the function that build plugin versions
should really be in plugin.go, not in suite.go.
2024-08-13 14:52:43 -04:00
Lucas Bajolet 2fe11fb967 packer_test: move compiledPlugins to attribute
The compiledPlugins map used to be a global variable, which can be
problematic as we move to independent test suites, since those test
suites run in the same process space, the global variable could point to
now deleted plugin versions/paths in separate suites, which would make
tests fail with random errors.

To avoid this, the map is now scoped to the test suite, and a new copy
is created lazily if used by the test suite.
2024-08-13 14:52:43 -04:00
Lucas Bajolet 9e4452329f packer_test: make packer test suite modular
Having only one test suite for the whole of Packer makes it harder to
segregate between test types, and makes for a longer runtime as no tests
run in parallel by default.

This commit splits the packer_test suite into several components in
order to make extension easier.

First we have `lib`: this package embeds the core for running Packer
test suites. This ships facilities to build your own test suite for
Packer core, and exposes convenience methods and structures for building
plugins, packer core, and use it to run a test suite in a temporary
directory.

Then we have two separate test suites: one for plugins, and one for core
itself, the latter of which does not depend on plugins being compiled at
all.

This sets the stage for more specialised test suites in the future, each
of which can run in parallel on different parts of the code.
2024-08-13 14:52:43 -04:00
Wilken Rivera 2a206ccd68 Enable github workflows on feature branches 2024-08-12 16:07:28 -04:00
Lucas Bajolet 199a751353 docs: remove trailing whitespaces from the docs 2024-08-08 10:14:20 -04:00
Lucas Bajolet 6514a66131 docs: update manually installing plugins docs
The installing plugins docs had information on manually installing
plugins that was misleading a bit, so we update that section with this
commit.
2024-08-08 10:14:20 -04:00
dependabot[bot] a1caaad47d build(deps): bump github.com/hashicorp/hcp-sdk-go from 0.99.0 to 0.105.0 (#13129)
Bumps [github.com/hashicorp/hcp-sdk-go](https://github.com/hashicorp/hcp-sdk-go) from 0.99.0 to 0.105.0.
- [Release notes](https://github.com/hashicorp/hcp-sdk-go/releases)
- [Changelog](https://github.com/hashicorp/hcp-sdk-go/blob/main/CHANGELOG.md)
- [Commits](https://github.com/hashicorp/hcp-sdk-go/compare/v0.99.0...v0.105.0)

---
updated-dependencies:
- dependency-name: github.com/hashicorp/hcp-sdk-go
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2024-08-05 14:04:28 -04:00
hashicorp-tsccr[bot]andhashicorp-tsccr[bot] eb77d54973 Result of tsccr-helper -log-level=info gha update . (#13131)
Co-authored-by: hashicorp-tsccr[bot] <hashicorp-tsccr[bot]@users.noreply.github.com>
2024-08-05 14:03:40 -04:00
Jeanne Angeles Franco 6f3aab147d Add artifacts manifest (automatically generated) (#13132)
* Add artifacts manifest (automatically generated)

* add copyright header
2024-08-05 14:02:39 -04:00
Lucas Bajolet 85b0325309 CHANGELOG: update for 1.11.2 release 2024-07-30 09:47:58 -04:00
Devashish 265dfe105a Remove suffix from CICD platform type (#13121) 2024-07-25 18:15:56 +05:30
Wilken Rivera c7dd5af450 Enable ci builds for feature branches 2024-07-24 16:43:10 -04:00
Devashish aa6c5f8405 feat: Phase 2 Extension of Build Metadata (#13092) 2024-07-22 23:08:14 +05:30
Lucas Bajolet 3e3b136f3c packer: address unused lint errors 2024-07-18 10:51:17 -04:00
Lucas Bajolet 962ccdfc80 packer: address gosimple lint errors 2024-07-18 10:51:17 -04:00
Lucas Bajolet e8d3a55b5f packer: address errcheck lint errors
In a couple places in the codebase we didn't check the errors from
functions we execute.

In some cases this is harmless (or at least ignorable), but others may
need to log what went wrong, so for all the reported occurrences we
either ignore explicitly or handle the error with a log.
2024-07-18 10:51:17 -04:00
Lucas Bajolet 805015c360 log: simplify the logOutput function
The logOutput function had a bunch of nested checks in the code for the
function, as well as one ineffasign pointed out by golangci-lint.

This commit changes how special cases are processed, and changes a bit
how log redirection to a file is handled.
Prior to this commit, only when PACKER_LOG and PACKER_LOG_FILE are set
does Packer redirect logs to the specified path, which is a bit
superfluous as setting PACKER_LOG_FILE should be enough on its own to
redirect logs and enable verbose logs.

Now, when neither is set, no logOutput is set, if PACKER_LOG_FILE is set
(regardless of PACKER_LOG), we redirect to the specified file, and
finally if PACKER_LOG is set, we redirect to stderr.
2024-07-18 10:51:17 -04:00
Lucas Bajolet 2009079246 packer: remove ineffasign pointed assigns/decls
Some of the variables we create are flagged by our linters as
ineffective assignments, which makes sense as those are generally fed by
code below, so we don't need to use the declaration/assignation syntax
(:=) but instead can fall back to using var with a type to get the zero
value of the declared entity.
2024-07-18 10:51:17 -04:00
Lucas Bajolet 02ac9628cc golangci.yml: add rule to not run errcheck on test
Test files have some calls that don't necessarily get checked since they
have a very low probability to fail, and in a testing environment it's
acceptable to not have bulletproof code.

Therefore, we add a rule to not run that check on any file that ends
with `_test.go` (Go test convention), so the linter isn't as noisy as it
used to be.
2024-07-18 10:51:17 -04:00
Lucas Bajolet 4a7f5f38a6 Makefile: replace enumer upstream with dmarkham's (#13107)
Since the enumer implementation we used hadn't been updated for 5+
years, this didn't work with recent linux/go versions, and enumer
crashed while attempting to parse/analyse the source files.

There's another alternative on Github, forked from the one we used,
which seems more maintained now, and does produce the expected files in
Packer.
2024-07-16 21:14:27 -04:00
Jamie Finnigan ae367bc114 .go-version: bump version of Go to 1.21.12 2024-07-03 13:11:45 -04:00
Wilken Rivera 1e446de977 Update CHANGELOG post 1.11.1 release 2024-07-01 12:57:21 -04:00
dependabot[bot] 7425ef3a45 build(deps): bump github.com/hashicorp/go-retryablehttp
Bumps [github.com/hashicorp/go-retryablehttp](https://github.com/hashicorp/go-retryablehttp) from 0.7.0 to 0.7.7.
- [Changelog](https://github.com/hashicorp/go-retryablehttp/blob/main/CHANGELOG.md)
- [Commits](https://github.com/hashicorp/go-retryablehttp/compare/v0.7.0...v0.7.7)

---
updated-dependencies:
- dependency-name: github.com/hashicorp/go-retryablehttp
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <[email protected]>
2024-07-01 12:50:39 -04:00
hashicorp-tsccr[bot] 863f3b0422 Result of tsccr-helper -log-level=info gha update . 2024-07-01 12:49:51 -04:00
Wilken Rivera 986b5c01ce Add entry for go-retryablehttp bump 2024-07-01 09:10:47 -04:00
Wilken Rivera 1bc0099c46 Update CHANGELOG 2024-07-01 09:10:47 -04:00
Wilken Rivera cceead82aa Bump github.com/hashicorp/go-retryablehttp to address CVE-2024-6104 (#13081)
Before change
```
~>  govulncheck ./...
=== Symbol Results ===

Vulnerability #1: GO-2024-2947
    Leak of sensitive information to log files in
    github.com/hashicorp/go-retryablehttp
  More info: https://pkg.go.dev/vuln/GO-2024-2947
  Module: github.com/hashicorp/go-retryablehttp
    Found in: github.com/hashicorp/[email protected]
    Fixed in: github.com/hashicorp/[email protected]
    Example traces found:
      #1: hcl2template/function/vault.go:30:30: function.init calls template.Vault, which eventually calls retryablehttp.Client.Do

Your code is affected by 1 vulnerability from 1 module.
```

After Change
```
~>  govulncheck ./...
No vulnerabilities found.
```
2024-06-28 13:57:52 -04:00
graevyandWilken Rivera e4ec754985 doc fix for unattended debian/ubuntu installer linkrot (#13023)
* doc fix for unattended debian/ubuntu installer linkrot

the links for chef-maintained preseeds/autoinstallers for debian/ubuntu both rotted. i'm just getting started with packer, so i hope this edit is accurate.

* Remove webarchive links for legacy JSON

When possible point users to HCL2 templates for getting started examples.

* As per the style guide aim for inclusive language

---------

Co-authored-by: Wilken Rivera <[email protected]>
2024-06-21 16:00:38 -04:00
dependabot[bot] 0f223cc9ac build(deps): bump google.golang.org/protobuf
Bumps google.golang.org/protobuf from 1.28.1 to 1.33.0.

---
updated-dependencies:
- dependency-name: google.golang.org/protobuf
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <[email protected]>
2024-06-21 15:48:19 -04:00
dependabot[bot] bf5555f0fb build(deps): bump github.com/hashicorp/hcp-sdk-go from 0.96.0 to 0.99.0
Bumps [github.com/hashicorp/hcp-sdk-go](https://github.com/hashicorp/hcp-sdk-go) from 0.96.0 to 0.99.0.
- [Release notes](https://github.com/hashicorp/hcp-sdk-go/releases)
- [Changelog](https://github.com/hashicorp/hcp-sdk-go/blob/main/CHANGELOG.md)
- [Commits](https://github.com/hashicorp/hcp-sdk-go/compare/v0.96.0...v0.99.0)

---
updated-dependencies:
- dependency-name: github.com/hashicorp/hcp-sdk-go
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <[email protected]>
2024-06-21 13:12:16 -04:00
Jenna Goldstrich 078ad45860 HCP Packer Buckets: Change UpsertBucket to call GetBucket (#13059)
* Update UpsertBucket to first call GetBucket, this will allow bucket level role based authentication, as CreateBucket uses project level auth

* Fix one incorrect test failure message
2024-06-21 08:28:09 -07:00
dependabot[bot]andWilken Rivera dd3b2e51f0 build(deps): bump github.com/hashicorp/packer-plugin-sdk from 0.5.3 to 0.5.4 (#13061)
* build(deps): bump github.com/hashicorp/packer-plugin-sdk

Bumps [github.com/hashicorp/packer-plugin-sdk](https://github.com/hashicorp/packer-plugin-sdk) from 0.5.3 to 0.5.4.
- [Release notes](https://github.com/hashicorp/packer-plugin-sdk/releases)
- [Changelog](https://github.com/hashicorp/packer-plugin-sdk/blob/main/CHANGELOG.md)
- [Commits](https://github.com/hashicorp/packer-plugin-sdk/compare/v0.5.3...v0.5.4)

---
updated-dependencies:
- dependency-name: github.com/hashicorp/packer-plugin-sdk
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <[email protected]>

* Bump Go mod version to 1.21.0

---------

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Wilken Rivera <[email protected]>
2024-06-20 14:12:49 -04:00
Wilken RiveraandLucas Bajolet d406613387 Document use of TMPDIR required for remote plugin installation (#13056)
* Document use of TMPDIR required for remote plugin installation

* Update website/content/docs/configure.mdx

Co-authored-by: Lucas Bajolet <[email protected]>

---------

Co-authored-by: Lucas Bajolet <[email protected]>
2024-06-17 17:32:42 -04:00
dependabot[bot] 5843c86c7e build(deps): bump google.golang.org/grpc in /packer_test/plugin_tester
Bumps [google.golang.org/grpc](https://github.com/grpc/grpc-go) from 1.50.1 to 1.56.3.
- [Release notes](https://github.com/grpc/grpc-go/releases)
- [Commits](https://github.com/grpc/grpc-go/compare/v1.50.1...v1.56.3)

---
updated-dependencies:
- dependency-name: google.golang.org/grpc
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <[email protected]>
2024-06-17 16:57:01 -04:00
Lucas Bajolet 13c52124de packer_test: check for a panic during execution
When a command is run, it is the expectation that no test should make
Packer panic. If it did, something is wrong and Packer should be fixed
so it doesn't panic anymore in that situation.

The way we did the check before was adding a PanicCheck after the
command ran, so we could make sure of that during `Assert`.

However, since we introduced the possibility to have multiple runs,
having this addition as part of the run loop meant that the PanicCheck
would be run as many times as there were runs.

While this worked, this implied that we'd do the same check multiple
times on a single command output, which is not optimal.

Instead, this commit moves the check to within the `Run` function, this
way for each run of the command we do the check once, and then we can
assert the results of the command on what output it produced.
2024-06-17 16:51:58 -04:00