Skip to content

Commit

Permalink
fix: Fix npm command for windows. #2075
Browse files Browse the repository at this point in the history
Also added `run_local_command` to `utils.py`.
  • Loading branch information
Luis Gonzalez committed Oct 25, 2021
1 parent 6baee2b commit dd3bfae
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 4 deletions.
26 changes: 26 additions & 0 deletions deps/wazuh_testing/wazuh_testing/qa_docs/lib/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
# Created by Wazuh, Inc. <[email protected]>.
# This program is free software; you can redistribute it and/or modify it under the terms of GPLv2

import subprocess
import os
import sys
import shutil

from wazuh_testing.qa_docs import QADOCS_LOGGER
Expand Down Expand Up @@ -212,3 +214,27 @@ def clean_folder(folder):
shutil.rmtree(file_path)
except Exception as e:
utils_logger.error(f"Failed to delete {file_path}. Reason: {e}")

def run_local_command(command):
"""Run local commands without getting the output, but validating the result code.
Args:
command (string): Command to run.
Raises:
QAValueError: If the run command has failed (rc != 0).
"""
if sys.platform == 'win32':
run = subprocess.Popen(command, shell=True)
else:
run = subprocess.Popen(['/bin/bash', '-c', command])

# Wait for the process to finish
run.communicate()

result_code = run.returncode

if result_code != 0:
print("error")
# raise QAValueError(f"The command {command} returned {result_code} as result code.", utils_logger.LOGGER.error,
# QADOCS_LOGGER)
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@ const httpsAgent = new https.Agent({
const httpAgent = new http.Agent();

exports.handler = function(event, context, callback) {
const host = process.env.ELASTICSEARCH_HOST;
// npm config var cannot have '_' within its name
const host = process.env.npm_config_elastichost;
const agent = host.startsWith("http:") ? httpAgent : httpsAgent;
const index = process.env.INDEX;
const index = process.env.npm_config_index;

fetch(`${host}/${index}/_search`, {
method: "POST",
Expand Down
6 changes: 4 additions & 2 deletions deps/wazuh_testing/wazuh_testing/scripts/qa_docs.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from wazuh_testing.qa_docs.lib.config import Config
from wazuh_testing.qa_docs.lib.index_data import IndexData
from wazuh_testing.qa_docs.lib.sanity import Sanity
from wazuh_testing.qa_docs.lib.utils import run_local_command
from wazuh_testing.qa_docs.doc_generator import DocGenerator
from wazuh_testing.qa_docs import QADOCS_LOGGER
from wazuh_testing.tools.logging import Logging
Expand Down Expand Up @@ -194,14 +195,15 @@ def install_searchui_deps():
os.chdir(SEARCH_UI_PATH)
if not os.path.exists(os.path.join(SEARCH_UI_PATH, 'node_modules')):
qadocs_logger.info('Installing SearchUI dependencies')
os.system("npm install")
run_local_command("npm install")


def run_searchui(index):
"""Run SearchUI installing its dependencies if necessary"""
install_searchui_deps()
qadocs_logger.debug('Running SearchUI')
os.system(f"ELASTICSEARCH_HOST=http://localhost:9200 INDEX={index} npm start")

run_local_command(f"npm --ELASTICHOST=http://localhost:9200 --INDEX={index} start")


def parse_data(args):
Expand Down

0 comments on commit dd3bfae

Please sign in to comment.