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