Skip to content
This repository has been archived by the owner on May 21, 2024. It is now read-only.

aktualizr-lite: Fix logic for finding latest version #1247

Merged
merged 3 commits into from
Jul 8, 2019

Conversation

doanac
Copy link
Collaborator

@doanac doanac commented Jun 29, 2019

You can't assume the targets will be ordered latest->oldest. This
creates a version comparison helper that tries its best to compare
things.

Signed-off-by: Andy Doan andy@foundries.io

@doanac
Copy link
Collaborator Author

doanac commented Jun 30, 2019

Trying to find a nice way to not use sscanf. Its actually doing what we need and strtol is kind of a pain for this.

@lbonn
Copy link
Contributor

lbonn commented Jul 1, 2019

If we're confident it's fine, you can still add a lint exception, we already have some.
But in any way, the version class and its comparator are the type of thing that would benefit from unit tests.

@doanac
Copy link
Collaborator Author

doanac commented Jul 1, 2019

I think its fine, but I'd like to add a unit test to prove it. That should also help explain what this is capable of comparing.

@codecov-io
Copy link

codecov-io commented Jul 1, 2019

Codecov Report

Merging #1247 into master will decrease coverage by 0.07%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1247      +/-   ##
==========================================
- Coverage   79.49%   79.42%   -0.08%     
==========================================
  Files         168      169       +1     
  Lines       10144    10153       +9     
==========================================
  Hits         8064     8064              
- Misses       2080     2089       +9
Impacted Files Coverage Δ
src/aktualizr_lite/version.h 100% <100%> (ø)
src/aktualizr_lite/main.cc 70.55% <100%> (+1.76%) ⬆️
src/libaktualizr-posix/ipuptanesecondary.cc 82.66% <0%> (-4%) ⬇️
src/libaktualizr/uptane/directorrepository.cc 97.14% <0%> (-1.43%) ⬇️
src/libaktualizr/storage/sql_utils.h 83.09% <0%> (-1.41%) ⬇️
src/aktualizr_primary/secondary.cc 86.3% <0%> (-1.37%) ⬇️
src/libaktualizr/storage/sqlstorage.cc 76.06% <0%> (-0.91%) ⬇️
src/libaktualizr/primary/sotauptaneclient.cc 93.11% <0%> (+0.29%) ⬆️
src/libaktualizr/uptane/imagesrepository.cc 93.2% <0%> (+0.61%) ⬆️
... and 1 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 12f8558...fa61e11. Read the comment docs.

Copy link
Contributor

@zabbal zabbal left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would be nice to also test how it deals with "known bad" versions:
"1..2"
"1.-1.3"
"2.lol.6"
"7..#.%1"
"3.&2.7.0.7.8.9"
You get the point :)

@doanac
Copy link
Collaborator Author

doanac commented Jul 1, 2019

Found an even better more used way to do this. I still think the tests are handy so that we have some idea of the various permutations that can happen and what they product.

You can't assume the targets will be ordered latest->oldest. This
creates a version comparison helper that tries its best to compare
things based on the glibc function:

 http://man7.org/linux/man-pages/man3/strverscmp.3.html

Signed-off-by: Andy Doan <andy@foundries.io>
Copy link
Contributor

@lbonn lbonn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Apart from the two things that break CI, it looks good.

aktualizr_source_file_checks(main.cc)
add_aktualizr_test(NAME lite-version SOURCES version_test.cc)

aktualizr_source_file_checks(${SOURCES} version_test.cc)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

main.cc is missing here and it causes a configure error when BUILD_OSTREE is not defined


struct Version {
std::string raw_ver;
Version(const std::string& version) : raw_ver(std::move(version)) {}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

from clang-tidy:

aktualizr/src/aktualizr_lite/version.h:7:49: error: std::move of the const variable 'version' has no effect; remove std::move() or make the variable non-const [performance-move-const-arg,-warnings-as-errors]
  Version(const std::string& version) : raw_ver(std::move(version)) {}

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry about always getting clang-tidy stuff wrong. I can't seem to find a way to run clang-tidy that produces the same results as TravisCI. I've tried installing clang-6 into to docker container and I think I've also tried clang-7. From a "clean" code base both versions produces lots of warnings. I need to just sit down and figure out how I can get this to work in the standard docker container.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No worries, this version problem is indeed annoying. If you run it from Dockerfile.debian.testing, you should be quite close from what's going on on CI.

e.g: ./scripts/run_docker_test.sh docker/Dockerfile.debian.testing, then ninja clang-tidy from a CMake directory or directly ./scripts/test.sh with the flags used in the CI job.

Signed-off-by: Andy Doan <andy@foundries.io>
@lbonn
Copy link
Contributor

lbonn commented Jul 4, 2019

Sorry it still fails, our clang-tidy setup is sometimes picky.

The fix should be:

diff --git a/src/aktualizr_lite/version.h b/src/aktualizr_lite/version.h
index 15e84f8d..6c643e8a 100644
--- a/src/aktualizr_lite/version.h
+++ b/src/aktualizr_lite/version.h
@@ -4,7 +4,7 @@
 
 struct Version {
   std::string raw_ver;
-  Version(const std::string& version) : raw_ver(version) {}
+  Version(std::string version) : raw_ver(std::move(version)) {}
 
   bool operator<(const Version& other) { return strverscmp(raw_ver.c_str(), other.raw_ver.c_str()) < 0; }
 };

Signed-off-by: Andy Doan <andy@foundries.io>
Copy link
Contributor

@lbonn lbonn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@lbonn lbonn merged commit b8c7952 into advancedtelematic:master Jul 8, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants