forked from openshift/origin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mongodb.go
66 lines (56 loc) · 1.65 KB
/
mongodb.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
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
}
// NewMongoDB creates a new util.Database instance.
func NewMongoDB(podName string) util.Database {
return &MongoDB{
podName: podName,
}
}
// 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 whether it is possible to remote login to hostAddress.
func (m MongoDB) TestRemoteLogin(oc *util.CLI, hostAddress string) error {
return errors.New("not implemented")
}
// // QueryPrimary queries the database on primary node as a regular user.
func (m MongoDB) QueryPrimary(oc *util.CLI, query string) (string, error) {
return executeShellCommand(
oc,
m.podName,
fmt.Sprintf(
`mongo --quiet "$MONGODB_DATABASE" --username "$MONGODB_USER" --password "$MONGODB_PASSWORD" --host "$MONGODB_REPLICA_NAME/localhost" --eval '%s'`,
query,
),
)
}