mirror of
				https://github.com/containers/podman.git
				synced 2025-11-04 08:56:05 +08:00 
			
		
		
		
	Add testcase for WSL dist conflicts
Signed-off-by: Brent Baude <bbaude@redhat.com>
This commit is contained in:
		
				
					committed by
					
						
						Jason T. Greene
					
				
			
			
				
	
			
			
			
						parent
						
							d23dd35dc1
						
					
				
				
					commit
					144e420bb9
				
			@ -235,3 +235,21 @@ func isVmtype(vmType define.VMType) bool {
 | 
			
		||||
func isWSL() bool {
 | 
			
		||||
	return isVmtype(define.WSLVirt)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func runSystemCommand(binary string, cmdArgs []string, timeout time.Duration, wait bool) (*machineSession, error) {
 | 
			
		||||
	if len(os.Getenv("DEBUG")) > 0 {
 | 
			
		||||
		cmdArgs = append([]string{"--log-level=debug"}, cmdArgs...)
 | 
			
		||||
	}
 | 
			
		||||
	GinkgoWriter.Println(binary + " " + strings.Join(cmdArgs, " "))
 | 
			
		||||
	c := exec.Command(binary, cmdArgs...)
 | 
			
		||||
	session, err := Start(c, GinkgoWriter, GinkgoWriter)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		Fail(fmt.Sprintf("Unable to start session: %q", err))
 | 
			
		||||
		return nil, err
 | 
			
		||||
	}
 | 
			
		||||
	ms := machineSession{session}
 | 
			
		||||
	if wait {
 | 
			
		||||
		ms.waitWithTimeout(timeout)
 | 
			
		||||
	}
 | 
			
		||||
	return &ms, nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -2,6 +2,7 @@ package e2e_test
 | 
			
		||||
 | 
			
		||||
import (
 | 
			
		||||
	"fmt"
 | 
			
		||||
	"os"
 | 
			
		||||
	"path/filepath"
 | 
			
		||||
 | 
			
		||||
	"github.com/Microsoft/go-winio/vhd"
 | 
			
		||||
@ -42,6 +43,7 @@ var _ = Describe("podman machine init - windows only", func() {
 | 
			
		||||
		Expect(inspectSession).To(Exit(0))
 | 
			
		||||
		Expect(inspectSession.outputToString()).To(Equal("true"))
 | 
			
		||||
	})
 | 
			
		||||
 | 
			
		||||
	It("init should not should not overwrite existing HyperV vms", func() {
 | 
			
		||||
		skipIfNotVmtype(define.HyperVVirt, "HyperV test only")
 | 
			
		||||
		name := randomString()
 | 
			
		||||
@ -75,4 +77,50 @@ var _ = Describe("podman machine init - windows only", func() {
 | 
			
		||||
		Expect(session).To(Exit(125))
 | 
			
		||||
		Expect(session.errorToString()).To(ContainSubstring("already exists on hypervisor"))
 | 
			
		||||
	})
 | 
			
		||||
 | 
			
		||||
	It("init should not should not overwrite existing HyperV vms", func() {
 | 
			
		||||
		skipIfNotVmtype(define.WSLVirt, "WSL test only")
 | 
			
		||||
 | 
			
		||||
		var (
 | 
			
		||||
			wsl string = "wsl"
 | 
			
		||||
		)
 | 
			
		||||
 | 
			
		||||
		name := randomString()
 | 
			
		||||
		distName := fmt.Sprintf("podman-%s", name)
 | 
			
		||||
		exportedPath := filepath.Join(testDir, "bogus.tar")
 | 
			
		||||
		distrDir := filepath.Join(testDir, "testDistro")
 | 
			
		||||
		err := os.Mkdir(distrDir, 0755)
 | 
			
		||||
		Expect(err).ToNot(HaveOccurred())
 | 
			
		||||
 | 
			
		||||
		// create a bogus machine
 | 
			
		||||
		i := new(initMachine)
 | 
			
		||||
		session, err := mb.setName("foobarexport").setCmd(i.withImagePath(mb.imagePath)).run()
 | 
			
		||||
		Expect(err).ToNot(HaveOccurred())
 | 
			
		||||
		Expect(session).To(Exit(0))
 | 
			
		||||
 | 
			
		||||
		// export the bogus machine so we have input for making
 | 
			
		||||
		// a vm outside the context of podman-machine and also
 | 
			
		||||
		// so we dont have to download a distribution from microsoft
 | 
			
		||||
		// servers
 | 
			
		||||
		exportSession, err := runSystemCommand(wsl, []string{"--export", "podman-foobarexport", exportedPath}, defaultTimeout, true)
 | 
			
		||||
		Expect(err).ToNot(HaveOccurred())
 | 
			
		||||
		Expect(exportSession).To(Exit(0))
 | 
			
		||||
 | 
			
		||||
		// importing the machine and creating a vm
 | 
			
		||||
		importSession, err := runSystemCommand(wsl, []string{"--import", distName, distrDir, exportedPath}, defaultTimeout, true)
 | 
			
		||||
		Expect(err).ToNot(HaveOccurred())
 | 
			
		||||
		Expect(importSession).To(Exit(0))
 | 
			
		||||
 | 
			
		||||
		defer func() {
 | 
			
		||||
			_, err := runSystemCommand(wsl, []string{"--unregister", distName}, defaultTimeout, true)
 | 
			
		||||
			if err != nil {
 | 
			
		||||
				fmt.Println("unable to remove bogus wsl instance")
 | 
			
		||||
			}
 | 
			
		||||
		}()
 | 
			
		||||
 | 
			
		||||
		// Trying to make a vm with the same name as an existing name should result in a 125
 | 
			
		||||
		checkSession, err := mb.setName(name).setCmd(i.withImagePath(mb.imagePath)).run()
 | 
			
		||||
		Expect(err).ToNot(HaveOccurred())
 | 
			
		||||
		Expect(checkSession).To(Exit(125))
 | 
			
		||||
	})
 | 
			
		||||
})
 | 
			
		||||
 | 
			
		||||
		Reference in New Issue
	
	Block a user