github.com/misfo/deis@v1.0.1-0.20141111224634-e0eee0392b8a/store/tests/store_test.go (about)

     1  package tests
     2  
     3  import (
     4  	"fmt"
     5  	"testing"
     6  	"time"
     7  
     8  	"github.com/deis/deis/tests/dockercli"
     9  	"github.com/deis/deis/tests/etcdutils"
    10  	"github.com/deis/deis/tests/utils"
    11  )
    12  
    13  func TestStore(t *testing.T) {
    14  	hostname := utils.Hostname()
    15  	var err error
    16  
    17  	// Set up etcd, which will be used by all containers
    18  	tag, etcdPort := utils.BuildTag(), utils.RandomPort()
    19  	etcdName := "deis-etcd-" + tag
    20  	cli, stdout, stdoutPipe := dockercli.NewClient()
    21  	dockercli.RunTestEtcd(t, etcdName, etcdPort)
    22  	defer cli.CmdRm("-f", etcdName)
    23  	host := utils.HostAddress()
    24  
    25  	// prep etcd with the monitor hostname -- this is done in an ExecStartPre in the monitor unit
    26  	etcdutils.SetSingle(t, "/deis/store/hosts/"+host, hostname, etcdPort)
    27  
    28  	// since we're only running one OSD, our default of 128 placement groups is too large
    29  	etcdutils.SetSingle(t, "/deis/store/pgNum", "64", etcdPort)
    30  
    31  	// test deis-store-monitor
    32  	fmt.Printf("--- Run deis/store-monitor:%s at %s\n", tag, host)
    33  	name := "deis-store-monitor-" + tag
    34  	defer cli.CmdRm("-f", name)
    35  	go func() {
    36  		_ = cli.CmdRm("-f", name)
    37  		err = dockercli.RunContainer(cli,
    38  			"--name", name,
    39  			"--rm",
    40  			"-e", "HOST="+host,
    41  			"-e", "ETCD_PORT="+etcdPort,
    42  			"-e", "NUM_STORES=1",
    43  			"--net=host",
    44  			"deis/store-monitor:"+tag)
    45  	}()
    46  	dockercli.PrintToStdout(t, stdout, stdoutPipe, "monmap e1: 1 mons at")
    47  	if err != nil {
    48  		t.Fatal(err)
    49  	}
    50  	// FIXME: Wait until etcd keys are published
    51  	time.Sleep(5000 * time.Millisecond)
    52  	dockercli.DeisServiceTest(t, name, "6789", "tcp")
    53  	etcdutils.VerifyEtcdKey(t, "/deis/store/monKeyring", etcdPort)
    54  	etcdutils.VerifyEtcdKey(t, "/deis/store/adminKeyring", etcdPort)
    55  	etcdutils.VerifyEtcdValue(t, "/deis/store/monSetupComplete", "youBetcha", etcdPort)
    56  
    57  	// test deis-store-daemon
    58  	fmt.Printf("--- Run deis/store-daemon:%s at %s\n", tag, host)
    59  	name = "deis-store-daemon-" + tag
    60  	cli2, stdout2, stdoutPipe2 := dockercli.NewClient()
    61  	defer cli2.CmdRm("-f", "-v", name)
    62  	go func() {
    63  		_ = cli2.CmdRm("-f", "-v", name)
    64  		err = dockercli.RunContainer(cli2,
    65  			"--name", name,
    66  			"--rm",
    67  			"-e", "HOST="+host,
    68  			"-e", "ETCD_PORT="+etcdPort,
    69  			"--net=host",
    70  			"deis/store-daemon:"+tag)
    71  	}()
    72  	dockercli.PrintToStdout(t, stdout2, stdoutPipe2, "journal close /var/lib/ceph/osd/ceph-0/journal")
    73  	if err != nil {
    74  		t.Fatal(err)
    75  	}
    76  	// FIXME: Wait until etcd keys are published
    77  	time.Sleep(5000 * time.Millisecond)
    78  	dockercli.DeisServiceTest(t, name, "6800", "tcp")
    79  	etcdutils.VerifyEtcdValue(t, "/deis/store/osds/"+host, "0", etcdPort)
    80  
    81  	// test deis-store-metadata
    82  	fmt.Printf("--- Run deis/store-metadata:%s at %s\n", tag, host)
    83  	name = "deis-store-metadata-" + tag
    84  	cli3, stdout3, stdoutPipe3 := dockercli.NewClient()
    85  	defer cli3.CmdRm("-f", "-v", name)
    86  	go func() {
    87  		_ = cli3.CmdRm("-f", "-v", name)
    88  		err = dockercli.RunContainer(cli3,
    89  			"--name", name,
    90  			"--rm",
    91  			"-e", "HOST="+host,
    92  			"-e", "ETCD_PORT="+etcdPort,
    93  			"--net=host",
    94  			"deis/store-metadata:"+tag)
    95  	}()
    96  	dockercli.PrintToStdout(t, stdout3, stdoutPipe3, "mds.0.1 active_start")
    97  	if err != nil {
    98  		t.Fatal(err)
    99  	}
   100  
   101  	// test deis-store-gateway
   102  	port := utils.RandomPort()
   103  	fmt.Printf("--- Run deis/store-gateway:%s at %s:%s\n", tag, host, port)
   104  	name = "deis-store-gateway-" + tag
   105  	cli4, stdout4, stdoutPipe4 := dockercli.NewClient()
   106  	defer cli4.CmdRm("-f", name)
   107  	go func() {
   108  		_ = cli4.CmdRm("-f", name)
   109  		err = dockercli.RunContainer(cli4,
   110  			"--name", name,
   111  			"--rm",
   112  			"-h", "deis-store-gateway",
   113  			"-p", port+":8888",
   114  			"-e", "HOST="+host,
   115  			"-e", "EXTERNAL_PORT="+port,
   116  			"-e", "ETCD_PORT="+etcdPort,
   117  			"deis/store-gateway:"+tag)
   118  	}()
   119  	dockercli.PrintToStdout(t, stdout4, stdoutPipe4, "deis-store-gateway running...")
   120  	if err != nil {
   121  		t.Fatal(err)
   122  	}
   123  	// FIXME: Wait until etcd keys are published
   124  	time.Sleep(5000 * time.Millisecond)
   125  	dockercli.DeisServiceTest(t, name, port, "http")
   126  	etcdutils.VerifyEtcdValue(t, "/deis/store/gateway/host", host, etcdPort)
   127  	etcdutils.VerifyEtcdValue(t, "/deis/store/gateway/port", port, etcdPort)
   128  	etcdutils.VerifyEtcdKey(t, "/deis/store/gatewayKeyring", etcdPort)
   129  	etcdutils.VerifyEtcdKey(t, "/deis/store/gateway/accessKey", etcdPort)
   130  	etcdutils.VerifyEtcdKey(t, "/deis/store/gateway/secretKey", etcdPort)
   131  }