Skip to content
This repository has been archived by the owner on Sep 5, 2024. It is now read-only.

Commit

Permalink
Fix issues with running tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ibuildthecloud committed Aug 15, 2018
1 parent bb20d87 commit 8a1a3d0
Show file tree
Hide file tree
Showing 10 changed files with 74 additions and 63 deletions.
2 changes: 1 addition & 1 deletion Dockerfile.dapper
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ ENV DAPPER_RUN_ARGS --privileged
ENV HOST_ARCH=${DAPPER_HOST_ARCH} ARCH=${DAPPER_HOST_ARCH}

RUN apt-get update && \
apt-get install -y npm zip squashfs-tools sudo gcc ca-certificates git wget curl vim less file && \
apt-get install -y npm zip squashfs-tools sudo gcc ca-certificates git wget curl vim less file jq && \
rm -f /bin/sh && ln -s /bin/bash /bin/sh

RUN npm install -g bats
Expand Down
11 changes: 8 additions & 3 deletions cli/cmd/run/run.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package run

import (
"time"

"fmt"
"os"
"time"

"github.com/onsi/ginkgo/reporters/stenographer/support/go-isatty"
"github.com/rancher/rio/cli/cmd/attach"
"github.com/rancher/rio/cli/cmd/create"
"github.com/rancher/rio/types/client/rio/v1beta1"
Expand All @@ -25,7 +26,11 @@ func (r *Run) Run(app *cli.Context) error {
return err
}

if !r.Detach && service.OpenStdin && service.Tty {
istty := isatty.IsTerminal(os.Stdout.Fd()) &&
isatty.IsTerminal(os.Stderr.Fd()) &&
isatty.IsTerminal(os.Stdin.Fd())

if istty && !r.Detach && service.OpenStdin && service.Tty {
fmt.Println("Attaching...")
return attach.RunAttach(app, time.Minute, true, true, service.ID)
}
Expand Down
37 changes: 1 addition & 36 deletions cli/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ func main() {
return
}

args := reformatArgs(os.Args)
args := os.Args

app := cli.NewApp()
app.Name = appName
Expand Down Expand Up @@ -250,38 +250,3 @@ If you are just looking for general "rio" CLI usage then run
`)
os.Exit(1)
}

func reformatArgs(args []string) []string {
var result []string
words := 0
for i, arg := range args {
if arg == "--" {
return append(result, args[i:]...)
}

if arg == "" {
result = append(result, arg)
continue
}

if arg[0:1] != "-" {
words++
if words > 2 {
return append(result, args[i:]...)
}
result = append(result, arg)
continue
}

if len(arg) <= 2 || arg[1:2] == "-" {
result = append(result, arg)
continue
}

for _, chars := range arg[1:] {
result = append(result, "-"+string(chars))
}
}

return result
}
10 changes: 6 additions & 4 deletions cli/pkg/builder/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,12 @@ func Command(obj interface{}, usage, usageText, description string) cli.Command
objValue := ptrValue.Elem()

c := cli.Command{
Name: strings.ToLower(strings.Replace(objValue.Type().Name(), "Command", "", 1)),
Usage: usage,
UsageText: usageText,
Description: description,
Name: strings.ToLower(strings.Replace(objValue.Type().Name(), "Command", "", 1)),
Usage: usage,
UsageText: usageText,
Description: description,
UseShortOptionHandling: true,
SkipArgReorder: true,
}

for _, info := range fields(obj) {
Expand Down
19 changes: 14 additions & 5 deletions cli/pkg/waiter/wait.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,22 @@ func waitForResources(app *cli.Context) error {
return err
}

timeout := app.GlobalInt("wait-timeout")
end := time.Now().Add(time.Duration(timeout) * time.Second)

for _, r := range ctx.CLIContext.Args() {
resource, err := lookup.Lookup(ctx.ClientLookup, r, waitTypes...)
if err != nil {
logrus.Info("%s does not exist")
continue
for {
resource, err := lookup.Lookup(ctx.ClientLookup, r, waitTypes...)
if err != nil {
if time.Now().After(end) {
return fmt.Errorf("timeout waiting for %s to exist", r)
}
time.Sleep(time.Second)
continue
}
w.Add(resource)
break
}
w.Add(resource)
}

return w.Wait()
Expand Down
19 changes: 11 additions & 8 deletions cli/server/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,20 +123,23 @@ func NewContextBuilder(config string, k8s bool) (*ContextBuilder, error) {
}

func createPrepareFunc(cfg *rest.Config) (func(req *http.Request) (*url.URL, error), error) {
rt, err := rest.HTTPWrappersForConfig(cfg, &fakeRT{})
if err != nil {
return nil, err
}

return func(req *http.Request) (*url.URL, error) {
_, err := rt.RoundTrip(req)
capture := &rtCapture{}
rt, err := rest.HTTPWrappersForConfig(cfg, capture)
if err != nil {
return nil, err
}
_, err = rt.RoundTrip(req)
*req = *capture.req
return nil, err
}, nil
}

type fakeRT struct {
type rtCapture struct {
req *http.Request
}

func (*fakeRT) RoundTrip(r *http.Request) (*http.Response, error) {
func (r *rtCapture) RoundTrip(req *http.Request) (*http.Response, error) {
r.req = req
return nil, nil
}
11 changes: 10 additions & 1 deletion controllers/backend/service/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ func (s *serviceController) sync(key string, service *v1beta1.Service) error {

if isUpgrading {
updated.Unknown(newService)
} else {
} else if hasAvailable(newService.Status.DeploymentStatus.Conditions) {
newService.Status.Conditions = nil
}

Expand All @@ -126,3 +126,12 @@ func (s *serviceController) sync(key string, service *v1beta1.Service) error {

return nil
}

func hasAvailable(cond []appsv1beta2.DeploymentCondition) bool {
for _, c := range cond {
if c.Type == "Available" {
return true
}
}
return false
}
6 changes: 6 additions & 0 deletions controllers/backend/stack/gather.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,12 @@ func (s *stackController) gatherObjects(ns string, stack *v1beta1.Stack, interna
newResource.Namespace = ns
newResource.Spec.SpaceName = stack.Namespace
newResource.Spec.StackName = ref.FromStrings(stack.Namespace, stack.Name)
newResource.Status.Conditions = []v1beta1.Condition{
{
Type: "Pending",
Status: "Unknown",
},
}

resources = append(resources, newResource)
}
Expand Down
1 change: 1 addition & 0 deletions scripts/package-tar
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ tar cvzf dist/artifacts/rio-${VERSION}-darwin.tar.gz bin/rio-darwin --xform='s!.

W=rio-${VERSION}-windows
mkdir -p $W
trap "rm -rf $W" EXIT

cp -f bin/rio-windows $W/rio.exe
zip dist/artifacts/rio-${VERSION}-windows.zip $W/rio.exe
21 changes: 16 additions & 5 deletions scripts/test
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,29 @@ echo Running tests

mkdir -p ./build

# prime sudo
sudo id
sudo ./bin/rio server | grep -v level=info &
PID=$!
mkdir -p /var/lib/rancher/rio/agent
mount -t tmpfs none /var/lib/rancher/rio/agent

./bin/rio server --disable-agent | grep -v level=info > /var/lib/rancher/rio/agent/agent.log 2>&1 &

for i in {1..20}; do
curl -sf http://localhost:7080/healthz >/dev/null && break
sleep .5
done
curl -sf http://localhost:7080/healthz >/dev/null

sudo env PATH=$(pwd)/bin:$PATH bats -r ./tests || {
ENTER_ROOT=$(pwd)/image/root ./bin/rio agent -s https://localhost:7443 -t $(</var/lib/rancher/rio/server/node-token) >>/var/lib/rancher/rio/agent/agent.log 2>&1 &

export PATH=$(pwd)/bin:$PATH

rio login -s https://localhost:7443 -t /var/lib/rancher/rio/server/client-token

echo Waiting for istio/gateway
rio --workspace=rio-system wait istio/istio-gateway
rio --workspace=rio-system ps
rio --workspace=rio-system ps -c

bats -r ./tests || {
tail -n 100 /var/lib/rancher/rio/agent/agent.log
exit 1
}

0 comments on commit 8a1a3d0

Please sign in to comment.