Пример #1
0
/*!
 * Determine the containers config file, its configuration
 * and state.
 *
 * \param[out] config_file Dynamically-allocated path to containers
 * config file.
 * \param[out] config \ref cc_oci_config.
 * \param[out] state \ref oci_state.
 *
 * \note Used by the "stop" command.
 *
 * \return \c true on success, else \c false.
 */
gboolean
cc_oci_get_config_and_state (gchar **config_file,
		struct cc_oci_config *config,
		struct oci_state **state)
{
	if ((!config_file) || (!config) || (!state)) {
		return false;
	}

	if (! cc_oci_runtime_path_get (config)) {
			return false;
	}

	if (! cc_oci_state_file_get (config)) {
		return false;
	}

	*state = cc_oci_state_file_read (config->state.state_file_path);
	if (! (*state)) {
		g_critical("failed to read state file for container %s",
		           config->optarg_container_id);
		goto err;
	}

	/* Fill in further details to make the config valid */
	config->bundle_path = g_strdup ((*state)->bundle_path);
	config->state.workload_pid = (*state)->pid;
	config->state.status = (*state)->status;

	g_strlcpy (config->state.comms_path, (*state)->comms_path,
			sizeof (config->state.comms_path));

	g_strlcpy (config->state.procsock_path,
			(*state)->procsock_path,
			sizeof (config->state.procsock_path));

	*config_file = cc_oci_config_file_path ((*state)->bundle_path);
	if (! (*config_file)) {
		goto err;
	}

	return true;

err:
	cc_oci_state_free (*state);
	g_free_if_set (*config_file);
	return false;
}
Пример #2
0
} END_TEST


START_TEST(test_cc_oci_state_file_read) {
	struct oci_state *state = NULL;

	/* Needs:
	 *
	 * - ociVersion
	 * - id
	 * - pid
	 * - bundlePath
	 * - commsPath
	 * - processPath
	 * - status
	 */

	ck_assert(! cc_oci_state_file_read(NULL));

	ck_assert(! cc_oci_state_file_read("/abc/123/xyz"));

	ck_assert(! cc_oci_state_file_read(TEST_DATA_DIR
	                "/state-no-bundlePath.json"));

	ck_assert(! cc_oci_state_file_read(TEST_DATA_DIR
	                "/state-no-ociVersion.json"));

	ck_assert(! cc_oci_state_file_read(TEST_DATA_DIR
	                "/state-no-id.json"));

	ck_assert(! cc_oci_state_file_read(TEST_DATA_DIR
	                "/state-no-commsPath.json"));

	ck_assert(! cc_oci_state_file_read(TEST_DATA_DIR
	                "/state-no-processPath.json"));

	ck_assert(! cc_oci_state_file_read(TEST_DATA_DIR
	                "/state-no-console.json"));

	ck_assert(! cc_oci_state_file_read(TEST_DATA_DIR
	                "/state-no-console-path.json"));

	ck_assert(! cc_oci_state_file_read(TEST_DATA_DIR
	                "/state-no-console-socket.json"));

	ck_assert(! cc_oci_state_file_read(TEST_DATA_DIR
	                "/state-no-vm-object.json"));

	/* Annotations are optional*/
	state = cc_oci_state_file_read(TEST_DATA_DIR
	                "/state-no-annotations.json");
	ck_assert (state);
	cc_oci_state_free (state);

	/* Mounts are optional */
	state = cc_oci_state_file_read(TEST_DATA_DIR
	                "/state-no-mounts.json");
	ck_assert (state);
	cc_oci_state_free (state);

	state = cc_oci_state_file_read(TEST_DATA_DIR
	                "/state-mounts-no-mount-destination.json");
	ck_assert (state);
	cc_oci_state_free (state);

	state = cc_oci_state_file_read(TEST_DATA_DIR
	                "/state-mounts-no-mount-directory_created.json");
	ck_assert (state);
	cc_oci_state_free (state);

	state = cc_oci_state_file_read(TEST_DATA_DIR "/state.json");
	ck_assert(state);
	ck_assert(state->oci_version);
	ck_assert(state->id);
	ck_assert(state->pid);
	ck_assert(state->bundle_path);
	ck_assert(state->comms_path);
	ck_assert(state->procsock_path);
	ck_assert(state->status);
	ck_assert(state->annotations);
	cc_oci_state_free(state);

} END_TEST