Skip to content

Create selenium test user in Eclipse Che on OCP remotely#9982

Merged
dmytro-ndp merged 6 commits intomasterfrom
che-9878
Jun 12, 2018
Merged

Create selenium test user in Eclipse Che on OCP remotely#9982
dmytro-ndp merged 6 commits intomasterfrom
che-9878

Conversation

@dmytro-ndp
Copy link
Copy Markdown
Contributor

What does this PR do?

It involves OpenShift CLI client into test user creation process when we are running E2E selenium tests against Eclipse Che Multiuser on OCP.
It makes it possible to create test user remotely when testing product is deployed to the remote host.

What issues does this PR fix or reference?

#9878

Signed-off-by: Dmytro Nochevnov <dnochevnov@codenvy.com>
@dmytro-ndp
Copy link
Copy Markdown
Contributor Author

ci-test

@dmytro-ndp dmytro-ndp added status/code-review This issue has a pull request posted for it and is awaiting code review completion by the community. kind/task Internal things, technical debt, and to-do tasks to be performed. labels Jun 8, 2018
@codenvy-ci
Copy link
Copy Markdown

ci-test build report:
Build details
Test report
selenium tests report data
docker image: eclipseche/che-server:9982
https://github.com/orgs/eclipse/teams/eclipse-che-qa please check this report.

Signed-off-by: Dmytro Nochevnov <dnochevnov@codenvy.com>
@dmytro-ndp
Copy link
Copy Markdown
Contributor Author

ci-test

@codenvy-ci
Copy link
Copy Markdown

ci-test build report:
Build details
Test report
selenium tests report data
docker image: eclipseche/che-server:9982
https://github.com/orgs/eclipse/teams/eclipse-che-qa please check this report.

@dmytro-ndp
Copy link
Copy Markdown
Contributor Author

ci-test

@codenvy-ci
Copy link
Copy Markdown

ci-test build report:
Build details
Test report
selenium tests report data
docker image: eclipseche/che-server:9982
https://github.com/orgs/eclipse/teams/eclipse-che-qa please check this report.

@dmytro-ndp
Copy link
Copy Markdown
Contributor Author

ci-test

@codenvy-ci
Copy link
Copy Markdown

ci-test build report:
Build details
Test report
selenium tests report data
docker image: eclipseche/che-server:9982
https://github.com/orgs/eclipse/teams/eclipse-che-qa please check this report.


private static final boolean IS_MAC_OS =
System.getProperty("os.name").toLowerCase().startsWith("mac");
private static final String DEFAULT_OPENSHIFT_USERNAME = "developer";
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

So, this only works if auth isn't configured in the cluster (by default with oc cluster up)? Wouldn't it make more sense to have it in conf, so that you can run tests against Che deployed on any cluster?

Copy link
Copy Markdown
Contributor Author

@dmytro-ndp dmytro-ndp Jun 11, 2018

Choose a reason for hiding this comment

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

Paths.get(System.getProperty("java.io.tmpdir"));

private static final Path PATH_TO_OPENSHIFT_CLI = PATH_TO_OPENSHIFT_CLI_DIRECTORY.resolve("oc");
public static final String ECLIPSE_CHE_NAMESPACE = "eclipse-che";
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

What if it's not eclipse-che namespace? Having it in configuration props will make it much more flexible.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thank you for advice!

private static final boolean IS_MAC_OS =
System.getProperty("os.name").toLowerCase().startsWith("mac");
private static final String DEFAULT_OPENSHIFT_USERNAME = "developer";
private static final String DEFAULT_OPENSHIFT_PASSWORD = "any";
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

You may need a token since if cluster is configured with oAuth, there's no way you can do oc login -u -p. Can we introduce a token for such use cases? Say, before running a test, you obtain a token, export it as env (or save to configuration file) and then run tests.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thank you for notice. Which environment variable we can use to hold the token?

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

You may pick any reasonable name. And if set, then oc login should use it. If not, username and password are used (default unless set by a user).

You can get your token this way:

oc login -u developer -p password
oc whoami -t

My point is that even though this PR makes interaction with Keycloak more efficient, it won't help if you need to run tests against any infra that different from a default cluster started with oc cluster up

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I can't find parameter to pass auth token to "oc login" command in docs.
Did you mean that we should add auth token directly into the ~/.kube/config file?

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

eugene@ivantsoft ~/projects/rhel-stacks/che-assembly (master) $ oc login --help
Log in to your server and save login for subsequent use 

First-time users of the client should run this command to connect to a server, establish an authenticated session, and
save connection to the configuration file. The default configuration will be saved to your home directory under
".kube/config". 

The information required to login -- like username and password, a session token, or the server details -- can be
provided through flags. If not provided, the command will prompt for user input as needed.

Usage:
  oc login [URL] [options]

Examples:
  # Log in interactively
  oc login
  
  # Log in to the given server with the given certificate authority file
  oc login localhost:8443 --certificate-authority=/path/to/cert.crt
  
  # Log in to the given server with the given credentials (will not prompt interactively)
  oc login localhost:8443 --username=myuser --password=mypass

Options:
  -p, --password='': Password, will prompt if not provided
  -u, --username='': Username, will prompt if not provided      --certificate-authority='': Path to a cert file for the
certificate authority
      --insecure-skip-tls-verify=false: If true, the server's certificate will not be checked for validity. This will
make your HTTPS connections insecure
      --token='': Bearer token for authentication to the API server

Use "oc options" for a list of global command-line options (applies to all commands).
eugene@ivantsoft ~/projects/rhel-stacks/che-assembly (master) $ 

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thank you, Eugene.

if (!matcher.matches()) {
throw new RuntimeException(
format(
"It's impossible to extract OpenShift host from Eclipse Che host '%s'. Make sure that correct value is set for `CHE_INFRASTRUCTURE`.",
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

It's just a question. Can you explain why you need to extract Che host (route?) from OpenShift web console URL? Also, we should not forget that 8443 is the default port. It can be just 443 (OSO for example).

Copy link
Copy Markdown
Contributor Author

@dmytro-ndp dmytro-ndp Jun 11, 2018

Choose a reason for hiding this comment

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

I am trying to avoid over-engineering here. It's kind of default behavior, but user is able to set OpenShift console URL manually through the "OPENSHIFT_URL" environment variable.

format(
"docker exec -i %s sh -c 'keycloak/bin/kcadm.sh delete users/%s -r che -s username=%s --no-config --server http://localhost:8080/auth --user %s --password %s --realm master 2>&1'",
keycloakContainerId,
"delete users/%s -r che -s username=%s --no-config --server http://localhost:8080/auth --user %s --password %s --realm master 2>&1",
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

What about a case when "CHE_PORT" variable is different from default "8080"?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Here we are using different port - for keycloak server from within keycloak container.


/** @author Dmytro Nochevnov */
@Singleton
public class DockerContainerCommandExecutor implements KeycloakCommandExecutor {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

In my opinion, the current name of the class "DockerContainerCommandExecutor" means that it describes the class which responsible for commands execution in some abstract docker container but not in the particular "Keycloak" container. Maybe it should be renamed to something like "DockerKeycloakCommandExecutor" or "KeycloakCommandExecutorImpl"?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

You are particularly right, but I took into account the name of package: keycloak.executor.

@Singleton
public class OpenShiftWebConsoleUrlProvider implements Provider<URL> {

private static final int PORT = 8443;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Is web console port always "8443" and can`t be reconfigured by any system variable?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

It can be reconfigured manually through the "OPENSHIFT_URL" environment variable.

…CommandExecutor

Signed-off-by: Dmytro Nochevnov <dnochevnov@codenvy.com>
Dmytro Nochevnov added 2 commits June 11, 2018 19:19
@dmytro-ndp
Copy link
Copy Markdown
Contributor Author

ci-test

@codenvy-ci
Copy link
Copy Markdown

ci-test build report:
Build details
Test report
selenium tests report data
docker image: eclipseche/che-server:9982
https://github.com/orgs/eclipse/teams/eclipse-che-qa please check this report.

Signed-off-by: Dmytro Nochevnov <dnochevnov@codenvy.com>
@dmytro-ndp dmytro-ndp merged commit e75fbce into master Jun 12, 2018
@dmytro-ndp dmytro-ndp deleted the che-9878 branch June 12, 2018 09:48
@dmytro-ndp dmytro-ndp removed the status/code-review This issue has a pull request posted for it and is awaiting code review completion by the community. label Jun 12, 2018
@dmytro-ndp dmytro-ndp added this to the 6.7.0 milestone Jun 12, 2018
hbhargav pushed a commit to hbhargav/che that referenced this pull request Dec 5, 2018
…#9982)

* Add KeycloakCommandExecutor to create test user in selenium tests
* Create test user in Eclipse Che on OCP which is run remotely
Signed-off-by: Dmytro Nochevnov <dnochevnov@codenvy.com>
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.

4 participants