Skip to content

Commit

Permalink
Merge pull request #1327 from zowe/next-background-daemon-enable
Browse files Browse the repository at this point in the history
Next background daemon enable
  • Loading branch information
gejohnston authored Mar 4, 2022
2 parents a1b3bc4 + 6a267ae commit 30b03ba
Show file tree
Hide file tree
Showing 8 changed files with 566 additions and 146 deletions.
3 changes: 3 additions & 0 deletions packages/cli/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

All notable changes to the Zowe CLI package will be documented in this file.

## Recent Changes
- Enhancement: the `zowe daemon enable` and `zowe daemon disable` commands run a process in the backgound so that they no longer require a user to copy and paste another command to successfully perform the operation.

## `7.0.0-next.202202241854`

- **LTS Breaking**: Added `stdin` property to `IHandlerParameters` which defaults to `process.stdin` and is overridden with another readable stream in daemon mode.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
/*
* This program and the accompanying materials are made available under the terms of the
* Eclipse Public License v2.0 which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-v20.html
*
* SPDX-License-Identifier: EPL-2.0
*
* Copyright Contributors to the Zowe Project.
*
*/

/* Our daemon-related tests create a TGZ for our EXE, which should be removed
* after testing. These tests also create and remove an EXE file in our bin
* directory. The file creations and deletions create problems when the tests
* are run in parallel. By placing the daemon tests within this top-level
* describe (thus contining the tests in a single file) the tests are serialized.
*/

import * as nodeJsPath from "path";
import * as tar from "tar";
import { IO, ProcessUtils, ISystemInfo } from "@zowe/imperative";

describe("Zowe daemon suite", () => {
const rimrafSync = require("rimraf").sync;

let prebuildsDir: string;

// establish path names and record whether we are running our EXE or node.js script
beforeAll(async () => {
let zoweExeTgzPath: string;
let zoweExeFileNm: string;

// determine executable file name and TGZ path for our current OS
const zoweRootDir: string = nodeJsPath.normalize(__dirname + "/../../../../..");
prebuildsDir = nodeJsPath.normalize(zoweRootDir + "/packages/cli/prebuilds");
const sysInfo: ISystemInfo = ProcessUtils.getBasicSystemInfo();
switch (sysInfo.platform) {
case "darwin": {
zoweExeFileNm = "zowe";
zoweExeTgzPath = nodeJsPath.resolve(prebuildsDir, "zowe-macos.tgz");
break;
}
case "linux": {
zoweExeFileNm = "zowe";
zoweExeTgzPath = nodeJsPath.resolve(prebuildsDir, "zowe-linux.tgz");
break;
}
case "win32": {
zoweExeFileNm = "zowe.exe";
zoweExeTgzPath = nodeJsPath.resolve(prebuildsDir, "zowe-windows.tgz");
break;
}
default: {
zoweExeFileNm = "exeForUnknownOs";
zoweExeTgzPath += "unknownOs.tgz";
throw "cli.zowe.daemon.integration.suite.test.ts: beforeAll: " +
sysInfo.platform + " is not a known OS.";
}
}

// Form the path name to our executable.
let zoweExeDirPath = nodeJsPath.normalize(zoweRootDir + "/zowex/target/release");
let zoweExePath = nodeJsPath.resolve(zoweExeDirPath, zoweExeFileNm);
if (!IO.existsSync(zoweExePath)) {
zoweExeDirPath = nodeJsPath.normalize(zoweRootDir + "/zowex/target/debug");
zoweExePath = nodeJsPath.resolve(zoweExeDirPath, zoweExeFileNm);
if (!IO.existsSync(zoweExePath)) {
zoweExeDirPath = "./NoZoweExeExists";
}
}

// Remove any existing prebuilds directory
rimrafSync(prebuildsDir);

// create our prebuilds directory
IO.createDirSync(prebuildsDir);

// tar our EXE into a TGZ for this platform, so that we can extract it in tests
tar.create({
sync: true,
gzip: true,
cwd: zoweExeDirPath,
file: zoweExeTgzPath
}, [zoweExeFileNm]);
});

afterAll(async () => {
// Remove any existing prebuilds directory
rimrafSync(prebuildsDir);
});

// run all of our daemon-related tests
require("./cli.zowe.exe.integration");
require("./enable/cli.daemon.enable.integration");
require("./disable/cli.daemon.disable.integration");
});
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,14 @@ import { ITestEnvironment, runCliScript } from "@zowe/cli-test-utils";
import { ITestPropertiesSchema } from "../../../../../__tests__/__src__/properties/ITestPropertiesSchema";
import { TestEnvironment } from "../../../../../__tests__/__src__/environment/TestEnvironment";

let testEnvironment: ITestEnvironment<ITestPropertiesSchema>;

describe("Zowe native executable", () => {
const exeCantRunDaemonMsg1: string = "You cannot run this 'daemon' command while using the Zowe CLI native executable.";
const exeCantRunDaemonMsg2: string = "Copy and paste the following command instead:";
const EXIT_CODE_CANT_RUN_DAEMON_CMD: number = 108;
const RUN_IN_BACKGROUND_MSG: string = "command will run in the background ...";
const WAIT_TO_SEE_RESULTS_MSG: string = "Wait to see the results below ...";
const NOW_PRESS_ENTER_MSG: string = "Now press ENTER to see your command prompt.";

let testEnvironment: ITestEnvironment<ITestPropertiesSchema>;
let zoweExeFileNm: string;
let zoweExeDirPath: string;
let zoweExePath: string;
let willRunZoweExe: boolean = true;

Expand All @@ -34,27 +35,33 @@ describe("Zowe native executable", () => {
skipProperties: true
});

// determine executable file extension for our current OS
let exeExt: string;
// determine executable file name for our current OS
const zoweRootDir: string = nodeJsPath.normalize(__dirname + "/../../../../..");
const sysInfo: ISystemInfo = ProcessUtils.getBasicSystemInfo();
if (sysInfo.platform == "win32") {
exeExt = ".exe";
zoweExeFileNm = "zowe.exe";
} else {
exeExt = "";
zoweExeFileNm = "zowe";
}

// Form the path name to our executable.
const zoweExeGrandParentDir: string = nodeJsPath.normalize(__dirname + "/../../../../../zowex/target");
zoweExePath = nodeJsPath.normalize(zoweExeGrandParentDir + "/release/zowe" + exeExt);
zoweExeDirPath = nodeJsPath.normalize(zoweRootDir + "/zowex/target/release");
zoweExePath = nodeJsPath.resolve(zoweExeDirPath, zoweExeFileNm);
if (!IO.existsSync(zoweExePath)) {
zoweExePath = nodeJsPath.normalize(zoweExeGrandParentDir + "/debug/zowe" + exeExt);
zoweExeDirPath = nodeJsPath.normalize(zoweRootDir + "/zowex/target/debug");
zoweExePath = nodeJsPath.resolve(zoweExeDirPath, zoweExeFileNm);
if (!IO.existsSync(zoweExePath)) {
willRunZoweExe = false;
zoweExePath = "./NoZoweExeExists";
}
}
});

afterAll(async () => {
// Remove any existing prebuilds directory
await TestEnvironment.cleanUp(testEnvironment);
});

it("should display its version number", async () => {
if (willRunZoweExe) {
const response = runCliScript(
Expand All @@ -67,29 +74,34 @@ describe("Zowe native executable", () => {
}
});

it("should refuse to run the enable command", async () => {
it("should run the enable command in the background", async () => {
if (willRunZoweExe) {
const response = runCliScript(
__dirname + "/__scripts__/run_zowe_exe.sh", testEnvironment,
[zoweExePath, "daemon", "enable"]
);
const stdoutStr = response.stdout.toString();
expect(stdoutStr).toContain(exeCantRunDaemonMsg1);
expect(stdoutStr).toContain(exeCantRunDaemonMsg2);
expect(response.status).toBe(EXIT_CODE_CANT_RUN_DAEMON_CMD);
expect(stdoutStr).toContain(RUN_IN_BACKGROUND_MSG);
expect(stdoutStr).toContain(WAIT_TO_SEE_RESULTS_MSG);
expect(stdoutStr).toContain("Zowe CLI daemon mode is enabled");
expect(stdoutStr).toContain("Zowe CLI native executable version =");
expect(stdoutStr).toContain(NOW_PRESS_ENTER_MSG);
expect(response.status).toBe(0);
}
});

it("should refuse to run the disable command", async () => {
it("should run the disable command in the background", async () => {
if (willRunZoweExe) {
const response = runCliScript(
__dirname + "/__scripts__/run_zowe_exe.sh", testEnvironment,
[zoweExePath, "daemon", "disable"]
);
const stdoutStr = response.stdout.toString();
expect(stdoutStr).toContain(exeCantRunDaemonMsg1);
expect(stdoutStr).toContain(exeCantRunDaemonMsg2);
expect(response.status).toBe(EXIT_CODE_CANT_RUN_DAEMON_CMD);
expect(stdoutStr).toContain(RUN_IN_BACKGROUND_MSG);
expect(stdoutStr).toContain(WAIT_TO_SEE_RESULTS_MSG);
expect(stdoutStr).toContain("Zowe CLI daemon mode is disabled");
expect(stdoutStr).toContain(NOW_PRESS_ENTER_MSG);
expect(response.status).toBe(0);
}
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ let testEnvironment: ITestEnvironment<ITestPropertiesSchema>;

describe("daemon disable", () => {
const rimrafSync = require("rimraf").sync;
const fakeExeContent = "This is not a real executable";
const zoweCmdRegEx = "zowe.*[/|\\\\]cli[/|\\\\]lib[/|\\\\]main.js.* --daemon" + "|" +
"[/|\\\\]bin[/|\\\\]zowe.* --daemon";

Expand All @@ -44,32 +43,23 @@ describe("daemon disable", () => {
const sysInfo: ISystemInfo = ProcessUtils.getBasicSystemInfo();

// form our tgz file name
let tgzFileName = "zowe-";
switch (sysInfo.platform) {
case "darwin": {
tgzFileName += "macos.tgz";
exePath = "zowe";
break;
}
case "darwin":
case "linux": {
tgzFileName += "linux.tgz";
exePath = "zowe";
break;
}
case "win32": {
tgzFileName += "windows.tgz";
exePath = "zowe.exe";
break;
}
default: {
tgzFileName += "unknownOs.tgz";
exePath = "exeForUnknownOs";
throw "cli.daemon.disable.integration.test.ts: beforeAll: " + sysInfo.platform + " is not a known OS.";
throw __filename + ": beforeAll: " + sysInfo.platform + " is not a known OS.";
}
}

// form the path to our bin directory, executable, and prebuilds tgz file
const tgzResourcePath = nodeJsPath.resolve(__dirname, "../../__resources__", tgzFileName);
pathToBin = nodeJsPath.resolve(testEnvironment.workingDir, "bin");
exePath = nodeJsPath.resolve(pathToBin, exePath);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,14 @@ import { ITestEnvironment, runCliScript } from "@zowe/cli-test-utils";
import { TestEnvironment } from "../../../../../../__tests__/__src__/environment/TestEnvironment";
import { ITestPropertiesSchema } from "../../../../../../__tests__/__src__/properties/ITestPropertiesSchema";

let testEnvironment: ITestEnvironment<ITestPropertiesSchema>;

describe("daemon enable", () => {
const rimrafSync = require("rimraf").sync;
const fakeExeContent = "This is not a real executable";
const EXIT_CODE_CANT_RUN_DAEMON_CMD: number = 107;

let testEnvironment: ITestEnvironment<ITestPropertiesSchema>;
let exePath: string;
let pathToBin: string;
let preBldDir: string;
let preBldTgzPath: string;

// is the zowe command that we will run our Node.js script?
Expand All @@ -45,7 +43,6 @@ describe("daemon enable", () => {
return true;
};


beforeAll(async () => {
// Create the unique test environment
testEnvironment = await TestEnvironment.setUp({
Expand Down Expand Up @@ -77,24 +74,15 @@ describe("daemon enable", () => {
default: {
tgzFileName += "unknownOs.tgz";
exePath = "exeForUnknownOs";
throw "cli.daemon.enable.integration.test.ts: beforeAll: " + sysInfo.platform + " is not a known OS.";
throw __filename + ": beforeAll: " + sysInfo.platform + " is not a known OS.";
}
}

// form the path to our bin directory, executable, and prebuilds tgz file
const tgzResourcePath = nodeJsPath.resolve(__dirname, "../../__resources__", tgzFileName);
preBldDir = nodeJsPath.resolve(__dirname, "../../../../prebuilds");
const preBldDir = nodeJsPath.resolve(__dirname, "../../../../prebuilds");
preBldTgzPath = nodeJsPath.resolve(preBldDir, tgzFileName);
pathToBin = nodeJsPath.resolve(testEnvironment.workingDir, "bin");
exePath = nodeJsPath.resolve(pathToBin, exePath);

// copy a fake tgz file from resources to our prebuilds directory for testing
if (!IO.existsSync(preBldDir)) {
IO.createDirSync(preBldDir);
}
if (!IO.existsSync(preBldTgzPath)) {
fs.copyFileSync(tgzResourcePath, preBldTgzPath);
}
});

beforeEach(async () => {
Expand All @@ -104,7 +92,6 @@ describe("daemon enable", () => {

afterAll(async () => {
rimrafSync(pathToBin);
rimrafSync(preBldDir);
await TestEnvironment.cleanUp(testEnvironment);
});

Expand Down
9 changes: 8 additions & 1 deletion zowex/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion zowex/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "zowe"
version = "0.7.2"
version = "0.8.0"
authors = ["Zowe Project"]
edition = "2018"
license = "EPL-2.0"
Expand All @@ -16,6 +16,7 @@ pathsearch = "0.2.0"
rpassword = "5.0.1"
serde = { version = "1.0.136", features = ["derive"]}
serde_json = "1.0.79"
simple-error = "0.2.3"
sysinfo = "0.23.5"
whoami = "1.2.1"

Expand Down
Loading

0 comments on commit 30b03ba

Please sign in to comment.