mirror of
https://github.com/containers/podman.git
synced 2025-10-17 19:24:04 +08:00
System tests: add podman system check
tests
Testing `podman system check` requires that we have a way to intentionally introduce storage corruptions. Add a hidden `podman testing` command that provides the necessary internal logic in subcommands. Stub out the tunnel implementation for now. Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
This commit is contained in:
118
cmd/podman-testing/remove.go
Normal file
118
cmd/podman-testing/remove.go
Normal file
@ -0,0 +1,118 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/containers/common/pkg/completion"
|
||||
"github.com/containers/podman/v5/cmd/podman/validate"
|
||||
"github.com/containers/podman/v5/internal/domain/entities"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
var (
|
||||
removeStorageLayerDescription = `Remove an unmanaged layer in local storage, potentially corrupting it.`
|
||||
removeStorageLayerCmd = &cobra.Command{
|
||||
Use: "remove-storage-layer [options]",
|
||||
Args: validate.NoArgs,
|
||||
Short: "Remove an unmanaged layer",
|
||||
Long: removeStorageLayerDescription,
|
||||
RunE: removeStorageLayer,
|
||||
ValidArgsFunction: completion.AutocompleteNone,
|
||||
Example: `podman testing remove-storage-layer`,
|
||||
}
|
||||
|
||||
removeStorageLayerOpts entities.RemoveStorageLayerOptions
|
||||
|
||||
removeLayerDescription = `Remove a layer in local storage, potentially corrupting it.`
|
||||
removeLayerCmd = &cobra.Command{
|
||||
Use: "remove-layer [options]",
|
||||
Args: validate.NoArgs,
|
||||
Short: "Remove a layer",
|
||||
Long: removeLayerDescription,
|
||||
RunE: removeLayer,
|
||||
ValidArgsFunction: completion.AutocompleteNone,
|
||||
Example: `podman testing remove-layer`,
|
||||
}
|
||||
|
||||
removeLayerOpts entities.RemoveLayerOptions
|
||||
|
||||
removeImageDescription = `Remove an image in local storage, potentially corrupting it.`
|
||||
removeImageCmd = &cobra.Command{
|
||||
Use: "remove-image [options]",
|
||||
Args: validate.NoArgs,
|
||||
Short: "Remove an image",
|
||||
Long: removeImageDescription,
|
||||
RunE: removeImage,
|
||||
ValidArgsFunction: completion.AutocompleteNone,
|
||||
Example: `podman testing remove-image`,
|
||||
}
|
||||
|
||||
removeImageOpts entities.RemoveImageOptions
|
||||
|
||||
removeContainerDescription = `Remove a container in local storage, potentially corrupting it.`
|
||||
removeContainerCmd = &cobra.Command{
|
||||
Use: "remove-container [options]",
|
||||
Args: validate.NoArgs,
|
||||
Short: "Remove an container",
|
||||
Long: removeContainerDescription,
|
||||
RunE: removeContainer,
|
||||
ValidArgsFunction: completion.AutocompleteNone,
|
||||
Example: `podman testing remove-container`,
|
||||
}
|
||||
|
||||
removeContainerOpts entities.RemoveContainerOptions
|
||||
)
|
||||
|
||||
func init() {
|
||||
mainCmd.AddCommand(removeStorageLayerCmd)
|
||||
flags := removeStorageLayerCmd.Flags()
|
||||
flags.StringVarP(&removeStorageLayerOpts.ID, "layer", "i", "", "ID of the layer to remove")
|
||||
|
||||
mainCmd.AddCommand(removeLayerCmd)
|
||||
flags = removeLayerCmd.Flags()
|
||||
flags.StringVarP(&removeLayerOpts.ID, "layer", "i", "", "ID of the layer to remove")
|
||||
|
||||
mainCmd.AddCommand(removeImageCmd)
|
||||
flags = removeImageCmd.Flags()
|
||||
flags.StringVarP(&removeImageOpts.ID, "image", "i", "", "ID of the image to remove")
|
||||
|
||||
mainCmd.AddCommand(removeContainerCmd)
|
||||
flags = removeContainerCmd.Flags()
|
||||
flags.StringVarP(&removeContainerOpts.ID, "container", "i", "", "ID of the container to remove")
|
||||
}
|
||||
|
||||
func removeStorageLayer(cmd *cobra.Command, args []string) error {
|
||||
results, err := testingEngine.RemoveStorageLayer(mainContext, removeStorageLayerOpts)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
fmt.Println(results.ID)
|
||||
return nil
|
||||
}
|
||||
|
||||
func removeLayer(cmd *cobra.Command, args []string) error {
|
||||
results, err := testingEngine.RemoveLayer(mainContext, removeLayerOpts)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
fmt.Println(results.ID)
|
||||
return nil
|
||||
}
|
||||
|
||||
func removeImage(cmd *cobra.Command, args []string) error {
|
||||
results, err := testingEngine.RemoveImage(mainContext, removeImageOpts)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
fmt.Println(results.ID)
|
||||
return nil
|
||||
}
|
||||
|
||||
func removeContainer(cmd *cobra.Command, args []string) error {
|
||||
results, err := testingEngine.RemoveContainer(mainContext, removeContainerOpts)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
fmt.Println(results.ID)
|
||||
return nil
|
||||
}
|
Reference in New Issue
Block a user