Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added functional tests for CLI start command #3870

Merged
merged 3 commits into from
Jan 25, 2017
Merged

Added functional tests for CLI start command #3870

merged 3 commits into from
Jan 25, 2017

Conversation

mlabuda
Copy link

@mlabuda mlabuda commented Jan 24, 2017

Signed-off-by: Marian Labuda [email protected]

What does this PR do?

Added basic functional tests for CLI start command. Plus few minors:

  • fixed usage of CLI image in cli prompts and usage tests suite
  • extended test base with function to get free port and find out whether a passed port is free

Changelog and Release Note Information

Changelog

Added basic CLI 'start' functional tests

Relase Notes and Docs PR N/A

  • Added to release note in community section

@codenvy-ci
Copy link

Can one of the admins verify this patch?

@TylerJewell TylerJewell added the kind/enhancement A feature request - must adhere to the feature request template. label Jan 24, 2017
@TylerJewell TylerJewell self-assigned this Jan 24, 2017
@TylerJewell
Copy link

Nice improvement. I learned something new by reading this about how to find open ports.

@TylerJewell TylerJewell requested a review from benoitf January 24, 2017 14:46
Copy link
Contributor

@benoitf benoitf left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I forgot to publish my comments

docker run -v $BATS_BASE_DIR:$BATS_BASE_DIR -e CLI_IMAGE_TAG=$TAG -e BATS_BASE_DIR=$BATS_BASE_DIR -v /var/run/docker.sock:/var/run/docker.sock $IMAGE_NAME bats $BATS_BASE_DIR/tests/cmd_init_destroy_tests.bats

echo "Running functionals bats tests for start command"
docker run -v $BATS_BASE_DIR:$BATS_BASE_DIR -e CLI_IMAGE_TAG=$TAG -e BATS_BASE_DIR=$BATS_BASE_DIR -v /var/run/docker.sock:/var/run/docker.sock $IMAGE_NAME bats $BATS_BASE_DIR/tests/cmd_start_tests.bats
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

question: do you think we could automate the commands ? (using a function)
because most of the lines are copy/paste of "docker run -v $BATS_BASE_DIR:$BATS_BASE_DIR -e CLI_IMAGE_TAG=$TAG -e BATS_BASE_DIR=$BATS_BASE_DIR -v /var/run/docker.sock:/var/run/docker.sock $IMAGE_NAME bats $BATS_"

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure thing, I will extract subcommand as a function.

echo "Removing named container $1"
docker rm $1 1>/dev/null
fi
}

# Pass a port as an argument to check whether is free or not
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should these utility methods should be moved in a library_test ?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think so. The test_base.sh is parent of all tests, if I would move all utility functions to a library_tests.sh, than the test_base.sh would have only few constants in header, sourced library and nothing else (no functions). It would be a transitive sourcing and not needed, I think.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok perfect

@test "test cli 'start' with custom port" {
#GIVEN
tmp_path=${TESTRUN_DIR}/start2
free_port=$(get_free_port)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we need get_free_port method ? AFAIK in docker we're in isolated env

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, we need it. I was looking into Che and it is using default network interface docker0 (On my side 172.17.0.1). Che server runs in a container with an IP (here 172.17.0.4). Che server is accessible via port 8080. I can access to the server via 172.17.0.4:8080 but also via 172.17.0.1:8080. But the server also expose ports and forward ports to localhost. So the server is accessible also on localhost:8080. The port 8080 can be found in state LISTEN in netstat output. Same applies also to workspaces, but those take ports from 32xxx (at least now when I was running them, haven't look closer to scripts what is the algorithm to choose ports). And those are forwarded as well.

Ok now to the reason why I need free ports. First problem could be caused if there would be other docker images running and those would use port required by a che server. It would fail. Second problem is having a service running on localhost (e.g. I have running wildfly locally, which uses port 8080). And this would fail too.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I still think it is strange. Because the check is performed inside the container while che for example use a docker port mapping.
So I don't see if when we check inside the container we can check the host ports if we don't have a port mapping

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Workspace map ports to free ports, but the che-server which is using this free port function is using same port and if on host is the port used, I cannot start the che server there. Therefore I cannot run che server with CHE_PORT=alreadyusedport and tests would fail.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, I did more digging. The way to get free ports is working on a host, but inside a container it is not working, basically because container itself is isolated from other containers... I will have to find a way to get free ports from inside, at the moment it is not working as expected, unfortunately (it takes first port from the range in free ports function, because output of netstat is empty).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes this was my first impression. But it's not a big issue

@mlabuda
Copy link
Author

mlabuda commented Jan 25, 2017

Applied changes to have correctly working netstat in a che-bats container. Basically I had to run the container in host network to have proper data. Now it works.

@slemeur
Copy link
Contributor

slemeur commented Jan 25, 2017

Added to Release Note - ok for me

@benoitf benoitf merged commit d18be47 into eclipse-che:master Jan 25, 2017
@benoitf
Copy link
Contributor

benoitf commented Jan 25, 2017

While it works on my computer when I tested, it is not on the CI server: #3902

@slemeur slemeur added kind/task Internal things, technical debt, and to-do tasks to be performed. and removed kind/enhancement A feature request - must adhere to the feature request template. labels Feb 1, 2017
@JamesDrummond JamesDrummond mentioned this pull request Feb 6, 2017
9 tasks
JPinkney pushed a commit to JPinkney/che that referenced this pull request Aug 17, 2017
* Added functional tests for CLI start command
Signed-off-by: Marian Labuda <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/task Internal things, technical debt, and to-do tasks to be performed.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants