Skip to content

Commit 56250fb

Browse files
committed
Extract repo and registry creation code into funcs
1 parent 87d9be5 commit 56250fb

File tree

3 files changed

+122
-240
lines changed

3 files changed

+122
-240
lines changed

integration/disconnected_install.go

+74
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
package integration
2+
3+
import (
4+
"fmt"
5+
"path/filepath"
6+
"time"
7+
8+
. "github.com/onsi/ginkgo"
9+
)
10+
11+
// creates a package repository mirror on the given node.
12+
func createPackageRepositoryMirror(repoNode NodeDeets, distro linuxDistro, sshKey string) error {
13+
var mirrorScript string
14+
switch distro {
15+
case CentOS7:
16+
mirrorScript = "mirror-rpms.sh"
17+
case Ubuntu1604LTS:
18+
mirrorScript = "mirror-debs.sh"
19+
default:
20+
return fmt.Errorf("unable to create repo mirror for distro %q", distro)
21+
}
22+
start := time.Now()
23+
err := copyFileToRemote("test-resources/disconnected-installation/"+mirrorScript, "/tmp/"+mirrorScript, repoNode, sshKey, 10*time.Second)
24+
if err != nil {
25+
return fmt.Errorf("failed to copy script to remote node: %v", err)
26+
}
27+
cmds := []string{"chmod +x /tmp/" + mirrorScript, "sudo /tmp/" + mirrorScript}
28+
err = runViaSSH(cmds, []NodeDeets{repoNode}, sshKey, 45*time.Minute)
29+
if err != nil {
30+
return fmt.Errorf("error running mirroring script: %v", err)
31+
}
32+
elapsed := time.Since(start)
33+
fmt.Println("Creating a package repository took", elapsed)
34+
return nil
35+
}
36+
37+
// seeds a container image registry using the kismatic seed-registry command
38+
func seedRegistry(repoNode NodeDeets, registryCAFile string, registryPort int, sshKey string) error {
39+
By("Adding the docker registry self-signed cert to the registry node")
40+
registry := fmt.Sprintf("%s:%d", repoNode.PublicIP, registryPort)
41+
err := copyFileToRemote(registryCAFile, "/tmp/docker-registry-ca.crt", repoNode, sshKey, 30*time.Second)
42+
if err != nil {
43+
return fmt.Errorf("Failed to copy registry cert to registry node: %v", err)
44+
}
45+
cmds := []string{
46+
fmt.Sprintf("sudo mkdir -p /etc/docker/certs.d/%s", registry),
47+
fmt.Sprintf("sudo mv /tmp/docker-registry-ca.crt /etc/docker/certs.d/%s/ca.crt", registry),
48+
}
49+
err = runViaSSH(cmds, []NodeDeets{repoNode}, sshKey, 10*time.Minute)
50+
if err != nil {
51+
return fmt.Errorf("Error adding self-signed cert to registry node: %v", err)
52+
}
53+
54+
By("Copying KET to the registry node for seeding")
55+
err = copyFileToRemote(filepath.Join(currentKismaticDir, "kismatic.tar.gz"), "/tmp/kismatic.tar.gz", repoNode, sshKey, 5*time.Minute)
56+
if err != nil {
57+
return fmt.Errorf("Error copying KET to the registry node: %v", err)
58+
}
59+
60+
By("Seeding the registry")
61+
start := time.Now()
62+
cmds = []string{
63+
fmt.Sprintf("sudo docker login -u kismaticuser -p kismaticpassword %s", registry),
64+
"sudo tar -xf /tmp/kismatic.tar.gz",
65+
fmt.Sprintf("sudo ./kismatic seed-registry --server %s", registry),
66+
}
67+
err = runViaSSH(cmds, []NodeDeets{repoNode}, sshKey, 30*time.Minute)
68+
if err != nil {
69+
return fmt.Errorf("failed to seed the registry: %v", err)
70+
}
71+
elapsed := time.Since(start)
72+
fmt.Println("Seeding the registry took", elapsed)
73+
return nil
74+
}

integration/disconnected_install_test.go

+16-76
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package integration
33
import (
44
"fmt"
55
"os"
6-
"path/filepath"
76
"time"
87

98
. "github.com/onsi/ginkgo"
@@ -24,53 +23,23 @@ var _ = Describe("disconnected installation", func() {
2423
Context("with an existing package mirror and image registry", func() {
2524
Context("on CentOS", func() {
2625
ItOnAWS("should install successfully [slow]", func(aws infrastructureProvisioner) {
27-
WithInfrastructure(NodeCount{1, 1, 2, 1, 1}, CentOS7, aws, func(nodes provisionedNodes, sshKey string) {
26+
distro := CentOS7
27+
WithInfrastructure(NodeCount{1, 1, 2, 1, 1}, distro, aws, func(nodes provisionedNodes, sshKey string) {
2828
// One of the workers is used as the repository and registry
2929
repoNode := nodes.worker[1]
3030
nodes.worker = nodes.worker[0:1]
3131

32-
// Create a package repo
3332
By("Creating a package repository")
34-
start := time.Now()
35-
err := copyFileToRemote("test-resources/disconnected-installation/mirror-rpms.sh", "/tmp/mirror-rpms.sh", repoNode, sshKey, 10*time.Second)
36-
FailIfError(err, "Failed to copy script to remote node")
37-
cmds := []string{"chmod +x /tmp/mirror-rpms.sh", "sudo /tmp/mirror-rpms.sh"}
38-
err = runViaSSH(cmds, []NodeDeets{repoNode}, sshKey, 45*time.Minute)
39-
FailIfError(err, "Failed to mirror package repositories")
40-
elapsed := time.Since(start)
41-
fmt.Println("Creating a package repository took", elapsed)
33+
err := createPackageRepositoryMirror(repoNode, distro, sshKey)
34+
FailIfError(err, "Error creating local package repo")
4235

43-
// Deploy a docker registry on the node
4436
By("Deploying a docker registry")
4537
caFile, err := deployAuthenticatedDockerRegistry(repoNode, dockerRegistryPort, sshKey)
4638
FailIfError(err, "Failed to deploy docker registry")
4739

48-
By("Adding the docker registry self-signed cert to the registry node")
49-
registry := fmt.Sprintf("%s:%d", repoNode.PublicIP, dockerRegistryPort)
50-
err = copyFileToRemote(caFile, "/tmp/docker-registry-ca.crt", repoNode, sshKey, 30*time.Second)
51-
FailIfError(err, "Failed to copy registry cert to registry node")
52-
cmds = []string{
53-
fmt.Sprintf("sudo mkdir -p /etc/docker/certs.d/%s", registry),
54-
fmt.Sprintf("sudo mv /tmp/docker-registry-ca.crt /etc/docker/certs.d/%s/ca.crt", registry),
55-
}
56-
err = runViaSSH(cmds, []NodeDeets{repoNode}, sshKey, 10*time.Minute)
57-
FailIfError(err, "Error adding self-signed cert to registry node")
58-
59-
By("Copying KET to the registry node for seeding")
60-
err = copyFileToRemote(filepath.Join(currentKismaticDir, "kismatic.tar.gz"), "/tmp/kismatic.tar.gz", repoNode, sshKey, 5*time.Minute)
61-
FailIfError(err, "Error copying KET to the registry node")
62-
63-
By("Seeding the registry")
64-
start = time.Now()
65-
cmds = []string{
66-
fmt.Sprintf("sudo docker login -u kismaticuser -p kismaticpassword %s", registry),
67-
"sudo tar -xf /tmp/kismatic.tar.gz",
68-
fmt.Sprintf("sudo ./kismatic seed-registry --server %s", registry),
69-
}
70-
err = runViaSSH(cmds, []NodeDeets{repoNode}, sshKey, 30*time.Minute)
71-
FailIfError(err, "Failed to seed the registry")
72-
elapsed = time.Since(start)
73-
fmt.Println("Seeding the registry took", elapsed)
40+
By("Seeding the local registry")
41+
err = seedRegistry(repoNode, caFile, dockerRegistryPort, sshKey)
42+
FailIfError(err, "Error seeding local registry")
7443

7544
By("Disabling internet access")
7645
err = disableInternetAccess(nodes.allNodes(), sshKey)
@@ -82,7 +51,7 @@ var _ = Describe("disconnected installation", func() {
8251
err = copyFileToRemote("test-resources/disconnected-installation/configure-rpm-mirrors.sh", "/tmp/configure-rpm-mirrors.sh", n, sshKey, 15*time.Second)
8352
FailIfError(err, "Failed to copy script to nodes")
8453
}
85-
cmds = []string{
54+
cmds := []string{
8655
"chmod +x /tmp/configure-rpm-mirrors.sh",
8756
fmt.Sprintf("sudo /tmp/configure-rpm-mirrors.sh http://%s", repoNode.PrivateIP),
8857
}
@@ -110,53 +79,24 @@ var _ = Describe("disconnected installation", func() {
11079

11180
Context("on Ubuntu", func() {
11281
ItOnAWS("should install successfully [slow]", func(aws infrastructureProvisioner) {
113-
WithInfrastructure(NodeCount{1, 1, 2, 1, 1}, Ubuntu1604LTS, aws, func(nodes provisionedNodes, sshKey string) {
82+
distro := Ubuntu1604LTS
83+
WithInfrastructure(NodeCount{1, 1, 2, 1, 1}, distro, aws, func(nodes provisionedNodes, sshKey string) {
11484
// One of the workers is used as the repository and registry
11585
repoNode := nodes.worker[1]
11686
nodes.worker = nodes.worker[0:1]
11787

118-
// Create a package repo
11988
By("Creating a package repository")
120-
start := time.Now()
121-
err := copyFileToRemote("test-resources/disconnected-installation/mirror-debs.sh", "/tmp/mirror-debs.sh", repoNode, sshKey, 10*time.Second)
122-
FailIfError(err, "Failed to copy script to remote node")
123-
cmds := []string{"chmod +x /tmp/mirror-debs.sh", "sudo /tmp/mirror-debs.sh"}
124-
err = runViaSSH(cmds, []NodeDeets{repoNode}, sshKey, 45*time.Minute)
125-
FailIfError(err, "Failed to mirror package repositories")
126-
elapsed := time.Since(start)
127-
fmt.Println("Creating a package repository took", elapsed)
89+
err := createPackageRepositoryMirror(repoNode, distro, sshKey)
90+
FailIfError(err, "Error creating local package repo")
12891

12992
// Deploy a docker registry on the node
13093
By("Deploying a docker registry")
13194
caFile, err := deployAuthenticatedDockerRegistry(repoNode, dockerRegistryPort, sshKey)
13295
FailIfError(err, "Failed to deploy docker registry")
13396

134-
By("Adding the docker registry self-signed cert to the registry node")
135-
registry := fmt.Sprintf("%s:%d", repoNode.PublicIP, dockerRegistryPort)
136-
err = copyFileToRemote(caFile, "/tmp/docker-registry-ca.crt", repoNode, sshKey, 30*time.Second)
137-
FailIfError(err, "Failed to copy registry cert to registry node")
138-
cmds = []string{
139-
fmt.Sprintf("sudo mkdir -p /etc/docker/certs.d/%s", registry),
140-
fmt.Sprintf("sudo mv /tmp/docker-registry-ca.crt /etc/docker/certs.d/%s/ca.crt", registry),
141-
}
142-
err = runViaSSH(cmds, []NodeDeets{repoNode}, sshKey, 10*time.Minute)
143-
FailIfError(err, "Error adding self-signed cert to registry node")
144-
145-
By("Copying KET to the registry node for seeding")
146-
err = copyFileToRemote(filepath.Join(currentKismaticDir, "kismatic.tar.gz"), "/tmp/kismatic.tar.gz", repoNode, sshKey, 5*time.Minute)
147-
FailIfError(err, "Error copying KET to the registry node")
148-
149-
By("Seeding the registry")
150-
start = time.Now()
151-
cmds = []string{
152-
fmt.Sprintf("sudo docker login -u kismaticuser -p kismaticpassword %s", registry),
153-
"sudo tar -xf /tmp/kismatic.tar.gz",
154-
fmt.Sprintf("sudo ./kismatic seed-registry --server %s", registry),
155-
}
156-
err = runViaSSH(cmds, []NodeDeets{repoNode}, sshKey, 30*time.Minute)
157-
FailIfError(err, "Failed to seed the registry")
158-
elapsed = time.Since(start)
159-
fmt.Println("Seeding the registry took", elapsed)
97+
By("Seeding the local registry")
98+
err = seedRegistry(repoNode, caFile, dockerRegistryPort, sshKey)
99+
FailIfError(err, "Error seeding local registry")
160100

161101
By("Disabling internet access")
162102
err = disableInternetAccess(nodes.allNodes(), sshKey)
@@ -168,7 +108,7 @@ var _ = Describe("disconnected installation", func() {
168108
err = copyFileToRemote("test-resources/disconnected-installation/configure-deb-mirrors.sh", "/tmp/configure-deb-mirrors.sh", n, sshKey, 15*time.Second)
169109
FailIfError(err, "Failed to copy script to nodes")
170110
}
171-
cmds = []string{
111+
cmds := []string{
172112
"chmod +x /tmp/configure-deb-mirrors.sh",
173113
fmt.Sprintf("sudo /tmp/configure-deb-mirrors.sh http://%s", repoNode.PrivateIP),
174114
}

0 commit comments

Comments
 (0)