Skip to content

Commit

Permalink
ci/e2e: add a ssh connection test
Browse files Browse the repository at this point in the history
Signed-off-by: Loic Devulder <ldevulder@suse.com>
  • Loading branch information
ldevulder committed May 17, 2022
1 parent f1f6b98 commit c596018
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 5 deletions.
6 changes: 3 additions & 3 deletions tests/assets/machineregistration.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ spec:
machineInventoryAnnotations: {}
# The cloud config that will be used to provision the node
cloudConfig:
hostname: ros-node-{{ trunc 4 .MachineID }}
hostname: %VM_NAME%-{{ trunc 4 .MachineID }}
users:
- name: root
passwd: r0s@pwd1
- name: %USER%
passwd: %PASSWORD%
rancheros:
install:
device: /dev/sda
Expand Down
38 changes: 36 additions & 2 deletions tests/e2e/bootstrap_with_rancher_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ limitations under the License.
package e2e

import (
"bytes"
"os"
"os/exec"
"path/filepath"
Expand All @@ -40,7 +41,9 @@ func getServerId(clusterNS string) string {

var _ = Describe("E2E - Bootstrapping node with Rancher", Label("bootstrapping"), func() {
const (
vmName = "ros-node"
vmName = "ros-node"
userName = "root"
userPassword = "r0s@pwd1"
)

var (
Expand Down Expand Up @@ -169,7 +172,18 @@ var _ = Describe("E2E - Bootstrapping node with Rancher", Label("bootstrapping")
})

By("Adding MachineRegistration in Rancher", func() {
err := kubectl.Apply(clusterNS, "../assets/machineregistration.yaml")
registrationYaml := "../assets/machineregistration.yaml"

err := tools.Sed("%VM_NAME%", vmName, registrationYaml)
Expect(err).NotTo(HaveOccurred())

err = tools.Sed("%USER%", userName, registrationYaml)
Expect(err).NotTo(HaveOccurred())

err = tools.Sed("%PASSWORD%", userPassword, registrationYaml)
Expect(err).NotTo(HaveOccurred())

err = kubectl.Apply(clusterNS, registrationYaml)
Expect(err).NotTo(HaveOccurred())
})

Expand Down Expand Up @@ -320,5 +334,25 @@ var _ = Describe("E2E - Bootstrapping node with Rancher", Label("bootstrapping")
// Check that the VM is added
Expect(internalClusterName).To(Equal(internalClusterToken))
})

By("Checking VM ssh connection", func() {
// TODO: Create a native Go function for this
ip, err := exec.Command("sed", "-n", "/name='"+vmName+"'/s/.*ip='\\(.*\\)'.*/\\1/p", "../assets/net-default.xml").CombinedOutput()
ip = bytes.Trim(ip, "\n")
GinkgoWriter.Printf("IP=%s\n", ip)
Expect(err).NotTo(HaveOccurred())

client := &tools.Client{
Host: string(ip) + ":22",
Username: userName,
Password: userPassword,
}

// Retry the SSH connection, as it can takes time for the user to be created
Eventually(func() string {
out, _ := client.RunSSH("uname -n")
return out
}, "5m", "5s").Should(ContainSubstring(vmName))
})
})
})

0 comments on commit c596018

Please sign in to comment.