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

Login to oc right after init #11366

Merged
merged 2 commits into from
Oct 2, 2018

Conversation

Katka92
Copy link
Contributor

@Katka92 Katka92 commented Sep 26, 2018

What does this PR do?

Login to oc right after the class OpenShiftCliCommandExecutor is initialized. As far as this class is accessed in test via HotUpdateUtil, we faced cases that user was not logged in. There is no method for login via HotUpdateUtil.
When the OpenShiftCliCommandExecutor is binded, it will need access to oc to provide execute and other methods so it should not be problem to log in right after init and then don't care about that later.

What issues does this PR fix or reference?

https://github.com/redhat-developer/che-functional-tests/issues/365

@riuvshin
Copy link
Contributor

Can one of the admins verify this patch?

2 similar comments
@riuvshin
Copy link
Contributor

Can one of the admins verify this patch?

@riuvshin
Copy link
Contributor

Can one of the admins verify this patch?

@benoitf benoitf added the status/code-review This issue has a pull request posted for it and is awaiting code review completion by the community. label Sep 26, 2018
@dmytro-ndp
Copy link
Contributor

Log into OpenShift is needed only for several tests of Eclipse Che, and OpenShiftCliCommandExecutor class doesn't need an access to oc just after it is bound. Even more - there are some commands which don't require being logged into OpenShift before execution, like oc version.

At the same time login operation is quite expensive because it requires downloading of OpenShift ClI client into the system, and we would avoid it if we run separate test which is not bound to OpenShift, like DialogAboutTest.

If this PR is aimed to get rid of calling OpenShiftCliCommandExecutor#login() method just before OpenShiftCliCommandExecutor#execute(), I would propose just to rewrite OpenShiftCliCommandExecutor#execute() method as follow:

...
  private boolean isLoggedIn;
  private ReentrantLock loginLock = new ReentrantLock();
...

  @Override
  public String execute(String command) throws IOException {
    return execute(command, true);
  }

  private String execute(String command, boolean needToLogin) throws IOException {
    if (!PATH_TO_OPENSHIFT_CLI.toFile().exists()) {
      downloadOpenShiftCli();
    }

    if (needToLogin && !isLoggedIn) {
      loginLock.lock();
      try {
        login();
        isLoggedIn = true;
      } catch (IOException e) {
        isLoggedIn = false;
        throw e;
      } finally {
        loginLock.unlock();
      }
    }

    String openShiftCliCommand = format("%s %s", PATH_TO_OPENSHIFT_CLI, command);

    return processAgent.process(openShiftCliCommand);
  }

  /** Logs into OpenShift as a regular user */
  public void login() throws IOException {
    String loginToOpenShiftCliCommand;
    if (openShiftToken != null) {
      loginToOpenShiftCliCommand =
          format(
              "login --server=%s --token=%s --insecure-skip-tls-verify",
              openShiftWebConsoleUrlProvider.get(), openShiftToken);
    } else {
      loginToOpenShiftCliCommand =
          format(
              "login --server=%s -u=%s -p=%s --insecure-skip-tls-verify",
              openShiftWebConsoleUrlProvider.get(),
              openShiftUsername != null ? openShiftUsername : DEFAULT_OPENSHIFT_USERNAME,
              openShiftPassword != null ? openShiftPassword : DEFAULT_OPENSHIFT_PASSWORD);
    }

    execute(loginToOpenShiftCliCommand, false);
  }

Don't also forget to remove calling of login() method from the tests so as it will become unnecessary.

@Katka92 Katka92 closed this Oct 1, 2018
@Katka92 Katka92 reopened this Oct 1, 2018
@Katka92
Copy link
Contributor Author

Katka92 commented Oct 1, 2018

Sorry I clicked wrong button by accident...

Signed-off-by: kkanova <kkanova@redhat.com>
@dmytro-ndp
Copy link
Contributor

dmytro-ndp commented Oct 1, 2018

Looks good as for me. Will execute the tests.

Copy link
Contributor

@dmytro-ndp dmytro-ndp left a comment

Choose a reason for hiding this comment

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

Local test execution against Eclipse Che Multiuser on OCP didn't show regression.

@dmytro-ndp dmytro-ndp merged commit 6049168 into eclipse-che:master Oct 2, 2018
nickboldt pushed a commit to nickboldt/che that referenced this pull request Oct 3, 2018
Signed-off-by: kkanova <kkanova@redhat.com>
@Katka92 Katka92 deleted the oc_login_after_init branch March 3, 2020 10:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status/code-review This issue has a pull request posted for it and is awaiting code review completion by the community.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants