mirror of
https://github.com/containers/podman.git
synced 2025-06-26 21:07:02 +08:00
Merge pull request #19666 from ashley-cui/testinit
Update machine init and set tests
This commit is contained in:
@ -23,18 +23,19 @@ Rootless only.
|
|||||||
|
|
||||||
Print results with a Go template.
|
Print results with a Go template.
|
||||||
|
|
||||||
| **Placeholder** | **Description** |
|
| **Placeholder** | **Description** |
|
||||||
| ------------------- | ----------------------------------------------------- |
|
| ------------------- | --------------------------------------------------------------------- |
|
||||||
| .ConfigPath ... | Machine configuration file location |
|
| .ConfigPath ... | Machine configuration file location |
|
||||||
| .ConnectionInfo ... | Machine connection information |
|
| .ConnectionInfo ... | Machine connection information |
|
||||||
| .Created | Machine creation time (string, ISO3601) |
|
| .Created | Machine creation time (string, ISO3601) |
|
||||||
| .Image ... | Machine image config |
|
| .Image ... | Machine image config |
|
||||||
| .LastUp | Time when machine was last booted |
|
| .LastUp | Time when machine was last booted |
|
||||||
| .Name | Name of the machine |
|
| .Name | Name of the machine |
|
||||||
| .Resources ... | Resources used by the machine |
|
| .Resources ... | Resources used by the machine |
|
||||||
| .SSHConfig ... | SSH configuration info for communitating with machine |
|
| .Rootful | Whether the machine prefers rootful or rootless container execution |
|
||||||
| .State ... | Machine state |
|
| .SSHConfig ... | SSH configuration info for communitating with machine |
|
||||||
| .UserModeNetworking | Whether this machine uses user-mode networking |
|
| .State ... | Machine state |
|
||||||
|
| .UserModeNetworking | Whether this machine uses user-mode networking |
|
||||||
|
|
||||||
#### **--help**
|
#### **--help**
|
||||||
|
|
||||||
|
@ -317,6 +317,7 @@ func (m *MacMachine) Inspect() (*machine.InspectInfo, error) {
|
|||||||
},
|
},
|
||||||
SSHConfig: m.SSHConfig,
|
SSHConfig: m.SSHConfig,
|
||||||
State: vmState,
|
State: vmState,
|
||||||
|
Rootful: m.Rootful,
|
||||||
}
|
}
|
||||||
return &ii, nil
|
return &ii, nil
|
||||||
}
|
}
|
||||||
|
@ -151,6 +151,7 @@ type InspectInfo struct {
|
|||||||
SSHConfig SSHConfig
|
SSHConfig SSHConfig
|
||||||
State Status
|
State Status
|
||||||
UserModeNetworking bool
|
UserModeNetworking bool
|
||||||
|
Rootful bool
|
||||||
}
|
}
|
||||||
|
|
||||||
func (rc RemoteConnectionType) MakeSSHURL(host, path, port, userName string) url.URL {
|
func (rc RemoteConnectionType) MakeSSHURL(host, path, port, userName string) url.URL {
|
||||||
|
@ -19,16 +19,17 @@ type initMachine struct {
|
|||||||
--volume-driver string Optional volume driver
|
--volume-driver string Optional volume driver
|
||||||
|
|
||||||
*/
|
*/
|
||||||
cpus *uint
|
cpus *uint
|
||||||
diskSize *uint
|
diskSize *uint
|
||||||
ignitionPath string
|
ignitionPath string
|
||||||
username string
|
username string
|
||||||
imagePath string
|
imagePath string
|
||||||
memory *uint
|
memory *uint
|
||||||
now bool
|
now bool
|
||||||
timezone string
|
timezone string
|
||||||
rootful bool
|
rootful bool
|
||||||
volumes []string
|
volumes []string
|
||||||
|
userModeNetworking bool
|
||||||
|
|
||||||
cmd []string
|
cmd []string
|
||||||
}
|
}
|
||||||
@ -65,6 +66,9 @@ func (i *initMachine) buildCmd(m *machineTestBuilder) []string {
|
|||||||
if i.rootful {
|
if i.rootful {
|
||||||
cmd = append(cmd, "--rootful")
|
cmd = append(cmd, "--rootful")
|
||||||
}
|
}
|
||||||
|
if i.userModeNetworking {
|
||||||
|
cmd = append(cmd, "--user-mode-networking")
|
||||||
|
}
|
||||||
cmd = append(cmd, m.name)
|
cmd = append(cmd, m.name)
|
||||||
i.cmd = cmd
|
i.cmd = cmd
|
||||||
return cmd
|
return cmd
|
||||||
@ -118,3 +122,8 @@ func (i *initMachine) withRootful(r bool) *initMachine {
|
|||||||
i.rootful = r
|
i.rootful = r
|
||||||
return i
|
return i
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (i *initMachine) withUserModeNetworking(r bool) *initMachine {
|
||||||
|
i.userModeNetworking = r
|
||||||
|
return i
|
||||||
|
}
|
||||||
|
@ -5,10 +5,11 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type setMachine struct {
|
type setMachine struct {
|
||||||
cpus *uint
|
cpus *uint
|
||||||
diskSize *uint
|
diskSize *uint
|
||||||
memory *uint
|
memory *uint
|
||||||
rootful bool
|
rootful bool
|
||||||
|
userModeNetworking bool
|
||||||
|
|
||||||
cmd []string
|
cmd []string
|
||||||
}
|
}
|
||||||
@ -27,6 +28,9 @@ func (i *setMachine) buildCmd(m *machineTestBuilder) []string {
|
|||||||
if i.rootful {
|
if i.rootful {
|
||||||
cmd = append(cmd, "--rootful")
|
cmd = append(cmd, "--rootful")
|
||||||
}
|
}
|
||||||
|
if i.userModeNetworking {
|
||||||
|
cmd = append(cmd, "--user-mode-networking")
|
||||||
|
}
|
||||||
cmd = append(cmd, m.name)
|
cmd = append(cmd, m.name)
|
||||||
i.cmd = cmd
|
i.cmd = cmd
|
||||||
return cmd
|
return cmd
|
||||||
@ -50,3 +54,8 @@ func (i *setMachine) withRootful(r bool) *setMachine {
|
|||||||
i.rootful = r
|
i.rootful = r
|
||||||
return i
|
return i
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (i *setMachine) withUserModeNetworking(r bool) *setMachine {
|
||||||
|
i.userModeNetworking = r
|
||||||
|
return i
|
||||||
|
}
|
||||||
|
@ -6,6 +6,7 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
"runtime"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@ -201,3 +202,16 @@ func (matcher *ValidJSONMatcher) FailureMessage(actual interface{}) (message str
|
|||||||
func (matcher *ValidJSONMatcher) NegatedFailureMessage(actual interface{}) (message string) {
|
func (matcher *ValidJSONMatcher) NegatedFailureMessage(actual interface{}) (message string) {
|
||||||
return format.Message(actual, "to _not_ be valid JSON")
|
return format.Message(actual, "to _not_ be valid JSON")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func checkReason(reason string) {
|
||||||
|
if len(reason) < 5 {
|
||||||
|
panic("Test must specify a reason to skip")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func SkipIfNotWindows(reason string) {
|
||||||
|
checkReason(reason)
|
||||||
|
if runtime.GOOS != "windows" {
|
||||||
|
Skip("[not windows]: " + reason)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -186,7 +186,7 @@ var _ = Describe("podman machine init", func() {
|
|||||||
|
|
||||||
})
|
})
|
||||||
|
|
||||||
It("machine init rootful docker.sock check", func() {
|
It("machine init rootful with docker.sock check", func() {
|
||||||
i := initMachine{}
|
i := initMachine{}
|
||||||
name := randomString()
|
name := randomString()
|
||||||
session, err := mb.setName(name).setCmd(i.withImagePath(mb.imagePath).withRootful(true)).run()
|
session, err := mb.setName(name).setCmd(i.withImagePath(mb.imagePath).withRootful(true)).run()
|
||||||
@ -198,6 +198,13 @@ var _ = Describe("podman machine init", func() {
|
|||||||
Expect(err).ToNot(HaveOccurred())
|
Expect(err).ToNot(HaveOccurred())
|
||||||
Expect(ssession).Should(Exit(0))
|
Expect(ssession).Should(Exit(0))
|
||||||
|
|
||||||
|
inspect := new(inspectMachine)
|
||||||
|
inspect = inspect.withFormat("{{.Rootful}}")
|
||||||
|
inspectSession, err := mb.setName(name).setCmd(inspect).run()
|
||||||
|
Expect(err).ToNot(HaveOccurred())
|
||||||
|
Expect(inspectSession).To(Exit(0))
|
||||||
|
Expect(inspectSession.outputToString()).To(Equal("true"))
|
||||||
|
|
||||||
ssh2 := sshMachine{}
|
ssh2 := sshMachine{}
|
||||||
sshSession2, err := mb.setName(name).setCmd(ssh2.withSSHCommand([]string{"readlink /var/run/docker.sock"})).run()
|
sshSession2, err := mb.setName(name).setCmd(ssh2.withSSHCommand([]string{"readlink /var/run/docker.sock"})).run()
|
||||||
Expect(err).ToNot(HaveOccurred())
|
Expect(err).ToNot(HaveOccurred())
|
||||||
@ -205,4 +212,21 @@ var _ = Describe("podman machine init", func() {
|
|||||||
output := strings.TrimSpace(sshSession2.outputToString())
|
output := strings.TrimSpace(sshSession2.outputToString())
|
||||||
Expect(output).To(Equal("/run/podman/podman.sock"))
|
Expect(output).To(Equal("/run/podman/podman.sock"))
|
||||||
})
|
})
|
||||||
|
|
||||||
|
It("init with user mode networking ", func() {
|
||||||
|
SkipIfNotWindows("setting user mode networking is only honored on Windows")
|
||||||
|
|
||||||
|
i := new(initMachine)
|
||||||
|
name := randomString()
|
||||||
|
session, err := mb.setName(name).setCmd(i.withImagePath(mb.imagePath).withUserModeNetworking(true)).run()
|
||||||
|
Expect(err).ToNot(HaveOccurred())
|
||||||
|
Expect(session).To(Exit(0))
|
||||||
|
|
||||||
|
inspect := new(inspectMachine)
|
||||||
|
inspect = inspect.withFormat("{{.UserModeNetworking}}")
|
||||||
|
inspectSession, err := mb.setName(name).setCmd(inspect).run()
|
||||||
|
Expect(err).ToNot(HaveOccurred())
|
||||||
|
Expect(inspectSession).To(Exit(0))
|
||||||
|
Expect(inspectSession.outputToString()).To(Equal("true"))
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
@ -101,7 +101,7 @@ var _ = Describe("podman machine set", func() {
|
|||||||
Expect(sshSession3.outputToString()).To(ContainSubstring("100 GiB"))
|
Expect(sshSession3.outputToString()).To(ContainSubstring("100 GiB"))
|
||||||
})
|
})
|
||||||
|
|
||||||
It("set rootful, docker sock change", func() {
|
It("set rootful with docker sock change", func() {
|
||||||
name := randomString()
|
name := randomString()
|
||||||
i := new(initMachine)
|
i := new(initMachine)
|
||||||
session, err := mb.setName(name).setCmd(i.withImagePath(mb.imagePath)).run()
|
session, err := mb.setName(name).setCmd(i.withImagePath(mb.imagePath)).run()
|
||||||
@ -118,6 +118,13 @@ var _ = Describe("podman machine set", func() {
|
|||||||
Expect(err).ToNot(HaveOccurred())
|
Expect(err).ToNot(HaveOccurred())
|
||||||
Expect(startSession).To(Exit(0))
|
Expect(startSession).To(Exit(0))
|
||||||
|
|
||||||
|
inspect := new(inspectMachine)
|
||||||
|
inspect = inspect.withFormat("{{.Rootful}}")
|
||||||
|
inspectSession, err := mb.setName(name).setCmd(inspect).run()
|
||||||
|
Expect(err).ToNot(HaveOccurred())
|
||||||
|
Expect(inspectSession).To(Exit(0))
|
||||||
|
Expect(inspectSession.outputToString()).To(Equal("true"))
|
||||||
|
|
||||||
ssh2 := sshMachine{}
|
ssh2 := sshMachine{}
|
||||||
sshSession2, err := mb.setName(name).setCmd(ssh2.withSSHCommand([]string{"readlink /var/run/docker.sock"})).run()
|
sshSession2, err := mb.setName(name).setCmd(ssh2.withSSHCommand([]string{"readlink /var/run/docker.sock"})).run()
|
||||||
Expect(err).ToNot(HaveOccurred())
|
Expect(err).ToNot(HaveOccurred())
|
||||||
@ -125,4 +132,26 @@ var _ = Describe("podman machine set", func() {
|
|||||||
output := strings.TrimSpace(sshSession2.outputToString())
|
output := strings.TrimSpace(sshSession2.outputToString())
|
||||||
Expect(output).To(Equal("/run/podman/podman.sock"))
|
Expect(output).To(Equal("/run/podman/podman.sock"))
|
||||||
})
|
})
|
||||||
|
|
||||||
|
It("set user mode networking", func() {
|
||||||
|
SkipIfNotWindows("Setting user mode networking is only honored on Windows")
|
||||||
|
|
||||||
|
name := randomString()
|
||||||
|
i := new(initMachine)
|
||||||
|
session, err := mb.setName(name).setCmd(i.withImagePath(mb.imagePath)).run()
|
||||||
|
Expect(err).ToNot(HaveOccurred())
|
||||||
|
Expect(session).To(Exit(0))
|
||||||
|
|
||||||
|
set := setMachine{}
|
||||||
|
setSession, err := mb.setName(name).setCmd(set.withUserModeNetworking(true)).run()
|
||||||
|
Expect(err).ToNot(HaveOccurred())
|
||||||
|
Expect(setSession).To(Exit(0))
|
||||||
|
|
||||||
|
inspect := new(inspectMachine)
|
||||||
|
inspect = inspect.withFormat("{{.UserModeNetworking}}")
|
||||||
|
inspectSession, err := mb.setName(name).setCmd(inspect).run()
|
||||||
|
Expect(err).ToNot(HaveOccurred())
|
||||||
|
Expect(inspectSession).To(Exit(0))
|
||||||
|
Expect(inspectSession.outputToString()).To(Equal("true"))
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
@ -303,6 +303,7 @@ func (m *HyperVMachine) Inspect() (*machine.InspectInfo, error) {
|
|||||||
},
|
},
|
||||||
SSHConfig: m.SSHConfig,
|
SSHConfig: m.SSHConfig,
|
||||||
State: vm.State().String(),
|
State: vm.State().String(),
|
||||||
|
Rootful: m.Rootful,
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1596,6 +1596,7 @@ func (v *MachineVM) Inspect() (*machine.InspectInfo, error) {
|
|||||||
SSHConfig: v.SSHConfig,
|
SSHConfig: v.SSHConfig,
|
||||||
State: state,
|
State: state,
|
||||||
UserModeNetworking: true, // always true
|
UserModeNetworking: true, // always true
|
||||||
|
Rootful: v.Rootful,
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1745,6 +1745,7 @@ func (v *MachineVM) Inspect() (*machine.InspectInfo, error) {
|
|||||||
SSHConfig: v.SSHConfig,
|
SSHConfig: v.SSHConfig,
|
||||||
State: state,
|
State: state,
|
||||||
UserModeNetworking: v.UserModeNetworking,
|
UserModeNetworking: v.UserModeNetworking,
|
||||||
|
Rootful: v.Rootful,
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user