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 3)

Signed-off-by: Fabio M. Di Nitto <fdinitto@redhat.com>
  • Loading branch information
fabbione committed Dec 18, 2018
1 parent c795578 commit c476707
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 160 deletions.
2 changes: 1 addition & 1 deletion libnozzle/libnozzle.c
Expand Up @@ -491,7 +491,7 @@ nozzle_t nozzle_open(char *devname, size_t devname_size, const char *updownpath)
return NULL;
}

int nozzle_close(nozzle_t nozzle, char **error_down, char **error_postdown)
int nozzle_close(nozzle_t nozzle)
{
int err = 0, savederrno = 0;
nozzle_t temp = lib_cfg.head;
Expand Down
13 changes: 1 addition & 12 deletions libnozzle/libnozzle.h
Expand Up @@ -59,23 +59,12 @@ nozzle_t nozzle_open(char *devname, size_t devname_size, const char *updownpath)
*
* nozzle - pointer to the nozzle struct to destroy
*
* error_down - pointers to string to record errors from executing down.d
* when configured. The string is malloc'ed, the caller needs to free those
* buffers.
*
* error_postdown - pointers to string to record errors from executing post-down.d
* when configured. The string is malloc'ed, the caller needs to free
* those buffers.
*
* @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_close(nozzle_t nozzle, char **error_down, char **error_postdown);
int nozzle_close(nozzle_t nozzle);


#define NOZZLE_PREUP 0
Expand Down
161 changes: 14 additions & 147 deletions libnozzle/tests/nozzle_test.c
Expand Up @@ -67,7 +67,6 @@ static int is_if_in_system(char *name)
static int test_iface(char *name, size_t size, const char *updownpath)
{
nozzle_t nozzle;
char *error_down = NULL, *error_postdown = NULL;

nozzle=nozzle_open(name, size, updownpath);
if (!nozzle) {
Expand All @@ -88,17 +87,7 @@ static int test_iface(char *name, size_t size, const char *updownpath)
printf("Found interface %s in nozzle db\n", name);
}

nozzle_close(nozzle, &error_down, &error_postdown);

if (error_down) {
printf("Error from error_down: %s\n", error_down);
free(error_down);
}

if (error_postdown) {
printf("Error from error_down: %s\n", error_postdown);
free(error_postdown);
}
nozzle_close(nozzle);

if (is_if_in_system(name) == 0)
printf("Successfully removed interface %s from the system\n", name);
Expand Down Expand Up @@ -200,7 +189,6 @@ static int check_knet_multi_eth(void)
int err=0;
nozzle_t nozzle1 = NULL;
nozzle_t nozzle2 = NULL;
char *error_down = NULL, *error_postdown = NULL;

printf("Testing multiple knet interface instances\n");

Expand Down Expand Up @@ -234,27 +222,11 @@ static int check_knet_multi_eth(void)
}

if (nozzle1) {
nozzle_close(nozzle1, &error_down, &error_postdown);
if (error_down) {
printf("Error from error_down: %s\n", error_down);
free(error_down);
}
if (error_postdown) {
printf("Error from error_down: %s\n", error_postdown);
free(error_postdown);
}
nozzle_close(nozzle1);
}

if (nozzle2) {
nozzle_close(nozzle2, &error_down, &error_postdown);
if (error_down) {
printf("Error from error_down: %s\n", error_down);
free(error_down);
}
if (error_postdown) {
printf("Error from error_down: %s\n", error_postdown);
free(error_postdown);
}
nozzle_close(nozzle2);
}

printf("Testing error conditions\n");
Expand Down Expand Up @@ -285,27 +257,11 @@ static int check_knet_multi_eth(void)

out_clean:
if (nozzle1) {
nozzle_close(nozzle1, &error_down, &error_postdown);
if (error_down) {
printf("Error from error_down: %s\n", error_down);
free(error_down);
}
if (error_postdown) {
printf("Error from error_down: %s\n", error_postdown);
free(error_postdown);
}
nozzle_close(nozzle1);
}

if (nozzle2) {
nozzle_close(nozzle2, &error_down, &error_postdown);
if (error_down) {
printf("Error from error_down: %s\n", error_down);
free(error_down);
}
if (error_postdown) {
printf("Error from error_down: %s\n", error_postdown);
free(error_postdown);
}
nozzle_close(nozzle2);
}

return err;
Expand All @@ -317,7 +273,6 @@ static int check_knet_mtu(void)
size_t size = IFNAMSIZ;
int err=0;
nozzle_t nozzle;
char *error_down = NULL, *error_postdown = NULL;
char *error_string = NULL;

int current_mtu = 0;
Expand Down Expand Up @@ -391,15 +346,7 @@ static int check_knet_mtu(void)

out_clean:
if (nozzle) {
nozzle_close(nozzle, &error_down, &error_postdown);
if (error_down) {
printf("Error from error_down: %s\n", error_down);
free(error_down);
}
if (error_postdown) {
printf("Error from error_down: %s\n", error_postdown);
free(error_postdown);
}
nozzle_close(nozzle);
}

return err;
Expand All @@ -413,7 +360,6 @@ static int check_knet_mtu_ipv6(void)
int err=0;
nozzle_t nozzle;
char *error_string = NULL;
char *error_down = NULL, *error_postdown = NULL;

printf("Testing get/set MTU with IPv6 address\n");

Expand Down Expand Up @@ -574,15 +520,7 @@ static int check_knet_mtu_ipv6(void)

out_clean:
if (nozzle) {
nozzle_close(nozzle, &error_down, &error_postdown);
if (error_down) {
printf("Error from error_down: %s\n", error_down);
free(error_down);
}
if (error_postdown) {
printf("Error from error_down: %s\n", error_postdown);
free(error_postdown);
}
nozzle_close(nozzle);
}

return err;
Expand All @@ -596,7 +534,6 @@ static int check_knet_mac(void)
nozzle_t nozzle;
char *current_mac = NULL, *temp_mac = NULL, *err_mac = NULL;
struct ether_addr *cur_mac, *tmp_mac;
char *error_down = NULL, *error_postdown = NULL;

printf("Testing get/set MAC\n");

Expand Down Expand Up @@ -691,15 +628,7 @@ static int check_knet_mac(void)
free(temp_mac);

if (nozzle) {
nozzle_close(nozzle, &error_down, &error_postdown);
if (error_down) {
printf("Error from error_down: %s\n", error_down);
free(error_down);
}
if (error_postdown) {
printf("Error from error_down: %s\n", error_postdown);
free(error_postdown);
}
nozzle_close(nozzle);
}

return err;
Expand Down Expand Up @@ -905,17 +834,7 @@ static int check_knet_up_down(void)
goto out_clean;
}

nozzle_close(nozzle, &error_down, &error_postdown);
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;
}
nozzle_close(nozzle);

printf("Testing interface pre-up/up/down/post-down (exec errors)\n");

Expand Down Expand Up @@ -972,17 +891,7 @@ static int check_knet_up_down(void)
error_down = NULL;
}

nozzle_close(nozzle, &error_down, &error_postdown);
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;
}
nozzle_close(nozzle);

printf("Testing interface pre-up/up/down/post-down\n");

Expand Down Expand Up @@ -1040,17 +949,7 @@ static int check_knet_up_down(void)
error_down = NULL;
}

nozzle_close(nozzle, &error_down, &error_postdown);
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;
}
nozzle_close(nozzle);

printf("Test ERROR conditions\n");

Expand Down Expand Up @@ -1088,17 +987,7 @@ static int check_knet_up_down(void)
}

out_clean:
nozzle_close(nozzle, &error_down, &error_postdown);
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;
}
nozzle_close(nozzle);

return err;
}
Expand All @@ -1110,7 +999,6 @@ static int check_knet_close_leak(void)
int err=0;
nozzle_t nozzle;
char *error_string = NULL;
char *error_down = NULL, *error_postdown = NULL;

printf("Testing close leak (needs valgrind)\n");

Expand Down Expand Up @@ -1151,17 +1039,7 @@ static int check_knet_close_leak(void)
}

out_clean:
nozzle_close(nozzle, &error_down, &error_postdown);
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;
}
nozzle_close(nozzle);

return err;
}
Expand All @@ -1176,7 +1054,6 @@ static int check_knet_set_del_ip(void)
char *ip_list = NULL;
int ip_list_entries = 0, i, offset = 0;
char *error_string = NULL;
char *error_down = NULL, *error_postdown = NULL;

printf("Testing interface add/remove ip\n");

Expand Down Expand Up @@ -1405,17 +1282,7 @@ static int check_knet_set_del_ip(void)
}

out_clean:
nozzle_close(nozzle, &error_down, &error_postdown);
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;
}
nozzle_close(nozzle);

return err;
}
Expand Down

0 comments on commit c476707

Please sign in to comment.