function_type->instance = (manager_network_function_instance_t *)realloc(function_type->instance, sizeof(manager_network_function_instance_t) * function_type->started_instances);
if(function_type->instance == 0) {
log_error("realloc failed");
+ function_type->started_instances--;
return NTS_ERR_FAILED;
}
asprintf(&instance->name, "%s-%d", function_type->docker_instance_name, function_type->started_instances - 1);
instance->mount_point_addressing_method = strdup(function_type->mount_point_addressing_method);
-
instance->docker_port = STANDARD_NETCONF_PORT;
instance->host_ip = strdup(framework_environment.host_ip);
instance->host_port = 0;
if(instance->host_port == 0) {
log_error("no ports available for operation");
+ free(instance->name);
+ free(instance->mount_point_addressing_method);
+ free(instance->host_ip);
+ function_type->started_instances--;
return NTS_ERR_FAILED;
}
int rc = docker_device_start(function_type, instance);
if(rc != NTS_ERR_OK) {
log_error("docker_device_start failed");
+ free(instance->name);
+ free(instance->mount_point_addressing_method);
+ free(instance->host_ip);
+ manager_port[instance->host_port] = 0;
+ function_type->started_instances--;
return NTS_ERR_FAILED;
}
rc = lyd_utils_dup(session_running, "/nts-manager:simulation/ves-endpoint", "/nts-network-function:simulation/ves-endpoint", &local_tree);
if(rc != NTS_ERR_OK) {
log_error("lyd_utils_dup failed");
+ lyd_free_withsiblings(local_tree);
return NTS_ERR_FAILED;
}
char *xpath_s = 0;
asprintf(&xpath_s, "/nts-manager:simulation/network-functions/network-function[function-type='%s']", function_type->function_type_string);
rc = lyd_utils_dup(session_running, xpath_s, "/nts-network-function:simulation/network-function", &local_tree);
+ free(xpath_s);
if(rc != NTS_ERR_OK) {
log_error("lyd_utils_dup failed");
+ lyd_free_withsiblings(local_tree);
return NTS_ERR_FAILED;
- }
- free(xpath_s);
+ }
nc_client_t *nc_client = nc_client_ssh_connect(instance->docker_ip, instance->docker_port, "netconf", "netconf");
if(nc_client == 0) {
log_error("nc_client_ssh_connect");
+ lyd_free_withsiblings(local_tree);
return NTS_ERR_FAILED;
}
rc += nc_client_edit_batch(nc_client, local_tree, 1000);
+ lyd_free_withsiblings(local_tree);
if(rc != NTS_ERR_OK) {
log_error("nc_client_edit_batch failed %d\n", rc);
+ nc_client_disconnect(nc_client);
return NTS_ERR_FAILED;
}
- lyd_free_withsiblings(local_tree);
-
if(instance->is_configured == false) {
//run datastore-random-populate rpc
rpc_node = lyd_new_path(0, session_context, "/nts-network-function:datastore-random-populate", 0, 0, 0);
if(rpc_node == 0) {
log_error("failed to create rpc node");
+ nc_client_disconnect(nc_client);
return NTS_ERR_FAILED;
}
rpcout = nc_client_send_rpc(nc_client, rpc_node, 5000);
if(rpcout == 0) {
log_error("datastore-random-populate rpc failed");
+ nc_client_disconnect(nc_client);
+ lyd_free_withsiblings(rpc_node);
return NTS_ERR_FAILED;
}
else {
lyd_free_withsiblings(rpc_node);
//run feature-control rpc
- rpc_node = lyd_new_path(0, session_context, "/nts-network-function:feature-control/features", "ves-file-ready ves-heartbeat ves-pnf-registration manual-notification-generation netconf-call-home", 0, 0);
+ rpc_node = lyd_new_path(0, session_context, "/nts-network-function:feature-control/features", "ves-file-ready ves-heartbeat ves-pnf-registration manual-notification-generation netconf-call-home web-cut-through", 0, 0);
if(rpc_node == 0) {
log_error("failed to create rpc node");
+ nc_client_disconnect(nc_client);
return NTS_ERR_FAILED;
}
rpcout = nc_client_send_rpc(nc_client, rpc_node, 1000);
if(rpcout == 0) {
log_error("feature-control rpc failed");
+ nc_client_disconnect(nc_client);
+ lyd_free_withsiblings(rpc_node);
return NTS_ERR_FAILED;
}
else {
if(instance->is_mounted) {
if(manager_unmount_instance(function_type) != NTS_ERR_OK) {
- return NTS_ERR_FAILED;
+ log_error("failed to unmount instance");
}
}
int rc = http_request(url, controller->username, controller->password, "PUT", json, 0, 0);
if(rc != NTS_ERR_OK) {
log_error("http_request failed");
+ free(url);
+ free(node_id);
+ free(json);
+ controller_details_free(controller);
return NTS_ERR_FAILED;
}
int manager_unmount_instance(manager_network_function_type *function_type) {
assert(function_type);
+ int ret = NTS_ERR_OK;
manager_network_function_instance_t *instance = &function_type->instance[function_type->mounted_instances - 1];
int rc = http_request(url, controller->username, controller->password, "DELETE", "", 0, 0);
if(rc != NTS_ERR_OK) {
log_error("http_request failed");
- return NTS_ERR_FAILED;
+ ret = NTS_ERR_FAILED;
}
free(url);
function_type->mounted_instances--;
function_type->instance[function_type->mounted_instances].is_mounted = false;
- return NTS_ERR_OK;
+ return ret;
}