Merge pull request #16223 from vrothberg/quadlet

move quadlet packages into pkg/systemd
This commit is contained in:
OpenShift Merge Robot
2022-10-19 09:58:43 -04:00
committed by GitHub
11 changed files with 24 additions and 24 deletions

View File

@ -9,8 +9,8 @@ import (
"path/filepath"
"strings"
"github.com/containers/podman/v4/pkg/quadlet"
"github.com/containers/podman/v4/pkg/systemdparser"
"github.com/containers/podman/v4/pkg/systemd/parser"
"github.com/containers/podman/v4/pkg/systemd/quadlet"
)
// This commandline app is the systemd generator (system and user,
@ -103,7 +103,7 @@ func getUnitDirs(user bool) []string {
return dirs
}
func loadUnitsFromDir(sourcePath string, units map[string]*systemdparser.UnitFile) {
func loadUnitsFromDir(sourcePath string, units map[string]*parser.UnitFile) {
files, err := os.ReadDir(sourcePath)
if err != nil {
if !errors.Is(err, os.ErrNotExist) {
@ -121,7 +121,7 @@ func loadUnitsFromDir(sourcePath string, units map[string]*systemdparser.UnitFil
Debugf("Loading source unit file %s", path)
if f, err := systemdparser.ParseUnitFile(path); err != nil {
if f, err := parser.ParseUnitFile(path); err != nil {
Logf("Error loading '%s', ignoring: %s", path, err)
} else {
units[name] = f
@ -130,7 +130,7 @@ func loadUnitsFromDir(sourcePath string, units map[string]*systemdparser.UnitFil
}
}
func generateServiceFile(service *systemdparser.UnitFile) error {
func generateServiceFile(service *parser.UnitFile) error {
Debugf("writing '%s'", service.Path)
service.PrependComment("",
@ -161,7 +161,7 @@ func generateServiceFile(service *systemdparser.UnitFile) error {
// symlinks to get systemd to start the newly generated file as needed.
// In a traditional setup this is done by "systemctl enable", but that doesn't
// work for auto-generated files like these.
func enableServiceFile(outputPath string, service *systemdparser.UnitFile) {
func enableServiceFile(outputPath string, service *parser.UnitFile) {
symlinks := make([]string, 0)
aliases := service.LookupAllStrv(quadlet.InstallGroup, "Alias")
@ -230,7 +230,7 @@ func main() {
sourcePaths := getUnitDirs(isUser)
units := make(map[string]*systemdparser.UnitFile)
units := make(map[string]*parser.UnitFile)
for _, d := range sourcePaths {
loadUnitsFromDir(d, units)
}
@ -242,7 +242,7 @@ func main() {
}
for name, unit := range units {
var service *systemdparser.UnitFile
var service *parser.UnitFile
var err error
switch {

View File

@ -1,4 +1,4 @@
package systemdparser
package parser
import (
"fmt"

View File

@ -1,4 +1,4 @@
package systemdparser
package parser
import (
"fmt"

View File

@ -1,4 +1,4 @@
package systemdparser
package parser
import (
"testing"

View File

@ -8,7 +8,7 @@ import (
"strings"
"unicode"
"github.com/containers/podman/v4/pkg/systemdparser"
"github.com/containers/podman/v4/pkg/systemd/parser"
)
// Overwritten at build time:
@ -152,7 +152,7 @@ func isPortRange(port string) bool {
return validPortRange.MatchString(port)
}
func checkForUnknownKeys(unit *systemdparser.UnitFile, groupName string, supportedKeys map[string]bool) error {
func checkForUnknownKeys(unit *parser.UnitFile, groupName string, supportedKeys map[string]bool) error {
keys := unit.ListKeys(groupName)
for _, key := range keys {
if !supportedKeys[key] {
@ -162,7 +162,7 @@ func checkForUnknownKeys(unit *systemdparser.UnitFile, groupName string, support
return nil
}
func lookupRanges(unit *systemdparser.UnitFile, groupName string, key string, nameLookup func(string) *Ranges, defaultValue *Ranges) *Ranges {
func lookupRanges(unit *parser.UnitFile, groupName string, key string, nameLookup func(string) *Ranges, defaultValue *Ranges) *Ranges {
v, ok := unit.Lookup(groupName, key)
if !ok {
if defaultValue != nil {
@ -277,7 +277,7 @@ func addIDMaps(podman *PodmanCmdline, argPrefix string, containerID, hostID, rem
// service file (unit file with Service group) based on the options in the
// Container group.
// The original Container group is kept around as X-Container.
func ConvertContainer(container *systemdparser.UnitFile, isUser bool) (*systemdparser.UnitFile, error) {
func ConvertContainer(container *parser.UnitFile, isUser bool) (*parser.UnitFile, error) {
service := container.Dup()
service.Filename = replaceExtension(container.Filename, ".service", "", "")
@ -643,7 +643,7 @@ func ConvertContainer(container *systemdparser.UnitFile, isUser bool) (*systemdp
// service file (unit file with Service group) based on the options in the
// Volume group.
// The original Container group is kept around as X-Container.
func ConvertVolume(volume *systemdparser.UnitFile, name string) (*systemdparser.UnitFile, error) {
func ConvertVolume(volume *parser.UnitFile, name string) (*parser.UnitFile, error) {
service := volume.Dup()
service.Filename = replaceExtension(volume.Filename, ".service", "", "-volume")

View File

@ -6,7 +6,7 @@ import (
"path/filepath"
"strings"
"github.com/containers/podman/v4/pkg/systemdparser"
"github.com/containers/podman/v4/pkg/systemd/parser"
"github.com/mattn/go-shellwords"
. "github.com/containers/podman/v4/test/utils"
@ -83,7 +83,7 @@ func (t *quadletTestcase) assertStdErrContains(args []string, session *PodmanSes
return strings.Contains(session.OutputToString(), args[0])
}
func (t *quadletTestcase) assertKeyIs(args []string, unit *systemdparser.UnitFile) bool {
func (t *quadletTestcase) assertKeyIs(args []string, unit *parser.UnitFile) bool {
group := args[0]
key := args[1]
values := args[2:]
@ -101,7 +101,7 @@ func (t *quadletTestcase) assertKeyIs(args []string, unit *systemdparser.UnitFil
return true
}
func (t *quadletTestcase) assertKeyContains(args []string, unit *systemdparser.UnitFile) bool {
func (t *quadletTestcase) assertKeyContains(args []string, unit *parser.UnitFile) bool {
group := args[0]
key := args[1]
value := args[2]
@ -110,12 +110,12 @@ func (t *quadletTestcase) assertKeyContains(args []string, unit *systemdparser.U
return ok && strings.Contains(realValue, value)
}
func (t *quadletTestcase) assertPodmanArgs(args []string, unit *systemdparser.UnitFile) bool {
func (t *quadletTestcase) assertPodmanArgs(args []string, unit *parser.UnitFile) bool {
podmanArgs, _ := unit.LookupLastArgs("Service", "ExecStart")
return findSublist(podmanArgs, args) != -1
}
func (t *quadletTestcase) assertFinalArgs(args []string, unit *systemdparser.UnitFile) bool {
func (t *quadletTestcase) assertFinalArgs(args []string, unit *parser.UnitFile) bool {
podmanArgs, _ := unit.LookupLastArgs("Service", "ExecStart")
if len(podmanArgs) < len(args) {
return false
@ -123,7 +123,7 @@ func (t *quadletTestcase) assertFinalArgs(args []string, unit *systemdparser.Uni
return matchSublistAt(podmanArgs, len(podmanArgs)-len(args), args)
}
func (t *quadletTestcase) assertSymlink(args []string, unit *systemdparser.UnitFile) bool {
func (t *quadletTestcase) assertSymlink(args []string, unit *parser.UnitFile) bool {
symlink := args[0]
expectedTarget := args[1]
@ -135,7 +135,7 @@ func (t *quadletTestcase) assertSymlink(args []string, unit *systemdparser.UnitF
return expectedTarget == target
}
func (t *quadletTestcase) doAssert(check []string, unit *systemdparser.UnitFile, session *PodmanSessionIntegration) error {
func (t *quadletTestcase) doAssert(check []string, unit *parser.UnitFile, session *PodmanSessionIntegration) error {
op := check[0]
args := make([]string, 0)
for _, a := range check[1:] {
@ -193,7 +193,7 @@ func (t *quadletTestcase) check(generateDir string, session *PodmanSessionIntegr
return // Successful fail
}
unit, err := systemdparser.ParseUnitFile(file)
unit, err := parser.ParseUnitFile(file)
Expect(err).To(BeNil())
for _, check := range t.checks {