Skip to content

Commit

Permalink
[nozzle] decouple running pre-up.d/up.d/down.d/post-down.d from inter…
Browse files Browse the repository at this point in the history
…face status (part 2)

Signed-off-by: Fabio M. Di Nitto <fdinitto@redhat.com>
  • Loading branch information
fabbione committed Mar 1, 2018
1 parent bc8d65b commit a9f17bd
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 58 deletions.
15 changes: 5 additions & 10 deletions libnozzle/libnozzle.c
Expand Up @@ -81,7 +81,7 @@ static void _close_cfg(void)
}
}

static int _set_down(nozzle_t nozzle, char **error_down, char **error_postdown)
static int _set_down(nozzle_t nozzle)
{
int err = 0, savederrno = 0;
struct ifreq ifr;
Expand Down Expand Up @@ -522,7 +522,7 @@ int nozzle_close(nozzle_t nozzle, char **error_down, char **error_postdown)
prev->next = nozzle->next;
}

_set_down(nozzle, error_down, error_postdown);
_set_down(nozzle);

ip = nozzle->ip;
while (ip) {
Expand Down Expand Up @@ -661,7 +661,7 @@ int nozzle_set_up(nozzle_t nozzle, char **error_preup, char **error_up)
return err;
}

int nozzle_set_down(nozzle_t nozzle, char **error_down, char **error_postdown)
int nozzle_set_down(nozzle_t nozzle)
{
int err = 0, savederrno = 0;

Expand All @@ -677,13 +677,7 @@ int nozzle_set_down(nozzle_t nozzle, char **error_down, char **error_postdown)
goto out_clean;
}

if ((nozzle->hasupdown) && ((!error_down) || (!error_postdown))) {
savederrno = EINVAL;
err = -1;
goto out_clean;
}

err = _set_down(nozzle, error_down, error_postdown);
err = _set_down(nozzle);
savederrno = errno;

out_clean:
Expand Down Expand Up @@ -947,6 +941,7 @@ int nozzle_run_updown(const nozzle_t nozzle, uint8_t action, char **exec_string)
}

err = execute_bin_sh_command(command, exec_string);
savederrno = errno;

out_clean:
pthread_mutex_unlock(&config_mutex);
Expand Down
15 changes: 2 additions & 13 deletions libnozzle/libnozzle.h
Expand Up @@ -128,27 +128,16 @@ int nozzle_set_up(nozzle_t nozzle, char **error_preup, char **error_up);

/**
* nozzle_set_down
* @brief equivalent of ifconfig down, executes down.d post-down.d
* @brief equivalent of ifconfig down
*
* nozzle - pointer to the nozzle struct
*
* error_down - pointer to a string pointer to record errors from executing down.d
* when configured. The string is malloc'ed, the caller needs to free that
* buffer.
*
* error_postdown - pointer to a string pointer to record errors from executing post-down.d
* when configured. The string is malloc'ed, the caller needs to free
* that buffer.
*
* @return
* 0 on success
* -1 on error and errno is set.
* error_down / error_postdown are set to NULL if execution of external scripts
* is sucessful
* error_down / error_postdown will contain strings recording the execution error.
*/

int nozzle_set_down(nozzle_t nozzle, char **error_down, char **error_postdown);
int nozzle_set_down(nozzle_t nozzle);

/**
* nozzle_add_ip
Expand Down
79 changes: 44 additions & 35 deletions libnozzle/tests/nozzle_test.c
Expand Up @@ -860,22 +860,30 @@ static int check_knet_up_down(void)

printf("Put the interface down\n");

err = nozzle_set_down(nozzle, &error_down, &error_postdown);
err = nozzle_run_updown(nozzle, NOZZLE_DOWN, &error_down);
if (err) {
printf("nozzle_run_updown NOZZLE_DOWN error: %s\n", strerror(errno));
}
if (error_down) {
printf("down output: %s\n", error_down);
free(error_down);
error_down = NULL;
}
if (error_postdown) {
printf("postdown output: %s\n", error_down);
free(error_down);
error_down = NULL;
}
err = nozzle_set_down(nozzle);
if (err < 0) {
printf("Unable to put the interface down\n");
err = -1;
goto out_clean;
}
err = nozzle_run_updown(nozzle, NOZZLE_POSTDOWN, &error_postdown);
if (err) {
printf("nozzle_run_updown NOZZLE_POSTDOWN error: %s\n", strerror(errno));
}
if (error_postdown) {
printf("postdown output: %s\n", error_down);
free(error_down);
error_down = NULL;
}

memset(verifycmd, 0, sizeof(verifycmd));
snprintf(verifycmd, sizeof(verifycmd)-1,
Expand Down Expand Up @@ -939,22 +947,30 @@ static int check_knet_up_down(void)

printf("Put the interface down\n");

err = nozzle_set_down(nozzle, &error_down, &error_postdown);
err = nozzle_run_updown(nozzle, NOZZLE_DOWN, &error_down);
if (err) {
printf("nozzle_run_updown NOZZLE_DOWN error: %s\n", strerror(errno));
}
if (error_down) {
printf("down output: %s\n", error_down);
free(error_down);
error_down = NULL;
}
if (error_postdown) {
printf("postdown output: %s\n", error_down);
free(error_down);
error_down = NULL;
}
err = nozzle_set_down(nozzle);
if (err < 0) {
printf("Unable to put the interface down\n");
err = -1;
goto out_clean;
}
err = nozzle_run_updown(nozzle, NOZZLE_POSTDOWN, &error_postdown);
if (err) {
printf("nozzle_run_updown NOZZLE_POSTDOWN error: %s\n", strerror(errno));
}
if (error_postdown) {
printf("postdown output: %s\n", error_down);
free(error_down);
error_down = NULL;
}

nozzle_close(nozzle, &error_down, &error_postdown);
if (error_down) {
Expand Down Expand Up @@ -999,22 +1015,30 @@ static int check_knet_up_down(void)

printf("Put the interface down\n");

err = nozzle_set_down(nozzle, &error_down, &error_postdown);
err = nozzle_run_updown(nozzle, NOZZLE_DOWN, &error_down);
if (err) {
printf("nozzle_run_updown NOZZLE_DOWN error: %s\n", strerror(errno));
}
if (error_down) {
printf("down output: %s\n", error_down);
free(error_down);
error_down = NULL;
}
if (error_postdown) {
printf("postdown output: %s\n", error_down);
free(error_down);
error_down = NULL;
}
err = nozzle_set_down(nozzle);
if (err < 0) {
printf("Unable to put the interface down\n");
err = -1;
goto out_clean;
}
err = nozzle_run_updown(nozzle, NOZZLE_POSTDOWN, &error_postdown);
if (err) {
printf("nozzle_run_updown NOZZLE_POSTDOWN error: %s\n", strerror(errno));
}
if (error_postdown) {
printf("postdown output: %s\n", error_down);
free(error_down);
error_down = NULL;
}

nozzle_close(nozzle, &error_down, &error_postdown);
if (error_down) {
Expand All @@ -1031,6 +1055,7 @@ static int check_knet_up_down(void)
printf("Test ERROR conditions\n");

printf("Pass NULL to nozzle set_up\n");
err = 0;
errno = 0;
if ((nozzle_set_up(NULL, &error_preup, &error_up) >= 0) || (errno != EINVAL)) {
printf("Something is wrong in nozzle_set_up sanity checks\n");
Expand All @@ -1056,23 +1081,7 @@ static int check_knet_up_down(void)

printf("Pass NULL to nozzle set_down\n");
errno = 0;
if ((nozzle_set_down(NULL, &error_down, &error_postdown) >= 0) || (errno != EINVAL)) {
printf("Something is wrong in nozzle_set_down sanity checks\n");
err = -1;
goto out_clean;
}

printf("Pass NULL to error_down set_down\n");
errno = 0;
if ((nozzle_set_down(nozzle, NULL, &error_postdown) >= 0) || (errno != EINVAL)) {
printf("Something is wrong in nozzle_set_down sanity checks\n");
err = -1;
goto out_clean;
}

printf("Pass NULL to error_postdown set_down\n");
errno = 0;
if ((nozzle_set_down(nozzle, &error_down, NULL) >= 0) || (errno != EINVAL)) {
if ((nozzle_set_down(NULL) >= 0) || (errno != EINVAL)) {
printf("Something is wrong in nozzle_set_down sanity checks\n");
err = -1;
goto out_clean;
Expand Down

0 comments on commit a9f17bd

Please sign in to comment.