-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Also refactored mysql/postgresql a bit by extracting structs and similar pieces of code.
- Loading branch information
Showing
8 changed files
with
412 additions
and
221 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
package images | ||
|
||
import ( | ||
"fmt" | ||
|
||
g "github.com/onsi/ginkgo" | ||
o "github.com/onsi/gomega" | ||
|
||
exutil "github.com/openshift/origin/test/extended/util" | ||
"github.com/openshift/origin/test/extended/util/db" | ||
"time" | ||
) | ||
|
||
var _ = g.Describe("images: mongodb: ephemeral template", func() { | ||
defer g.GinkgoRecover() | ||
|
||
templatePath := exutil.FixturePath("..", "..", "examples", "db-templates", "mongodb-ephemeral-template.json") | ||
oc := exutil.NewCLI("mongodb-create", exutil.KubeConfigPath()).Verbose() | ||
|
||
g.Describe("creating from a template", func() { | ||
g.It(fmt.Sprintf("should process and create the %q template", templatePath), func() { | ||
|
||
g.By("creating a new app") | ||
o.Expect(oc.Run("new-app").Args("-f", templatePath).Execute()).Should(o.Succeed()) | ||
|
||
g.By("expecting the mongodb service get endpoints") | ||
o.Expect(oc.KubeFramework().WaitForAnEndpoint("mongodb")).Should(o.Succeed()) | ||
|
||
g.By("expecting the mongodb pod is running") | ||
podNames, err := exutil.WaitForPods( | ||
oc.KubeREST().Pods(oc.Namespace()), | ||
exutil.ParseLabelsOrDie("name=mongodb"), | ||
exutil.CheckPodIsRunningFn, | ||
1, | ||
1*time.Minute, | ||
) | ||
o.Expect(err).ShouldNot(o.HaveOccurred()) | ||
o.Expect(podNames).Should(o.HaveLen(1)) | ||
|
||
g.By("expecting the mongodb service is answering for ping") | ||
mongo := db.NewMongoDB(podNames[0], "") | ||
|
||
for times := 0; times < 10; times++ { | ||
ok, err := mongo.IsReady(oc) | ||
if ok { | ||
break | ||
} | ||
|
||
if times == 10 { | ||
o.Expect(err).ShouldNot(o.HaveOccurred()) | ||
o.Expect(ok).Should(o.BeTrue()) | ||
break | ||
} | ||
|
||
time.Sleep(1 * time.Second) | ||
} | ||
|
||
g.By("expecting that we can insert a new record") | ||
result, err := mongo.Query(oc, `db.foo.save({ "status": "passed" })`) | ||
o.Expect(err).ShouldNot(o.HaveOccurred()) | ||
o.Expect(result).Should(o.ContainSubstring(`WriteResult({ "nInserted" : 1 })`)) | ||
|
||
g.By("expecting that we can read a record") | ||
findCmd := "printjson(db.foo.find({}, {_id: 0}).toArray())" // don't include _id field to output because it changes every time | ||
result, err = mongo.Query(oc, findCmd) | ||
o.Expect(err).ShouldNot(o.HaveOccurred()) | ||
o.Expect(result).Should(o.ContainSubstring(`{ "status" : "passed" }`)) | ||
}) | ||
}) | ||
|
||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
package db | ||
|
||
import ( | ||
"fmt" | ||
"os/exec" | ||
"strings" | ||
|
||
"github.com/openshift/origin/test/extended/util" | ||
kclient "k8s.io/kubernetes/pkg/client/unversioned" | ||
) | ||
|
||
// PodConfig holds configuration for a pod. | ||
type PodConfig struct { | ||
Container string | ||
Env map[string]string | ||
} | ||
|
||
func getPodConfig(c kclient.PodInterface, podName string) (conf *PodConfig, err error) { | ||
pod, err := c.Get(podName) | ||
if err != nil { | ||
return nil, err | ||
} | ||
env := make(map[string]string) | ||
for _, container := range pod.Spec.Containers { | ||
for _, e := range container.Env { | ||
env[e.Name] = e.Value | ||
} | ||
} | ||
return &PodConfig{pod.Spec.Containers[0].Name, env}, nil | ||
} | ||
|
||
func firstContainerName(c kclient.PodInterface, podName string) (string, error) { | ||
pod, err := c.Get(podName) | ||
if err != nil { | ||
return "", err | ||
} | ||
|
||
return pod.Spec.Containers[0].Name, nil | ||
} | ||
|
||
func isReady(oc *util.CLI, podName string, pingCommand, expectedOutput string) (bool, error) { | ||
out, err := executeShellCommand(oc, podName, pingCommand) | ||
ok := strings.Contains(out, expectedOutput) | ||
if !ok { | ||
err = fmt.Errorf("Expected output: %q but actual: %q", expectedOutput, out) | ||
} | ||
return ok, err | ||
} | ||
|
||
func executeShellCommand(oc *util.CLI, podName string, command string) (string, error) { | ||
out, err := oc.Run("exec").Args(podName, "--", "bash", "-c", command).Output() | ||
if err != nil { | ||
switch err.(type) { | ||
case *exec.ExitError: | ||
return "", nil | ||
default: | ||
return "", err | ||
} | ||
} | ||
|
||
return out, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
package db | ||
|
||
import ( | ||
"errors" | ||
"fmt" | ||
|
||
"github.com/openshift/origin/test/extended/util" | ||
) | ||
|
||
// MongoDB is a MongoDB helper for executing commands. | ||
type MongoDB struct { | ||
podName string | ||
masterPodName string | ||
} | ||
|
||
// NewMongoDB creates a new util.Database instance. | ||
func NewMongoDB(podName, masterPodName string) util.Database { | ||
if masterPodName == "" { | ||
masterPodName = podName | ||
} | ||
return &MongoDB{ | ||
podName: podName, | ||
masterPodName: masterPodName, | ||
} | ||
} | ||
|
||
// PodName implements Database. | ||
func (m MongoDB) PodName() string { | ||
return m.podName | ||
} | ||
|
||
// IsReady pings the MongoDB server. | ||
func (m MongoDB) IsReady(oc *util.CLI) (bool, error) { | ||
return isReady( | ||
oc, | ||
m.podName, | ||
`mongo --quiet --eval '{"ping", 1}'`, | ||
"1", | ||
) | ||
} | ||
|
||
// Query executes a query as an ordinary user and returns the result. | ||
func (m MongoDB) Query(oc *util.CLI, query string) (string, error) { | ||
return executeShellCommand( | ||
oc, | ||
m.podName, | ||
fmt.Sprintf(`mongo --quiet "$MONGODB_DATABASE" --username "$MONGODB_USER" --password "$MONGODB_PASSWORD" --eval '%s'`, query), | ||
) | ||
} | ||
|
||
// QueryPrivileged queries the database as a privileged user. | ||
func (m MongoDB) QueryPrivileged(oc *util.CLI, query string) (string, error) { | ||
return "", errors.New("not implemented") | ||
} | ||
|
||
// TestRemoteLogin tests wheather it is possible to remote login to hostAddress. | ||
func (m MongoDB) TestRemoteLogin(oc *util.CLI, hostAddress string) error { | ||
return errors.New("not implemented") | ||
} |
Oops, something went wrong.