Пример #1
0
void test_spec_handler(struct spec_handler* handler, struct spec_handler_test* tests) {
	GNode* node;
	GNode* handler_node;
	GNode test_node;
	struct cc_oci_config config;
	struct spec_handler_test* test;
	int fd;

	ck_assert(! handler->handle_section(NULL, NULL));
	ck_assert(! handler->handle_section(&test_node, NULL));
	ck_assert(! handler->handle_section(NULL, &config));

	/**
	 * Create fake files for Kernel and image so
	 * path validation won't fail
	 */

	fd = g_creat("CONTAINER-KERNEL",0755);
	if (fd < 0) {
		g_critical ("failed to create file CONTAINER-KERNEL");
	} else {
		close(fd);
	}

	fd = g_creat("CLEAR-CONTAINERS.img",0755);
	if (fd < 0) {
		g_critical ("failed to create file CLEAR-CONTAINERS.img");
	} else {
		close(fd);
	}
	fd = g_creat("QEMU-LITE",0755);
	if (fd < 0) {
		g_critical ("failed to create file QEMU-LITE");
	} else {
		close(fd);
	}

	for (test=tests; test->file; test++) {
		memset(&config, 0, sizeof(config));
		cc_oci_json_parse(&node, test->file);
		handler_node = node_find_child(node, handler->name);
		ck_assert_msg(handler->handle_section(
		    handler_node, &config) == test->test_result,
		    test->file);
		cc_oci_config_free(&config);
		g_free_node(node);
	}

	if (g_remove("CONTAINER-KERNEL") < 0) {
		g_critical ("failed to remove file CONTAINER-KERNEL");
	}

	if (g_remove ("CLEAR-CONTAINERS.img") < 0) {
		g_critical ("failed to remove file CLEAR-CONTAINERS.img");
	}

	if (g_remove ("QEMU-LITE") < 0) {
		g_critical ("failed to remove file QEMU-LITE");
	}
}
Пример #2
0
} END_TEST

START_TEST(test_cc_oci_node_dump) {
	GNode* node;
	cc_oci_node_dump(NULL);
	cc_oci_json_parse(&node, TEST_DATA_DIR "/node.json");
	ck_assert(node);
	cc_oci_node_dump(node);
	g_free_node(node);
} END_TEST
Пример #3
0
/*!
 * Handle commands to stop the Hypervisor cleanly.
 *
 * \param sub \ref subcommand.
 * \param config \ref cc_oci_config.
 * \param argc Argument count.
 * \param argv Argument vector.
 *
 * \return \c true on success, else \c false.
 */
gboolean
handle_command_stop (const struct subcommand *sub,
		struct cc_oci_config *config,
		int argc, char *argv[])
{
	struct oci_state  *state = NULL;
	gchar             *config_file = NULL;
	gboolean           ret;
	GNode*             root = NULL;

	g_assert (sub);
	g_assert (config);

	if (handle_default_usage (argc, argv, sub->name,
				&ret, 1, NULL)) {
		return ret;
	}

	/* Used to allow us to find the state file */
	config->optarg_container_id = argv[0];

	/* FIXME: deal with containerd calling "delete" twice */
	if (! cc_oci_state_file_exists (config)) {
		g_warning ("state file does not exist for container %s",
				config->optarg_container_id);

		/* don't make this fatal to keep containerd happy */
		ret = true;
		goto out;
	}

	ret = cc_oci_get_config_and_state (&config_file, config, &state);
	if (! ret) {
		goto out;
	}

	/* convert json file to GNode */
	if (! cc_oci_json_parse(&root, config_file)) {
		goto out;
	}

#ifdef DEBUG
	/* show json file converted to GNode */
	cc_oci_node_dump(root);
#endif /*DEBUG*/

	if (! cc_oci_process_config(root, config, stop_spec_handlers)) {
		g_critical ("failed to process config");
		goto out;
	}

	g_free_node(root);

	ret = cc_oci_stop (config, state);
	if (! ret) {
		goto out;
	}

	ret = true;

	g_print ("stopped container %s\n", config->optarg_container_id);

out:
	g_free_if_set (config_file);
	cc_oci_state_free (state);

	if (! ret) {
		g_critical ("failed to stop container %s\n",
				config->optarg_container_id);
	}

	return ret;
}