Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
242 changes: 242 additions & 0 deletions tests/bdd-smoke/suites/config/libvirt/install_config_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,242 @@
package config_test

import (
"os"
"testing"

"github.com/openshift/installer/tests/bdd-smoke/utils"

. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
)

func TestInstallConfig(t *testing.T) {
RegisterFailHandler(Fail)
RunSpecs(t, "Test Suite for create install-config in libvirt")
}

var _ = Describe("Feature: Check that install-config command generates the install configuration asset for libvirt", func() {

openshiftInstallerPath := os.Getenv("GOPATH") + "/src/github.com/openshift/installer"
openshiftInstallBinPath := openshiftInstallerPath + "/bin/openshift-install"

AfterSuite(func() {
args := []string{"-rf",
"scenario1/",
"scenario3/",
"scenario4/",
"scenario5/",
"tests/bdd-smoke/suites/config/libvirt/scenario6/",
".openshift_install_state.json",
".openshift_install.log",
"install-config.yaml"}
utils.RunOSCommandWithArgs("rm", args, openshiftInstallerPath)
})

// tests for openshift-install create install-config
Context("Scenario: Generate configuration asset specifying a directory", func() {
testData := &utils.DataToValidate{
BaseDomain: "tt.testing",
ClusterName: "test1",
SSH: "id_rsa.pub",
PullSecret: `{"auths": {"quay.io": {"auth": "aValidPullSecret","email": ""}}}`,
ConnectionURI: "qemu+tcp://192.168.122.1/system",
}

It("Given that the openshift-install is compiled", func() {
Ω(openshiftInstallBinPath).Should(BeAnExistingFile())
})
It("When I execute openshift-install create install-config --dir=scenario1", func() {
args := []string{"create", "install-config", "--dir=scenario1"}
commandLineArgs := [][]string{
{"SSH Public Key", testData.SSH},
{"Platform", "libvirt"},
{"Libvirt Connection URI", testData.ConnectionURI},
{"Base Domain", testData.BaseDomain},
{"Cluster Name", testData.ClusterName},
{"Pull Secret", testData.PullSecret},
}
cmdOut := utils.RunInstallerWithSurvey(args, openshiftInstallerPath, commandLineArgs)
Ω(cmdOut).Should(ContainSubstring(".ssh/id_rsa.pub"))
Ω(cmdOut).Should(ContainSubstring("Platform libvirt"))
Ω(cmdOut).Should(ContainSubstring("Libvirt Connection URI qemu+tcp://192.168.122.1/system"))
Ω(cmdOut).Should(ContainSubstring("Base Domain tt.testing"))
Ω(cmdOut).Should(ContainSubstring("Cluster Name test1"))
})
Specify("Then I expect to see the install-config.yaml file in the path ./scenario1/", func() {
Ω(openshiftInstallerPath + "/scenario1/install-config.yaml").Should(BeAnExistingFile())
})
Specify("And I expect install-config.yaml file contains the info specified in the environment variables", func() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: these aren't environment variables any more (and also in several other Specify strings in this commit).

utils.ValidateInstallConfig(openshiftInstallerPath+"/scenario1/install-config.yaml", *testData)
})
Specify("And I expect .openshift_install_state.json file contains the info specified in the environment variables", func() {
utils.ValidateInstallStateConfig(openshiftInstallerPath+"/scenario1/.openshift_install_state.json", *testData)
})
})

Context("Scenario: Generate configuration asset without specifying a directory with log level in debug", func() {
testData := &utils.DataToValidate{
BaseDomain: "tt.testing",
ClusterName: "test1",
SSH: "id_rsa.pub",
PullSecret: `{"auths": {"quay.io": {"auth": "aValidPullSecret","email": ""}}}`,
ConnectionURI: "qemu+tcp://192.168.122.1/system",
}
It("Given that the openshift-install is compiled", func() {
Ω(openshiftInstallBinPath).Should(BeAnExistingFile())
})
It("When I execute bin/openshift-install install-config --log-level=debug", func() {
args := []string{"create", "install-config", "--log-level=debug"}
commandLineArgs := [][]string{
{"SSH Public Key", testData.SSH},
{"Platform", "libvirt"},
{"Libvirt Connection URI", testData.ConnectionURI},
{"Base Domain", testData.BaseDomain},
{"Cluster Name", testData.ClusterName},
{"Pull Secret", testData.PullSecret},
}
cmdOut := utils.RunInstallerWithSurvey(args, openshiftInstallerPath, commandLineArgs)
Ω(cmdOut).Should(ContainSubstring(".ssh/id_rsa.pub"))
Ω(cmdOut).Should(ContainSubstring("Platform libvirt"))
Ω(cmdOut).Should(ContainSubstring("Libvirt Connection URI qemu+tcp://192.168.122.1/system"))
Ω(cmdOut).Should(ContainSubstring("Base Domain tt.testing"))
Ω(cmdOut).Should(ContainSubstring("Cluster Name test1"))
})
Specify("Then I expect to see the install-config.yaml file in the path ./", func() {
Ω(openshiftInstallerPath + "/install-config.yaml").Should(BeAnExistingFile())
})
Specify("And I expect to see the .openshift_install_state.json file in the path ./", func() {
Ω(openshiftInstallerPath + "/.openshift_install_state.json").Should(BeAnExistingFile())
})
Specify("And I expect install-config.yaml file contains the info specified in the environment variables", func() {
utils.ValidateInstallConfig(openshiftInstallerPath+"/install-config.yaml", *testData)
})
Specify("And I expect .openshift_install_state.json file contains the info specified in the environment variables", func() {
utils.ValidateInstallStateConfig(openshiftInstallerPath+"/.openshift_install_state.json", *testData)
})
})

Context("Scenario: Generate configuration asset specifying a directory with log level in error", func() {
cmdOut := ""
testData := &utils.DataToValidate{
BaseDomain: "tt.testing",
ClusterName: "test1",
SSH: "id_rsa.pub",
PullSecret: `{"auths": {"quay.io": {"auth": "aValidPullSecret","email": ""}}}`,
ConnectionURI: "qemu+tcp://192.168.122.1/system",
}
It("Given that the openshift-install is compiled", func() {
Ω(openshiftInstallBinPath).Should(BeAnExistingFile())
})
It("When I execute bin/openshift-install install-config --dir=scenario3 --log-level=error", func() {
args := []string{"create", "install-config", "--dir=scenario3", "--log-level=error"}
commandLineArgs := [][]string{
{"SSH Public Key", testData.SSH},
{"Platform", "libvirt"},
{"Libvirt Connection URI", testData.ConnectionURI},
{"Base Domain", testData.BaseDomain},
{"Cluster Name", testData.ClusterName},
{"Pull Secret", testData.PullSecret},
}
cmdOut := utils.RunInstallerWithSurvey(args, openshiftInstallerPath, commandLineArgs)
Ω(cmdOut).Should(ContainSubstring(".ssh/id_rsa.pub"))
Ω(cmdOut).Should(ContainSubstring("Platform libvirt"))
Ω(cmdOut).Should(ContainSubstring("Libvirt Connection URI qemu+tcp://192.168.122.1/system"))
Ω(cmdOut).Should(ContainSubstring("Base Domain tt.testing"))
Ω(cmdOut).Should(ContainSubstring("Cluster Name test1"))
})
Specify("Then I expect to see the install-config.yaml file in the path ./scenario3", func() {
Ω(openshiftInstallerPath + "/scenario3/install-config.yaml").Should(BeAnExistingFile())
})
Specify("And I expect install-config.yaml file contains the info specified in the environment variables", func() {
utils.ValidateInstallConfig(openshiftInstallerPath+"/scenario3/install-config.yaml", *testData)
})
Specify("And I expect .openshift_install_state.json file contains the info specified in the environment variables", func() {
utils.ValidateInstallStateConfig(openshiftInstallerPath+"/scenario3/.openshift_install_state.json", *testData)
})
Specify("And I expect to not to get any error in output log from the console", func() {
Ω(cmdOut).Should(Equal(""))
})
})

Context("Scenario: Generate configuration asset specifying a directory running it from other path", func() {
cmdOut := ""
testData := &utils.DataToValidate{
BaseDomain: "tt.testing",
ClusterName: "test1",
SSH: "id_rsa.pub",
PullSecret: `{"auths": {"quay.io": {"auth": "aValidPullSecret","email": ""}}}`,
ConnectionURI: "qemu+tcp://192.168.122.1/system",
}
It("Given that the openshift-install is compiled", func() {
Ω(openshiftInstallBinPath).Should(BeAnExistingFile())
})
It("When I execute bin/openshift-install install-config --dir=scenario6 --log-level=error", func() {
args := []string{"create", "install-config", "--dir=scenario6"}
commandLineArgs := [][]string{
{"SSH Public Key", testData.SSH},
{"Platform", "libvirt"},
{"Libvirt Connection URI", testData.ConnectionURI},
{"Base Domain", testData.BaseDomain},
{"Cluster Name", testData.ClusterName},
{"Pull Secret", testData.PullSecret},
}
cmdOut := utils.RunInstallerWithSurvey(args, ".", commandLineArgs)
Ω(cmdOut).Should(ContainSubstring(".ssh/id_rsa.pub"))
Ω(cmdOut).Should(ContainSubstring("Platform libvirt"))
Ω(cmdOut).Should(ContainSubstring("Libvirt Connection URI qemu+tcp://192.168.122.1/system"))
Ω(cmdOut).Should(ContainSubstring("Base Domain tt.testing"))
Ω(cmdOut).Should(ContainSubstring("Cluster Name test1"))
})
Specify("Then I expect to see the install-config.yaml file in the path ./scenario6", func() {
Ω("scenario6/install-config.yaml").Should(BeAnExistingFile())
})
Specify("And I expect install-config.yaml file contains the info specified in the environment variables", func() {
utils.ValidateInstallConfig("scenario6/install-config.yaml", *testData)
})
Specify("And I expect .openshift_install_state.json file contains the info specified in the environment variables", func() {
utils.ValidateInstallStateConfig("scenario6/.openshift_install_state.json", *testData)
})
Specify("And I expect to not to get any error in output log from the console", func() {
Ω(cmdOut).Should(Equal(""))
})
})

Context("Scenario: Use previously generated configuration asset without specifying a directory with log level in debug", func() {
testData := &utils.DataToValidate{
BaseDomain: "tt.testing",
ClusterName: "test1",
SSH: "id_rsa.pub",
PullSecret: `{"auths": {"quay.io": {"auth": "aValidPullSecret","email": ""}}}`,
ConnectionURI: "qemu+tcp://192.168.122.1/system",
}
It("Given that the openshift-install is compiled", func() {
Ω(openshiftInstallBinPath).Should(BeAnExistingFile())
})
It("When I execute bin/openshift-install install-config --log-level=debug", func() {
args := []string{"create", "install-config", "--log-level=debug"}
commandLineArgs := [][]string{
{"SSH Public Key", testData.SSH},
{"Platform", "libvirt"},
{"Libvirt Connection URI", testData.ConnectionURI},
{"Base Domain", testData.BaseDomain},
{"Cluster Name", testData.ClusterName},
{"Pull Secret", testData.PullSecret},
}
cmdOut := utils.RunInstallerWithSurvey(args, openshiftInstallerPath, commandLineArgs)
Ω(cmdOut).Should(ContainSubstring(""))
})
Specify("Then I expect to see the install-config.yaml file in the path ./", func() {
Ω(openshiftInstallerPath + "/install-config.yaml").Should(BeAnExistingFile())
})
Specify("And I expect to see the .openshift_install_state.json file in the path ./", func() {
Ω(openshiftInstallerPath + "/.openshift_install_state.json").Should(BeAnExistingFile())
})
Specify("And I expect install-config.yaml file contains the info specified in the environment variables", func() {
utils.ValidateInstallConfig(openshiftInstallerPath+"/install-config.yaml", *testData)
})
Specify("And I expect .openshift_install_state.json file contains the info specified in the environment variables", func() {
utils.ValidateInstallStateConfig(openshiftInstallerPath+"/.openshift_install_state.json", *testData)
})
})
})
13 changes: 13 additions & 0 deletions tests/bdd-smoke/utils/assertion.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package utils

import (
"log"
"strings"
)

// AssertStringContains compares two strings and fails if it isn't contained
func AssertStringContains(mainString string, subString string, errorMessage string) {
if !strings.Contains(mainString, subString) {
log.Fatal("Error: " + errorMessage + "\nExpected <<" + mainString + ">> but was <<" + subString + ">>")
}
}
76 changes: 76 additions & 0 deletions tests/bdd-smoke/utils/command_runner.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
package utils

import (
"bytes"
"context"
"fmt"
"log"
"os"
"os/exec"
"strings"
"time"

expect "github.com/Netflix/go-expect"
"github.com/hinshun/vt10x"
)

// RunOSCommandWithArgs executes a command in the operating system with arguments
func RunOSCommandWithArgs(command string, arguments []string, path string) string {
cmd := exec.Command(command, arguments...)
cmd.Dir = path
cmd.Stdin = strings.NewReader("")
var outb, errb bytes.Buffer
cmd.Stdout = &outb
cmd.Stderr = &errb
err := cmd.Run()
if err != nil {
fmt.Println("Error: failed running the command \"" + command + "\" with the arguments:")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: this could be more robust and compact with:

fmt.Printf("Error: failed running the command %q with the arguments:", command)

although printing straight to the terminal feels strange anyway. Does that get captured somewhere? Should we be logging these instead, or attaching it to the error before passing it to log.Fatal?

fmt.Println(arguments)
fmt.Println(errb.String())
log.Fatal(err)
}
return outb.String() + errb.String()
}

// RunInstallerWithSurvey run the installer given the command arguments, the path where will be launched and the command line values for survey
func RunInstallerWithSurvey(arguments []string, path string, commandLineArgs [][]string) string {
openshiftInstallBin := os.Getenv("GOPATH") + "/src/github.com/openshift/installer/bin/openshift-install"

c, state, errVt10x := vt10x.NewVT10XConsole()
if errVt10x != nil {
fmt.Println("Error: failed starting vt10x console")
log.Fatal(errVt10x)
}
defer c.Close()

donec := make(chan struct{})
go func() {
defer close(donec)

for _, command := range commandLineArgs {
c.ExpectString(command[0])
c.SendLine(command[1])
}
c.ExpectEOF()
}()

ctx, cancel := context.WithTimeout(context.Background(), 2*time.Second)
defer cancel()
cmd := exec.CommandContext(ctx, openshiftInstallBin, arguments...)
cmd.Dir = path
cmd.Stdin = c.Tty()
cmd.Stdout = c.Tty()
cmd.Stderr = c.Tty()

errCmd := cmd.Run()
if errVt10x != nil {
fmt.Println("Error: running the command : " + openshiftInstallBin + " with the arguments")
fmt.Println(arguments)
fmt.Println(commandLineArgs)
log.Fatal(errCmd)
}
c.Tty().Close()
<-donec

return expect.StripTrailingEmptyLines(state.String())
}
Loading