提交 0d31bb4b 编写于 作者: W wujing 提交者: lifeng68

image health check config unit test

Signed-off-by: Nwujing <wujing50@huawei.com>
上级 28ad73d6
......@@ -1455,10 +1455,12 @@ static int append_big_data_name(storage_image *image, const char *name)
static int update_image_with_big_data(image_t *image, const char *key, const char *data, bool *should_save)
{
int ret = 0;
bool size_found = false;
int64_t old_size;
const char *old_digest = NULL;
char *new_digest = NULL;
char *full_digest = NULL;
bool add_name = true;
size_t i;
digest_image_t *digest_filter_images = NULL;
......@@ -1489,10 +1491,11 @@ static int update_image_with_big_data(image_t *image, const char *key, const cha
old_digest = get_value_from_json_map_string_string(im->big_data_digests, key);
new_digest = sha256_digest_str(data);
full_digest = util_full_digest(new_digest);
if (old_digest != NULL) {
update_json_map_string_string(im->big_data_digests, key, new_digest);
update_json_map_string_string(im->big_data_digests, key, full_digest);
} else {
append_json_map_string_string(im->big_data_digests, key, new_digest);
append_json_map_string_string(im->big_data_digests, key, full_digest);
}
if (!size_found || old_size != (int64_t)strlen(data) || old_digest == NULL || strcmp(old_digest, new_digest) != 0) {
......@@ -1509,7 +1512,8 @@ static int update_image_with_big_data(image_t *image, const char *key, const cha
if (add_name) {
if (append_big_data_name(im, key) != 0) {
ERROR("Failed to append big data name");
return -1;
ret = -1;
goto out;
}
*should_save = true;
}
......@@ -1519,7 +1523,8 @@ static int update_image_with_big_data(image_t *image, const char *key, const cha
if (remove_image_from_digest_index(g_image_store, image, old_digest) != 0) {
ERROR("Failed to remove the image from the list of images in the digest-based "
"index which corresponds to the old digest for this item, unless it's also the hard-coded digest");
return -1;
ret = -1;
goto out;
}
}
......@@ -1530,12 +1535,16 @@ static int update_image_with_big_data(image_t *image, const char *key, const cha
digest_image_slice_without_value(digest_filter_images, image);
if (append_image_to_digest_images(digest_filter_images, image) != 0) {
ERROR("Failed to append image to digest images");
return -1;
ret = -1;
goto out;
}
}
}
return 0;
out:
free(new_digest);
free(full_digest);
return ret;
}
int image_store_set_big_data(const char *id, const char *key, const char *data)
......@@ -2072,33 +2081,6 @@ out:
return ret;
}
/*typedef struct {
char *id;
char **repo_tags;
size_t repo_tags_len;
char **repo_digests;
size_t repo_digests_len;
uint64_t size;
char *created;
char *loaded;
imagetool_image_uid *uid;
char *username;
oci_image_spec *spec;
defs_health_check *healthcheck;
}
imagetool_image;*/
static int resort_image_names(const char **names, size_t names_len, char **first_name, char ***image_tags,
char ***image_digests)
{
......@@ -2402,7 +2384,6 @@ static imagetool_image *get_image_info(const image_t *image)
}
nret = asprintf(&sha256_key, "sha256:%s", img->id);
// if (nret < 0 || (size_t)nret > strlen("sha256:") + strlen(img->id) + 1) {
if (nret < 0) {
ERROR("Failed to get sha256 key");
ret = -1;
......@@ -2430,7 +2411,7 @@ static imagetool_image *get_image_info(const image_t *image)
}
if (pack_image_summary_item(config_file, info) != 0) {
ERROR("Failed to pack health check config from image config");
ERROR("Failed to pack image summary item from image config");
ret = -1;
goto out;
}
......@@ -2446,8 +2427,6 @@ static imagetool_image *get_image_info(const image_t *image)
goto out;
}
// info->size = img->names_len;
out:
if (ret != 0) {
free_imagetool_image(info);
......
{"architecture":"amd64","config":{"Hostname":"","Domainname":"","User":"","AttachStdin":false,"AttachStdout":false,"AttachStderr":false,"Tty":false,"OpenStdin":false,"StdinOnce":false,"Env":["PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"],"Cmd":["sh"],"Healthcheck":{"Test":["CMD-SHELL","date \u003e\u003e /tmp/health_check || exit 1"],"Interval":3000000000,"Timeout":3000000000,"StartPeriod":1000000000,"Retries":3,"ExitOnUnhealthy":true},"ArgsEscaped":true,"Image":"sha256:e4db68de4ff27c2adfea0c54bbb73a61a42f5b667c326de4d7d5b19ab71c6a3b","Volumes":null,"WorkingDir":"","Entrypoint":null,"OnBuild":null,"Labels":null,"Annotations":null},"container":"ed0b5c882c5b98b9f67a6dff3be078658d45d49540c8d8778b878d68a75bd8b7","container_config":{"Hostname":"ed0b5c882c5b","Domainname":"","User":"","AttachStdin":false,"AttachStdout":false,"AttachStderr":false,"Tty":false,"OpenStdin":false,"StdinOnce":false,"Env":["PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"],"Cmd":["/bin/sh","-c","#(nop) ","HEALTHCHECK \u0026{[\"CMD-SHELL\" \"date \u003e\u003e /tmp/health_check || exit 1\"] \"3s\" \"3s\" \"1s\" '\\x03' %!q(bool=true)}"],"Healthcheck":{"Test":["CMD-SHELL","date \u003e\u003e /tmp/health_check || exit 1"],"Interval":3000000000,"Timeout":3000000000,"StartPeriod":1000000000,"Retries":3,"ExitOnUnhealthy":true},"ArgsEscaped":true,"Image":"sha256:e4db68de4ff27c2adfea0c54bbb73a61a42f5b667c326de4d7d5b19ab71c6a3b","Volumes":null,"WorkingDir":"","Entrypoint":null,"OnBuild":null,"Labels":{},"Annotations":{"native.umask":"secure"}},"created":"2020-03-30T08:02:50.586247435Z","docker_version":"dev","history":[{"created":"2019-06-15T00:19:54.271494486Z","created_by":"/bin/sh -c #(nop) ADD file:b265aa0ea2ef7ff1f4a3e087217e75aca2c90f5c345406299664cc7969b2b28e in / "},{"created":"2019-06-15T00:19:54.402459069Z","created_by":"/bin/sh -c #(nop) CMD [\"sh\"]","empty_layer":true},{"created":"2020-03-30T08:02:50.586247435Z","created_by":"/bin/sh -c #(nop) HEALTHCHECK \u0026{[\"CMD-SHELL\" \"date \u003e\u003e /tmp/health_check || exit 1\"] \"3s\" \"3s\" \"1s\" '\\x03' %!q(bool=true)}","empty_layer":true}],"os":"linux","rootfs":{"type":"layers","diff_ids":["sha256:6194458b07fcf01f1483d96cd6c34302ffff7f382bb151a6d023c4e80ba3050a"]}}
\ No newline at end of file
{"architecture":"amd64","config":{"Hostname":"","Domainname":"","User":"","AttachStdin":false,"AttachStdout":false,"AttachStderr":false,"Tty":false,"OpenStdin":false,"StdinOnce":false,"Env":["PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"],"Cmd":["sh"],"HealthCheck":{"Test":["CMD-SHELL","date \u003e\u003e /tmp/health_check || exit 1"],"Interval":3000000000,"Timeout":3000000000,"StartPeriod":1000000000,"Retries":3,"ExitOnUnhealthy":true},"ArgsEscaped":true,"Image":"sha256:e4db68de4ff27c2adfea0c54bbb73a61a42f5b667c326de4d7d5b19ab71c6a3b","Volumes":null,"WorkingDir":"","Entrypoint":null,"OnBuild":null,"Labels":null,"Annotations":null},"container":"ed0b5c882c5b98b9f67a6dff3be078658d45d49540c8d8778b878d68a75bd8b7","container_config":{"Hostname":"ed0b5c882c5b","Domainname":"","User":"","AttachStdin":false,"AttachStdout":false,"AttachStderr":false,"Tty":false,"OpenStdin":false,"StdinOnce":false,"Env":["PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"],"Cmd":["/bin/sh","-c","#(nop) ","HEALTHCHECK \u0026{[\"CMD-SHELL\" \"date \u003e\u003e /tmp/health_check || exit 1\"] \"3s\" \"3s\" \"1s\" '\\x03' %!q(bool=true)}"],"HealthCheck":{"Test":["CMD-SHELL","date \u003e\u003e /tmp/health_check || exit 1"],"Interval":3000000000,"Timeout":3000000000,"StartPeriod":1000000000,"Retries":3,"ExitOnUnhealthy":true},"ArgsEscaped":true,"Image":"sha256:e4db68de4ff27c2adfea0c54bbb73a61a42f5b667c326de4d7d5b19ab71c6a3b","Volumes":null,"WorkingDir":"","Entrypoint":null,"OnBuild":null,"Labels":{},"Annotations":{"native.umask":"secure"}},"created":"2020-03-30T08:02:50.586247435Z","docker_version":"dev","history":[{"created":"2019-06-15T00:19:54.271494486Z","created_by":"/bin/sh -c #(nop) ADD file:b265aa0ea2ef7ff1f4a3e087217e75aca2c90f5c345406299664cc7969b2b28e in / "},{"created":"2019-06-15T00:19:54.402459069Z","created_by":"/bin/sh -c #(nop) CMD [\"sh\"]","empty_layer":true},{"created":"2020-03-30T08:02:50.586247435Z","created_by":"/bin/sh -c #(nop) HEALTHCHECK \u0026{[\"CMD-SHELL\" \"date \u003e\u003e /tmp/health_check || exit 1\"] \"3s\" \"3s\" \"1s\" '\\x03' %!q(bool=true)}","empty_layer":true}],"os":"linux","rootfs":{"type":"layers","diff_ids":["sha256:6194458b07fcf01f1483d96cd6c34302ffff7f382bb151a6d023c4e80ba3050a"]}}
......@@ -248,7 +248,7 @@ TEST_F(StorageImagesUnitTest, test_image_store_create)
GetDirectory() +
"/data/resources/ffc8ef7968a2acb7545006bed022001addaa262c0f760883146c4a4fae54e689/"
"=c2hhMjU2OmZmYzhlZjc5NjhhMmFjYjc1NDUwMDZiZWQwMjIwMDFhZGRhYTI2MmMwZjc2MDg4MzE0NmM0YTRmYWU1NGU2ODk=";
ASSERT_STRNE(cleanpath(config_file.c_str(), real_path, sizeof(real_path)), nullptr);
ASSERT_STRNE(cleanpath(config_file.c_str(), real_path, sizeof(real_path)), "manifest");
std::ifstream t(real_path);
std::string buffer((std::istreambuf_iterator<char>(t)),
......@@ -277,21 +277,27 @@ TEST_F(StorageImagesUnitTest, test_image_store_create)
auto image = image_store_get_image(id.c_str());
ASSERT_NE(image, nullptr);
// ASSERT_STREQ(image->created, "2020-03-30T08:02:50.586247435Z");
// ASSERT_STREQ(image->loaded, "2020-04-29T09:06:29.385966253Z");
ASSERT_NE(image->created, nullptr);
ASSERT_NE(image->loaded, nullptr);
ASSERT_NE(image->repo_tags, nullptr);
ASSERT_EQ(image->repo_tags_len, 1);
ASSERT_STREQ(image->repo_tags[0], "docker.io/library/health_check:latest");
ASSERT_EQ(image->healthcheck, nullptr);
ASSERT_EQ(image->username, nullptr);
ASSERT_EQ(image->size, 0);
ASSERT_EQ(image->spec->config->env_len, 1);
ASSERT_STREQ(image->spec->config->env[0],
"PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin");
ASSERT_EQ(image->spec->config->cmd_len, 4);
ASSERT_STREQ(image->spec->config->cmd[0], "/bin/bash");
ASSERT_EQ(image->spec->config->cmd_len, 1);
ASSERT_STREQ(image->spec->config->cmd[0], "sh");
ASSERT_NE(image->healthcheck, nullptr);
ASSERT_EQ(image->healthcheck->test_len, 2);
ASSERT_STREQ(image->healthcheck->test[0], "CMD-SHELL");
ASSERT_STREQ(image->healthcheck->test[1], "date >> /tmp/health_check || exit 1");
ASSERT_EQ(image->healthcheck->interval, 3000000000);
ASSERT_EQ(image->healthcheck->retries, 3);
ASSERT_EQ(image->healthcheck->start_period, 1000000000);
ASSERT_EQ(image->healthcheck->timeout, 3000000000);
ASSERT_TRUE(image->healthcheck->exit_on_unhealthy);
ASSERT_EQ(image_store_delete(id.c_str()), 0);
ASSERT_EQ(image_store_get_image(id.c_str()), nullptr);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册