diff --git a/cmd/upgrade.go b/cmd/upgrade.go index 32ff924c..fd139f27 100644 --- a/cmd/upgrade.go +++ b/cmd/upgrade.go @@ -43,6 +43,8 @@ var upgradeCmd = &cobra.Command{ universe, _ := cmd.Flags().GetBool("universe") clean, _ := cmd.Flags().GetBool("clean") sync, _ := cmd.Flags().GetBool("sync") + osCheck, _ := cmd.Flags().GetBool("oscheck") + yes := viper.GetBool("yes") downloadOnly, _ := cmd.Flags().GetBool("download-only") @@ -67,6 +69,7 @@ var upgradeCmd = &cobra.Command{ UpgradeNewRevisions: sync, PreserveSystemEssentialData: true, Ask: !yes, + AutoOSCheck: osCheck, DownloadOnly: downloadOnly, PackageRepositories: util.DefaultContext.Config.SystemRepositories, Context: util.DefaultContext, @@ -97,6 +100,7 @@ func init() { upgradeCmd.Flags().Bool("solver-concurrent", false, "Use concurrent solver (experimental)") upgradeCmd.Flags().BoolP("yes", "y", false, "Don't ask questions") upgradeCmd.Flags().Bool("download-only", false, "Download only") + upgradeCmd.Flags().Bool("oscheck", false, "Perform automatically oschecks after upgrades") RootCmd.AddCommand(upgradeCmd) } diff --git a/pkg/installer/installer.go b/pkg/installer/installer.go index ff9a8af8..5b8afc40 100644 --- a/pkg/installer/installer.go +++ b/pkg/installer/installer.go @@ -53,6 +53,7 @@ type LuetInstallerOptions struct { DownloadOnly bool Relaxed bool PackageRepositories types.LuetRepositories + AutoOSCheck bool Context *types.Context } @@ -494,6 +495,17 @@ func (l *LuetInstaller) checkAndUpgrade(r Repositories, s *System) error { Uninstall, Install pkg.Packages }{Uninstall: uninstall, Install: toInstall, Error: err}) + if err != nil { + return err + } + + if l.Options.AutoOSCheck { + packs := s.OSCheck() + if len(packs) > 0 { + return l.swap(o, r, packs, packs, s) + } + } + return err } diff --git a/tests/fixtures/upgrade_integration_oscheck/c/build.yaml b/tests/fixtures/upgrade_integration_oscheck/c/build.yaml new file mode 100644 index 00000000..dc3fba0a --- /dev/null +++ b/tests/fixtures/upgrade_integration_oscheck/c/build.yaml @@ -0,0 +1,10 @@ +prelude: + - echo foo > /test + - echo bar > /test2 +steps: + - echo c > /c + - echo c > /cd +requires: +- category: "test" + name: "a" + version: ">=1.0" diff --git a/tests/fixtures/upgrade_integration_oscheck/c/definition.yaml b/tests/fixtures/upgrade_integration_oscheck/c/definition.yaml new file mode 100644 index 00000000..e63d83a3 --- /dev/null +++ b/tests/fixtures/upgrade_integration_oscheck/c/definition.yaml @@ -0,0 +1,9 @@ +category: "test" +name: "c" +version: "1.0" +# Boom? + +requires: +- category: "test" + name: "a" + version: ">=0.1" \ No newline at end of file diff --git a/tests/fixtures/upgrade_integration_oscheck/cat/a/a/build.yaml b/tests/fixtures/upgrade_integration_oscheck/cat/a/a/build.yaml new file mode 100644 index 00000000..b9fe4c1d --- /dev/null +++ b/tests/fixtures/upgrade_integration_oscheck/cat/a/a/build.yaml @@ -0,0 +1,11 @@ +image: "alpine" +prelude: + - echo foo > /test + - echo bar > /test2 +steps: + - echo artifact3 > /test3 + - echo artifact4 > /test4 +requires: +- category: "test" + name: "b" + version: "1.0" diff --git a/tests/fixtures/upgrade_integration_oscheck/cat/a/a/definition.yaml b/tests/fixtures/upgrade_integration_oscheck/cat/a/a/definition.yaml new file mode 100644 index 00000000..8636f875 --- /dev/null +++ b/tests/fixtures/upgrade_integration_oscheck/cat/a/a/definition.yaml @@ -0,0 +1,8 @@ +category: "test" +name: "a" +version: "1.1" +requires: +- category: "test" + name: "b" + version: ">=0.1" + diff --git a/tests/fixtures/upgrade_integration_oscheck/cat/a/a1.0/build.yaml b/tests/fixtures/upgrade_integration_oscheck/cat/a/a1.0/build.yaml new file mode 100644 index 00000000..d62078ca --- /dev/null +++ b/tests/fixtures/upgrade_integration_oscheck/cat/a/a1.0/build.yaml @@ -0,0 +1,11 @@ +image: "alpine" +prelude: + - echo foo > /test + - echo bar > /test2 +steps: + - echo artifact3 > /testaa + - echo artifact4 > /testaa2 +requires: +- category: "test" + name: "b" + version: "1.0" diff --git a/tests/fixtures/upgrade_integration_oscheck/cat/a/a1.0/definition.yaml b/tests/fixtures/upgrade_integration_oscheck/cat/a/a1.0/definition.yaml new file mode 100644 index 00000000..6180c317 --- /dev/null +++ b/tests/fixtures/upgrade_integration_oscheck/cat/a/a1.0/definition.yaml @@ -0,0 +1,3 @@ +category: "test" +name: "a" +version: "1.0" diff --git a/tests/fixtures/upgrade_integration_oscheck/cat/a/alatest/build.yaml b/tests/fixtures/upgrade_integration_oscheck/cat/a/alatest/build.yaml new file mode 100644 index 00000000..496c04ca --- /dev/null +++ b/tests/fixtures/upgrade_integration_oscheck/cat/a/alatest/build.yaml @@ -0,0 +1,11 @@ +image: "alpine" +prelude: + - echo foo > /test + - echo bar > /test2 +steps: + - echo artifact3 > /testlatest + - echo artifact4 > /testlatest2 +requires: +- category: "test" + name: "b" + version: "1.0" diff --git a/tests/fixtures/upgrade_integration_oscheck/cat/a/alatest/definition.yaml b/tests/fixtures/upgrade_integration_oscheck/cat/a/alatest/definition.yaml new file mode 100644 index 00000000..006dd943 --- /dev/null +++ b/tests/fixtures/upgrade_integration_oscheck/cat/a/alatest/definition.yaml @@ -0,0 +1,3 @@ +category: "test" +name: "a" +version: "1.2" diff --git a/tests/fixtures/upgrade_integration_oscheck/cat/b-1.1/build.yaml b/tests/fixtures/upgrade_integration_oscheck/cat/b-1.1/build.yaml new file mode 100644 index 00000000..d906104d --- /dev/null +++ b/tests/fixtures/upgrade_integration_oscheck/cat/b-1.1/build.yaml @@ -0,0 +1,9 @@ +image: "alpine" +prelude: + - echo foo > /test + - echo bar > /test2 +steps: + - echo artifact5 > /newc + - echo artifact6 > /newnewc + - chmod +x generate.sh + - ./generate.sh diff --git a/tests/fixtures/upgrade_integration_oscheck/cat/b-1.1/definition.yaml b/tests/fixtures/upgrade_integration_oscheck/cat/b-1.1/definition.yaml new file mode 100644 index 00000000..e695c6c9 --- /dev/null +++ b/tests/fixtures/upgrade_integration_oscheck/cat/b-1.1/definition.yaml @@ -0,0 +1,3 @@ +category: "test" +name: "b" +version: "1.1" diff --git a/tests/fixtures/upgrade_integration_oscheck/cat/b-1.1/generate.sh b/tests/fixtures/upgrade_integration_oscheck/cat/b-1.1/generate.sh new file mode 100644 index 00000000..3b2dc1b2 --- /dev/null +++ b/tests/fixtures/upgrade_integration_oscheck/cat/b-1.1/generate.sh @@ -0,0 +1 @@ +echo generated > /sonewc diff --git a/tests/fixtures/upgrade_integration_oscheck/cat/b/build.yaml b/tests/fixtures/upgrade_integration_oscheck/cat/b/build.yaml new file mode 100644 index 00000000..7edb9842 --- /dev/null +++ b/tests/fixtures/upgrade_integration_oscheck/cat/b/build.yaml @@ -0,0 +1,9 @@ +image: "alpine" +prelude: + - echo foo > /test + - echo bar > /test2 +steps: + - echo artifact5 > /test5 + - echo artifact6 > /test6 + - chmod +x generate.sh + - ./generate.sh \ No newline at end of file diff --git a/tests/fixtures/upgrade_integration_oscheck/cat/b/definition.yaml b/tests/fixtures/upgrade_integration_oscheck/cat/b/definition.yaml new file mode 100644 index 00000000..b02a44e8 --- /dev/null +++ b/tests/fixtures/upgrade_integration_oscheck/cat/b/definition.yaml @@ -0,0 +1,3 @@ +category: "test" +name: "b" +version: "1.0" diff --git a/tests/fixtures/upgrade_integration_oscheck/cat/b/generate.sh b/tests/fixtures/upgrade_integration_oscheck/cat/b/generate.sh new file mode 100644 index 00000000..b67417f6 --- /dev/null +++ b/tests/fixtures/upgrade_integration_oscheck/cat/b/generate.sh @@ -0,0 +1 @@ +echo generated > /artifact42 diff --git a/tests/fixtures/upgrade_integration_oscheck/z/build.yaml b/tests/fixtures/upgrade_integration_oscheck/z/build.yaml new file mode 100644 index 00000000..d4ef5dba --- /dev/null +++ b/tests/fixtures/upgrade_integration_oscheck/z/build.yaml @@ -0,0 +1,9 @@ +prelude: + - echo foo > /test + - echo bar > /test2 +steps: + - echo z > /z +requires: +- category: "test" + name: "a" + version: ">=1.0" diff --git a/tests/fixtures/upgrade_integration_oscheck/z/definition.yaml b/tests/fixtures/upgrade_integration_oscheck/z/definition.yaml new file mode 100644 index 00000000..efa1d012 --- /dev/null +++ b/tests/fixtures/upgrade_integration_oscheck/z/definition.yaml @@ -0,0 +1,3 @@ +category: "test" +name: "z" +version: "1.0" diff --git a/tests/integration/05_upgrade_oscheck.sh b/tests/integration/05_upgrade_oscheck.sh new file mode 100755 index 00000000..3d31af6b --- /dev/null +++ b/tests/integration/05_upgrade_oscheck.sh @@ -0,0 +1,131 @@ +#!/bin/bash + +export LUET_NOLOCK=true + +oneTimeSetUp() { +export tmpdir="$(mktemp -d)" +} + +oneTimeTearDown() { + rm -rf "$tmpdir" +} + +testBuild() { + mkdir $tmpdir/testbuild + luet build --tree "$ROOT_DIR/tests/fixtures/upgrade_integration_oscheck" --destination $tmpdir/testbuild --compression gzip test/b@1.0 + buildst=$? + assertTrue 'create package B 1.0' "[ -e '$tmpdir/testbuild/b-test-1.0.package.tar.gz' ]" + assertEquals 'builds successfully' "$buildst" "0" + + luet build --tree "$ROOT_DIR/tests/fixtures/upgrade_integration_oscheck" --destination $tmpdir/testbuild --compression gzip test/b@1.1 + buildst=$? + assertEquals 'builds successfully' "$buildst" "0" + assertTrue 'create package B 1.1' "[ -e '$tmpdir/testbuild/b-test-1.1.package.tar.gz' ]" + + luet build --tree "$ROOT_DIR/tests/fixtures/upgrade_integration_oscheck" --destination $tmpdir/testbuild --compression gzip test/a@1.0 + buildst=$? + assertEquals 'builds successfully' "$buildst" "0" + assertTrue 'create package A 1.0' "[ -e '$tmpdir/testbuild/a-test-1.0.package.tar.gz' ]" + + luet build --tree "$ROOT_DIR/tests/fixtures/upgrade_integration_oscheck" --destination $tmpdir/testbuild --compression gzip test/a@1.1 + buildst=$? + assertEquals 'builds successfully' "$buildst" "0" + + assertTrue 'create package A 1.1' "[ -e '$tmpdir/testbuild/a-test-1.1.package.tar.gz' ]" + + luet build --tree "$ROOT_DIR/tests/fixtures/upgrade_integration_oscheck" --destination $tmpdir/testbuild --compression gzip test/a@1.2 + buildst=$? + assertEquals 'builds successfully' "$buildst" "0" + assertTrue 'create package A 1.2' "[ -e '$tmpdir/testbuild/a-test-1.2.package.tar.gz' ]" + + luet build --tree "$ROOT_DIR/tests/fixtures/upgrade_integration_oscheck" --destination $tmpdir/testbuild --compression gzip test/z@1.0 + buildst=$? + assertEquals 'builds successfully' "$buildst" "0" + assertTrue 'create package Z 1.0' "[ -e '$tmpdir/testbuild/z-test-1.0.package.tar.gz' ]" + + luet build --tree "$ROOT_DIR/tests/fixtures/upgrade_integration_oscheck" --destination $tmpdir/testbuild --compression gzip test/c@1.0 + buildst=$? + assertEquals 'builds successfully' "$buildst" "0" + assertTrue 'create package C 1.0' "[ -e '$tmpdir/testbuild/c-test-1.0.package.tar.gz' ]" + +} + +testRepo() { + assertTrue 'no repository' "[ ! -e '$tmpdir/testbuild/repository.yaml' ]" + luet create-repo --tree "$ROOT_DIR/tests/fixtures/upgrade_integration_oscheck" \ + --output $tmpdir/testbuild \ + --packages $tmpdir/testbuild \ + --name "test" \ + --descr "Test Repo" \ + --urls $tmpdir/testrootfs \ + --type http + + createst=$? + assertEquals 'create repo successfully' "$createst" "0" + assertTrue 'create repository' "[ -e '$tmpdir/testbuild/repository.yaml' ]" +} + +testConfig() { + mkdir $tmpdir/testrootfs + cat < $tmpdir/luet.yaml +general: + debug: true +system: + rootfs: $tmpdir/testrootfs + database_path: "/" + database_engine: "boltdb" +config_from_host: true +repositories: + - name: "main" + type: "disk" + enable: true + urls: + - "$tmpdir/testbuild" +EOF + luet config --config $tmpdir/luet.yaml + res=$? + assertEquals 'config test successfully' "$res" "0" +} + +testInstall() { + luet install -y --relax --config $tmpdir/luet.yaml test/b@1.0 + installst=$? + assertEquals 'install test successfully' "$installst" "0" + assertTrue 'package installed B' "[ -e '$tmpdir/testrootfs/test5' ]" + + luet install -y --relax --config $tmpdir/luet.yaml test/z@1.0 + installst=$? + assertEquals 'install test successfully' "$installst" "0" + assertTrue 'package installed Z' "[ -e '$tmpdir/testrootfs/z' ]" + + luet install -y --relax --config $tmpdir/luet.yaml test/a@1.0 + assertTrue 'package installed A' "[ -e '$tmpdir/testrootfs/testaa' ]" + installst=$? + assertEquals 'install test successfully' "$installst" "0" + + luet install -y --relax --config $tmpdir/luet.yaml test/c@1.0 + installst=$? + assertEquals 'install test successfully' "$installst" "0" + assertTrue 'package installed C' "[ -e '$tmpdir/testrootfs/c' ]" +} + +testUpgrade() { + rm -rf $tmpdir/testrootfs/z + assertTrue 'package Z corrupted' "[ ! -e '$tmpdir/testrootfs/z' ]" + + upgrade=$(luet --config $tmpdir/luet.yaml upgrade --oscheck -y) + installst=$? + echo "$upgrade" + assertEquals 'install test successfully' "$installst" "0" + assertTrue 'package uninstalled B' "[ ! -e '$tmpdir/testrootfs/test5' ]" + assertTrue 'package installed B' "[ -e '$tmpdir/testrootfs/newc' ]" + assertTrue 'package uninstalled A' "[ ! -e '$tmpdir/testrootfs/testaa' ]" + assertTrue 'package Z restored' "[ -e '$tmpdir/testrootfs/z' ]" + assertTrue 'package installed new A' "[ -e '$tmpdir/testrootfs/testlatest' ]" + assertNotContains 'does not contain test/c@1.0' "$upgrade" 'test/c-1.0' + assertNotContains 'does not attempt to download test/c@1.0' "$upgrade" 'test/c-1.0 downloaded' +} + +# Load shUnit2. +. "$ROOT_DIR/tests/integration/shunit2"/shunit2 +