Skip to content

Commit 86bad0a

Browse files
Merge pull request #371 from ArangoGutierrez/fix/tests
Fix tests after v0.2.9
2 parents 1ba2ae8 + 2d92e03 commit 86bad0a

17 files changed

+123
-83
lines changed

pkg/provisioner/provisioner.go

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -182,9 +182,19 @@ func (p *Provisioner) Run(env v1alpha1.Environment) error {
182182

183183
// resetConnection resets the ssh connection, and retries if it fails to connect
184184
func (p *Provisioner) resetConnection() error {
185-
// Close the current ssh connection
186-
if err := p.Client.Close(); err != nil {
187-
return fmt.Errorf("failed to close ssh client: %v", err)
185+
// Check if the connection is still active before closing
186+
if p.Client != nil {
187+
// Try to create a new session to check if connection is alive
188+
session, err := p.Client.NewSession()
189+
if err == nil {
190+
session.Close() // nolint:errcheck, gosec
191+
// Connection is alive, close it
192+
if err := p.Client.Close(); err != nil {
193+
return fmt.Errorf("failed to close ssh client: %w", err)
194+
}
195+
}
196+
// If we get here, either the connection was already closed or we couldn't create a session
197+
p.Client = nil
188198
}
189199

190200
return nil

pkg/provisioner/templates/container-toolkit.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,6 @@ install_packages_with_retry nvidia-container-toolkit
3939
# Configure container runtime
4040
sudo nvidia-ctk runtime configure --runtime={{.ContainerRuntime}} --set-as-default --enable-cdi={{.EnableCDI}}
4141
sudo systemctl restart {{.ContainerRuntime}}
42-
43-
# safely close the ssh connection
44-
exit 0
4542
`
4643

4744
type ContainerToolkit struct {

pkg/provisioner/templates/container-toolkit_test.go

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,4 @@ func TestContainerToolkit_Execute(t *testing.T) {
6060
if !strings.Contains(out, "nvidia-ctk runtime configure --runtime=containerd --set-as-default --enable-cdi=true") {
6161
t.Errorf("template output missing expected runtime config: %s", out)
6262
}
63-
64-
// Test safe exit
65-
if !strings.Contains(out, "exit 0") {
66-
t.Errorf("template output missing safe exit: %s", out)
67-
}
6863
}

pkg/provisioner/templates/containerd.go

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,6 @@ sudo systemctl daemon-reload
289289
sudo systemctl enable --now containerd
290290
291291
# Wait for containerd to be ready
292-
echo "Waiting for containerd to be ready..."
293292
timeout=60
294293
while ! sudo ctr version &>/dev/null; do
295294
if [ $timeout -le 0 ]; then
@@ -304,20 +303,15 @@ done
304303
sudo chmod 666 /run/containerd/containerd.sock
305304
306305
# Verify installation
307-
echo "Verifying installation..."
308306
containerd --version
309307
runc --version
310308
sudo ctr version
311309
312310
# Test containerd functionality
313-
echo "Testing containerd functionality..."
314311
sudo ctr images pull docker.io/library/hello-world:latest
315312
sudo ctr run --rm docker.io/library/hello-world:latest test
316313
317-
echo "Containerd installation completed successfully!"
318-
319-
# safely close the ssh connection
320-
exit 0
314+
# Containerd installation completed successfully!
321315
`
322316

323317
type Containerd struct {

pkg/provisioner/templates/containerd_test.go

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -199,11 +199,6 @@ func TestContainerd_Execute_SystemChecks(t *testing.T) {
199199
t.Error("template output missing temporary directory creation")
200200
}
201201

202-
// Test safe exit
203-
if !strings.Contains(out, "exit 0") {
204-
t.Error("template output missing safe exit")
205-
}
206-
207202
// Test error handling
208203
if !strings.Contains(out, "Error: Failed to download containerd tarball") {
209204
t.Error("template output missing download error handling")

pkg/provisioner/templates/crio.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,6 @@ apt install -y cri-o
3838
# Start and enable Service
3939
systemctl daemon-reload
4040
systemctl start crio.service
41-
42-
# safely close the ssh connection
43-
exit 0
4441
`
4542

4643
type CriO struct {

pkg/provisioner/templates/crio_test.go

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,4 @@ func TestCriO_Execute(t *testing.T) {
4343
if !strings.Contains(out, "systemctl start crio.service") {
4444
t.Errorf("template output missing crio start: %s", out)
4545
}
46-
47-
// Test safe exit
48-
if !strings.Contains(out, "exit 0") {
49-
t.Errorf("template output missing safe exit: %s", out)
50-
}
5146
}

pkg/provisioner/templates/docker.go

Lines changed: 58 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,64 @@ sudo systemctl restart docker
7474
sudo usermod -aG docker $USER
7575
newgrp docker
7676
77-
# safely close the ssh connection
78-
exit 0
77+
# Install cri-dockerd
78+
CRI_DOCKERD_VERSION="0.3.17"
79+
CRI_DOCKERD_ARCH="amd64"
80+
CRI_DOCKERD_URL="https://github.com/Mirantis/cri-dockerd/releases/download/v${CRI_DOCKERD_VERSION}/cri-dockerd-${CRI_DOCKERD_VERSION}.${CRI_DOCKERD_ARCH}.tgz"
81+
82+
# Download and install cri-dockerd
83+
curl -L ${CRI_DOCKERD_URL} | sudo tar xzv -C /usr/local/bin --strip-components=1
84+
85+
# Create systemd service file for cri-dockerd
86+
sudo tee /etc/systemd/system/cri-docker.service <<EOF
87+
[Unit]
88+
Description=CRI Interface for Docker Application Container Engine
89+
Documentation=https://docs.mirantis.com
90+
After=network-online.target firewalld.service docker.service
91+
Wants=network-online.target
92+
Requires=cri-docker.socket
93+
94+
[Service]
95+
Type=notify
96+
ExecStart=/usr/local/bin/cri-dockerd --container-runtime-endpoint fd://
97+
ExecReload=/bin/kill -s HUP $MAINPID
98+
TimeoutSec=0
99+
RestartSec=2
100+
Restart=always
101+
StartLimitBurst=3
102+
StartLimitInterval=60s
103+
LimitNOFILE=infinity
104+
LimitNPROC=infinity
105+
LimitCORE=infinity
106+
TasksMax=infinity
107+
Delegate=yes
108+
KillMode=process
109+
110+
[Install]
111+
WantedBy=multi-user.target
112+
EOF
113+
114+
# Create socket file for cri-dockerd
115+
sudo tee /etc/systemd/system/cri-docker.socket <<EOF
116+
[Unit]
117+
Description=CRI Docker Socket for the API
118+
PartOf=cri-docker.service
119+
120+
[Socket]
121+
ListenStream=/run/cri-dockerd.sock
122+
SocketMode=0660
123+
SocketUser=root
124+
SocketGroup=docker
125+
126+
[Install]
127+
WantedBy=sockets.target
128+
EOF
129+
130+
# Enable and start cri-dockerd
131+
sudo systemctl daemon-reload
132+
sudo systemctl enable cri-docker.service
133+
sudo systemctl enable cri-docker.socket
134+
sudo systemctl start cri-docker.service
79135
`
80136

81137
type Docker struct {

pkg/provisioner/templates/docker_test.go

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ func TestDocker_Execute(t *testing.T) {
4545
t.Fatalf("Execute failed: %v", err)
4646
}
4747
out := buf.String()
48+
49+
// Test Docker installation
4850
if !strings.Contains(out, "docker-ce=$DOCKER_VERSION") {
4951
t.Errorf("template output missing expected docker version install command: %s", out)
5052
}
@@ -55,8 +57,20 @@ func TestDocker_Execute(t *testing.T) {
5557
t.Errorf("template output missing enable docker: %s", out)
5658
}
5759

58-
// Test safe exit
59-
if !strings.Contains(out, "exit 0") {
60-
t.Errorf("template output missing safe exit: %s", out)
60+
// Test cri-dockerd installation
61+
if !strings.Contains(out, "CRI_DOCKERD_VERSION=\"0.3.17\"") {
62+
t.Errorf("template output missing cri-dockerd version: %s", out)
63+
}
64+
if !strings.Contains(out, "curl -L ${CRI_DOCKERD_URL} | sudo tar xzv -C /usr/local/bin --strip-components=1") {
65+
t.Errorf("template output missing cri-dockerd installation command: %s", out)
66+
}
67+
if !strings.Contains(out, "systemctl enable cri-docker.service") {
68+
t.Errorf("template output missing enable cri-docker service: %s", out)
69+
}
70+
if !strings.Contains(out, "systemctl enable cri-docker.socket") {
71+
t.Errorf("template output missing enable cri-docker socket: %s", out)
72+
}
73+
if !strings.Contains(out, "systemctl start cri-docker.service") {
74+
t.Errorf("template output missing start cri-docker service: %s", out)
6175
}
6276
}

pkg/provisioner/templates/kernel.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,6 @@ if [ "${CURRENT_KERNEL}" != "${KERNEL_VERSION}" ]; then
6060
# Run the reboot command with nohup to avoid abrupt SSH closure issues
6161
nohup sudo reboot &
6262
fi
63-
64-
# safely close the ssh connection
65-
exit 0
6663
{{- end }}
6764
`
6865

0 commit comments

Comments
 (0)