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

moduletest: add --config option #811

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 1 addition & 6 deletions .github/workflows/module-test-run.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,6 @@ jobs:
with:
name: ${{ inputs.target }}

- name: Create osconfig.json
run: |
sudo mkdir -p /etc/osconfig
sudo cp -r ./src/adapters/pnp/daemon/osconfig.json /etc/osconfig/osconfig.json

- name: Run moduletest
working-directory: ${{ steps.download.outputs.download-path }}/modules/test
run: |
Expand All @@ -56,7 +51,7 @@ jobs:

echo -n "testing $name ... "

if output=$(sudo ./moduletest $recipe --bin ../bin); then
if output=$(sudo ./moduletest $recipe --bin ../bin --config ../../src/adapters/pnp/daemon/osconfig.json ); then
Copy link
Contributor

Choose a reason for hiding this comment

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

../bin --config ../../src/adapters/pnp/daemon/osconfig.json

Why?

moduletest supports command line arguments, if invoked manually. We do not need more for now.

Can you please explain why do you believe this change is necessary and what needs is going to solve?

Thanks

echo passed
else
echo failed
Expand Down
21 changes: 18 additions & 3 deletions src/modules/test/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#include <math.h>

#define DEFAULT_BIN_PATH "/usr/lib/osconfig"
#define OSCONFIG_CONFIG_FILE "/etc/osconfig/osconfig.json"
#define DEFAULT_OSCONFIG_CONFIG_FILE "/etc/osconfig/osconfig.json"
Copy link
Contributor

Choose a reason for hiding this comment

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

Why changing this?


#define AZURE_OSCONFIG "Azure OSConfig"

Expand Down Expand Up @@ -92,6 +92,7 @@ typedef struct FAILURE
} FAILURE;

static bool g_verbose = false;
static const char* g_osconfig_config_file = DEFAULT_OSCONFIG_CONFIG_FILE;

void FreeStep(STEP* step)
{
Expand Down Expand Up @@ -739,9 +740,9 @@ int GetClientName(char** client)
JSON_Value* config = NULL;
JSON_Object* configObject = NULL;

if (NULL == (config = json_parse_file(OSCONFIG_CONFIG_FILE)))
if (NULL == (config = json_parse_file(g_osconfig_config_file)))
{
LOG_ERROR("Failed to parse %s\n", OSCONFIG_CONFIG_FILE);
LOG_ERROR("Failed to parse %s\n", g_osconfig_config_file);
status = EINVAL;
}
else if (NULL == (configObject = json_value_get_object(config)))
Expand Down Expand Up @@ -782,6 +783,7 @@ void Usage(const char* executable)
printf("\n");
printf("options:\n");
printf(" --bin <path> path to load modules from (default: %s)\n", DEFAULT_BIN_PATH);
printf(" --config <path> path of osconfig.json from (default: %s)\n", DEFAULT_OSCONFIG_CONFIG_FILE);
printf(" --verbose enable verbose logging\n");
printf(" --help display this help and exit\n");
}
Expand Down Expand Up @@ -838,6 +840,19 @@ int main(int argc, char const* argv[])
break;
}
}
else if (strcmp(argv[i], "--config") == 0)
{
if (i + 1 < argc)
{
g_osconfig_config_file = argv[++i];
}
else
{
printf("missing argument for --config\n");
result = EXIT_FAILURE;
break;
}
}
else if (strcmp(argv[i], "--verbose") == 0)
{
g_verbose = true;
Expand Down
Loading